[vala] Fix short and ushort properties in GObject classes



commit 121870d130385a85185bbf99b2d0a077a6ab0413
Author: Jürg Billeter <j bitron ch>
Date:   Wed Jul 8 14:06:53 2009 +0100

    Fix short and ushort properties in GObject classes
    
    Fixes bug 587493.

 codegen/valaccodebasemodule.vala |   12 +++----
 codegen/valagobjectmodule.vala   |   71 ++++++++++++++++---------------------
 vala/valastruct.vala             |    2 +-
 vapi/glib-2.0.vapi               |    4 +-
 4 files changed, 39 insertions(+), 50 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e926e92..240485e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1423,14 +1423,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			}
 
 			// notify on property changes
-			var typesymbol = (TypeSymbol) prop.parent_symbol;
-			var st = prop.property_type.data_type as Struct;
-			if (typesymbol.is_subtype_of (gobject_type) &&
-			    (st == null || st.has_type_id) &&
-			    !(prop.property_type is ArrayType) &&
+			if (is_gobject_property (prop) &&
 			    prop.notify &&
-			    prop.access != SymbolAccessibility.PRIVATE && // FIXME: use better means to detect gobject properties
-			    prop.binding == MemberBinding.INSTANCE &&
 			    (acc.writable || acc.construction)) {
 				var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify"));
 				notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GObject *"));
@@ -4011,6 +4005,10 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 		return new CCodeExpressionStatement (cassert);
 	}
+
+	public virtual bool is_gobject_property (Property prop) {
+		return false;
+	}
 }
 
 // vim:sw=8 noet
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 6b3e7a1..588e383 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -134,17 +134,7 @@ internal class Vala.GObjectModule : GTypeModule {
 		/* create properties */
 		var props = cl.get_properties ();
 		foreach (Property prop in props) {
-			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.property_type is ArrayType) {
+			if (!is_gobject_property (prop)) {
 				continue;
 			}
 
@@ -209,20 +199,11 @@ internal class Vala.GObjectModule : GTypeModule {
 			if (prop.get_accessor == null || prop.is_abstract) {
 				continue;
 			}
-			if (prop.access == SymbolAccessibility.PRIVATE) {
+			if (!is_gobject_property (prop)) {
 				// 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.property_type is ArrayType) {
-				continue;
-			}
-
 			string prefix = cl.get_lower_case_cname (null);
 			CCodeExpression cself = new CCodeIdentifier ("self");
 			if (prop.base_property != null) {
@@ -237,6 +218,7 @@ internal class Vala.GObjectModule : GTypeModule {
 
 			cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
 			if (prop.property_type.is_real_struct_type ()) {
+				var st = prop.property_type.data_type as Struct;
 				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"));
@@ -293,17 +275,7 @@ internal class Vala.GObjectModule : GTypeModule {
 			if (prop.set_accessor == null || prop.is_abstract) {
 				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.property_type is ArrayType) {
+			if (!is_gobject_property (prop)) {
 				continue;
 			}
 
@@ -692,16 +664,35 @@ internal class Vala.GObjectModule : GTypeModule {
 	public override void visit_property (Property prop) {
 		base.visit_property (prop);
 
+		if (is_gobject_property (prop)) {
+			prop_enum.add_value (new CCodeEnumValue (prop.get_upper_case_cname ()));
+		}
+	}
+
+	public override bool is_gobject_property (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 ()));
-			}
+		if (cl == null || !cl.is_subtype_of (gobject_type)) {
+			return false;
+		}
+
+		if (prop.binding != MemberBinding.INSTANCE) {
+			return false;
+		}
+
+		if (prop.access == SymbolAccessibility.PRIVATE) {
+			return false;
+		}
+
+		var st = prop.property_type.data_type as Struct;
+		if (st != null && !st.has_type_id) {
+			return false;
+		}
+
+		if (prop.property_type is ArrayType) {
+			return false;
 		}
+
+		return true;
 	}
 }
 
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 166edba..02d4c5c 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -460,7 +460,7 @@ public class Vala.Struct : TypeSymbol {
 					}
 				}
 				if (is_simple_type ()) {
-					Report.error (source_reference, "The type `%s` doesn't declare a type id".printf (get_full_name ()));
+					return null;
 				} else {
 					return "G_TYPE_POINTER";
 				}
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 56e8839..03a216a 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -156,7 +156,7 @@ public struct uint {
 }
 
 [SimpleType]
-[CCode (cname = "gshort", cheader_filename = "glib.h", default_value = "0", type_signature = "n")]
+[CCode (cname = "gshort", cheader_filename = "glib.h", has_type_id = false, default_value = "0", type_signature = "n")]
 [IntegerType (rank = 4, min = -32768, max = 32767)]
 public struct short {
 	[CCode (cname = "G_MINSHORT")]
@@ -176,7 +176,7 @@ public struct short {
 }
 
 [SimpleType]
-[CCode (cname = "gushort", cheader_filename = "glib.h", default_value = "0U", type_signature = "q")]
+[CCode (cname = "gushort", cheader_filename = "glib.h", has_type_id = false, default_value = "0U", type_signature = "q")]
 [IntegerType (rank = 5, min = 0, max = 65535)]
 public struct ushort {
 	[CCode (cname = "0U")]



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