]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Improve consistency in constructor chain up handling 8aa6299ea7a39e7a652ce3896324aaa47af99a18
authorJürg Billeter <j@bitron.ch>
Sat, 21 Aug 2010 17:12:16 +0000 (19:12 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 21 Aug 2010 17:13:03 +0000 (19:13 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagobjectmodule.vala
vala/valacreationmethod.vala

index 66b3761ddcd8caa4dd46e740e43b4f7f393a127f..fcfe5c931ac0fc1577c73a12d71cf846d7932f39 100644 (file)
@@ -5715,10 +5715,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                return false;
        }
 
-       public virtual CCodeExpression get_construct_property_assignment (CCodeConstant canonical_cconstant, DataType property_type, CCodeExpression value) {
-               return new CCodeConstant ("");
-       }
-
        public virtual CCodeFunctionCall get_param_spec (Property prop) {
                return new CCodeFunctionCall (new CCodeIdentifier (""));
        }
index 3aff0957e05150346b9627623ef4c3316e569d34..cef50c6f47b1808b244e86be10d266eac846acdb 100644 (file)
@@ -492,47 +492,10 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 
                                if (m is CreationMethod) {
                                        if (in_gobject_creation_method) {
-                                               if (!((CreationMethod) m).chain_up) {
-                                                       if (current_class.get_type_parameters ().size > 0) {
-                                                               // declare construction parameter array
-                                                               var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
-                                                               cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
-                                                               cparamsinit.add_argument (new CCodeConstant ((3 * current_class.get_type_parameters ().size).to_string ()));
-                                               
-                                                               var cdecl = new CCodeDeclaration ("GParameter *");
-                                                               cdecl.add_declarator (new CCodeVariableDeclarator ("__params", cparamsinit));
-                                                               cinit.append (cdecl);
-                                               
-                                                               cdecl = new CCodeDeclaration ("GParameter *");
-                                                               cdecl.add_declarator (new CCodeVariableDeclarator ("__params_it", new CCodeIdentifier ("__params")));
-                                                               cinit.append (cdecl);
-                                                       }
-
-                                                       /* type, dup func, and destroy func properties for generic types */
-                                                       foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
-                                                               CCodeConstant prop_name;
-                                                               CCodeIdentifier param_name;
-
-                                                               prop_name = new CCodeConstant ("\"%s-type\"".printf (type_param.name.down ()));
-                                                               param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.down ()));
-                                                               cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new IntegerType ((Struct) gtype_type), param_name)));
+                                               var cdeclaration = new CCodeDeclaration ("%s *".printf (((Class) current_type_symbol).get_cname ()));
+                                               cdeclaration.add_declarator (new CCodeVariableDeclarator ("self"));
 
-                                                               prop_name = new CCodeConstant ("\"%s-dup-func\"".printf (type_param.name.down ()));
-                                                               param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ()));
-                                                               cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new PointerType (new VoidType ()), param_name)));
-
-                                                               prop_name = new CCodeConstant ("\"%s-destroy-func\"".printf (type_param.name.down ()));
-                                                               param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()));
-                                                               cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new PointerType (new VoidType ()), param_name)));
-                                                       }
-
-                                                       add_object_creation (cinit, current_class.get_type_parameters ().size > 0);
-                                               } else {
-                                                       var cdeclaration = new CCodeDeclaration ("%s *".printf (((Class) current_type_symbol).get_cname ()));
-                                                       cdeclaration.add_declarator (new CCodeVariableDeclarator ("self"));
-
-                                                       cinit.append (cdeclaration);
-                                               }
+                                               cinit.append (cdeclaration);
                                        } else if (is_gtypeinstance_creation_method (m)) {
                                                var cl = (Class) m.parent_symbol;
                                                var cdeclaration = new CCodeDeclaration (cl.get_cname () + "*");
@@ -540,8 +503,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                                                cdeclaration.add_declarator (cdecl);
                                                cinit.append (cdeclaration);
 
-                                               if (!((CreationMethod) m).chain_up) {
-                                                       // TODO implicitly chain up to base class as in add_object_creation
+                                               if (cl.is_fundamental ()) {
                                                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_create_instance"));
                                                        ccall.add_argument (new CCodeIdentifier ("object_type"));
                                                        cdecl.initializer = new CCodeCastExpression (ccall, cl.get_cname () + "*");
@@ -1037,31 +999,6 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                return null;
        }
 
-       private void add_object_creation (CCodeFragment ccode, bool has_params) {
-               var cl = (Class) current_type_symbol;
-
-               if (!has_params && cl.base_class != gobject_type) {
-                       // possibly report warning or error about missing base call
-               }
-
-               var cdecl = new CCodeVariableDeclarator ("self");
-               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
-               ccall.add_argument (new CCodeIdentifier ("object_type"));
-               if (has_params) {
-                       ccall.add_argument (new CCodeConstant ("__params_it - __params"));
-                       ccall.add_argument (new CCodeConstant ("__params"));
-               } else {
-                       ccall.add_argument (new CCodeConstant ("0"));
-                       ccall.add_argument (new CCodeConstant ("NULL"));
-               }
-               cdecl.initializer = ccall;
-               
-               var cdeclaration = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
-               cdeclaration.add_declarator (cdecl);
-               
-               ccode.append (cdeclaration);
-       }
-
        public override void visit_creation_method (CreationMethod m) {
                bool visible = !m.is_private_symbol ();
 
@@ -1102,22 +1039,6 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                        cfile.add_function (vfunc);
                }
 
-               if (current_type_symbol is Class && gobject_type != null && current_class.is_subtype_of (gobject_type)
-                   && 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"))));
-                       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));
-                       function.block.add_statement (new CCodeWhileStatement (ccond, cdofreeparam));
-
-                       var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
-                       cfreeparams.add_argument (new CCodeIdentifier ("__params"));
-                       function.block.add_statement (new CCodeExpressionStatement (cfreeparams));
-               }
-
                if (current_type_symbol is Class) {
                        CCodeExpression cresult = new CCodeIdentifier ("self");
                        if (get_custom_creturn_type (m) != null) {
index 4fe80d3f394a8275ac47b95ee888b202dc2c863b..c2be061fb92c783f219e712462076e2a5e5559ea 100644 (file)
@@ -411,40 +411,6 @@ public class Vala.GObjectModule : GTypeModule {
                return new CCodeExpressionStatement (cwarn);
        }
 
-       public override CCodeExpression get_construct_property_assignment (CCodeConstant canonical_cconstant, DataType property_type, CCodeExpression value) {
-               // this property is used as a construction parameter
-               var cpointer = new CCodeIdentifier ("__params_it");
-               
-               var ccomma = new CCodeCommaExpression ();
-               // set name in array for current parameter
-               var cnamemember = new CCodeMemberAccess.pointer (cpointer, "name");
-               var cnameassign = new CCodeAssignment (cnamemember, canonical_cconstant);
-               ccomma.append_expression (cnameassign);
-               
-               var gvaluearg = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (cpointer, "value"));
-               
-               // initialize GValue in array for current parameter
-               var cvalueinit = new CCodeFunctionCall (new CCodeIdentifier ("g_value_init"));
-               cvalueinit.add_argument (gvaluearg);
-               cvalueinit.add_argument (new CCodeIdentifier (property_type.get_type_id ()));
-               ccomma.append_expression (cvalueinit);
-               
-               // set GValue for current parameter
-               var cvalueset = new CCodeFunctionCall (get_value_setter_function (property_type));
-               cvalueset.add_argument (gvaluearg);
-               if (property_type.is_real_struct_type ()) {
-                       cvalueset.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, value));
-               } else {
-                       cvalueset.add_argument (value);
-               }
-               ccomma.append_expression (cvalueset);
-               
-               // move pointer to next parameter in array
-               ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, cpointer));
-
-               return ccomma;
-       }
-
        public override void visit_constructor (Constructor c) {
                bool old_method_inner_error = current_method_inner_error;
                current_method_inner_error = false;
index 1243be2189fbb5205c3c0b1ebea9cef0248ad55d..01d09fcc7708aad1bb9f434e2037ee03109173cf 100644 (file)
@@ -193,7 +193,17 @@ public class Vala.CreationMethod : Method {
                                if (analyzer.context.profile == Profile.GOBJECT
                                    && cl.base_class.default_construction_method != null
                                    && !cl.base_class.default_construction_method.has_construct_function) {
-                                       // chain up impossible
+                                       // directly chain up to Object
+                                       var old_insert_block = analyzer.insert_block;
+                                       analyzer.current_symbol = body;
+                                       analyzer.insert_block = body;
+
+                                       var stmt = new ExpressionStatement (new MethodCall (new MemberAccess (new MemberAccess.simple ("GLib", source_reference), "Object", source_reference), source_reference), source_reference);
+                                       body.insert_statement (0, stmt);
+                                       stmt.check (analyzer);
+
+                                       analyzer.current_symbol = this;
+                                       analyzer.insert_block = old_insert_block;
                                } else if (cl.base_class.default_construction_method == null
                                    || cl.base_class.default_construction_method.access == SymbolAccessibility.PRIVATE) {
                                        Report.error (source_reference, "unable to chain up to private base constructor");