[vala/switch-to-gir: 5/8] girparser: Move parse_constructor inside common parse_function.



commit e9e6e11467eafcc1c6053ddc4c489295e47aca97
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Dec 26 11:32:35 2010 +0100

    girparser: Move parse_constructor inside common parse_function.

 vala/valagirparser.vala |   78 +++++++++++++++++------------------------------
 1 files changed, 28 insertions(+), 50 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index f4c8217..8b0f379 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1755,7 +1755,7 @@ public class Vala.GirParser : CodeVisitor {
 		string allow_none = reader.get_attribute ("allow-none");
 		next ();
 		var transfer_elements = transfer == "full";
-		var type = &ctype != null ? parse_type(out ctype, null, transfer_elements) : parse_type (null, null, transfer_elements);
+		var type = parse_type (out ctype, null, transfer_elements);
 		if (transfer == "full" || transfer == "container") {
 			type.value_owned = true;
 		}
@@ -2086,8 +2086,10 @@ public class Vala.GirParser : CodeVisitor {
 
 		next ();
 		var first_field = true;
+		var old_symbol = current_symbol;
 		var old_symbols_info = current_symbols_info;
 		current_symbols_info = new ArrayList<SymbolInfo> ();
+		current_symbol = cl;
 		while (current_token == MarkupTokenType.START_ELEMENT) {
 			if (!push_metadata ()) {
 				skip_element ();
@@ -2116,7 +2118,7 @@ public class Vala.GirParser : CodeVisitor {
 			} else if (reader.name == "property") {
 				add_symbol_info (parse_property ());
 			} else if (reader.name == "constructor") {
-				add_symbol_info (parse_constructor (cname));
+				add_symbol_info (parse_constructor ());
 			} else if (reader.name == "function") {
 				add_symbol_info (parse_method ("function"));
 			} else if (reader.name == "method") {
@@ -2144,6 +2146,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		merge_add_process (cl);
 		current_symbols_info = old_symbols_info;
+		current_symbol = old_symbol;
 
 		end_element ("class");
 		return cl;
@@ -2261,52 +2264,8 @@ public class Vala.GirParser : CodeVisitor {
 		return this.parse_function ("callback") as Delegate;
 	}
 
-	Method parse_constructor (string? parent_ctype = null) {
-		start_element ("constructor");
-
-		string throws_string = reader.get_attribute ("throws");
-		string cname = reader.get_attribute ("c:identifier");
-		var m = new CreationMethod (null, element_get_name (), get_current_src ());
-		m.access = SymbolAccessibility.PUBLIC;
-		m.has_construct_function = false;
-
-		if (m.name == "new") {
-			m.name = null;
-		} else if (m.name.has_prefix ("new_")) {
-			m.name = m.name.offset ("new_".length);
-		}
-		if (cname != null) {
-			m.set_cname (cname);
-		}
-
-		next ();
-		string? ctype;
-		parse_return_value (out ctype);
-		if (ctype != null && (parent_ctype == null || ctype != parent_ctype + "*")) {
-			m.custom_return_type_cname = ctype;
-		}
-
-		if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
-			start_element ("parameters");
-			next ();
-			while (current_token == MarkupTokenType.START_ELEMENT) {
-				if (!push_metadata ()) {
-					skip_element ();
-					continue;
-				}
-
-				m.add_parameter (parse_parameter ());
-
-				pop_metadata ();
-			}
-			end_element ("parameters");
-		}
-
-		if (throws_string == "1") {
-			m.add_error_type (new ErrorType (null, null));
-		}
-		end_element ("constructor");
-		return m;
+	CreationMethod parse_constructor () {
+		return parse_function ("constructor") as CreationMethod;
 	}
 
 	class ParameterInfo {
@@ -2333,10 +2292,12 @@ public class Vala.GirParser : CodeVisitor {
 		string cname = reader.get_attribute ("c:identifier");
 		string throws_string = reader.get_attribute ("throws");
 		string invoker = reader.get_attribute ("invoker");
+
 		next ();
 		DataType return_type;
+		string return_ctype = null;
 		if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "return-value") {
-			return_type = parse_return_value ();
+			return_type = parse_return_value (out return_ctype);
 		} else {
 			return_type = new VoidType ();
 		}
@@ -2346,6 +2307,23 @@ public class Vala.GirParser : CodeVisitor {
 
 		if (element_name == "callback") {
 			s = new Delegate (name, return_type, get_current_src ());
+		} else if (element_name == "constructor") {
+			if (name == "new") {
+				name = null;
+			} else if (name.has_prefix ("new_")) {
+				name = name.offset ("new_".length);
+			}
+			var m = new CreationMethod (null, name, get_current_src ());
+			m.has_construct_function = false;
+
+			string parent_ctype = null;
+			if (current_symbol is Class) {
+				parent_ctype = ((Class) current_symbol).get_cname ();
+			}
+			if (return_ctype != null && (parent_ctype == null || return_ctype != parent_ctype + "*")) {
+				m.custom_return_type_cname = return_ctype;
+			}
+			s = m;
 		} else {
 			s = new Method (name, return_type, get_current_src ());
 		}
@@ -2374,7 +2352,7 @@ public class Vala.GirParser : CodeVisitor {
 			((Method) s).binding = MemberBinding.STATIC;
 		}
 
-		if (s is Method) {
+		if (s is Method && !(s is CreationMethod)) {
 			var method = (Method) s;
 			if (metadata.has_argument (ArgumentType.VIRTUAL)) {
 				method.is_virtual = metadata.get_bool (ArgumentType.VIRTUAL);



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