]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use builder API for struct equal function
authorJürg Billeter <j@bitron.ch>
Sun, 10 Oct 2010 09:45:17 +0000 (11:45 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 10 Oct 2010 09:45:17 +0000 (11:45 +0200)
codegen/valaccodebasemodule.vala

index e8d676411ed2a97259ce535b785fda6c12824ef3..e028a4e8db41b2693ce2eb5f2192f7d2a1c16e5b 100644 (file)
@@ -2332,7 +2332,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                        // wrapper already defined
                        return equal_func;
                }
-               // declaration
 
                var function = new CCodeFunction (equal_func, "gboolean");
                function.modifiers = CCodeModifiers.STATIC;
@@ -2340,30 +2339,26 @@ 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 ();
                }
 
                foreach (Field f in st.get_fields ()) {
@@ -2394,29 +2389,26 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                                cexp = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, s1, s2);
                        }
 
-                       var block = new CCodeBlock ();
-                       block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
-                       var cif = new CCodeIfStatement (cexp, block);
-                       cblock.add_statement (cif);
+                       ccode.open_if (cexp);
+                       ccode.add_return (new CCodeConstant ("FALSE"));
+                       ccode.close ();
                }
 
                if (st.get_fields().size == 0) {
                        // either opaque structure or simple type
                        if (st.is_simple_type ()) {
                                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);
                        } else {
-                               cblock.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
+                               ccode.add_return (new CCodeConstant ("FALSE"));
                        }
                } else {
-                       cblock.add_statement (new CCodeReturnStatement (new CCodeConstant ("TRUE")));
+                       ccode.add_return (new CCodeConstant ("TRUE"));
                }
 
-               // append to file
+               pop_function ();
 
                cfile.add_function_declaration (function);
-
-               function.block = cblock;
                cfile.add_function (function);
 
                return equal_func;