[vala/switch-to-gir] girparser: Move callbacks processing after symbol mapping
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir] girparser: Move callbacks processing after symbol mapping
- Date: Thu, 26 Aug 2010 16:42:00 +0000 (UTC)
commit 1ab3c2eaf59f42af9849e927cd33774ed3c6e76a
Author: Luca Bruno <lethalman88 gmail com>
Date: Thu Aug 26 18:40:51 2010 +0200
girparser: Move callbacks processing after symbol mapping
vala/valagirparser.vala | 102 ++++++++++++++++++++++++++++-------------------
1 files changed, 61 insertions(+), 41 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 5ef83ef..8347503 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -425,10 +425,15 @@ public class Vala.GirParser : CodeVisitor {
}
class Alias {
- public SourceReference source_reference;
public string name;
public DataType base_type;
public Namespace parent_namespace;
+ public SourceReference source_reference;
+ }
+
+ class CallbackScope {
+ public Namespace parent_namespace;
+ public UnresolvedSymbol gtype_struct_for;
}
static GLib.Regex type_from_string_regex;
@@ -450,11 +455,10 @@ public class Vala.GirParser : CodeVisitor {
ArrayList<Metadata> metadata_stack;
Metadata metadata;
- HashMap<string,ArrayList<Delegate>> gtype_callbacks;
-
HashMap<UnresolvedSymbol,Symbol> symbols_map = new HashMap<UnresolvedSymbol,Symbol> (unresolved_symbol_hash, unresolved_symbol_equal);
ArrayList<UnresolvedSymbol> unresolved_gir_symbols = new ArrayList<UnresolvedSymbol> ();
+ HashMap<CallbackScope,ArrayList<Delegate>> gtype_callbacks = new HashMap<CallbackScope,ArrayList<Delegate>> (callback_scope_hash, callback_scope_equal);
ArrayList<Alias> aliases = new ArrayList<Alias> ();
/**
@@ -469,6 +473,8 @@ public class Vala.GirParser : CodeVisitor {
context.accept (this);
resolve_gir_symbols ();
+
+ postprocess_gtype_callbacks ();
postprocess_aliases ();
}
@@ -499,9 +505,6 @@ public class Vala.GirParser : CodeVisitor {
public void parse_file (SourceFile source_file) {
this.current_source_file = source_file;
- // create callbacks structure
- gtype_callbacks = new HashMap<string,ArrayList<Delegate>> (str_hash, str_equal);
-
// load metadata
metadata_stack = new ArrayList<Metadata> ();
metadata = Metadata.empty;
@@ -961,8 +964,6 @@ public class Vala.GirParser : CodeVisitor {
}
end_element ("namespace");
- postprocess_gtype_callbacks (ns);
-
if (!new_namespace) {
ns = null;
}
@@ -1636,10 +1637,13 @@ public class Vala.GirParser : CodeVisitor {
var type = parse_type ();
if (type is DelegateType && current_gtype_struct_for != null) {
// virtual
- ArrayList<Delegate> callbacks = gtype_callbacks.get (current_gtype_struct_for);
+ var callback_scope = new CallbackScope ();
+ callback_scope.parent_namespace = current_namespace;
+ callback_scope.gtype_struct_for = parse_symbol_from_string (current_gtype_struct_for);
+ ArrayList<Delegate> callbacks = gtype_callbacks.get (callback_scope);
if (callbacks == null) {
callbacks = new ArrayList<Delegate> ();
- gtype_callbacks.set (current_gtype_struct_for, callbacks);
+ gtype_callbacks.set (callback_scope, callbacks);
}
callbacks.add (((DelegateType) type).delegate_symbol);
}
@@ -2042,37 +2046,7 @@ public class Vala.GirParser : CodeVisitor {
return c;
}
- void postprocess_gtype_callbacks (Namespace ns) {
- foreach (string gtype_name in gtype_callbacks.get_keys ()) {
- var gtype = ns.scope.lookup (gtype_name) as ObjectTypeSymbol;
- if (gtype == null) {
- Report.error (null, "unknown type `%s.%s'".printf (ns.name, gtype_name));
- continue;
- }
- ArrayList<Delegate> callbacks = gtype_callbacks.get (gtype_name);
- foreach (Delegate d in callbacks) {
- var symbol = gtype.scope.lookup (d.name);
- if (symbol == null) {
- continue;
- } else if (symbol is Method) {
- var meth = (Method) symbol;
- if (gtype is Class) {
- meth.is_virtual = true;
- } else if (gtype is Interface) {
- meth.is_abstract = true;
- }
- } else if (symbol is Signal) {
- var sig = (Signal) symbol;
- sig.is_virtual = true;
- } else if (symbol is Property) {
- var prop = (Property) symbol;
- prop.is_virtual = true;
- } else {
- Report.error (get_current_src (), "unknown member type `%s' in `%s'".printf (d.name, gtype.name));
- }
- }
- }
- }
+ /* Post-parsing */
void resolve_gir_symbols () {
// gir has simple namespaces, we won't get deeper than 2 levels here
@@ -2124,6 +2098,38 @@ public class Vala.GirParser : CodeVisitor {
return null;
}
+ void postprocess_gtype_callbacks () {
+ foreach (CallbackScope callback_scope in gtype_callbacks.get_keys ()) {
+ var gtype = resolve_symbol (callback_scope.parent_namespace.scope, callback_scope.gtype_struct_for) as ObjectTypeSymbol;
+ if (gtype == null) {
+ Report.error (null, "unknown symbol %s".printf (callback_scope.gtype_struct_for.to_string ()));
+ continue;
+ }
+ ArrayList<Delegate> callbacks = gtype_callbacks.get (callback_scope);
+ foreach (Delegate d in callbacks) {
+ var symbol = gtype.scope.lookup (d.name);
+ if (symbol == null) {
+ continue;
+ } else if (symbol is Method) {
+ var meth = (Method) symbol;
+ if (gtype is Class) {
+ meth.is_virtual = true;
+ } else if (gtype is Interface) {
+ meth.is_abstract = true;
+ }
+ } else if (symbol is Signal) {
+ var sig = (Signal) symbol;
+ sig.is_virtual = true;
+ } else if (symbol is Property) {
+ var prop = (Property) symbol;
+ prop.is_virtual = true;
+ } else {
+ Report.error (get_current_src (), "unknown member type `%s' in `%s'".printf (d.name, gtype.name));
+ }
+ }
+ }
+ }
+
void postprocess_aliases () {
/* this is unfortunate because <alias> tag has no type information, thus we have
to guess it from the target */
@@ -2160,6 +2166,7 @@ public class Vala.GirParser : CodeVisitor {
}
}
+ /* Reporting */
void report_unused_metadata (Metadata metadata) {
if (metadata == Metadata.empty) {
return;
@@ -2187,6 +2194,8 @@ public class Vala.GirParser : CodeVisitor {
}
}
+ /* Hash and equal functions */
+
static uint unresolved_symbol_hash (void *ptr) {
var sym = (UnresolvedSymbol) ptr;
var builder = new StringBuilder ();
@@ -2212,5 +2221,16 @@ public class Vala.GirParser : CodeVisitor {
}
return true;
}
+
+ static uint callback_scope_hash (void *ptr) {
+ var cs = (CallbackScope) ptr;
+ return unresolved_symbol_hash (cs.gtype_struct_for);
+ }
+
+ static bool callback_scope_equal (void *ptr1, void *ptr2) {
+ var cs1 = (CallbackScope) ptr1;
+ var cs2 = (CallbackScope) ptr2;
+ return cs1.parent_namespace == cs2.parent_namespace && unresolved_symbol_equal (cs1.gtype_struct_for, cs2.gtype_struct_for);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]