]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support creation method chain up to g_object_new
authorJürg Billeter <j@bitron.ch>
Thu, 3 Sep 2009 09:20:45 +0000 (11:20 +0200)
committerJürg Billeter <j@bitron.ch>
Thu, 3 Sep 2009 09:22:42 +0000 (11:22 +0200)
codegen/valaccodebasemodule.vala
vala/valacreationmethod.vala
vala/valamethod.vala
vapi/gobject-2.0.vapi

index 11324a50a28eaafc9f9f1cf24d7e6157666ceab5..ed3ef180fd9d5676b18c41cc5dd05c429ac82f96 100644 (file)
@@ -3174,7 +3174,15 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
                        generate_method_declaration (m, source_declarations);
 
-                       creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
+                       var cl = expr.type_reference.data_type as Class;
+
+                       if (!m.has_new_function) {
+                               // use construct function directly
+                               creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+                               creation_call.add_argument (new CCodeIdentifier (cl.get_type_id ()));
+                       } else {
+                               creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
+                       }
 
                        if ((st != null && !st.is_simple_type ()) && !(m.cinstance_parameter_position < 0)) {
                                creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
@@ -3182,7 +3190,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
                        generate_type_declaration (expr.type_reference, source_declarations);
 
-                       var cl = expr.type_reference.data_type as Class;
                        if (cl != null && !cl.is_compact) {
                                add_generic_type_arguments (creation_call, expr.type_reference.get_type_arguments (), expr);
                        }
index 35dedf27e5f41a5dbe005ca14ca837f039ed8af4..e4785ff461c4619248ddbb71717476506b70c16c 100644 (file)
@@ -107,6 +107,11 @@ public class Vala.CreationMethod : Method {
                        return get_cname ();
                }
 
+               var ccode_attribute = get_attribute ("CCode");
+               if (ccode_attribute != null && ccode_attribute.has_argument ("construct_function")) {
+                       return ccode_attribute.get_string ("construct_function");
+               }
+
                string infix = "construct";
 
                if (name == ".new") {
index 4680889cf6523a844e42d447ecac46455fd3f569..0d2190296345618c17051220f50d1abc721a3b3b 100644 (file)
@@ -204,6 +204,12 @@ public class Vala.Method : Member {
         */
        public bool scanf_format { get; set; }
 
+       /**
+        * Specifies whether a new function without a GType parameter is
+        * available. This is only applicable to creation methods.
+        */
+       public bool has_new_function { get; set; default = true; }
+
        /**
         * Specifies whether a construct function with a GType parameter is
         * available. This is only applicable to creation methods.
@@ -396,6 +402,9 @@ public class Vala.Method : Member {
                if (a.has_argument ("delegate_target_pos")) {
                        cdelegate_target_parameter_position = a.get_double ("delegate_target_pos");
                }
+               if (a.has_argument ("has_new_function")) {
+                       has_new_function = a.get_bool ("has_new_function");
+               }
                if (a.has_argument ("has_construct_function")) {
                        has_construct_function = a.get_bool ("has_construct_function");
                }
index f1cd4874384ff7a2b335b0d0e7b7cee19df39bc7..f37adf97e2d192690a4ddb247f903e354cf3c6d7 100644 (file)
@@ -175,8 +175,8 @@ namespace GLib {
        public class Object {
                public uint ref_count;
 
-               [CCode (has_construct_function = false)]
-               public Object (Type type = typeof (Object), ...);
+               [CCode (has_new_function = false, construct_function = "g_object_new")]
+               public Object (...);
 
 #if VALA_0_7_6_NEW_METHODS
                public static Object @new (Type type, ...);