[vala/switch-to-gir] girparser: Make virtual methods/signals/property work again



commit d0e16e793f35f289520c8fce25cb4e3823d3e23c
Author: Luca Bruno <lethalman88 gmail com>
Date:   Wed Aug 25 22:54:10 2010 +0200

    girparser: Make virtual methods/signals/property work again

 vala/valagirparser.vala |   51 ++++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 9beb789..c8b59ed 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -504,6 +504,7 @@ public class Vala.GirParser : CodeVisitor {
 
 	SourceFile current_source_file;
 	Namespace current_namespace;
+	string current_gtype_struct_for;
 	SourceLocation begin;
 	SourceLocation end;
 	MarkupTokenType current_token;
@@ -513,7 +514,7 @@ public class Vala.GirParser : CodeVisitor {
 	ArrayList<Metadata> metadata_stack;
 	Metadata metadata = Metadata.empty;
 
-	HashMap<string,ArrayList<Method>> gtype_callbacks = new HashMap<string,ArrayList<Method>> (str_hash, str_equal);
+	HashMap<string,ArrayList<Delegate>> gtype_callbacks;
 
 	HashMap<string,string> gir_namespaces = new HashMap<string,string> (str_hash, str_equal);
 	ArrayList<UnresolvedType> unresolved_namespaced_types = new ArrayList<UnresolvedType> ();
@@ -559,6 +560,9 @@ 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;
@@ -1203,7 +1207,7 @@ public class Vala.GirParser : CodeVisitor {
 		var st = new Struct (reader.get_attribute ("name"), get_current_src ());
 		st.external = true;
 
-		string glib_is_gtype_struct_for = reader.get_attribute ("glib:is-gtype-struct-for");
+		current_gtype_struct_for = reader.get_attribute ("glib:is-gtype-struct-for");
 
 		st.access = SymbolAccessibility.PUBLIC;
 		next ();
@@ -1214,17 +1218,9 @@ public class Vala.GirParser : CodeVisitor {
 			}
 
 			if (reader.name == "field") {
-				st.add_field (parse_field ());
-			} else if (reader.name == "callback") {
-				if (glib_is_gtype_struct_for != null) {
-					ArrayList<Method> callbacks = gtype_callbacks.get (glib_is_gtype_struct_for);
-					if (callbacks == null) {
-						callbacks = new ArrayList<Method> ();
-						gtype_callbacks.set (glib_is_gtype_struct_for, callbacks);
-					}
-					callbacks.add (parse_method ("callback"));
-				} else {
-					parse_callback ();
+				var field = parse_field ();
+				if (field != null) {
+					st.add_field (field);
 				}
 			} else if (reader.name == "constructor") {
 				parse_constructor ();
@@ -1248,8 +1244,9 @@ public class Vala.GirParser : CodeVisitor {
 		}
 		end_element ("record");
 
-		if (glib_is_gtype_struct_for != null || (current_namespace.name == "Atk" && st.name == "Implementor")) {
+		if (current_gtype_struct_for != null || (current_namespace.name == "Atk" && st.name == "Implementor")) {
 			// skip *Class or *Iface or AtkImplementor empty struct
+			current_gtype_struct_for = null;
 			return null;
 		}
 
@@ -1259,9 +1256,13 @@ public class Vala.GirParser : CodeVisitor {
 	void postprocess_gtype_callbacks (Namespace ns) {
 		foreach (string gtype_name in gtype_callbacks.get_keys ()) {
 			var gtype = ns.scope.lookup (gtype_name) as ObjectTypeSymbol;
-			ArrayList<Method> callbacks = gtype_callbacks.get (gtype_name);
-			foreach (Method m in callbacks) {
-				var symbol = gtype.scope.lookup (m.name);
+			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)  {
@@ -1274,8 +1275,11 @@ public class Vala.GirParser : CodeVisitor {
 				} 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 (m.name, gtype.name));
+					Report.error (get_current_src (), "unknown member type `%s' in `%s'".printf (d.name, gtype.name));
 				}
 			}
 		}
@@ -1587,12 +1591,23 @@ public class Vala.GirParser : CodeVisitor {
 		string name = reader.get_attribute ("name");
 		string allow_none = reader.get_attribute ("allow-none");
 		next ();
+
 		var type = parse_type ();
+		if (type is DelegateType && current_gtype_struct_for != null) {
+			// virtual
+			ArrayList<Delegate> callbacks = gtype_callbacks.get (current_gtype_struct_for);
+			if (callbacks == null) {
+				callbacks = new ArrayList<Delegate> ();
+				gtype_callbacks.set (current_gtype_struct_for, callbacks);
+			}
+			callbacks.add (((DelegateType) type).delegate_symbol);
+		}
 		var field = new Field (name, type, null, get_current_src ());
 		field.access = SymbolAccessibility.PUBLIC;
 		if (allow_none == "1") {
 			type.nullable = true;
 		}
+
 		end_element ("field");
 		return field;
 	}



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