]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
ccodegen: Port the remaining code to use the ccode builder
authorLuca Bruno <lucabru@src.gnome.org>
Thu, 5 May 2011 12:27:49 +0000 (14:27 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Thu, 5 May 2011 13:57:50 +0000 (15:57 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodedelegatemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
codegen/valagasyncmodule.vala
codegen/valagdbusclientmodule.vala
codegen/valagdbusmodule.vala
codegen/valagdbusservermodule.vala
codegen/valagerrormodule.vala
codegen/valagobjectmodule.vala

index e248a58e5c8917a079d4b2f9e588043465bc38b5..afa97fecc76d858856ec68462096c239e68ead48 100644 (file)
@@ -1824,19 +1824,22 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        var ref_fun = new CCodeFunction ("block%d_data_ref".printf (block_id), struct_name + "*");
                        ref_fun.add_parameter (new CCodeParameter ("_data%d_".printf (block_id), struct_name + "*"));
                        ref_fun.modifiers = CCodeModifiers.STATIC;
-                       cfile.add_function_declaration (ref_fun);
-                       ref_fun.block = new CCodeBlock ();
+
+                       push_function (ref_fun);
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_inc"));
                        ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
-                       ref_fun.block.add_statement (new CCodeExpressionStatement (ccall));
-                       ref_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_data%d_".printf (block_id))));
+                       ccode.add_expression (ccall);
+                       ccode.add_return (new CCodeIdentifier ("_data%d_".printf (block_id)));
+
+                       pop_function ();
+
+                       cfile.add_function_declaration (ref_fun);
                        cfile.add_function (ref_fun);
 
                        var unref_fun = new CCodeFunction ("block%d_data_unref".printf (block_id), "void");
                        unref_fun.add_parameter (new CCodeParameter ("_data%d_".printf (block_id), struct_name + "*"));
                        unref_fun.modifiers = CCodeModifiers.STATIC;
-                       cfile.add_function_declaration (unref_fun);
                        
                        push_function (unref_fun);
 
@@ -1929,6 +1932,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        pop_function ();
 
+                       cfile.add_function_declaration (unref_fun);
                        cfile.add_function (unref_fun);
                }
 
@@ -2748,13 +2752,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        wrapper.modifiers = CCodeModifiers.STATIC;
                        wrapper.add_parameter (new CCodeParameter ("node", collection_type.get_cname ()));
                        wrapper.add_parameter (new CCodeParameter ("unused", "gpointer"));
-                       var wrapper_block = new CCodeBlock ();
+                       push_function (wrapper);
+
                        var free_call = new CCodeFunctionCall (element_destroy_func_expression);
                        free_call.add_argument (new CCodeMemberAccess.pointer(new CCodeIdentifier("node"), "data"));
-                       wrapper_block.add_statement (new CCodeExpressionStatement (free_call));
-                       wrapper_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
+                       ccode.add_expression (free_call);
+                       ccode.add_return (new CCodeConstant ("FALSE"));
+
+                       pop_function ();
                        cfile.add_function_declaration (function);
-                       wrapper.block = wrapper_block;
                        cfile.add_function (wrapper);
 
                        /* Now the code to call g_traverse with the above */
index c225ce95e360e03f8113ff9f7478103023b39d0b..a22e0cb9513c99a2eb9f458b3fe05c22b8cfec3a 100644 (file)
@@ -205,6 +205,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                var function = new CCodeFunction (wrapper_name, return_type_cname);
                function.modifiers = CCodeModifiers.STATIC;
 
+               push_function (function);
+
                var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
 
                if (d.has_target) {
@@ -400,13 +402,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        ccall.add_argument (new CCodeConstant ("NULL"));
                        ccall.add_argument (new CCodeConstant ("NULL"));
                }
-               var block = new CCodeBlock ();
                if (m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ()) {
-                       block.add_statement (new CCodeExpressionStatement (ccall));
+                       ccode.add_expression (ccall);
                } else {
-                       var cdecl = new CCodeDeclaration (return_type_cname);
-                       cdecl.add_declarator (new CCodeVariableDeclarator ("result", ccall));
-                       block.add_statement (cdecl);
+                       ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", ccall));
                }
 
                if (d.has_target && !dt.value_owned && dt.is_called_once && expr != null) {
@@ -434,19 +433,18 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        if (destroy_notify != null) {
                                var unref_call = new CCodeFunctionCall (destroy_notify);
                                unref_call.add_argument (new CCodeIdentifier ("self"));
-                               block.add_statement (new CCodeExpressionStatement (unref_call));
+                               ccode.add_expression (unref_call);
                        }
                }
 
                if (!(m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ())) {
-                       block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
+                       ccode.add_return (new CCodeIdentifier ("result"));
                }
 
-               // append to file
+               pop_function ();
 
+               // append to file
                cfile.add_function_declaration (function);
-
-               function.block = block;
                cfile.add_function (function);
 
                return wrapper_name;
index f082fca60bf37751ce3e76152c19b28b9aa137ef..957532f939f76dabb2da627b09748518af87ea75 100644 (file)
@@ -614,12 +614,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                            && current_class.get_type_parameters ().size > 0
                                            && !((CreationMethod) m).chain_up) {
                                                var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new CCodeIdentifier ("__params_it"), new CCodeIdentifier ("__params"));
-                                               var cdofreeparam = new CCodeBlock ();
-                                               cdofreeparam.add_statement (new CCodeExpressionStatement (new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_DECREMENT, new CCodeIdentifier ("__params_it"))));
+                                               ccode.open_while (ccond);
+                                               ccode.add_expression (new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_DECREMENT, new CCodeIdentifier ("__params_it")));
                                                var cunsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_unset"));
                                                cunsetcall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("__params_it"), "value")));
-                                               cdofreeparam.add_statement (new CCodeExpressionStatement (cunsetcall));
-                                               ccode.add_statement (new CCodeWhileStatement (ccond, cdofreeparam));
+                                               ccode.add_expression (cunsetcall);
+                                               ccode.close ();
 
                                                var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
                                                cfreeparams.add_argument (new CCodeIdentifier ("__params"));
@@ -692,26 +692,24 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        cmain.line = function.line;
                        cmain.add_parameter (new CCodeParameter ("argc", "int"));
                        cmain.add_parameter (new CCodeParameter ("argv", "char **"));
-                       var main_block = new CCodeBlock ();
+                       push_function (cmain);
 
                        if (context.profile == Profile.GOBJECT) {
                                if (context.mem_profiler) {
                                        var mem_profiler_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable"));
                                        mem_profiler_init_call.line = cmain.line;
                                        mem_profiler_init_call.add_argument (new CCodeConstant ("glib_mem_profiler_table"));
-                                       main_block.add_statement (new CCodeExpressionStatement (mem_profiler_init_call));
+                                       ccode.add_expression (mem_profiler_init_call);
                                }
 
                                if (context.thread) {
                                        var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
                                        thread_init_call.line = cmain.line;
                                        thread_init_call.add_argument (new CCodeConstant ("NULL"));
-                                       main_block.add_statement (new CCodeExpressionStatement (thread_init_call));
+                                       ccode.add_expression (thread_init_call);
                                }
 
-                               var type_init_call = new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
-                               type_init_call.line = cmain.line;
-                               main_block.add_statement (type_init_call);
+                               ccode.add_expression (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
                        }
 
                        var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name));
@@ -721,18 +719,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        }
                        if (m.return_type is VoidType) {
                                // method returns void, always use 0 as exit code
-                               var main_stmt = new CCodeExpressionStatement (main_call);
-                               main_stmt.line = cmain.line;
-                               main_block.add_statement (main_stmt);
-                               var ret_stmt = new CCodeReturnStatement (new CCodeConstant ("0"));
-                               ret_stmt.line = cmain.line;
-                               main_block.add_statement (ret_stmt);
+                               ccode.add_expression (main_call);
+                               ccode.add_return (new CCodeConstant ("0"));
                        } else {
-                               var main_stmt = new CCodeReturnStatement (main_call);
-                               main_stmt.line = cmain.line;
-                               main_block.add_statement (main_stmt);
+                               ccode.add_return (main_call);
                        }
-                       cmain.block = main_block;
+                       pop_function ();
                        cfile.add_function (cmain);
                }
        }
@@ -1028,21 +1020,19 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
                        var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
 
-                       var vblock = new CCodeBlock ();
+                       push_function (vfunc);
 
                        var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
                        vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ()));
 
                        generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall);
-                       CCodeStatement cstmt = new CCodeReturnStatement (vcall);
-                       cstmt.line = vfunc.line;
-                       vblock.add_statement (cstmt);
+                       ccode.add_return (vcall);
 
                        if (!visible) {
                                vfunc.modifiers |= CCodeModifiers.STATIC;
                        }
 
-                       vfunc.block = vblock;
+                       pop_function ();
 
                        cfile.add_function (vfunc);
                }
index b6114dcbfae5e1ecc8d8b84a661a89a3fc58a029..5b13e679c0717f3295b953d6f13d0bee5ac13ad0 100644 (file)
@@ -185,22 +185,20 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 
                function.add_parameter (new CCodeParameter ("self", "const " + st.get_cname () + "*"));
 
-               var cblock = new CCodeBlock ();
+               push_function (function);
 
-               var cdecl = new CCodeDeclaration (st.get_cname () + "*");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("dup"));
-               cblock.add_statement (cdecl);
+               ccode.add_declaration (st.get_cname () + "*", new CCodeVariableDeclarator ("dup"));
 
                var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
                creation_call.add_argument (new CCodeConstant (st.get_cname ()));
                creation_call.add_argument (new CCodeConstant ("1"));
-               cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("dup"), creation_call)));
+               ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
 
                if (st.is_disposable ()) {
                        var copy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_copy_function ()));
                        copy_call.add_argument (new CCodeIdentifier ("self"));
                        copy_call.add_argument (new CCodeIdentifier ("dup"));
-                       cblock.add_statement (new CCodeExpressionStatement (copy_call));
+                       ccode.add_expression (copy_call);
                } else {
                        cfile.add_include ("string.h");
 
@@ -211,12 +209,12 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                        copy_call.add_argument (new CCodeIdentifier ("dup"));
                        copy_call.add_argument (new CCodeIdentifier ("self"));
                        copy_call.add_argument (sizeof_call);
-                       cblock.add_statement (new CCodeExpressionStatement (copy_call));
+                       ccode.add_expression (copy_call);
                }
 
-               cblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("dup")));
+               ccode.add_return (new CCodeIdentifier ("dup"));
 
-               function.block = cblock;
+               pop_function ();
 
                cfile.add_function (function);
        }
@@ -229,19 +227,19 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 
                function.add_parameter (new CCodeParameter ("self", st.get_cname () + "*"));
 
-               var cblock = new CCodeBlock ();
+               push_function (function);
 
                if (st.is_disposable ()) {
                        var destroy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_destroy_function ()));
                        destroy_call.add_argument (new CCodeIdentifier ("self"));
-                       cblock.add_statement (new CCodeExpressionStatement (destroy_call));
+                       ccode.add_expression (destroy_call);
                }
 
                var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
                free_call.add_argument (new CCodeIdentifier ("self"));
-               cblock.add_statement (new CCodeExpressionStatement (free_call));
+               ccode.add_expression (free_call);
 
-               function.block = cblock;
+               pop_function ();
 
                cfile.add_function (function);
        }
index a5b2edec2997ddbba7c7594d65b3f095bdf0dbd4..143911f9fefcb9943320b1727f28a43443a47b88 100644 (file)
@@ -488,22 +488,20 @@ public class Vala.GAsyncModule : GSignalModule {
                readyfunc.add_parameter (new CCodeParameter ("_res_", "GAsyncResult*"));
                readyfunc.add_parameter (new CCodeParameter ("_user_data_", "gpointer"));
 
-               var readyblock = new CCodeBlock ();
+               push_function (readyfunc);
 
-               var datadecl = new CCodeDeclaration (dataname + "*");
-               datadecl.add_declarator (new CCodeVariableDeclarator ("data"));
-               readyblock.add_statement (datadecl);
-               readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), new CCodeIdentifier ("_user_data_"))));
-               readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_source_object_"), new CCodeIdentifier ("source_object"))));
-               readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_res_"), new CCodeIdentifier ("_res_"))));
+               ccode.add_declaration (dataname + "*", new CCodeVariableDeclarator ("data"));
+               ccode.add_assignment (new CCodeIdentifier ("data"), new CCodeIdentifier ("_user_data_"));
+               ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_source_object_"), new CCodeIdentifier ("source_object"));
+               ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_res_"), new CCodeIdentifier ("_res_"));
 
                var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname () + "_co"));
                ccall.add_argument (new CCodeIdentifier ("data"));
-               readyblock.add_statement (new CCodeExpressionStatement (ccall));
+               ccode.add_expression (ccall);
 
                readyfunc.modifiers |= CCodeModifiers.STATIC;
 
-               readyfunc.block = readyblock;
+               pop_function ();
 
                cfile.add_function_declaration (readyfunc);
                cfile.add_function (readyfunc);
index 1d6edad92f3f27733e8121cf1c3bb9a25afbefd6..e462d6dff479b7891fc6d05d5805661dbe47b72f 100644 (file)
@@ -79,7 +79,7 @@ public class Vala.GDBusClientModule : GDBusModule {
                var proxy_iface_init = new CCodeFunction (lower_cname + "_" + iface.get_lower_case_cprefix () + "interface_init", "void");
                proxy_iface_init.add_parameter (new CCodeParameter ("iface", iface.get_cname () + "Iface*"));
 
-               var iface_block = new CCodeBlock ();
+               push_function (proxy_iface_init);
 
                foreach (Method m in iface.get_methods ()) {
                        if (!m.is_abstract) {
@@ -88,11 +88,11 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                        var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), m.vfunc_name);
                        if (!m.coroutine) {
-                               iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_method (main_iface, iface, m)))));
+                               ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_method (main_iface, iface, m)));
                        } else {
-                               iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_async_dbus_proxy_method (main_iface, iface, m)))));
+                               ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_async_dbus_proxy_method (main_iface, iface, m)));
                                vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), m.get_finish_vfunc_name ());
-                               iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_finish_dbus_proxy_method (main_iface, iface, m)))));
+                               ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_finish_dbus_proxy_method (main_iface, iface, m)));
                        }
                }
 
@@ -103,17 +103,17 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                        if (prop.get_accessor != null) {
                                var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), "get_" + prop.name);
-                               iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_get (main_iface, iface, prop)))));
+                               ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_get (main_iface, iface, prop)));
                        }
                        if (prop.set_accessor != null) {
                                var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), "set_" + prop.name);
-                               iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_set (main_iface, iface, prop)))));
+                               ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_set (main_iface, iface, prop)));
                        }
                }
 
                proxy_iface_init.modifiers = CCodeModifiers.STATIC;
+               pop_function ();
                cfile.add_function_declaration (proxy_iface_init);
-               proxy_iface_init.block = iface_block;
                cfile.add_function (proxy_iface_init);
        }
 
@@ -187,10 +187,11 @@ public class Vala.GDBusClientModule : GDBusModule {
                var proxy_class_init = new CCodeFunction (lower_cname + "_class_init", "void");
                proxy_class_init.add_parameter (new CCodeParameter ("klass", cname + "Class*"));
                proxy_class_init.modifiers = CCodeModifiers.STATIC;
-               proxy_class_init.block = new CCodeBlock ();
+               push_function (proxy_class_init);
                var proxy_class = new CCodeFunctionCall (new CCodeIdentifier ("G_DBUS_PROXY_CLASS"));
                proxy_class.add_argument (new CCodeIdentifier ("klass"));
-               proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (proxy_class, "g_signal"), new CCodeIdentifier (lower_cname + "_g_signal"))));
+               ccode.add_assignment (new CCodeMemberAccess.pointer (proxy_class, "g_signal"), new CCodeIdentifier (lower_cname + "_g_signal"));
+               pop_function ();
                cfile.add_function (proxy_class_init);
 
                generate_signal_handler_function (iface);
@@ -198,7 +199,6 @@ public class Vala.GDBusClientModule : GDBusModule {
                var proxy_instance_init = new CCodeFunction (lower_cname + "_init", "void");
                proxy_instance_init.add_parameter (new CCodeParameter ("self", cname + "*"));
                proxy_instance_init.modifiers = CCodeModifiers.STATIC;
-               proxy_instance_init.block = new CCodeBlock ();
                cfile.add_function (proxy_instance_init);
 
                generate_proxy_interface_init (iface, iface);
@@ -427,10 +427,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                cfile.add_function_declaration (cfunc);
 
-               var block = new CCodeBlock ();
-               cfunc.block = block;
+               push_function (cfunc);
 
-               CCodeIfStatement clastif = null;
+               bool firstif = true;
 
                foreach (Signal sig in sym.get_signals ()) {
                        if (sig.access != SymbolAccessibility.PUBLIC) {
@@ -443,24 +442,24 @@ public class Vala.GDBusClientModule : GDBusModule {
                        ccheck.add_argument (new CCodeIdentifier ("signal_name"));
                        ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (sig))));
 
-                       var callblock = new CCodeBlock ();
+                       if (!firstif) {
+                               ccode.add_else ();
+                       }
+                       ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
+                       firstif = false;
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_signal_handler (sig, sym)));
                        ccall.add_argument (new CCodeCastExpression (new CCodeIdentifier ("proxy"), sym.get_cname () + "*"));
                        ccall.add_argument (new CCodeIdentifier ("parameters"));
 
-                       callblock.add_statement (new CCodeExpressionStatement (ccall));
-
-                       var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
-                       if (clastif == null) {
-                               block.add_statement (cif);
-                       } else {
-                               clastif.false_statement = cif;
-                       }
-
-                       clastif = cif;
+                       ccode.add_expression (ccall);
+               }
+               if (!firstif) {
+                       ccode.close ();
                }
 
+               pop_function ();
+
                cfile.add_function (cfunc);
        }
 
index 9f1328108d2c97592fbb97ae973287573bb4426c..1708d03b12077d89aa54e456171d69d6714ef7d9 100644 (file)
@@ -87,14 +87,11 @@ public class Vala.GDBusModule : GVariantModule {
                string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
 
                var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
-               var cquark_block = new CCodeBlock ();
+               push_function (cquark_fun);
 
                string quark_name = "%squark_volatile".printf (edomain.get_lower_case_cprefix ());
 
-               cdecl = new CCodeDeclaration ("gsize");
-               cdecl.add_declarator (new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")));
-               cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
-               cquark_block.add_statement (cdecl);
+               ccode.add_declaration ("gsize", new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")), CCodeModifiers.STATIC | CCodeModifiers.VOLATILE);
 
                var register_call = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_error_register_error_domain"));
                register_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
@@ -103,11 +100,11 @@ public class Vala.GDBusModule : GVariantModule {
                var nentries = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
                nentries.add_argument (new CCodeIdentifier (edomain.get_lower_case_cname () + "_entries"));
                register_call.add_argument (nentries);
-               cquark_block.add_statement (new CCodeExpressionStatement (register_call));
+               ccode.add_expression (register_call);
 
-               cquark_block.add_statement (new CCodeReturnStatement (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark")));
+               ccode.add_return (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark"));
 
-               cquark_fun.block = cquark_block;
+               pop_function ();
                cfile.add_function (cquark_fun);
        }
 
index e2db9e416821f98437c68bcabf7dfc069a45c095..78fd7d53b548becd991a72962648e20fa7ce9186 100644 (file)
@@ -589,7 +589,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                return wrapper_name;
        }
 
-       void handle_signals (ObjectTypeSymbol sym, CCodeBlock block) {
+       void handle_signals (ObjectTypeSymbol sym) {
                string dbus_iface_name = get_dbus_name (sym);
                if (dbus_iface_name == null) {
                        return;
@@ -608,7 +608,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        connect.add_argument (sig.get_canonical_cconstant ());
                        connect.add_argument (new CCodeCastExpression (new CCodeIdentifier (generate_dbus_signal_wrapper (sig, sym, dbus_iface_name)), "GCallback"));
                        connect.add_argument (new CCodeIdentifier ("data"));
-                       block.add_statement (new CCodeExpressionStatement (connect));
+                       ccode.add_expression (connect);
                }
        }
 
@@ -693,18 +693,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
                cfile.add_function_declaration (cfunc);
 
-               var block = new CCodeBlock ();
-               cfunc.block = block;
+               push_function (cfunc);
 
-               var cdecl = new CCodeDeclaration ("gpointer*");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
 
-               cdecl = new CCodeDeclaration ("gpointer");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
 
-               CCodeIfStatement clastif = null;
+               bool firstif = true;
 
                foreach (Property prop in sym.get_properties ()) {
                        if (prop.binding != MemberBinding.INSTANCE
@@ -724,25 +719,24 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        ccheck.add_argument (new CCodeIdentifier ("property_name"));
                        ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
 
-                       var callblock = new CCodeBlock ();
+                       if (!firstif) {
+                               ccode.add_else ();
+                       }
+                       ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
+                       firstif = false;
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_property_get_wrapper (prop, sym)));
                        ccall.add_argument (new CCodeIdentifier ("object"));
 
-                       callblock.add_statement (new CCodeReturnStatement (ccall));
-
-                       var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
-                       if (clastif == null) {
-                               block.add_statement (cif);
-                       } else {
-                               clastif.false_statement = cif;
-                       }
-
-                       clastif = cif;
+                       ccode.add_return (ccall);
+               }
+               if (!firstif) {
+                       ccode.close ();
                }
 
-               block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
+               ccode.add_return (new CCodeConstant ("NULL"));
 
+               pop_function ();
                cfile.add_function (cfunc);
        }
 
@@ -761,18 +755,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
                cfile.add_function_declaration (cfunc);
 
-               var block = new CCodeBlock ();
-               cfunc.block = block;
+               push_function (cfunc);
 
-               var cdecl = new CCodeDeclaration ("gpointer*");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
 
-               cdecl = new CCodeDeclaration ("gpointer");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
 
-               CCodeIfStatement clastif = null;
+               bool firstif = true;
 
                foreach (Property prop in sym.get_properties ()) {
                        if (prop.binding != MemberBinding.INSTANCE
@@ -792,27 +781,25 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        ccheck.add_argument (new CCodeIdentifier ("property_name"));
                        ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
 
-                       var callblock = new CCodeBlock ();
+                       if (!firstif) {
+                               ccode.add_else ();
+                       }
+                       ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
+                       firstif = false;
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_property_set_wrapper (prop, sym)));
                        ccall.add_argument (new CCodeIdentifier ("object"));
                        ccall.add_argument (new CCodeIdentifier ("value"));
 
-                       callblock.add_statement (new CCodeExpressionStatement (ccall));
-                       callblock.add_statement (new CCodeReturnStatement (new CCodeConstant ("TRUE")));
-
-                       var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
-                       if (clastif == null) {
-                               block.add_statement (cif);
-                       } else {
-                               clastif.false_statement = cif;
-                       }
-
-                       clastif = cif;
+                       ccode.add_expression (ccall);
+                       ccode.add_return (new CCodeConstant ("TRUE"));
                }
+               if (!firstif) {
+                       ccode.close ();
+               }
+               ccode.add_return (new CCodeConstant ("FALSE"));
 
-               block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
-
+               pop_function ();
                cfile.add_function (cfunc);
        }
 
@@ -1221,35 +1208,30 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        cfunc.modifiers |= CCodeModifiers.STATIC;
                }
 
-               var block = new CCodeBlock ();
-               cfunc.block = block;
+               push_function (cfunc);
 
-               var cdecl = new CCodeDeclaration ("guint");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("guint", new CCodeVariableDeclarator ("result"));
 
 
                // data consists of 3 pointers: object, connection, path
-               cdecl = new CCodeDeclaration ("gpointer");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("*data"));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("*data"));
 
                var alloc_data = new CCodeFunctionCall (new CCodeIdentifier ("g_new"));
                alloc_data.add_argument (new CCodeIdentifier ("gpointer"));
                alloc_data.add_argument (new CCodeConstant ("3"));
-               block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), alloc_data)));
+               ccode.add_assignment (new CCodeIdentifier ("data"), alloc_data);
 
                var ref_object = new CCodeFunctionCall (new CCodeIdentifier (sym.get_ref_function ()));
                ref_object.add_argument (new CCodeIdentifier ("object"));
-               block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")), ref_object)));
+               ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")), ref_object);
 
                ref_object = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
                ref_object.add_argument (new CCodeIdentifier ("connection"));
-               block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")), ref_object)));
+               ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")), ref_object);
 
                var dup_path = new CCodeFunctionCall (new CCodeIdentifier ("g_strdup"));
                dup_path.add_argument (new CCodeIdentifier ("path"));
-               block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")), dup_path)));
+               ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")), dup_path);
 
 
                var cregister = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_connection_register_object"));
@@ -1263,47 +1245,46 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                cregister.add_argument (new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "unregister_object"));
                cregister.add_argument (new CCodeIdentifier ("error"));
 
-               block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("result"), cregister)));
+               ccode.add_assignment (new CCodeIdentifier ("result"), cregister);
 
-               var error_block = new CCodeBlock ();
-               error_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("0")));
-               block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("result")), error_block));
+               ccode.open_if (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("result")));
+               ccode.add_return (new CCodeConstant ("0"));
+               ccode.close ();
 
-               handle_signals (sym, block);
+               handle_signals (sym);
 
-               block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
+               ccode.add_return (new CCodeIdentifier ("result"));
 
+               pop_function ();
                cfile.add_function (cfunc);
 
 
                cfunc = new CCodeFunction ("_" + sym.get_lower_case_cprefix () + "unregister_object");
                cfunc.add_parameter (new CCodeParameter ("user_data", "gpointer"));
                cfunc.modifiers |= CCodeModifiers.STATIC;
-               cfile.add_function_declaration (cfunc);
 
-               block = new CCodeBlock ();
-               cfunc.block = block;
+               push_function (cfunc);
 
-               cdecl = new CCodeDeclaration ("gpointer*");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
-               block.add_statement (cdecl);
+               ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
 
                var unref_object = new CCodeFunctionCall (new CCodeIdentifier (sym.get_unref_function ()));
                unref_object.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")));
-               block.add_statement (new CCodeExpressionStatement (unref_object));
+               ccode.add_expression (unref_object);
 
                unref_object = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
                unref_object.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")));
-               block.add_statement (new CCodeExpressionStatement (unref_object));
+               ccode.add_expression (unref_object);
 
                var free_path = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
                free_path.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")));
-               block.add_statement (new CCodeExpressionStatement (free_path));
+               ccode.add_expression (free_path);
 
                var free_data = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
                free_data.add_argument (new CCodeIdentifier ("data"));
-               block.add_statement (new CCodeExpressionStatement (free_data));
+               ccode.add_expression (free_data);
 
+               pop_function ();
+               cfile.add_function_declaration (cfunc);
                cfile.add_function (cfunc);
        }
 
index bcc4f6d050df86720ceea4dbd78842eaf566e559..7331280d4d5a607746dbcfb2e2c61fd4bd33b64c 100644 (file)
@@ -73,14 +73,14 @@ public class Vala.GErrorModule : CCodeDelegateModule {
                string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
 
                var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
-               var cquark_block = new CCodeBlock ();
+               push_function (cquark_fun);
 
                var cquark_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
                cquark_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
 
-               cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
+               ccode.add_return (cquark_call);
 
-               cquark_fun.block = cquark_block;
+               pop_function ();
                cfile.add_function (cquark_fun);
        }
 
index 2a076096bc831c5899df8d01d893f3edc667cd9e..ad50455ea5740ecd9e15fcd43579288aa6182be6 100644 (file)
@@ -262,7 +262,7 @@ public class Vala.GObjectModule : GTypeModule {
                        ccode.add_break ();
                }
                ccode.add_default ();
-               ccode.add_statement (get_invalid_property_id_warn_statement ());
+               emit_invalid_property_id_warn ();
                ccode.add_break ();
 
                ccode.close ();
@@ -280,17 +280,13 @@ public class Vala.GObjectModule : GTypeModule {
                set_prop.add_parameter (new CCodeParameter ("property_id", "guint"));
                set_prop.add_parameter (new CCodeParameter ("value", "const GValue *"));
                set_prop.add_parameter (new CCodeParameter ("pspec", "GParamSpec *"));
-               
-               var block = new CCodeBlock ();
+
+               push_function (set_prop);
                
                CCodeFunctionCall ccall = generate_instance_cast (new CCodeIdentifier ("object"), cl);
-               var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
-               cdecl.add_declarator (new CCodeVariableDeclarator ("self", ccall));
-               block.add_statement (cdecl);
-
-               var boxed_declared = false;
+               ccode.add_declaration ("%s *".printf (cl.get_cname ()), new CCodeVariableDeclarator ("self", ccall));
 
-               var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
+               ccode.open_switch (new CCodeIdentifier ("property_id"));
                var props = cl.get_properties ();
                foreach (Property prop in props) {
                        if (prop.set_accessor == null || prop.is_abstract) {
@@ -316,24 +312,23 @@ public class Vala.GObjectModule : GTypeModule {
                                generate_property_accessor_declaration (prop.base_interface_property.set_accessor, cfile);
                        }
 
-                       cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
+                       ccode.add_case (new CCodeIdentifier (prop.get_upper_case_cname ()));
                        ccall = new CCodeFunctionCall (new CCodeIdentifier (base_prop.set_accessor.get_cname ()));
                        ccall.add_argument (cself);
                        if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type == string_type.data_type) {
-                               if (!boxed_declared) {
-                                       cdecl = new CCodeDeclaration ("gpointer");
-                                       cdecl.add_declarator (new CCodeVariableDeclarator ("boxed"));
-                                       block.add_statement (cdecl);
-                                       boxed_declared = true;
-                               }
+                               ccode.open_block ();
+                               ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("boxed"));
+
                                var cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_boxed"));
                                cgetcall.add_argument (new CCodeIdentifier ("value"));
-                               cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("boxed"), cgetcall)));
+                               ccode.add_assignment (new CCodeIdentifier ("boxed"), cgetcall);
                                ccall.add_argument (new CCodeIdentifier ("boxed"));
 
                                var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
                                cstrvlen.add_argument (new CCodeIdentifier ("boxed"));
                                ccall.add_argument (cstrvlen);
+                               ccode.add_expression (ccall);
+                               ccode.close ();
                        } else {
                                var cgetcall = new CCodeFunctionCall ();
                                if (prop.property_type.data_type != null) {
@@ -343,15 +338,10 @@ public class Vala.GObjectModule : GTypeModule {
                                }
                                cgetcall.add_argument (new CCodeIdentifier ("value"));
                                ccall.add_argument (cgetcall);
+                               ccode.add_expression (ccall);
                        }
-                       cswitch.add_statement (new CCodeExpressionStatement (ccall));
-                       cswitch.add_statement (new CCodeBreakStatement ());
+                       ccode.add_break ();
                }
-               cswitch.add_statement (new CCodeLabel ("default"));
-               cswitch.add_statement (get_invalid_property_id_warn_statement ());
-               cswitch.add_statement (new CCodeBreakStatement ());
-
-               block.add_statement (cswitch);
 
                /* type, dup func, and destroy func properties for generic types */
                foreach (TypeParameter type_param in cl.get_type_parameters ()) {
@@ -361,46 +351,50 @@ public class Vala.GObjectModule : GTypeModule {
 
                        func_name = "%s_type".printf (type_param.name.down ());
                        enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
-                       cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+                       ccode.add_case (new CCodeIdentifier (enum_value));
                        cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
                        cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_gtype"));
                        cgetcall.add_argument (new CCodeIdentifier ("value"));
-                       cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
-                       cswitch.add_statement (new CCodeBreakStatement ());
+                       ccode.add_assignment (cfield, cgetcall);
+                       ccode.add_break ();
 
                        func_name = "%s_dup_func".printf (type_param.name.down ());
                        enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
-                       cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+                       ccode.add_case (new CCodeIdentifier (enum_value));
                        cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
                        cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                        cgetcall.add_argument (new CCodeIdentifier ("value"));
-                       cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
-                       cswitch.add_statement (new CCodeBreakStatement ());
+                       ccode.add_assignment (cfield, cgetcall);
+                       ccode.add_break ();
 
                        func_name = "%s_destroy_func".printf (type_param.name.down ());
                        enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
-                       cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+                       ccode.add_case (new CCodeIdentifier (enum_value));
                        cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
                        cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                        cgetcall.add_argument (new CCodeIdentifier ("value"));
-                       cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
-                       cswitch.add_statement (new CCodeBreakStatement ());
+                       ccode.add_assignment (cfield, cgetcall);
+                       ccode.add_break ();
                }
+               ccode.add_default ();
+               emit_invalid_property_id_warn ();
+               ccode.add_break ();
 
-               cfile.add_function_declaration (set_prop);
+               ccode.close ();
 
-               set_prop.block = block;
-               
+               pop_function ();
+
+               cfile.add_function_declaration (set_prop);
                cfile.add_function (set_prop);
        }
 
-       private CCodeStatement get_invalid_property_id_warn_statement () {
+       private void emit_invalid_property_id_warn () {
                // warn on invalid property id
                var cwarn = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_WARN_INVALID_PROPERTY_ID"));
                cwarn.add_argument (new CCodeIdentifier ("object"));
                cwarn.add_argument (new CCodeIdentifier ("property_id"));
                cwarn.add_argument (new CCodeIdentifier ("pspec"));
-               return new CCodeExpressionStatement (cwarn);
+               ccode.add_expression (cwarn);
        }
 
        public override void visit_constructor (Constructor c) {
@@ -531,13 +525,24 @@ public class Vala.GObjectModule : GTypeModule {
 
                func.add_parameter (new CCodeParameter ("obj", prop.dynamic_type.get_cname ()));
 
-               var block = new CCodeBlock ();
-               generate_gobject_property_getter_wrapper (prop, block);
+               push_function (func);
+
+               ccode.add_declaration (prop.property_type.get_cname (), new CCodeVariableDeclarator ("result"));
+
+               var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_get"));
+               call.add_argument (new CCodeIdentifier ("obj"));
+               call.add_argument (prop.get_canonical_cconstant ());
+               call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+               call.add_argument (new CCodeConstant ("NULL"));
+
+               ccode.add_expression (call);
+
+               ccode.add_return (new CCodeIdentifier ("result"));
+
+               pop_function ();
 
                // append to C source file
                cfile.add_function_declaration (func);
-
-               func.block = block;
                cfile.add_function (func);
 
                return getter_cname;
@@ -553,46 +558,26 @@ public class Vala.GObjectModule : GTypeModule {
 
                var func = new CCodeFunction (setter_cname, "void");
                func.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.INLINE;
-
                func.add_parameter (new CCodeParameter ("obj", prop.dynamic_type.get_cname ()));
                func.add_parameter (new CCodeParameter ("value", prop.property_type.get_cname ()));
 
-               var block = new CCodeBlock ();
-               generate_gobject_property_setter_wrapper (prop, block);
+               push_function (func);
 
-               // append to C source file
-               cfile.add_function_declaration (func);
-
-               func.block = block;
-               cfile.add_function (func);
-
-               return setter_cname;
-       }
-
-       void generate_gobject_property_getter_wrapper (DynamicProperty node, CCodeBlock block) {
-               var cdecl = new CCodeDeclaration (node.property_type.get_cname ());
-               cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
-               block.add_statement (cdecl);
-
-               var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_get"));
+               var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set"));
                call.add_argument (new CCodeIdentifier ("obj"));
-               call.add_argument (node.get_canonical_cconstant ());
-               call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+               call.add_argument (prop.get_canonical_cconstant ());
+               call.add_argument (new CCodeIdentifier ("value"));
                call.add_argument (new CCodeConstant ("NULL"));
 
-               block.add_statement (new CCodeExpressionStatement (call));
+               ccode.add_expression (call);
 
-               block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
-       }
+               pop_function ();
 
-       void generate_gobject_property_setter_wrapper (DynamicProperty node, CCodeBlock block) {
-               var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set"));
-               call.add_argument (new CCodeIdentifier ("obj"));
-               call.add_argument (node.get_canonical_cconstant ());
-               call.add_argument (new CCodeIdentifier ("value"));
-               call.add_argument (new CCodeConstant ("NULL"));
+               // append to C source file
+               cfile.add_function_declaration (func);
+               cfile.add_function (func);
 
-               block.add_statement (new CCodeExpressionStatement (call));
+               return setter_cname;
        }
 
        public override string get_dynamic_signal_cname (DynamicSignal node) {
@@ -611,13 +596,12 @@ public class Vala.GObjectModule : GTypeModule {
                func.add_parameter (new CCodeParameter ("signal_name", "const char *"));
                func.add_parameter (new CCodeParameter ("handler", "GCallback"));
                func.add_parameter (new CCodeParameter ("data", "gpointer"));
-               var block = new CCodeBlock ();
-               generate_gobject_connect_wrapper (sig, block, false);
+               push_function (func);
+               generate_gobject_connect_wrapper (sig, false);
+               pop_function ();
 
                // append to C source file
                cfile.add_function_declaration (func);
-
-               func.block = block;
                cfile.add_function (func);
 
                return connect_wrapper_name;
@@ -635,19 +619,18 @@ public class Vala.GObjectModule : GTypeModule {
                func.add_parameter (new CCodeParameter ("signal_name", "const char *"));
                func.add_parameter (new CCodeParameter ("handler", "GCallback"));
                func.add_parameter (new CCodeParameter ("data", "gpointer"));
-               var block = new CCodeBlock ();
-               generate_gobject_connect_wrapper (sig, block, true);
+               push_function (func);
+               generate_gobject_connect_wrapper (sig, true);
+               pop_function ();
 
                // append to C source file
                cfile.add_function_declaration (func);
-
-               func.block = block;
                cfile.add_function (func);
 
                return connect_wrapper_name;
        }
 
-       void generate_gobject_connect_wrapper (DynamicSignal sig, CCodeBlock block, bool after) {
+       void generate_gobject_connect_wrapper (DynamicSignal sig, bool after) {
                var m = (Method) sig.handler.symbol_reference;
 
                sig.accept (this);
@@ -667,13 +650,14 @@ public class Vala.GObjectModule : GTypeModule {
                call.add_argument (new CCodeIdentifier ("data"));
 
                if (m.binding == MemberBinding.INSTANCE) {
-                       if (!after)
+                       if (!after) {
                                call.add_argument (new CCodeConstant ("0"));
-                       else
+                       } else {
                                call.add_argument (new CCodeConstant ("G_CONNECT_AFTER"));
+                       }
                }
 
-               block.add_statement (new CCodeExpressionStatement (call));
+               ccode.add_expression (call);
        }
 
        public override void visit_property (Property prop) {