vala r2235 - in trunk: . gobject vala vapi



Author: juergbi
Date: Sun Dec 21 12:05:24 2008
New Revision: 2235
URL: http://svn.gnome.org/viewvc/vala?rev=2235&view=rev

Log:
2008-12-21  JÃrg Billeter  <j bitron ch>

	* vala/valastruct.vala:
	* gobject/valaccodebasemodule.vala:
	* gobject/valagobjectmodule.vala:
	* vapi/glib-2.0.vapi:

	Support boxed structs as GObject properties,
	based on patch by Ãtienne Bersac, fixes bug 520001


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/gobject/valagobjectmodule.vala
   trunk/vala/valastruct.vala
   trunk/vapi/glib-2.0.vapi

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Sun Dec 21 12:05:24 2008
@@ -1078,19 +1078,6 @@
 
 		next_temp_var_id = old_next_temp_var_id;
 		variable_name_map = old_variable_name_map;
-
-		var cl = prop.parent_symbol as Class;
-		if (cl != null && cl.is_subtype_of (gobject_type)
-		    && prop.binding == MemberBinding.INSTANCE) {
-			// GObject property
-			// FIXME: omit real struct types for now since they
-			// cannot be expressed as gobject property yet
-			// don't register private properties
-			if (!prop.property_type.is_real_struct_type ()
-			    && prop.access != SymbolAccessibility.PRIVATE) {
-				prop_enum.add_value (new CCodeEnumValue (prop.get_upper_case_cname ()));
-			}
-		}
 	}
 
 	public override void visit_property_accessor (PropertyAccessor acc) {

Modified: trunk/gobject/valagobjectmodule.vala
==============================================================================
--- trunk/gobject/valagobjectmodule.vala	(original)
+++ trunk/gobject/valagobjectmodule.vala	Sun Dec 21 12:05:24 2008
@@ -946,15 +946,16 @@
 			/* create properties */
 			var props = cl.get_properties ();
 			foreach (Property prop in props) {
-				// FIXME: omit real struct types for now since they cannot be expressed as gobject property yet
-				if (prop.property_type.is_real_struct_type ()) {
-					continue;
-				}
 				if (prop.access == SymbolAccessibility.PRIVATE) {
 					// don't register private properties
 					continue;
 				}
 
+				var st = prop.property_type.data_type as Struct;
+				if (st != null && !st.has_type_id) {
+					continue;
+				}
+
 				if (prop.overrides || prop.base_interface_property != null) {
 					var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_class_override_property"));
 					cinst.add_argument (ccall);
@@ -1252,12 +1253,15 @@
 		var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
 		cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall));
 		block.add_statement (cdecl);
-		
+
+		cdecl = new CCodeDeclaration ("gpointer");
+		cdecl.add_declarator (new CCodeVariableDeclarator ("boxed"));
+		block.add_statement (cdecl);
+
 		var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
 		var props = cl.get_properties ();
 		foreach (Property prop in props) {
-			// FIXME: omit real struct types for now since they cannot be expressed as gobject property yet
-			if (prop.get_accessor == null || prop.is_abstract || prop.property_type.is_real_struct_type ()) {
+			if (prop.get_accessor == null || prop.is_abstract) {
 				continue;
 			}
 			if (prop.access == SymbolAccessibility.PRIVATE) {
@@ -1265,6 +1269,11 @@
 				continue;
 			}
 
+			var st = prop.property_type.data_type as Struct;
+			if (st != null && !st.has_type_id) {
+				continue;
+			}
+
 			string prefix = cl.get_lower_case_cname (null);
 			CCodeExpression cself = new CCodeIdentifier ("self");
 			if (prop.base_property != null) {
@@ -1278,13 +1287,27 @@
 			}
 
 			cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
-			ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (prefix, prop.name)));
-			ccall.add_argument (cself);
-			var csetcall = new CCodeFunctionCall ();
-			csetcall.call = head.get_value_setter_function (prop.property_type);
-			csetcall.add_argument (new CCodeIdentifier ("value"));
-			csetcall.add_argument (ccall);
-			cswitch.add_statement (new CCodeExpressionStatement (csetcall));
+			if (prop.property_type.is_real_struct_type ()) {
+				var struct_creation = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
+				struct_creation.add_argument (new CCodeIdentifier (st.get_cname ()));
+				struct_creation.add_argument (new CCodeConstant ("1"));
+				cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("boxed"), struct_creation)));
+				ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (prefix, prop.name)));
+				ccall.add_argument (cself);
+				ccall.add_argument (new CCodeIdentifier ("boxed"));
+				var csetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_boxed"));
+				csetcall.add_argument (new CCodeIdentifier ("value"));
+				csetcall.add_argument (new CCodeIdentifier ("boxed"));
+				cswitch.add_statement (new CCodeExpressionStatement (csetcall));
+			} else {
+				ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (prefix, prop.name)));
+				ccall.add_argument (cself);
+				var csetcall = new CCodeFunctionCall ();
+				csetcall.call = head.get_value_setter_function (prop.property_type);
+				csetcall.add_argument (new CCodeIdentifier ("value"));
+				csetcall.add_argument (ccall);
+				cswitch.add_statement (new CCodeExpressionStatement (csetcall));
+			}
 			cswitch.add_statement (new CCodeBreakStatement ());
 		}
 		cswitch.add_statement (new CCodeLabel ("default"));
@@ -1316,8 +1339,7 @@
 		var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
 		var props = cl.get_properties ();
 		foreach (Property prop in props) {
-			// FIXME: omit real struct types for now since they cannot be expressed as gobject property yet
-			if (prop.set_accessor == null || prop.is_abstract || prop.property_type.is_real_struct_type ()) {
+			if (prop.set_accessor == null || prop.is_abstract) {
 				continue;
 			}
 			if (prop.access == SymbolAccessibility.PRIVATE) {
@@ -1325,6 +1347,11 @@
 				continue;
 			}
 
+			var st = prop.property_type.data_type as Struct;
+			if (st != null && !st.has_type_id) {
+				continue;
+			}
+
 			string prefix = cl.get_lower_case_cname (null);
 			CCodeExpression cself = new CCodeIdentifier ("self");
 			if (prop.base_property != null) {
@@ -1417,7 +1444,7 @@
 			if (param_spec_name == null) {
 				cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
 			} else {
-				cspec.call = new CCodeIdentifier ( param_spec_name );
+				cspec.call = new CCodeIdentifier (param_spec_name);
 				cspec.add_argument (new CCodeIdentifier (prop.property_type.data_type.get_type_id ()));
 			}
 		} else if (prop.property_type.data_type == string_type.data_type) {
@@ -1556,7 +1583,8 @@
 					cspec.add_argument (new CCodeConstant ("G_TYPE_NONE"));
 				}
 			} else {
-				cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
+				cspec.call = new CCodeIdentifier ("g_param_spec_boxed");
+				cspec.add_argument (new CCodeIdentifier (st.get_type_id ()));
 			}
 		} else {
 			cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
@@ -1873,5 +1901,20 @@
 
 		block.add_statement (new CCodeExpressionStatement (call));
 	}
+
+	public override void visit_property (Property prop) {
+		base.visit_property (prop);
+
+		var cl = prop.parent_symbol as Class;
+		if (cl != null && cl.is_subtype_of (gobject_type)
+		    && prop.binding == MemberBinding.INSTANCE) {
+			// GObject property
+			var st = prop.property_type.data_type as Struct;
+			if (prop.access != SymbolAccessibility.PRIVATE
+			    && (st == null || st.has_type_id)) {
+				prop_enum.add_value (new CCodeEnumValue (prop.get_upper_case_cname ()));
+			}
+		}
+	}
 }
 

Modified: trunk/vala/valastruct.vala
==============================================================================
--- trunk/vala/valastruct.vala	(original)
+++ trunk/vala/valastruct.vala	Sun Dec 21 12:05:24 2008
@@ -54,7 +54,12 @@
 	 * Specifies the default construction method.
 	 */
 	public Method default_construction_method { get; set; }
-	
+
+	/**
+	 * Specifies whether this struct has a registered GType.
+	 */
+	public bool has_type_id { get; set; default = true; }
+
 	/**
 	 * Creates a new struct.
 	 *
@@ -316,6 +321,9 @@
 				add_cheader_filename (filename);
 			}
 		}
+		if (a.has_argument ("has_type_id")) {
+			has_type_id = a.get_bool ("has_type_id");
+		}
 		if (a.has_argument ("type_id")) {
 			set_type_id (a.get_string ("type_id"));
 		}
@@ -429,6 +437,8 @@
 			if (is_simple_type ()) {
 				Report.error (source_reference, "The value type `%s` doesn't declare a GValue get function".printf (get_full_name ()));
 				return null;
+			} else if (has_type_id) {
+				return "g_value_get_boxed";
 			} else {
 				return "g_value_get_pointer";
 			}
@@ -448,6 +458,8 @@
 			if (is_simple_type ()) {
 				Report.error (source_reference, "The value type `%s` doesn't declare a GValue set function".printf (get_full_name ()));
 				return null;
+			} else if (has_type_id) {
+				return "g_value_set_boxed";
 			} else {
 				return "g_value_set_pointer";
 			}

Modified: trunk/vapi/glib-2.0.vapi
==============================================================================
--- trunk/vapi/glib-2.0.vapi	(original)
+++ trunk/vapi/glib-2.0.vapi	Sun Dec 21 12:05:24 2008
@@ -1577,7 +1577,8 @@
 	}
 
 	/* Date and Time Functions */
-	
+
+	[CCode (has_type_id = false)]
 	public struct TimeVal {
 		public long tv_sec;
 		public long tv_usec;
@@ -1694,7 +1695,7 @@
 		public static bool valid_weekday (DateWeekday weekday);
 	}
 
-	[CCode (cname = "struct tm", cheader_filename="time.h")]
+	[CCode (cname = "struct tm", cheader_filename = "time.h", has_type_id = false)]
 	public struct Time {
 		[CCode (cname = "tm_sec")]
 		public int second;



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