]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Ensure interfaces have at least one instantiable prerequisite
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 19 Dec 2010 21:46:38 +0000 (22:46 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 20 Dec 2010 21:25:03 +0000 (22:25 +0100)
When parsing a GIR file, add a prerequisite on GLib.Object to interfaces
which don't have an instantiable prerequisite specified in the GIR file,
as g-ir-scanner considers this prerequisite to be implicit.

Based on commit 65bc5e64725900961ec, reverts fc7fe82fbd0b19b6caaf7ef.

Fixes bug 624923.

vala/valagirparser.vala

index 3a8e92fd6f1c58630c09bab9f4d3f3bad21cbabe..38c12d4aa6a0be08c9953819156ea2c27face178 100644 (file)
@@ -522,6 +522,7 @@ public class Vala.GirParser : CodeVisitor {
        HashMap<Namespace,ArrayList<Method>> namespace_methods = new HashMap<Namespace,ArrayList<Method>> ();
        HashMap<CallbackScope,ArrayList<Delegate>> gtype_callbacks = new HashMap<CallbackScope,ArrayList<Delegate>> (callback_scope_hash, callback_scope_equal);
        ArrayList<Alias> aliases = new ArrayList<Alias> ();
+       ArrayList<Interface> interfaces = new ArrayList<Interface> ();
 
        /**
         * Parses all .gir source files in the specified code
@@ -536,6 +537,7 @@ public class Vala.GirParser : CodeVisitor {
 
                resolve_gir_symbols ();
 
+               postprocess_interfaces ();
                postprocess_reparenting ();
                postprocess_gtype_callbacks ();
                postprocess_aliases ();
@@ -1377,7 +1379,9 @@ public class Vala.GirParser : CodeVisitor {
                        } else if (reader.name == "class") {
                                add_symbol_info (parse_class ());
                        } else if (reader.name == "interface") {
-                               add_symbol_info (parse_interface ());
+                               var iface = parse_interface ();
+                               add_symbol_info (iface);
+                               interfaces.add (iface);
                        } else if (reader.name == "glib:boxed") {
                                add_symbol_info (parse_boxed ());
                        } else if (reader.name == "union") {
@@ -2591,6 +2595,31 @@ public class Vala.GirParser : CodeVisitor {
                return null;
        }
 
+       void postprocess_interfaces () {
+               foreach (var iface in interfaces) {
+                       /* Temporarily workaround G-I bug not adding GLib.Object prerequisite:
+                          ensure we have at least one instantiable prerequisite */
+                       bool has_instantiable_prereq = false;
+                       foreach (DataType prereq in iface.get_prerequisites ()) {
+                               Symbol sym = null;
+                               if (prereq is UnresolvedType) {
+                                       var unresolved_symbol = ((UnresolvedType) prereq).unresolved_symbol;
+                                       sym = resolve_symbol (iface.parent_symbol.scope, unresolved_symbol);
+                               } else {
+                                       sym = prereq.data_type;
+                               }
+                               if (sym is Class) {
+                                       has_instantiable_prereq = true;
+                                       break;
+                               }
+                       }
+
+                       if (!has_instantiable_prereq) {
+                               iface.add_prerequisite (new ObjectType ((ObjectTypeSymbol) glib_ns.scope.lookup ("Object")));
+                       }
+               }
+       }
+
        void postprocess_reparenting () {
                foreach (UnresolvedSymbol target_unresolved_symbol in symbol_reparent_map.get_keys ()) {
                        var target_symbol = resolve_symbol (context.root.scope, target_unresolved_symbol);