]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix short and ushort properties in GObject classes
authorJürg Billeter <j@bitron.ch>
Wed, 8 Jul 2009 13:06:53 +0000 (14:06 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 8 Jul 2009 13:12:06 +0000 (14:12 +0100)
Fixes bug 587493.

codegen/valaccodebasemodule.vala
codegen/valagobjectmodule.vala
vala/valastruct.vala
vapi/glib-2.0.vapi

index e926e9203a57125b7d833dba9a91baabf78cf59f..240485e25e1bb5e35678642e554f38b24d13ba0f 100644 (file)
@@ -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
index 6b3e7a190427937b1100e99aeba6e0d4d5c01bd1..588e383f17685a24c629c9e815522945224e1432 100644 (file)
@@ -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;
        }
 }
 
index 166edba43d0f9f38c26e4aaed874ff47fe08791b..02d4c5c2b9a2ab486197a4470f96a4bde38ab77e 100644 (file)
@@ -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";
                                }
index 56e8839bccddf5f2ff8e045e3aab3c870c599c70..03a216a9c3da629a2c082fd4592d1baa6be77077 100644 (file)
@@ -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")]