[vala] Support creation method chain up to g_object_new



commit 03069e255ccd9dcfe9851343bf5b17eb20477176
Author: Jürg Billeter <j bitron ch>
Date:   Thu Sep 3 11:20:45 2009 +0200

    Support creation method chain up to g_object_new

 codegen/valaccodebasemodule.vala |   11 +++++++++--
 vala/valacreationmethod.vala     |    5 +++++
 vala/valamethod.vala             |    9 +++++++++
 vapi/gobject-2.0.vapi            |    4 ++--
 4 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 11324a5..ed3ef18 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 35dedf2..e4785ff 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 4680889..0d21902 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -205,6 +205,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 f1cd487..f37adf9 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, ...);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]