From: Luca Bruno Date: Sun, 19 Dec 2010 21:46:38 +0000 (+0100) Subject: girparser: Ensure interfaces have at least one instantiable prerequisite X-Git-Tag: 0.11.3~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af2ba3f92712bb92ca7b16963501a1801fe48cde;p=thirdparty%2Fvala.git girparser: Ensure interfaces have at least one instantiable prerequisite 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. --- diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 3a8e92fd6..38c12d4aa 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -522,6 +522,7 @@ public class Vala.GirParser : CodeVisitor { HashMap> namespace_methods = new HashMap> (); HashMap> gtype_callbacks = new HashMap> (callback_scope_hash, callback_scope_equal); ArrayList aliases = new ArrayList (); + ArrayList interfaces = new ArrayList (); /** * 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);