[vala/wip/attributes: 121/121] Fix girparser



commit 0c6b84b5bd4c774ac3e4b23c2af4b087ffe09c5e
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon Jul 4 18:54:57 2011 +0200

    Fix girparser

 vala/valagirparser.vala |   80 +++++++++++++++++------------------------------
 vala/valamethod.vala    |   12 +++---
 2 files changed, 35 insertions(+), 57 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index f33a655..9db47f4 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -601,17 +601,28 @@ public class Vala.GirParser : CodeVisitor {
 				cname = girdata["c:type"];
 			}
 			if (cname == null) {
-				if (symbol is Field) {
-					if (((Field) symbol).binding == MemberBinding.STATIC) {
-						cname = parent.get_lower_case_cprefix () + name;
-					} else {
-						cname = name;
-					}
+				cname = get_default_cname ();
+			}
+			return cname;
+		}
+
+		public string get_default_cname () {
+			if (name == null) {
+				return "";
+			}
+			if (symbol is Field) {
+				if (((Field) symbol).binding == MemberBinding.STATIC) {
+					return parent.get_lower_case_cprefix () + name;
 				} else {
-					cname = "%s%s".printf (parent.get_cprefix (), name);
+					return name;
 				}
+			} else if (symbol is EnumValue) {
+				return "%s%s".printf (parent.get_lower_case_cprefix ().up (), name);
+			} else if (symbol is Method) {
+				return "%s%s".printf (parent.get_lower_case_cprefix (), name);
+			} else {
+				return "%s%s".printf (parent.get_cprefix (), name);
 			}
-			return cname;
 		}
 
 		public string get_finish_cname () {
@@ -872,6 +883,9 @@ public class Vala.GirParser : CodeVisitor {
 				} else if (metadata.has_argument (ArgumentType.CHEADER_FILENAME)) {
 					symbol.set_attribute_string ("CCode", "cheader_filename", metadata.get_string (ArgumentType.CHEADER_FILENAME));
 				}
+				if (get_cname () != get_default_cname ()) {
+					symbol.set_attribute_string ("CCode", "cname", get_cname ());
+				}
 			}
 
 			if (!(new_symbol && merged) && is_container (symbol)) {
@@ -1646,6 +1660,8 @@ public class Vala.GirParser : CodeVisitor {
 			ns.attributes = null;
 			ns.source_reference = current.source_reference;
 		}
+		ns.set_attribute_string ("CCode", "gir_namespace", gir_namespace);
+		ns.set_attribute_string ("CCode", "gir_version", gir_version);
 
 		if (cprefix != null) {
 			ns.set_attribute_string ("CCode", "cprefix", cprefix);
@@ -1771,7 +1787,6 @@ public class Vala.GirParser : CodeVisitor {
 		sym.external = true;
 		sym.access = SymbolAccessibility.PUBLIC;
 
-		string cname = reader.get_attribute ("c:type");
 		string common_prefix = null;
 
 		next ();
@@ -1799,9 +1814,6 @@ public class Vala.GirParser : CodeVisitor {
 			pop_metadata ();
 		}
 
-		if (cname != null) {
-			sym.set_attribute_string ("CCode", "cname", "cname");
-		}
 		if (common_prefix != null) {
 			sym.set_attribute_string ("CCode", "cprefix", common_prefix);
 		}
@@ -1823,10 +1835,6 @@ public class Vala.GirParser : CodeVisitor {
 		push_node (element_get_name().up().replace ("-", "_"), false);
 
 		var ev = new EnumValue (current.name, metadata.get_expression (ArgumentType.DEFAULT), current.source_reference);
-		var cname = reader.get_attribute ("c:identifier");
-		if (cname != null) {
-			ev.set_attribute_string ("CCode", "cname", cname);
-		}
 		current.symbol = ev;
 		next ();
 
@@ -1846,10 +1854,6 @@ public class Vala.GirParser : CodeVisitor {
 			ec = new ErrorCode (current.name);
 		}
 		current.symbol = ec;
-		var cname = reader.get_attribute ("c:identifier");
-		if (cname != null) {
-			ec.set_attribute_string ("CCode", "cname", cname);
-		}
 		next ();
 
 		pop_node ();
@@ -2132,10 +2136,6 @@ public class Vala.GirParser : CodeVisitor {
 		Struct st;
 		if (current.new_symbol) {
 			st = new Struct (reader.get_attribute ("name"), current.source_reference);
-			var cname = reader.get_attribute ("c:type");
-			if (cname != null) {
-				st.set_attribute_string ("CCode", "cname", cname);
-			}
 			current.symbol = st;
 		} else {
 			st = (Struct) current.symbol;
@@ -2190,10 +2190,6 @@ public class Vala.GirParser : CodeVisitor {
 		if (current.new_symbol) {
 			cl = new Class (current.name, current.source_reference);
 			cl.set_attribute_string ("CCode", "type_id", "%s ()".printf (reader.get_attribute ("glib:get-type")));
-			var cname = reader.get_attribute ("c:type");
-			if (cname != null) {
-				cl.set_attribute_string ("CCode", "cname", cname);
-			}
 			if (metadata.has_argument (ArgumentType.CPREFIX)) {
 				cl.set_attribute_string ("CCode", "cprefix", metadata.get_string (ArgumentType.CPREFIX));
 			}
@@ -2272,10 +2268,6 @@ public class Vala.GirParser : CodeVisitor {
 		Interface iface;
 		if (current.new_symbol) {
 			iface = new Interface (current.name, current.source_reference);
-			var cname = reader.get_attribute ("c:type");
-			if (cname != null) {
-				iface.set_attribute_string ("CCode", "cname", cname);
-			}
 			var typeid = reader.get_attribute ("glib:get-type");
 			if (typeid != null) {
 				iface.set_attribute_string ("CCode", "type_id", "%s ()".printf (typeid));
@@ -2420,7 +2412,6 @@ public class Vala.GirParser : CodeVisitor {
 		push_node (element_get_name (reader.get_attribute ("invoker")).replace ("-", "_"), false);
 
 		string name = current.name;
-		string cname = reader.get_attribute ("c:identifier");
 		string throws_string = reader.get_attribute ("throws");
 		string invoker = reader.get_attribute ("invoker");
 
@@ -2440,6 +2431,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		if (element_name == "callback") {
 			s = new Delegate (name, return_type, current.source_reference);
+			((Delegate) s).has_target = false;
 		} else if (element_name == "constructor") {
 			if (name == "new") {
 				name = null;
@@ -2464,10 +2456,6 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		s.access = SymbolAccessibility.PUBLIC;
-		if (cname != null) {
-			s.set_attribute_string ("CCode", "cname", cname);
-		}
-
 		s.external = true;
 
 		if (s is Method) {
@@ -2609,15 +2597,11 @@ public class Vala.GirParser : CodeVisitor {
 		if (current.new_symbol) {
 			cl = new Class (current.name, current.source_reference);
 			cl.is_compact = true;
-			var cname = reader.get_attribute ("c:type");
-			if (cname != null) {
-				cl.set_attribute_string ("CCode", "cname", reader.get_attribute ("c:type"));
-			}
 			var typeid = reader.get_attribute ("glib:get-type");
 			if (typeid != null) {
 				cl.set_attribute_string ("CCode", "type_id", "%s ()".printf (typeid));
 				cl.set_attribute_string ("CCode", "free_function", "g_boxed_free");
-				cl.set_attribute_string ("Ccode", "copy_function", "g_boxed_copy");
+				cl.set_attribute_string ("CCode", "copy_function", "g_boxed_copy");
 			}
 
 			current.symbol = cl;
@@ -2833,10 +2817,6 @@ public class Vala.GirParser : CodeVisitor {
 				st.base_type = base_type;
 			}
 			st.external = true;
-			var cname = alias.girdata["c:type"];
-			if (cname != null) {
-				st.set_attribute_string ("CCode", "cname", cname);
-			}
 			if (simple_type) {
 				st.set_simple_type ();
 			}
@@ -2848,10 +2828,6 @@ public class Vala.GirParser : CodeVisitor {
 				cl.add_base_type (base_type);
 			}
 			cl.external = true;
-			var cname = alias.girdata["c:type"];
-			if (cname != null) {
-				cl.set_attribute_string ("CCode", "cname", cname);
-			}
 			alias.symbol = cl;
 		}
 	}
@@ -2970,7 +2946,9 @@ public class Vala.GirParser : CodeVisitor {
 						Report.error (get_current_src (), "invalid closure index");
 						continue;
 					}
-					info.param.set_attribute_double ("CCode", "delegate_target_pos", parameters[info.closure_idx].vala_idx);
+					if ("%g".printf (parameters[info.closure_idx].vala_idx) != "%g".printf (info.vala_idx + 0.1)) {
+						info.param.set_attribute_double ("CCode", "delegate_target_pos", parameters[info.closure_idx].vala_idx);
+					}
 				}
 				if (info.destroy_idx != -1) {
 					if (info.destroy_idx >= parameters.size) {
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 4c5cd1f..110ccb3 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -140,14 +140,14 @@ public class Vala.Method : Subroutine {
 	 */
 	public bool has_construct_function {
 		get {
-			var a = get_attribute ("CCode");
-			if (a != null && a.has_argument ("has_construct_function")) {
-				return a.get_bool ("has_construct_function");
-			}
-			return true;
+			return get_attribute_bool ("CCode", "has_construct_function", true);
 		}
 		set {
-			set_attribute_bool ("CCode", "has_construct_function", true);
+			if (!value) {
+				set_attribute_bool ("CCode", "has_construct_function", false);
+			} else {
+				remove_attribute_argument ("CCode", "has_construct_function");
+			}
 		}
 	}
 



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