Re: [Vala] [PATCH] The external symbol/code writer nightmare



Attached patch will not use SOURCE in vapigen but will fix several external
usage. The purpose is to start properly handling extern symbols in source files.
In gidl and gir parser it's not mandatory to set .external but still good
pratice.

-- 
http://www.debian.org - The Universal Operating System
From d0e07e3fecd0023ff7b54197355b2f0d0ad4d29e Mon Sep 17 00:00:00 2001
From: Luca Bruno <lucabru src gnome org>
Date: Tue, 16 Nov 2010 09:39:11 +0100
Subject: [PATCH] Fix some external usage in semantic check, gir parser and gidl parser.

---
 vala/valaclass.vala            |    4 ++--
 vala/valafield.vala            |    2 +-
 vala/valagirparser.vala        |    9 +++++++++
 vala/valamethod.vala           |    4 ++--
 vala/valaparser.vala           |    3 +++
 vala/valaproperty.vala         |    2 +-
 vala/valapropertyaccessor.vala |    2 +-
 vala/valasignal.vala           |    2 +-
 vapigen/valagidlparser.vala    |   21 +++++++++++++++++++++
 9 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 0ba8032..baf7ffc 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -1165,8 +1165,8 @@ public class Vala.Class : ObjectTypeSymbol {
 			Report.error (source_reference, error_string);
 		}
 
-		/* VAPI classes don't have to specify overridden methods */
-		if (source_type == SourceFileType.SOURCE) {
+		/* External classes don't have to specify overridden methods */
+		if (!external && source_type != SourceFileType.FAST) {
 			/* all abstract symbols defined in base types have to be at least defined (or implemented) also in this type */
 			foreach (DataType base_type in get_base_types ()) {
 				if (base_type.data_type is Interface) {
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 6bf4868..819ae53 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -333,7 +333,7 @@ public class Vala.Field : Variable, Lockable {
 			}
 		}
 
-		if (!external_package && !hides && get_hidden_member () != null) {
+		if (!external && source_type != SourceFileType.FAST && !hides && get_hidden_member () != null) {
 			Report.warning (source_reference, "%s hides inherited field `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
 		}
 
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 38c12d4..15197aa 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1447,6 +1447,7 @@ public class Vala.GirParser : CodeVisitor {
 		start_element ("enumeration");
 		var en = new Enum (reader.get_attribute ("name"), get_current_src ());
 		en.access = SymbolAccessibility.PUBLIC;
+		en.external = true;
 
 		string enum_cname = reader.get_attribute ("c:type");
 		if (enum_cname != null) {
@@ -1487,6 +1488,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		var ed = new ErrorDomain (reader.get_attribute ("name"), get_current_src ());
 		ed.access = SymbolAccessibility.PUBLIC;
+		ed.external = true;
 
 		string enum_cname = reader.get_attribute ("c:type");
 		if (enum_cname != null) {
@@ -1526,6 +1528,7 @@ public class Vala.GirParser : CodeVisitor {
 		start_element ("bitfield");
 		var en = new Enum (reader.get_attribute ("name"), get_current_src ());
 		en.access = SymbolAccessibility.PUBLIC;
+		en.external = true;
 		next ();
 		while (current_token == MarkupTokenType.START_ELEMENT) {
 			if (!push_metadata ()) {
@@ -1551,6 +1554,7 @@ public class Vala.GirParser : CodeVisitor {
 		start_element ("member");
 		var ev = new EnumValue (reader.get_attribute ("name").up ().replace ("-", "_"), null, get_current_src ());
 		ev.set_cname (reader.get_attribute ("c:identifier"));
+		ev.external = true;
 		next ();
 		end_element ("member");
 		return ev;
@@ -1567,6 +1571,7 @@ public class Vala.GirParser : CodeVisitor {
 		} else {
 			ec = new ErrorCode (name);
 		}
+		ec.external = true;
 
 		next ();
 		end_element ("member");
@@ -2080,6 +2085,7 @@ public class Vala.GirParser : CodeVisitor {
 		}
 		var field = new Field (name, type, null, get_current_src ());
 		field.access = SymbolAccessibility.PUBLIC;
+		field.external = true;
 		field.no_array_length = true;
 		if (allow_none == "1") {
 			type.nullable = true;
@@ -2101,6 +2107,7 @@ public class Vala.GirParser : CodeVisitor {
 		var type = parse_type (null, null, false, out no_array_length, out array_null_terminated);
 		var prop = new Property (name, type, null, null, get_current_src ());
 		prop.access = SymbolAccessibility.PUBLIC;
+		prop.external = true;
 		prop.no_accessor_method = true;
 		prop.no_array_length = no_array_length;
 		prop.array_null_terminated = array_null_terminated;
@@ -2130,6 +2137,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		var m = new CreationMethod (null, name, get_current_src ());
 		m.access = SymbolAccessibility.PUBLIC;
+		m.external = true;
 		m.has_construct_function = false;
 		if (ctype != null && (parent_ctype == null || ctype != parent_ctype + "*")) {
 			m.custom_return_type_cname = ctype;
@@ -2207,6 +2215,7 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		s.access = SymbolAccessibility.PUBLIC;
+		s.external = true;
 		if (cname != null) {
 			if (s is Method) {
 				((Method) s).set_cname (cname);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index bc301f5..f255e07 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -824,7 +824,7 @@ public class Vala.Method : Subroutine {
 			Report.error (source_reference, "Extern methods cannot be abstract or virtual");
 		} else if (external && body != null) {
 			Report.error (source_reference, "Extern methods cannot have bodies");
-		} else if (!is_abstract && !external && source_type == SourceFileType.SOURCE && body == null) {
+		} else if (!is_abstract && !external && source_type != SourceFileType.FAST && body == null) {
 			Report.error (source_reference, "Non-abstract, non-extern methods must have bodies");
 		}
 
@@ -915,7 +915,7 @@ public class Vala.Method : Subroutine {
 			return false;
 		}
 
-		if (!external_package && !overrides && !hides && get_hidden_member () != null) {
+		if (!external && source_type != SourceFileType.FAST && !overrides && !hides && get_hidden_member () != null) {
 			Report.warning (source_reference, "%s hides inherited method `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
 		}
 
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 60ba794..25d8cb8 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2845,6 +2845,9 @@ public class Vala.Parser : CodeVisitor {
 		if (ModifierFlags.NEW in flags) {
 			sig.hides = true;
 		}
+		if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
+			sig.external = true;
+		}
 		expect (TokenType.OPEN_PARENS);
 		if (current () != TokenType.CLOSE_PARENS) {
 			do {
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 467cdf8..7125329 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -507,7 +507,7 @@ public class Vala.Property : Symbol, Lockable {
 			Report.error (source_reference, "%s: no suitable property found to override".printf (get_full_name ()));
 		}
 
-		if (!external_package && !overrides && !hides && get_hidden_member () != null) {
+		if (!external && source_type != SourceFileType.FAST && !overrides && !hides && get_hidden_member () != null) {
 			Report.warning (source_reference, "%s hides inherited property `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
 		}
 
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index fbec601..a9352ea 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -167,7 +167,7 @@ public class Vala.PropertyAccessor : Subroutine {
 
 		context.analyzer.current_symbol = this;
 
-		if (prop.source_type == SourceFileType.SOURCE) {
+		if (!prop.external && prop.source_type != SourceFileType.FAST) {
 			if (body == null && !prop.interface_only && !prop.is_abstract) {
 				/* no accessor body specified, insert default body */
 
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index a2ed64a..7dc1289 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -311,7 +311,7 @@ public class Vala.Signal : Symbol, Lockable {
 		}
 
 
-		if (!external_package && !hides && get_hidden_member () != null) {
+		if (!external && source_type != SourceFileType.FAST && !hides && get_hidden_member () != null) {
 			Report.warning (source_reference, "%s hides inherited signal `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
 		}
 
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index f7061bc..6171008 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -355,6 +355,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			cc = cp.scope.lookup (tok) as Symbol;
 			if ( cc == null ) {
 				cc = new Namespace (tok, current_source_reference);
+				cc.external = true;
 				((Namespace) cc).add_cprefix (cp.get_cprefix () + tok);
 				add_symbol_to_container (cp, cc);
 			}
@@ -375,6 +376,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			}
 		} else {
 			ns = new Namespace (module.name, current_source_reference);
+			ns.external = true;
 		}
 
 		current_namespace = ns;
@@ -450,6 +452,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 		var cb = new Delegate (node.name, return_type, current_source_reference);
 		cb.access = SymbolAccessibility.PUBLIC;
+		cb.external = true;
 
 		bool check_has_target = true;
 
@@ -615,6 +618,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			if (st == null) {
 				st = new Struct (name, current_source_reference);
 				st.access = SymbolAccessibility.PUBLIC;
+				st.external = true;
 
 				var st_attributes = get_attributes (node.name);
 				if (st_attributes != null) {
@@ -698,6 +702,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 				cl = new Class (name, current_source_reference);
 				cl.access = SymbolAccessibility.PUBLIC;
+				cl.external = true;
 				cl.is_compact = true;
 
 				var cl_attributes = get_attributes (node.name);
@@ -822,6 +827,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			if (st == null) {
 				st = new Struct (name, current_source_reference);
 				st.access = SymbolAccessibility.PUBLIC;
+				st.external = true;
 
 				var st_attributes = get_attributes (node.name);
 				if (st_attributes != null) {
@@ -871,6 +877,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			if (cl == null) {
 				cl = new Class (name, current_source_reference);
 				cl.access = SymbolAccessibility.PUBLIC;
+				cl.external = true;
 				cl.is_compact = true;
 
 				var cl_attributes = get_attributes (node.name);
@@ -962,6 +969,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			if (st == null) {
 				st = new Struct (name, current_source_reference);
 				st.access = SymbolAccessibility.PUBLIC;
+				st.external = true;
 
 				var st_attributes = get_attributes (node.name);
 				if (st_attributes != null) {
@@ -1028,6 +1036,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 				cl = new Class (name, current_source_reference);
 				cl.access = SymbolAccessibility.PUBLIC;
+				cl.external = true;
 				cl.is_compact = true;
 
 				var cl_attributes = get_attributes (node.name);
@@ -1132,6 +1141,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		if (en == null) {
 			en = new Enum (name, current_source_reference);
 			en.access = SymbolAccessibility.PUBLIC;
+			en.external = true;
 			existing = false;
 		} else {
 			// ignore dummy enum values in -custom.vala files
@@ -1218,6 +1228,7 @@ public class Vala.GIdlParser : CodeVisitor {
 					return_type.value_owned = false;
 					var m = new Method ("to_string", return_type, current_source_reference);
 					m.access = SymbolAccessibility.PUBLIC;
+					m.external = true;
 					m.set_cname (eval(nv[1]));
 					en.add_method (m);
 				}
@@ -1240,6 +1251,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 			if (!is_hidden) {
 				var ev = new EnumValue (value2.name.offset (common_prefix.length), null);
+				ev.external = true;
 				en.add_value (ev);
 			}
 		}
@@ -1247,6 +1259,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		if (is_errordomain) {
 			var ed = new ErrorDomain (en.name, current_source_reference);
 			ed.access = SymbolAccessibility.PUBLIC;
+			ed.external = true;
 			ed.set_cprefix (common_prefix);
 
 			foreach (string filename in cheader_filenames) {
@@ -1279,6 +1292,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		if (cl == null) {
 			cl = new Class (name, current_source_reference);
 			cl.access = SymbolAccessibility.PUBLIC;
+			cl.external = true;
 			
 			var attributes = get_attributes (node.gtype_name);
 			if (attributes != null) {
@@ -1412,6 +1426,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			var cm = new CreationMethod (null, null, cl.source_reference);
 			cm.has_construct_function = false;
 			cm.access = SymbolAccessibility.PROTECTED;
+			cm.external = true;
 			cl.add_method (cm);
 		}
 
@@ -1426,6 +1441,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		if (iface == null) {
 			iface = new Interface (name, current_source_reference);
 			iface.access = SymbolAccessibility.PUBLIC;
+			iface.external = true;
 			
 			var attributes = get_attributes (node.gtype_name);
 			if (attributes != null) {
@@ -1920,6 +1936,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		if (!is_interface && (is_constructor || name.has_prefix ("new"))) {
 			m = new CreationMethod (null, name, current_source_reference);
 			m.has_construct_function = false;
+			m.external = true;
 			if (m.name == "new") {
 				m.name = null;
 			} else if (m.name.has_prefix ("new_")) {
@@ -1936,6 +1953,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			}
 		} else {
 			m = new Method (name, return_type, current_source_reference);
+			m.external = true;
 		}
 		m.access = SymbolAccessibility.PUBLIC;
 
@@ -2379,6 +2397,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		
 		var prop = new Property (fix_prop_name (node.name), parse_type (prop_node.type), null, null, current_source_reference);
 		prop.access = SymbolAccessibility.PUBLIC;
+		prop.external = true;
 		prop.interface_only = true;
 
 		if (prop_node.type.is_interface && prop_node.type.interface == "GStrv") {
@@ -2556,6 +2575,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 		var field = new Field (field_name, type, null, current_source_reference);
 		field.access = SymbolAccessibility.PUBLIC;
+		field.external = true;
 
 		if (field_name != node.name) {
 			field.set_cname (node.name);
@@ -2679,6 +2699,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		
 		var sig = new Signal (fix_prop_name (node.name), parse_param (sig_node.result), current_source_reference);
 		sig.access = SymbolAccessibility.PUBLIC;
+		sig.external = true;
 		
 		var attributes = get_attributes ("%s::%s".printf (current_data_type.get_cname (), sig.name));
 		if (attributes != null) {
-- 
1.7.1

Attachment: signature.asc
Description: Digital signature



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