Add CCodeTypesymbolBinding, CCodeClassBinding, and CCodeInterfaceBinding
authorJuerg Billeter <j@bitron.ch>
Sat, 19 Apr 2008 06:06:38 +0000 (06:06 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 19 Apr 2008 06:06:38 +0000 (06:06 +0000)
2008-04-19  Juerg Billeter  <j@bitron.ch>

* vala/valaclass.vala, vala/valainterface.vala, gobject/Makefile.am,
  gobject/valaccodeassignmentbinding.vala,
  gobject/valaccodebinding.vala, gobject/valaccodeclassbinding.vala,
  gobject/valaccodegenerator.vala,
  gobject/valaccodeinterfacebinding.vala,
  gobject/valaccodetypesymbolbinding.vala:

  Add CCodeTypesymbolBinding, CCodeClassBinding, and
  CCodeInterfaceBinding classes

svn path=/trunk/; revision=1260

ChangeLog
gobject/Makefile.am
gobject/valaccodeassignmentbinding.vala
gobject/valaccodebinding.vala
gobject/valaccodeclassbinding.vala [moved from gobject/valaccodegeneratorclass.vala with 81% similarity]
gobject/valaccodegenerator.vala
gobject/valaccodeinterfacebinding.vala [new file with mode: 0644]
gobject/valaccodetypesymbolbinding.vala [moved from gobject/valaccodegeneratorinterface.vala with 57% similarity]
vala/valaclass.vala
vala/valainterface.vala

index 5fbc48b..7970b92 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-04-19  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valaclass.vala, vala/valainterface.vala, gobject/Makefile.am,
+         gobject/valaccodeassignmentbinding.vala,
+         gobject/valaccodebinding.vala, gobject/valaccodeclassbinding.vala,
+         gobject/valaccodegenerator.vala,
+         gobject/valaccodeinterfacebinding.vala,
+         gobject/valaccodetypesymbolbinding.vala:
+
+         Add CCodeTypesymbolBinding, CCodeClassBinding, and
+         CCodeInterfaceBinding classes
+
+2008-04-19  Jürg Billeter  <j@bitron.ch>
+
        * vala/valaarraycreationexpression.vala, vala/valaassignment.vala,
          vala/valacodebinding.vala, vala/valacodecontext.vala,
          vala/valacodenode.vala, vala/valaelementaccess.vala,
index f8b471f..1787883 100644 (file)
@@ -15,19 +15,20 @@ libvala_la_VALASOURCES = \
        valaccodearraycreationexpressionbinding.vala \
        valaccodeassignmentbinding.vala \
        valaccodebinding.vala \
+       valaccodeclassbinding.vala \
        valaccodecompiler.vala \
        valaccodeelementaccessbinding.vala \
        valaccodeexpressionbinding.vala \
        valaccodegenerator.vala \
-       valaccodegeneratorclass.vala \
-       valaccodegeneratorinterface.vala \
        valaccodegeneratorinvocationexpression.vala \
        valaccodegeneratormemberaccess.vala \
        valaccodegeneratormethod.vala \
        valaccodegeneratorsignal.vala \
        valaccodegeneratorsourcefile.vala \
        valaccodegeneratorstruct.vala \
+       valaccodeinterfacebinding.vala \
        valaccodemethodbinding.vala \
+       valaccodetypesymbolbinding.vala \
        valaclassregisterfunction.vala \
        valadbusbindingprovider.vala \
        valadbusmethod.vala \
index 96dda7e..2165f87 100644 (file)
@@ -59,7 +59,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
                        ccomma.append_expression (cvalueinit);
                        
                        // set GValue for current parameter
-                       var cvalueset = new CCodeFunctionCall (codegen.get_value_setter_function (prop.type_reference));
+                       var cvalueset = new CCodeFunctionCall (get_value_setter_function (prop.type_reference));
                        cvalueset.add_argument (gvaluearg);
                        cvalueset.add_argument ((CCodeExpression) assignment.right.ccodenode);
                        ccomma.append_expression (cvalueset);
index c8469b6..1d5f306 100644 (file)
@@ -36,6 +36,14 @@ public abstract class Vala.CCodeBinding : CodeBinding {
         */
        public abstract void emit ();
 
+       public CCodeIdentifier get_value_setter_function (DataType type_reference) {
+               if (type_reference.data_type != null) {
+                       return new CCodeIdentifier (type_reference.data_type.get_set_value_function ());
+               } else {
+                       return new CCodeIdentifier ("g_value_set_pointer");
+               }
+       }
+
        public CCodeBinding? code_binding (CodeNode node) {
                return (CCodeBinding) node.get_code_binding (codegen);
        }
similarity index 81%
rename from gobject/valaccodegeneratorclass.vala
rename to gobject/valaccodeclassbinding.vala
index 1723c28..e766134 100644 (file)
@@ -1,4 +1,4 @@
-/* valaccodegeneratorclass.vala
+/* valaccodeclassbinding.vala
  *
  * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
  *
 
 using GLib;
 
-public class Vala.CCodeGenerator {
-       public override void visit_class (Class cl) {
-               var old_symbol = current_symbol;
-               var old_type_symbol = current_type_symbol;
-               var old_class = current_class;
-               var old_instance_struct = instance_struct;
-               var old_type_struct = type_struct;
-               var old_instance_priv_struct = instance_priv_struct;
-               var old_prop_enum = prop_enum;
-               var old_class_init_fragment = class_init_fragment;
-               var old_instance_init_fragment = instance_init_fragment;
-               var old_instance_dispose_fragment = instance_dispose_fragment;
-               current_symbol = cl;
-               current_type_symbol = cl;
-               current_class = cl;
+public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
+       public Class cl { get; set; }
+
+       public CCodeClassBinding (CCodeGenerator codegen, Class cl) {
+               this.cl = cl;
+               this.codegen = codegen;
+       }
+
+       public override void emit () {
+               var old_symbol = codegen.current_symbol;
+               var old_type_symbol = codegen.current_type_symbol;
+               var old_class = codegen.current_class;
+               var old_instance_struct = codegen.instance_struct;
+               var old_type_struct = codegen.type_struct;
+               var old_instance_priv_struct = codegen.instance_priv_struct;
+               var old_prop_enum = codegen.prop_enum;
+               var old_class_init_fragment = codegen.class_init_fragment;
+               var old_instance_init_fragment = codegen.instance_init_fragment;
+               var old_instance_dispose_fragment = codegen.instance_dispose_fragment;
+               codegen.current_symbol = cl;
+               codegen.current_type_symbol = cl;
+               codegen.current_class = cl;
                
-               bool is_gtypeinstance = cl.is_subtype_of (gtypeinstance_type);
-               bool is_gobject = cl.is_subtype_of (gobject_type);
-               bool is_fundamental = (cl.base_class == gtypeinstance_type);
+               bool is_gtypeinstance = cl.is_subtype_of (codegen.gtypeinstance_type);
+               bool is_gobject = cl.is_subtype_of (codegen.gobject_type);
+               bool is_fundamental = (cl.base_class == codegen.gtypeinstance_type);
 
                if (cl.get_cname().len () < 3) {
                        cl.error = true;
@@ -50,24 +57,24 @@ public class Vala.CCodeGenerator {
                }
 
                if (!cl.is_static) {
-                       instance_struct = new CCodeStruct ("_%s".printf (cl.get_cname ()));
-                       type_struct = new CCodeStruct ("_%sClass".printf (cl.get_cname ()));
-                       instance_priv_struct = new CCodeStruct ("_%sPrivate".printf (cl.get_cname ()));
-                       prop_enum = new CCodeEnum ();
-                       prop_enum.add_value (new CCodeEnumValue ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null))));
-                       class_init_fragment = new CCodeFragment ();
-                       instance_init_fragment = new CCodeFragment ();
-                       instance_dispose_fragment = new CCodeFragment ();
+                       codegen.instance_struct = new CCodeStruct ("_%s".printf (cl.get_cname ()));
+                       codegen.type_struct = new CCodeStruct ("_%sClass".printf (cl.get_cname ()));
+                       codegen.instance_priv_struct = new CCodeStruct ("_%sPrivate".printf (cl.get_cname ()));
+                       codegen.prop_enum = new CCodeEnum ();
+                       codegen.prop_enum.add_value (new CCodeEnumValue ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null))));
+                       codegen.class_init_fragment = new CCodeFragment ();
+                       codegen.instance_init_fragment = new CCodeFragment ();
+                       codegen.instance_dispose_fragment = new CCodeFragment ();
                }
 
                CCodeFragment decl_frag;
                CCodeFragment def_frag;
                if (cl.access != SymbolAccessibility.PRIVATE) {
-                       decl_frag = header_type_declaration;
-                       def_frag = header_type_definition;
+                       decl_frag = codegen.header_type_declaration;
+                       def_frag = codegen.header_type_definition;
                } else {
-                       decl_frag = source_type_declaration;
-                       def_frag = source_type_definition;
+                       decl_frag = codegen.source_type_declaration;
+                       def_frag = codegen.source_type_definition;
                }
 
                if (is_gtypeinstance) {
@@ -94,28 +101,28 @@ public class Vala.CCodeGenerator {
 
 
                if (!cl.is_static && cl.source_reference.file.cycle == null) {
-                       decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
+                       decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
                }
 
                if (cl.base_class != null) {
-                       instance_struct.add_field (cl.base_class.get_cname (), "parent_instance");
+                       codegen.instance_struct.add_field (cl.base_class.get_cname (), "parent_instance");
                        if (is_fundamental) {
-                               instance_struct.add_field ("volatile int", "ref_count");
+                               codegen.instance_struct.add_field ("volatile int", "ref_count");
                        }
                }
 
                if (is_gtypeinstance) {
                        if (cl.source_reference.file.cycle == null) {
-                               decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
+                               decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
                        }
-                       decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
+                       decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
 
-                       instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
+                       codegen.instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
                        if (is_fundamental) {
-                               type_struct.add_field ("GTypeClass", "parent_class");
-                               type_struct.add_field ("void", "(*finalize) (%s *self)".printf (cl.get_cname ()));
+                               codegen.type_struct.add_field ("GTypeClass", "parent_class");
+                               codegen.type_struct.add_field ("void", "(*finalize) (%s *self)".printf (cl.get_cname ()));
                        } else {
-                               type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent_class");
+                               codegen.type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent_class");
                        }
                }
 
@@ -123,26 +130,26 @@ public class Vala.CCodeGenerator {
                        if (cl.source_reference.comment != null) {
                                def_frag.append (new CCodeComment (cl.source_reference.comment));
                        }
-                       def_frag.append (instance_struct);
+                       def_frag.append (codegen.instance_struct);
                }
 
                if (is_gtypeinstance) {
-                       def_frag.append (type_struct);
+                       def_frag.append (codegen.type_struct);
                        /* only add the *Private struct if it is not empty, i.e. we actually have private data */
                        if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
-                               source_type_member_declaration.append (instance_priv_struct);
+                               codegen.source_type_member_declaration.append (codegen.instance_priv_struct);
                                var macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
-                               source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
+                               codegen.source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
                        }
-                       source_type_member_declaration.append (prop_enum);
+                       codegen.source_type_member_declaration.append (codegen.prop_enum);
                }
 
-               cl.accept_children (this);
+               cl.accept_children (codegen);
 
                if (is_gtypeinstance) {
                        if (is_fundamental) {
                                var ref_count = new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "ref_count"), new CCodeConstant ("1"));
-                               instance_init_fragment.append (new CCodeExpressionStatement (ref_count));
+                               codegen.instance_init_fragment.append (new CCodeExpressionStatement (ref_count));
                        } else if (is_gobject) {
                                if (class_has_readable_properties (cl) || cl.get_type_parameters ().size > 0) {
                                        add_get_property_function (cl);
@@ -168,19 +175,19 @@ public class Vala.CCodeGenerator {
                        }
 
                        var type_fun = new ClassRegisterFunction (cl);
-                       type_fun.init_from_type (in_plugin);
+                       type_fun.init_from_type (codegen.in_plugin);
                        if (cl.access != SymbolAccessibility.PRIVATE) {
-                               header_type_member_declaration.append (type_fun.get_declaration ());
+                               codegen.header_type_member_declaration.append (type_fun.get_declaration ());
                        } else {
-                               source_type_member_declaration.append (type_fun.get_declaration ());
+                               codegen.source_type_member_declaration.append (type_fun.get_declaration ());
                        }
-                       source_type_member_definition.append (type_fun.get_definition ());
+                       codegen.source_type_member_definition.append (type_fun.get_definition ());
                        
-                       if (in_plugin) {
+                       if (codegen.in_plugin) {
                                // FIXME resolve potential dependency issues, i.e. base types have to be registered before derived types
                                var register_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_register_type".printf (cl.get_lower_case_cname (null))));
-                               register_call.add_argument (new CCodeIdentifier (module_init_param_name));
-                               module_init_fragment.append (new CCodeExpressionStatement (register_call));
+                               register_call.add_argument (new CCodeIdentifier (codegen.module_init_param_name));
+                               codegen.module_init_fragment.append (new CCodeExpressionStatement (register_call));
                        }
 
                        if (is_fundamental) {
@@ -195,11 +202,11 @@ public class Vala.CCodeGenerator {
                                unref_fun.add_parameter (new CCodeFormalParameter ("instance", "gpointer"));
 
                                if (cl.access != SymbolAccessibility.PRIVATE) {
-                                       header_type_member_declaration.append (ref_fun.copy ());
-                                       header_type_member_declaration.append (unref_fun.copy ());
+                                       codegen.header_type_member_declaration.append (ref_fun.copy ());
+                                       codegen.header_type_member_declaration.append (unref_fun.copy ());
                                } else {
-                                       source_type_member_declaration.append (ref_fun.copy ());
-                                       source_type_member_declaration.append (unref_fun.copy ());
+                                       codegen.source_type_member_declaration.append (ref_fun.copy ());
+                                       codegen.source_type_member_declaration.append (unref_fun.copy ());
                                }
 
                                var ref_block = new CCodeBlock ();
@@ -236,8 +243,8 @@ public class Vala.CCodeGenerator {
                                ref_fun.block = ref_block;
                                unref_fun.block = unref_block;
 
-                               source_type_member_definition.append (ref_fun);
-                               source_type_member_definition.append (unref_fun);
+                               codegen.source_type_member_definition.append (ref_fun);
+                               codegen.source_type_member_definition.append (unref_fun);
                        }
                } else if (!cl.is_static) {
                        var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
@@ -248,14 +255,14 @@ public class Vala.CCodeGenerator {
                        function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
 
                        if (cl.access != SymbolAccessibility.PRIVATE) {
-                               header_type_member_declaration.append (function.copy ());
+                               codegen.header_type_member_declaration.append (function.copy ());
                        } else {
-                               source_type_member_declaration.append (function.copy ());
+                               codegen.source_type_member_declaration.append (function.copy ());
                        }
 
                        var cblock = new CCodeBlock ();
 
-                       cblock.add_statement (instance_dispose_fragment);
+                       cblock.add_statement (codegen.instance_dispose_fragment);
 
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
                        ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
@@ -264,18 +271,18 @@ public class Vala.CCodeGenerator {
 
                        function.block = cblock;
 
-                       source_type_member_definition.append (function);
+                       codegen.source_type_member_definition.append (function);
                }
 
-               current_type_symbol = old_type_symbol;
-               current_class = old_class;
-               instance_struct = old_instance_struct;
-               type_struct = old_type_struct;
-               instance_priv_struct = old_instance_priv_struct;
-               prop_enum = old_prop_enum;
-               class_init_fragment = old_class_init_fragment;
-               instance_init_fragment = old_instance_init_fragment;
-               instance_dispose_fragment = old_instance_dispose_fragment;
+               codegen.current_type_symbol = old_type_symbol;
+               codegen.current_class = old_class;
+               codegen.instance_struct = old_instance_struct;
+               codegen.type_struct = old_type_struct;
+               codegen.instance_priv_struct = old_instance_priv_struct;
+               codegen.prop_enum = old_prop_enum;
+               codegen.class_init_fragment = old_class_init_fragment;
+               codegen.instance_init_fragment = old_instance_init_fragment;
+               codegen.instance_dispose_fragment = old_instance_dispose_fragment;
        }
        
        private void add_class_init_function (Class cl) {
@@ -294,7 +301,7 @@ public class Vala.CCodeGenerator {
                parent_var_decl.initializer = new CCodeConstant ("NULL");
                parent_decl.add_declarator (parent_var_decl);
                parent_decl.modifiers = CCodeModifiers.STATIC;
-               source_type_member_declaration.append (parent_decl);
+               codegen.source_type_member_declaration.append (parent_decl);
                ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_peek_parent"));
                ccall.add_argument (new CCodeIdentifier ("klass"));
                var parent_assignment = new CCodeAssignment (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))), ccall);
@@ -308,7 +315,7 @@ public class Vala.CCodeGenerator {
                        init_block.add_statement (new CCodeExpressionStatement (ccall));
                }
 
-               if (cl.is_subtype_of (gobject_type)) {
+               if (cl.is_subtype_of (codegen.gobject_type)) {
                        /* set property handlers */
                        ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
                        ccall.add_argument (new CCodeIdentifier ("klass"));
@@ -346,7 +353,7 @@ public class Vala.CCodeGenerator {
                        init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccast, m.base_method.vfunc_name), new CCodeIdentifier (m.get_real_cname ()))));
                }
 
-               if (cl.is_subtype_of (gobject_type)) {
+               if (cl.is_subtype_of (codegen.gobject_type)) {
                        /* create type, dup_func, and destroy_func properties for generic types */
                        foreach (TypeParameter type_param in cl.get_type_parameters ()) {
                                string func_name, enum_value;
@@ -367,9 +374,9 @@ public class Vala.CCodeGenerator {
                                cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
                                cinst.add_argument (cspec);
                                init_block.add_statement (new CCodeExpressionStatement (cinst));
-                               prop_enum.add_value (new CCodeEnumValue (enum_value));
+                               codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
 
-                               instance_priv_struct.add_field ("GType", func_name);
+                               codegen.instance_priv_struct.add_field ("GType", func_name);
 
 
                                func_name = "%s_dup_func".printf (type_param.name.down ());
@@ -385,9 +392,9 @@ public class Vala.CCodeGenerator {
                                cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
                                cinst.add_argument (cspec);
                                init_block.add_statement (new CCodeExpressionStatement (cinst));
-                               prop_enum.add_value (new CCodeEnumValue (enum_value));
+                               codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
 
-                               instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
+                               codegen.instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
 
 
                                func_name = "%s_destroy_func".printf (type_param.name.down ());
@@ -403,9 +410,9 @@ public class Vala.CCodeGenerator {
                                cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
                                cinst.add_argument (cspec);
                                init_block.add_statement (new CCodeExpressionStatement (cinst));
-                               prop_enum.add_value (new CCodeEnumValue (enum_value));
+                               codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
 
-                               instance_priv_struct.add_field ("GDestroyNotify", func_name);
+                               codegen.instance_priv_struct.add_field ("GDestroyNotify", func_name);
                        }
 
                        /* create properties */
@@ -443,9 +450,9 @@ public class Vala.CCodeGenerator {
                        }
                }
 
-               init_block.add_statement (class_init_fragment);
+               init_block.add_statement (codegen.class_init_fragment);
                
-               source_type_member_definition.append (class_init);
+               codegen.source_type_member_definition.append (class_init);
        }
        
        private void add_interface_init_function (Class cl, Interface iface) {
@@ -465,7 +472,7 @@ public class Vala.CCodeGenerator {
                parent_var_decl.initializer = new CCodeConstant ("NULL");
                parent_decl.add_declarator (parent_var_decl);
                parent_decl.modifiers = CCodeModifiers.STATIC;
-               source_type_member_declaration.append (parent_decl);
+               codegen.source_type_member_declaration.append (parent_decl);
                ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_peek_parent"));
                ccall.add_argument (new CCodeIdentifier ("iface"));
                var parent_assignment = new CCodeAssignment (new CCodeIdentifier (parent_iface_var), ccall);
@@ -490,7 +497,7 @@ public class Vala.CCodeGenerator {
                        init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ciface, m.base_interface_method.vfunc_name), new CCodeIdentifier (cname))));
                }
                
-               source_type_member_definition.append (iface_init);
+               codegen.source_type_member_definition.append (iface_init);
        }
        
        private void add_instance_init_function (Class cl) {
@@ -507,7 +514,7 @@ public class Vala.CCodeGenerator {
                        init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), ccall)));
                }
                
-               init_block.add_statement (instance_init_fragment);
+               init_block.add_statement (codegen.instance_init_fragment);
                
                var init_sym = cl.scope.lookup ("init");
                if (init_sym != null) {
@@ -515,16 +522,16 @@ public class Vala.CCodeGenerator {
                        init_block.add_statement (init_fun.body.ccodenode);
                }
                
-               source_type_member_definition.append (instance_init);
+               codegen.source_type_member_definition.append (instance_init);
        }
        
        private void add_dispose_function (Class cl) {
-               function = new CCodeFunction ("%s_dispose".printf (cl.get_lower_case_cname (null)), "void");
+               var function = new CCodeFunction ("%s_dispose".printf (cl.get_lower_case_cname (null)), "void");
                function.modifiers = CCodeModifiers.STATIC;
                
                function.add_parameter (new CCodeFormalParameter ("obj", "GObject *"));
                
-               source_type_member_declaration.append (function.copy ());
+               codegen.source_type_member_declaration.append (function.copy ());
 
 
                var cblock = new CCodeBlock ();
@@ -540,7 +547,7 @@ public class Vala.CCodeGenerator {
                        cblock.add_statement ((CCodeBlock) cl.destructor.body.ccodenode);
                }
 
-               cblock.add_statement (instance_dispose_fragment);
+               cblock.add_statement (codegen.instance_dispose_fragment);
 
                // chain up to dispose function of the base class
                var ccast = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
@@ -552,15 +559,7 @@ public class Vala.CCodeGenerator {
 
                function.block = cblock;
 
-               source_type_member_definition.append (function);
-       }
-       
-       public CCodeIdentifier get_value_setter_function (DataType type_reference) {
-               if (type_reference.data_type != null) {
-                       return new CCodeIdentifier (type_reference.data_type.get_set_value_function ());
-               } else {
-                       return new CCodeIdentifier ("g_value_set_pointer");
-               }
+               codegen.source_type_member_definition.append (function);
        }
 
        private bool class_has_readable_properties (Class cl) {
@@ -633,7 +632,7 @@ public class Vala.CCodeGenerator {
 
                get_prop.block = block;
                
-               source_type_member_definition.append (get_prop);
+               codegen.source_type_member_definition.append (get_prop);
        }
        
        private void add_set_property_function (Class cl) {
@@ -730,7 +729,7 @@ public class Vala.CCodeGenerator {
 
                set_prop.block = block;
                
-               source_type_member_definition.append (set_prop);
+               codegen.source_type_member_definition.append (set_prop);
        }
 
        private CCodeStatement get_invalid_property_id_warn_statement () {
index 6776aeb..d8e0bcf 100644 (file)
@@ -30,52 +30,52 @@ using Gee;
 public class Vala.CCodeGenerator : CodeGenerator {
        private CodeContext context;
        
-       Symbol root_symbol;
-       Symbol current_symbol;
+       public Symbol root_symbol;
+       public Symbol current_symbol;
        public Typesymbol current_type_symbol;
        public Class current_class;
-       Method current_method;
-       DataType current_return_type;
-       TryStatement current_try;
-       PropertyAccessor current_property_accessor;
-
-       CCodeFragment header_begin;
-       CCodeFragment header_type_declaration;
-       CCodeFragment header_type_definition;
-       CCodeFragment header_type_member_declaration;
-       CCodeFragment header_constant_declaration;
-       CCodeFragment source_begin;
-       CCodeFragment source_include_directives;
-       CCodeFragment source_type_declaration;
-       CCodeFragment source_type_definition;
+       public Method current_method;
+       public DataType current_return_type;
+       public TryStatement current_try;
+       public PropertyAccessor current_property_accessor;
+
+       public CCodeFragment header_begin;
+       public CCodeFragment header_type_declaration;
+       public CCodeFragment header_type_definition;
+       public CCodeFragment header_type_member_declaration;
+       public CCodeFragment header_constant_declaration;
+       public CCodeFragment source_begin;
+       public CCodeFragment source_include_directives;
+       public CCodeFragment source_type_declaration;
+       public CCodeFragment source_type_definition;
        public CCodeFragment source_type_member_declaration;
-       CCodeFragment source_constant_declaration;
-       CCodeFragment source_signal_marshaller_declaration;
+       public CCodeFragment source_constant_declaration;
+       public CCodeFragment source_signal_marshaller_declaration;
        public CCodeFragment source_type_member_definition;
-       CCodeFragment class_init_fragment;
-       CCodeFragment instance_init_fragment;
-       CCodeFragment instance_dispose_fragment;
-       CCodeFragment source_signal_marshaller_definition;
-       CCodeFragment module_init_fragment;
+       public CCodeFragment class_init_fragment;
+       public CCodeFragment instance_init_fragment;
+       public CCodeFragment instance_dispose_fragment;
+       public CCodeFragment source_signal_marshaller_definition;
+       public CCodeFragment module_init_fragment;
        
-       CCodeStruct instance_struct;
-       CCodeStruct type_struct;
-       CCodeStruct instance_priv_struct;
-       CCodeEnum prop_enum;
-       CCodeEnum cenum;
-       CCodeFunction function;
-       CCodeBlock block;
+       public CCodeStruct instance_struct;
+       public CCodeStruct type_struct;
+       public CCodeStruct instance_priv_struct;
+       public CCodeEnum prop_enum;
+       public CCodeEnum cenum;
+       public CCodeFunction function;
+       public CCodeBlock block;
        
        /* all temporary variables */
        public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
        /* temporary variables that own their content */
-       ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
+       public ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
        /* cache to check whether a certain marshaller has been created yet */
-       Gee.Set<string> user_marshal_set;
+       public Gee.Set<string> user_marshal_set;
        /* (constant) hash table with all predefined marshallers */
-       Gee.Set<string> predefined_marshal_set;
+       public Gee.Set<string> predefined_marshal_set;
        /* (constant) hash table with all C keywords */
-       Gee.Set<string> c_keywords;
+       public Gee.Set<string> c_keywords;
        
        private int next_temp_var_id = 0;
        private int current_try_id = 0;
@@ -117,8 +117,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
 
        Method substring_method;
 
-       private bool in_plugin = false;
-       private string module_init_param_name;
+       public bool in_plugin = false;
+       public string module_init_param_name;
        
        private bool string_h_needed;
        private bool requires_free_checked;
@@ -269,6 +269,14 @@ public class Vala.CCodeGenerator : CodeGenerator {
                }
        }
 
+       public override void visit_class (Class cl) {
+               code_binding (cl).emit ();
+       }
+
+       public override void visit_interface (Interface iface) {
+               code_binding (iface).emit ();
+       }
+
        public override void visit_enum (Enum en) {
                cenum = new CCodeEnum (en.get_cname ());
 
@@ -3570,7 +3578,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        public override CodeBinding? create_class_binding (Class node) {
-               return null;
+               return new CCodeClassBinding (this, node);
        }
 
        public override CodeBinding? create_struct_binding (Struct node) {
@@ -3578,7 +3586,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        public override CodeBinding? create_interface_binding (Interface node) {
-               return null;
+               return new CCodeInterfaceBinding (this, node);
        }
 
        public override CodeBinding? create_enum_binding (Enum node) {
diff --git a/gobject/valaccodeinterfacebinding.vala b/gobject/valaccodeinterfacebinding.vala
new file mode 100644 (file)
index 0000000..c4009cc
--- /dev/null
@@ -0,0 +1,137 @@
+/* valaccodeinterfacebinding.vala
+ *
+ * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ *     Raffaele Sandrini <raffaele@sandrini.ch>
+ */
+
+using GLib;
+
+public class Vala.CCodeInterfaceBinding : CCodeTypesymbolBinding {
+       public Interface iface { get; set; }
+
+       public CCodeInterfaceBinding (CCodeGenerator codegen, Interface iface) {
+               this.iface = iface;
+               this.codegen = codegen;
+       }
+
+       public override void emit () {
+               codegen.current_symbol = iface;
+               codegen.current_type_symbol = iface;
+
+               if (iface.get_cname().len () < 3) {
+                       iface.error = true;
+                       Report.error (iface.source_reference, "Interface name `%s' is too short".printf (iface.get_cname ()));
+                       return;
+               }
+
+               CCodeFragment decl_frag;
+               CCodeFragment def_frag;
+               if (iface.access != SymbolAccessibility.PRIVATE) {
+                       decl_frag = codegen.header_type_declaration;
+                       def_frag = codegen.header_type_definition;
+               } else {
+                       decl_frag = codegen.source_type_declaration;
+                       def_frag = codegen.source_type_definition;
+               }
+
+               if (!iface.is_static && !iface.declaration_only) {
+                       codegen.type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
+                       
+                       decl_frag.append (new CCodeNewline ());
+                       var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
+                       decl_frag.append (new CCodeMacroReplacement (iface.get_upper_case_cname ("TYPE_"), macro));
+
+                       macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
+                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
+
+                       macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
+                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
+
+                       macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_type_cname ());
+                       decl_frag.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
+                       decl_frag.append (new CCodeNewline ());
+
+
+                       if (iface.source_reference.file.cycle == null) {
+                               decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
+                               decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
+                       }
+                       
+                       codegen.type_struct.add_field ("GTypeInterface", "parent_iface");
+
+                       if (iface.source_reference.comment != null) {
+                               def_frag.append (new CCodeComment (iface.source_reference.comment));
+                       }
+                       def_frag.append (codegen.type_struct);
+               }
+
+               iface.accept_children (codegen);
+
+               if (!iface.is_static && !iface.declaration_only) {
+                       add_interface_base_init_function (iface);
+
+                       var type_fun = new InterfaceRegisterFunction (iface);
+                       type_fun.init_from_type ();
+                       if (iface.access != SymbolAccessibility.PRIVATE) {
+                               codegen.header_type_member_declaration.append (type_fun.get_declaration ());
+                       } else {
+                               codegen.source_type_member_declaration.append (type_fun.get_declaration ());
+                       }
+                       codegen.source_type_member_definition.append (type_fun.get_definition ());
+               }
+
+               codegen.current_type_symbol = null;
+       }
+
+       private void add_interface_base_init_function (Interface iface) {
+               var base_init = new CCodeFunction ("%s_base_init".printf (iface.get_lower_case_cname (null)), "void");
+               base_init.add_parameter (new CCodeFormalParameter ("iface", "%sIface *".printf (iface.get_cname ())));
+               base_init.modifiers = CCodeModifiers.STATIC;
+               
+               var init_block = new CCodeBlock ();
+               
+               /* make sure not to run the initialization code twice */
+               base_init.block = new CCodeBlock ();
+               var decl = new CCodeDeclaration (codegen.bool_type.get_cname ());
+               decl.modifiers |= CCodeModifiers.STATIC;
+               decl.add_declarator (new CCodeVariableDeclarator.with_initializer ("initialized", new CCodeConstant ("FALSE")));
+               base_init.block.add_statement (decl);
+               var cif = new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("initialized")), init_block);
+               base_init.block.add_statement (cif);
+               init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("initialized"), new CCodeConstant ("TRUE"))));
+               
+               /* create properties */
+               var props = iface.get_properties ();
+               foreach (Property prop in props) {
+                       var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_interface_install_property"));
+                       cinst.add_argument (new CCodeIdentifier ("iface"));
+                       cinst.add_argument (get_param_spec (prop));
+
+                       init_block.add_statement (new CCodeExpressionStatement (cinst));
+               }
+               
+               /* create signals */
+               foreach (Signal sig in iface.get_signals ()) {
+                       init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, iface)));
+               }
+               
+               codegen.source_type_member_definition.append (base_init);
+       }
+}
similarity index 57%
rename from gobject/valaccodegeneratorinterface.vala
rename to gobject/valaccodetypesymbolbinding.vala
index 069746d..c551323 100644 (file)
@@ -1,6 +1,6 @@
-/* valaccodegeneratorinterface.vala
+/* valaccodetypesymbolbinding.vala
  *
- * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2008  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 
 using GLib;
 
-public class Vala.CCodeGenerator {
-       public override void visit_interface (Interface iface) {
-               current_symbol = iface;
-               current_type_symbol = iface;
-
-               if (iface.get_cname().len () < 3) {
-                       iface.error = true;
-                       Report.error (iface.source_reference, "Interface name `%s' is too short".printf (iface.get_cname ()));
-                       return;
-               }
-
-               CCodeFragment decl_frag;
-               CCodeFragment def_frag;
-               if (iface.access != SymbolAccessibility.PRIVATE) {
-                       decl_frag = header_type_declaration;
-                       def_frag = header_type_definition;
-               } else {
-                       decl_frag = source_type_declaration;
-                       def_frag = source_type_definition;
-               }
-
-               if (!iface.is_static && !iface.declaration_only) {
-                       type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
-                       
-                       decl_frag.append (new CCodeNewline ());
-                       var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
-                       decl_frag.append (new CCodeMacroReplacement (iface.get_upper_case_cname ("TYPE_"), macro));
-
-                       macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
-                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
-
-                       macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
-                       decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
-
-                       macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_type_cname ());
-                       decl_frag.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
-                       decl_frag.append (new CCodeNewline ());
-
-
-                       if (iface.source_reference.file.cycle == null) {
-                               decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
-                               decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
-                       }
-                       
-                       type_struct.add_field ("GTypeInterface", "parent_iface");
-
-                       if (iface.source_reference.comment != null) {
-                               def_frag.append (new CCodeComment (iface.source_reference.comment));
-                       }
-                       def_frag.append (type_struct);
-               }
-
-               iface.accept_children (this);
-
-               if (!iface.is_static && !iface.declaration_only) {
-                       add_interface_base_init_function (iface);
-
-                       var type_fun = new InterfaceRegisterFunction (iface);
-                       type_fun.init_from_type ();
-                       if (iface.access != SymbolAccessibility.PRIVATE) {
-                               header_type_member_declaration.append (type_fun.get_declaration ());
-                       } else {
-                               source_type_member_declaration.append (type_fun.get_declaration ());
-                       }
-                       source_type_member_definition.append (type_fun.get_definition ());
-               }
-
-               current_type_symbol = null;
-       }
-       
-       private CCodeFunctionCall get_param_spec (Property prop) {
+public abstract class Vala.CCodeTypesymbolBinding : CCodeBinding {
+       public CCodeFunctionCall get_param_spec (Property prop) {
                var cspec = new CCodeFunctionCall ();
                cspec.add_argument (prop.get_canonical_cconstant ());
                cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
                cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.blurb)));
-               if ((prop.type_reference.data_type is Class && ((Class) prop.type_reference.data_type).is_subtype_of (gobject_type)) || prop.type_reference.data_type is Interface) {
+               if ((prop.type_reference.data_type is Class && ((Class) prop.type_reference.data_type).is_subtype_of (codegen.gobject_type)) || prop.type_reference.data_type is Interface) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_object");
                        cspec.add_argument (new CCodeIdentifier (prop.type_reference.data_type.get_upper_case_cname ("TYPE_")));
-               } else if (prop.type_reference.data_type == string_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.string_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_string");
                        cspec.add_argument (new CCodeConstant ("NULL"));
                } else if (prop.type_reference.data_type is Enum) {
@@ -130,7 +61,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant (prop.type_reference.data_type.get_default_value ()));
                        }
-               } else if (prop.type_reference.data_type == int_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.int_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_int");
                        cspec.add_argument (new CCodeConstant ("G_MININT"));
                        cspec.add_argument (new CCodeConstant ("G_MAXINT"));
@@ -139,7 +70,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0"));
                        }
-               } else if (prop.type_reference.data_type == uint_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.uint_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_uint");
                        cspec.add_argument (new CCodeConstant ("0"));
                        cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
@@ -148,7 +79,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0U"));
                        }
-               } else if (prop.type_reference.data_type == long_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.long_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_long");
                        cspec.add_argument (new CCodeConstant ("G_MINLONG"));
                        cspec.add_argument (new CCodeConstant ("G_MAXLONG"));
@@ -157,7 +88,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0L"));
                        }
-               } else if (prop.type_reference.data_type == ulong_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.ulong_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_ulong");
                        cspec.add_argument (new CCodeConstant ("0"));
                        cspec.add_argument (new CCodeConstant ("G_MAXULONG"));
@@ -166,14 +97,14 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0UL"));
                        }
-               } else if (prop.type_reference.data_type == bool_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.bool_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_boolean");
                        if (prop.default_expression != null) {
                                cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
                        } else {
                                cspec.add_argument (new CCodeConstant ("FALSE"));
                        }
-               } else if (prop.type_reference.data_type == float_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.float_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_float");
                        cspec.add_argument (new CCodeConstant ("-G_MAXFLOAT"));
                        cspec.add_argument (new CCodeConstant ("G_MAXFLOAT"));
@@ -182,7 +113,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0.0F"));
                        }
-               } else if (prop.type_reference.data_type == double_type.data_type) {
+               } else if (prop.type_reference.data_type == codegen.double_type.data_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_double");
                        cspec.add_argument (new CCodeConstant ("-G_MAXDOUBLE"));
                        cspec.add_argument (new CCodeConstant ("G_MAXDOUBLE"));
@@ -191,7 +122,7 @@ public class Vala.CCodeGenerator {
                        } else {
                                cspec.add_argument (new CCodeConstant ("0.0"));
                        }
-               } else if (prop.type_reference.data_type == gtype_type) {
+               } else if (prop.type_reference.data_type == codegen.gtype_type) {
                        cspec.call = new CCodeIdentifier ("g_param_spec_gtype");
                        if (prop.default_expression != null) {
                                cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
@@ -221,7 +152,7 @@ public class Vala.CCodeGenerator {
                return cspec;
        }
 
-       private CCodeFunctionCall get_signal_creation (Signal sig, Typesymbol type) {   
+       public CCodeFunctionCall get_signal_creation (Signal sig, Typesymbol type) {    
                var csignew = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_new"));
                csignew.add_argument (new CCodeConstant ("\"%s\"".printf (sig.name)));
                csignew.add_argument (new CCodeIdentifier (type.get_upper_case_cname ("TYPE_")));
@@ -230,7 +161,7 @@ public class Vala.CCodeGenerator {
                csignew.add_argument (new CCodeConstant ("NULL"));
                csignew.add_argument (new CCodeConstant ("NULL"));
 
-               string marshaller = get_signal_marshaller_function (sig);
+               string marshaller = codegen.get_signal_marshaller_function (sig);
 
                var marshal_arg = new CCodeIdentifier (marshaller);
                csignew.add_argument (marshal_arg);
@@ -261,39 +192,4 @@ public class Vala.CCodeGenerator {
 
                return csignew;
        }
-
-       private void add_interface_base_init_function (Interface iface) {
-               var base_init = new CCodeFunction ("%s_base_init".printf (iface.get_lower_case_cname (null)), "void");
-               base_init.add_parameter (new CCodeFormalParameter ("iface", "%sIface *".printf (iface.get_cname ())));
-               base_init.modifiers = CCodeModifiers.STATIC;
-               
-               var init_block = new CCodeBlock ();
-               
-               /* make sure not to run the initialization code twice */
-               base_init.block = new CCodeBlock ();
-               var decl = new CCodeDeclaration (bool_type.get_cname ());
-               decl.modifiers |= CCodeModifiers.STATIC;
-               decl.add_declarator (new CCodeVariableDeclarator.with_initializer ("initialized", new CCodeConstant ("FALSE")));
-               base_init.block.add_statement (decl);
-               var cif = new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("initialized")), init_block);
-               base_init.block.add_statement (cif);
-               init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("initialized"), new CCodeConstant ("TRUE"))));
-               
-               /* create properties */
-               var props = iface.get_properties ();
-               foreach (Property prop in props) {
-                       var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_interface_install_property"));
-                       cinst.add_argument (new CCodeIdentifier ("iface"));
-                       cinst.add_argument (get_param_spec (prop));
-
-                       init_block.add_statement (new CCodeExpressionStatement (cinst));
-               }
-               
-               /* create signals */
-               foreach (Signal sig in iface.get_signals ()) {
-                       init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, iface)));
-               }
-               
-               source_type_member_definition.append (base_init);
-       }
 }
index 5b504ad..4dfb60d 100644 (file)
@@ -696,5 +696,9 @@ public class Vala.Class : Typesymbol {
                        }
                }
        }
+
+       public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+               return codegen.create_class_binding (this);
+       }
 }
 
index 74a2826..7c1b3ed 100644 (file)
@@ -486,4 +486,8 @@ public class Vala.Interface : Typesymbol {
                        }
                }
        }
+
+       public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+               return codegen.create_interface_binding (this);
+       }
 }