[vala/wip/attributes: 24/27] codegen: Add get_ccode_param_spec_function



commit 475c7dbfa8750da0da723e34397d2d2d4a491bdd
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 14:54:59 2011 +0200

    codegen: Add get_ccode_param_spec_function

 codegen/valaccodebasemodule.vala |   39 ++++++++++++++++++++++++++++++++++++++
 codegen/valagtypemodule.vala     |    2 +-
 2 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ad41c00..7437046 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5655,6 +5655,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).take_value_function;
 	}
 
+	public static string get_ccode_param_spec_function (CodeNode sym) {
+		return get_ccode_attribute(sym).param_spec_function;
+	}
+
 	public static string get_ccode_type_check_function (TypeSymbol sym) {
 		var cl = sym as Class;
 		var a = sym.get_attribute ("CCode");
@@ -6192,6 +6196,15 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string param_spec_function {
+		get {
+			if (_param_spec_function == null) {
+				_param_spec_function = get_default_param_spec_function ();
+			}
+			return _param_spec_function;
+		}
+	}
+
 	private string _name;
 	private string _const_name;
 	private string _type_name;
@@ -6210,6 +6223,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 	private string _get_value_function;
 	private string _set_value_function;
 	private string _take_value_function;
+	private string _param_spec_function;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -6246,6 +6260,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 			_get_value_function = attr.get_string ("get_value_function");
 			_set_value_function = attr.get_string ("set_value_function");
 			_take_value_function = attr.get_string ("take_value_function");
+			_param_spec_function = attr.get_string ("param_spec_function");
 		}
 	}
 
@@ -6777,4 +6792,28 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 		return "";
 	}
+
+	private string get_default_param_spec_function () {
+		if (sym is Class) {
+			var cl = (Class) sym;
+			if (cl.is_fundamental ()) {
+				return CCodeBaseModule.get_ccode_lower_case_cname (cl, "value_take_");
+			} else if (cl.base_class != null) {
+				return CCodeBaseModule.get_ccode_param_spec_function (cl.base_class);
+			} else if (type_id == "G_TYPE_POINTER") {
+				return "g_param_spec_pointer";
+			} else {
+				return "g_param_spec_boxed";
+			}
+		} else if (sym is Interface) {
+			foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
+				var func = CCodeBaseModule.get_ccode_param_spec_function (prereq.data_type);
+				if (func != "") {
+					return func;
+				}
+			}
+			return "g_param_spec_pointer";
+		}
+		return "";
+	}
 }
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index f02f18e..442281f 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1661,7 +1661,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 
 		if (prop.property_type.data_type is Class || prop.property_type.data_type is Interface) {
-			string param_spec_name = prop.property_type.data_type.get_param_spec_function ();
+			string param_spec_name = get_ccode_param_spec_function (prop.property_type.data_type);
 			cspec.call = new CCodeIdentifier (param_spec_name);
 			if (param_spec_name == "g_param_spec_string") {
 				cspec.add_argument (new CCodeConstant ("NULL"));



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