[vala] codegen: Use builder API for numeric equal function



commit 58998a9d4d45b04507abf58c51c9928196173402
Author: Jürg Billeter <j bitron ch>
Date:   Sun Oct 10 11:48:29 2010 +0200

    codegen: Use builder API for numeric equal function

 codegen/valaccodebasemodule.vala |   31 ++++++++++++-------------------
 1 files changed, 12 insertions(+), 19 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e028a4e..13202e8 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2421,7 +2421,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			// wrapper already defined
 			return equal_func;
 		}
-		// declaration
 
 		var function = new CCodeFunction (equal_func, "gboolean");
 		function.modifiers = CCodeModifiers.STATIC;
@@ -2429,42 +2428,36 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		function.add_parameter (new CCodeFormalParameter ("s1", "const " + st.get_cname () + "*"));
 		function.add_parameter (new CCodeFormalParameter ("s2", "const " + st.get_cname () + "*"));
 
-		// definition
-		var cblock = new CCodeBlock ();
+		push_function (function);
 
 		// if (s1 == s2) return TRUE;
 		{
-			var block = new CCodeBlock ();
-			block.add_statement (new CCodeReturnStatement (new CCodeConstant ("TRUE")));
-
 			var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeIdentifier ("s2"));
-			var cif = new CCodeIfStatement (cexp, block);
-			cblock.add_statement (cif);
+			ccode.open_if (cexp);
+			ccode.add_return (new CCodeConstant ("TRUE"));
+			ccode.close ();
 		}
 		// if (s1 == NULL || s2 == NULL) return FALSE;
 		{
-			var block = new CCodeBlock ();
-			block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
-
 			var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeConstant ("NULL"));
-			var cif = new CCodeIfStatement (cexp, block);
-			cblock.add_statement (cif);
+			ccode.open_if (cexp);
+			ccode.add_return (new CCodeConstant ("FALSE"));
+			ccode.close ();
 
 			cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s2"), new CCodeConstant ("NULL"));
-			cif = new CCodeIfStatement (cexp, block);
-			cblock.add_statement (cif);
+			ccode.open_if (cexp);
+			ccode.add_return (new CCodeConstant ("FALSE"));
+			ccode.close ();
 		}
 		// return (*s1 == *s2);
 		{
 			var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s1")), new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s2")));
-			cblock.add_statement (new CCodeReturnStatement (cexp));
+			ccode.add_return (cexp);
 		}
 
-		// append to file
+		pop_function ();
 
 		cfile.add_function_declaration (function);
-
-		function.block = cblock;
 		cfile.add_function (function);
 
 		return equal_func;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]