[vala/wip/attributes: 85/119] girparser: Fix against new attributes changes



commit 5e2d3f4537d9c9e94dd89cdd3c960087534a0ac7
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Jun 30 12:56:11 2011 +0200

    girparser: Fix against new attributes changes

 vala/valagirparser.vala |  171 +++++++++++++++++++++-------------------------
 1 files changed, 78 insertions(+), 93 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index c5c2229..7a444a6 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -565,80 +565,70 @@ public class Vala.GirParser : CodeVisitor {
 			if (name == null) {
 				return "";
 			}
-			if (new_symbol) {
-				if (metadata.has_argument (ArgumentType.CPREFIX)) {
-					return metadata.get_string (ArgumentType.CPREFIX);
+			if (prefix == null) {
+				prefix = symbol.get_attribute_string ("CCode", "lower_case_cprefix");
+			}
+			if (prefix == null && (symbol is ObjectTypeSymbol || symbol is Struct)) {
+				prefix = metadata.get_string (ArgumentType.CPREFIX);
+				if (prefix == null) {
+					prefix = symbol.get_attribute_string ("CCode", "cprefix");
 				}
-				return "%s%s_".printf (parent.get_lower_case_cprefix (), Symbol.camel_case_to_lower_case (name));
-			} else {
-				return symbol.get_lower_case_cprefix ();
 			}
+			if (prefix == null) {
+				prefix = "%s%s_".printf (parent.get_lower_case_cprefix (), Symbol.camel_case_to_lower_case (name));
+			}
+			return prefix;
 		}
 
 		public string get_cprefix () {
 			if (name == null) {
 				return "";
 			}
-			if (new_symbol) {
-				var cprefix = girdata["c:identifier-prefixes"];
-				if (cprefix != null) {
-					return cprefix;
-				} else {
-					return get_cname ();
-				}
-			} else {
-				return symbol.get_cprefix ();
+			var prefix = symbol.get_attribute_string ("CCode", "cprefix");
+			if (prefix == null) {
+				prefix = girdata["c:identifier-prefixes"];
 			}
+			if (prefix == null) {
+				prefix = get_cname ();
+			}
+			return prefix;
 		}
 
 		public string get_cname () {
 			if (name == null) {
 				return "";
 			}
-			if (new_symbol) {
-				var cname = girdata["c:identifier"];
-				if (cname == null) {
-					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;
-						}
+			var cname = symbol.get_attribute_string ("CCode", "cname");
+			if (cname == null) {
+				cname = girdata["c:identifier"];
+			}
+			if (cname == null) {
+				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 = "%s%s".printf (parent.get_cprefix (), name);
+						cname = name;
 					}
-				}
-				return cname;
-			} else {
-				if (symbol is TypeSymbol) {
-					return ((TypeSymbol) symbol).get_cname ();
-				} else if (symbol is Constant) {
-					return ((Constant) symbol).get_cname ();
-				} else if (symbol is Method) {
-					return ((Method) symbol).get_cname ();
-				} else if (symbol is PropertyAccessor) {
-					return ((PropertyAccessor) symbol).get_cname ();
-				} else if (symbol is Field) {
-					return ((Field) symbol).get_cname ();
 				} else {
-					assert_not_reached ();
+					cname = "%s%s".printf (parent.get_cprefix (), name);
 				}
 			}
+			return cname;
 		}
 
 		public string get_finish_cname () {
 			var finish_cname = symbol.get_attribute_string ("CCode", "finish_name");
-			if (finish_cname != null) {
-				return finish_cname;
-			}
-			var result = get_cname ();
-			if (result.has_suffix ("_async")) {
-				result = result.substring (0, result.length - "_async".length);
+			if (finish_cname == null) {
+				finish_cname = get_cname ();
+				if (finish_cname.has_suffix ("_async")) {
+					finish_cname = finish_cname.substring (0, finish_cname.length - "_async".length);
+				}
+				finish_cname += "_finish";
 			}
-			return result + "_finish";
+			return finish_cname;
 		}
 
 		public void process (GirParser parser) {
@@ -744,7 +734,7 @@ public class Vala.GirParser : CodeVisitor {
 						setter = null;
 					}
 					var prop = (Property) symbol;
-					if (prop.add_attribute ("NoAccessorMethod")) {
+					if (prop.get_attribute ("NoAccessorMethod") != null) {
 						// property getter and setter must both match, otherwise it's NoAccessorMethod
 						prop.remove_attribute ("NoAccessorMethod");
 						if (prop.get_accessor != null) {
@@ -809,12 +799,12 @@ public class Vala.GirParser : CodeVisitor {
 							field.set_array_length_cname (length_field.name);
 							var length_type = length_field.variable_type.to_qualified_string ();
 							if (length_type != "int") {
-								var st = parser.context.root.scope.lookup (length_type) as Struct;
+								var st = parser.root.lookup (length_type);
 								if (st != null) {
-									field.array_length_type = st.get_cname ();
+									field.set_attribute_string ("CCode", "array_length_type", st.get_cname ());
 								}
 							}
-							field.no_array_length = false;
+							field.remove_attribute_argument ("CCode", "array_length");
 							field.array_null_terminated = false;
 						}
 					}
@@ -831,7 +821,7 @@ public class Vala.GirParser : CodeVisitor {
 							var f = fn.symbol as Field;
 							if (f != null) {
 								if (f.binding == MemberBinding.INSTANCE) {
-									f.set_cname (name + "." + f.get_cname ());
+									f.set_attribute_string ("CCode", "cname", name + "." + fn.get_cname ());
 								}
 								f.name = symbol.name + "_" + f.name;
 								fn.name = f.name;
@@ -846,7 +836,7 @@ public class Vala.GirParser : CodeVisitor {
 							var iface = parser.resolve_symbol (parent, parser.parse_symbol_from_string (gtype_struct_for, source_reference)) as Interface;
 							if (iface != null) {
 								// set the interface struct name
-								iface.set_attribute_string ("CCode", "type_cname", node.get_cname ());
+								iface.set_attribute_string ("CCode", "type_cname", get_cname ());
 							}
 							merged = true;
 						}
@@ -1464,7 +1454,7 @@ public class Vala.GirParser : CodeVisitor {
 		}
 		var type_name = info.param.variable_type.to_qualified_string ();
 		if (type_name != "int") {
-			var st = context.root.scope.lookup (type_name) as Struct;
+			var st = root.lookup (type_name);
 			if (st != null) {
 				if (sym is Method) {
 					var m = (Method) sym;
@@ -1649,8 +1639,8 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		if (cprefix != null) {
-			ns.add_cprefix (cprefix);
-			ns.set_lower_case_cprefix (Symbol.camel_case_to_lower_case (cprefix) + "_");
+			ns.set_attribute_string ("CCode", "cprefix", cprefix);
+			ns.set_attribute_string ("CCode", "lower_case_cprefix", Symbol.camel_case_to_lower_case (cprefix) + "_");
 		}
 
 		if (cheader_filenames != null) {
@@ -1801,21 +1791,10 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		if (cname != null) {
-			if (sym is Enum) {
-				if (cname != null) {
-					((Enum) sym).set_cname (cname);
-				}
-				if (common_prefix != null) {
-					((Enum) sym).set_cprefix (common_prefix);
-				}
-			} else {
-				if (cname != null) {
-					((ErrorDomain) sym).set_cname (cname);
-				}
-				if (common_prefix != null) {
-					((ErrorDomain) sym).set_cprefix (common_prefix);
-				}
-			}
+			sym.set_attribute_string ("CCode", "cname", "cname");
+		}
+		if (common_prefix != null) {
+			sym.set_attribute_string ("CCode", "cprefix", common_prefix);
 		}
 
 		pop_node ();
@@ -1837,7 +1816,7 @@ public class Vala.GirParser : CodeVisitor {
 		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_cname (cname);
+			ev.set_attribute_string ("CCode", "cname", cname);
 		}
 		current.symbol = ev;
 		next ();
@@ -1860,7 +1839,7 @@ public class Vala.GirParser : CodeVisitor {
 		current.symbol = ec;
 		var cname = reader.get_attribute ("c:identifier");
 		if (cname != null) {
-			ec.set_cname (cname);
+			ec.set_attribute_string ("CCode", "cname", cname);
 		}
 		next ();
 
@@ -1963,7 +1942,9 @@ public class Vala.GirParser : CodeVisitor {
 			if (type is ArrayType && metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) {
 				array_length_idx = metadata.get_integer (ArgumentType.ARRAY_LENGTH_IDX);
 			} else {
-				param.no_array_length = no_array_length;
+				if (no_array_length) {
+					param.set_attribute_bool ("CCode", "array_length", false);
+				}
 				param.array_null_terminated = array_null_terminated;
 			}
 			param.initializer = metadata.get_expression (ArgumentType.DEFAULT);
@@ -2140,7 +2121,7 @@ public class Vala.GirParser : CodeVisitor {
 			st = new Struct (reader.get_attribute ("name"), current.source_reference);
 			var cname = reader.get_attribute ("c:type");
 			if (cname != null) {
-				st.set_cname (cname);
+				st.set_attribute_string ("CCode", "cname", cname);
 			}
 			current.symbol = st;
 		} else {
@@ -2198,7 +2179,7 @@ public class Vala.GirParser : CodeVisitor {
 			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_cname (cname);
+				cl.set_attribute_string ("CCode", "cname", cname);
 			}
 			if (metadata.has_argument (ArgumentType.CPREFIX)) {
 				cl.set_lower_case_cprefix (metadata.get_string (ArgumentType.CPREFIX));
@@ -2280,7 +2261,7 @@ public class Vala.GirParser : CodeVisitor {
 			iface = new Interface (current.name, current.source_reference);
 			var cname = reader.get_attribute ("c:type");
 			if (cname != null) {
-				iface.set_cname (cname);
+				iface.set_attribute_string ("CCode", "cname", cname);
 			}
 			var typeid = reader.get_attribute ("glib:get-type");
 			if (typeid != null) {
@@ -2345,7 +2326,9 @@ public class Vala.GirParser : CodeVisitor {
 
 		var field = new Field (current.name, type, null, current.source_reference);
 		field.access = SymbolAccessibility.PUBLIC;
-		field.no_array_length = no_array_length;
+		if (no_array_length) {
+			field.set_attribute_bool ("CCode", "array_length", false);
+		}
 		field.array_null_terminated = true;
 		if (allow_none == "1") {
 			type.nullable = true;
@@ -2373,7 +2356,9 @@ public class Vala.GirParser : CodeVisitor {
 		prop.access = SymbolAccessibility.PUBLIC;
 		prop.external = true;
 		prop.add_attribute ("NoAccessorMethod");
-		prop.no_array_length = no_array_length;
+		if (no_array_length) {
+			prop.set_attribute_bool ("CCode", "array_length", false);
+		}
 		prop.array_null_terminated = array_null_terminated;
 		if (readable != "0") {
 			prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, null);
@@ -2465,11 +2450,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		s.access = SymbolAccessibility.PUBLIC;
 		if (cname != null) {
-			if (s is Method) {
-				((Method) s).set_cname (cname);
-			} else if (s is Delegate) {
-				((Delegate) s).set_cname (cname);
-			}
+			s.set_attribute_string ("CCode", "cname", cname);
 		}
 
 		s.external = true;
@@ -2529,13 +2510,14 @@ public class Vala.GirParser : CodeVisitor {
 		if (return_type is ArrayType && metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) {
 			return_array_length_idx = metadata.get_integer (ArgumentType.ARRAY_LENGTH_IDX);
 		} else {
+			if (return_no_array_length) {
+				s.set_attribute_bool ("CCode", "array_length", false);
+			}
 			if (s is Method) {
 				var m = (Method) s;
-				m.no_array_length = return_no_array_length;
 				m.array_null_terminated = return_array_null_terminated;
 			} else if (s is Delegate) {
 				var d = (Delegate) s;
-				d.no_array_length = return_no_array_length;
 				d.array_null_terminated = return_array_null_terminated;
 			}
 		}
@@ -2616,7 +2598,7 @@ public class Vala.GirParser : CodeVisitor {
 			cl.is_compact = true;
 			var cname = reader.get_attribute ("c:type");
 			if (cname != null) {
-				cl.set_cname (reader.get_attribute ("c:type"));
+				cl.set_attribute_string ("CCode", "cname", reader.get_attribute ("c:type"));
 			}
 			var typeid = reader.get_attribute ("glib:get-type");
 			if (typeid != null) {
@@ -2840,7 +2822,7 @@ public class Vala.GirParser : CodeVisitor {
 			st.external = true;
 			var cname = alias.girdata["c:type"];
 			if (cname != null) {
-				st.set_cname (cname);
+				st.set_attribute_string ("CCode", "cname", cname);
 			}
 			if (simple_type) {
 				st.set_simple_type ();
@@ -2855,7 +2837,7 @@ public class Vala.GirParser : CodeVisitor {
 			cl.external = true;
 			var cname = alias.girdata["c:type"];
 			if (cname != null) {
-				cl.set_cname (cname);
+				cl.set_attribute_string ("CCode", "cname", cname);
 			}
 			alias.symbol = cl;
 		}
@@ -3148,7 +3130,7 @@ public class Vala.GirParser : CodeVisitor {
 				method.coroutine = true;
 				method.has_construct_function = finish_method.has_construct_function;
 				method.attributes = m.attributes.copy ();
-				method.set_cname (node.get_cname ());
+				method.set_attribute_string ("CCode", "cname", node.get_cname ());
 				if (finish_method_base == "new") {
 					method.name = null;
 				} else if (finish_method_base.has_prefix ("new_")) {
@@ -3160,7 +3142,10 @@ public class Vala.GirParser : CodeVisitor {
 				node.symbol = method;
 			} else {
 				method.return_type = finish_method.return_type.copy ();
-				method.no_array_length = finish_method.no_array_length;
+				var a = finish_method.get_attribute ("CCode");
+				if (a != null && a.has_argument ("array_length")) {
+					method.set_attribute_bool ("CCode", "array_length", a.get_bool ("array_length"));
+				}
 				method.array_null_terminated = finish_method.array_null_terminated;
 
 				foreach (var param in finish_method.get_parameters ()) {



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