[vala/switch-to-gir-gio: 33/40] girparser: Move parse_constructor inside common parse_function.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir-gio: 33/40] girparser: Move parse_constructor inside common parse_function.
- Date: Thu, 30 Dec 2010 18:48:06 +0000 (UTC)
commit 955093a9350f2d5e61146ec734561812a99a1432
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 7f750ae..5048616 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1763,7 +1763,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;
}
@@ -2094,8 +2094,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 ();
@@ -2124,7 +2126,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") {
@@ -2152,6 +2154,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;
@@ -2272,52 +2275,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 {
@@ -2344,10 +2303,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 ();
}
@@ -2357,6 +2318,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 ());
}
@@ -2385,7 +2363,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]