From: Jürg Billeter Date: Thu, 3 Sep 2009 09:20:45 +0000 (+0200) Subject: Support creation method chain up to g_object_new X-Git-Tag: 0.7.6~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03069e255ccd9dcfe9851343bf5b17eb20477176;p=thirdparty%2Fvala.git Support creation method chain up to g_object_new --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 11324a50a..ed3ef180f 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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); } diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index 35dedf27e..e4785ff46 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -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") { diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 4680889cf..0d2190296 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -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"); } diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi index f1cd48743..f37adf97e 100644 --- a/vapi/gobject-2.0.vapi +++ b/vapi/gobject-2.0.vapi @@ -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, ...);