[vala/switch-to-gir: 8/8] girparser: Use the same function for enumeration, bitfield and error domain.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir: 8/8] girparser: Use the same function for enumeration, bitfield and error domain.
- Date: Tue, 28 Dec 2010 19:25:14 +0000 (UTC)
commit ba02d1f1ec2ca1b73ea39b72646e006b1e6c49e2
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Dec 28 20:20:02 2010 +0100
girparser: Use the same function for enumeration, bitfield and error domain.
vala/valagirparser.vala | 114 +++++++++++++++-------------------------------
1 files changed, 37 insertions(+), 77 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index bb1e8c2..f8547c6 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1618,20 +1618,25 @@ public class Vala.GirParser : CodeVisitor {
}
}
- Enum parse_enumeration () {
- start_element ("enumeration");
-
- var en = new Enum (element_get_name (), get_current_src ());
- en.access = SymbolAccessibility.PUBLIC;
+ Symbol parse_enumeration (string element_name = "enumeration", bool error_domain = false) {
+ start_element (element_name);
- string enum_cname = reader.get_attribute ("c:type");
- if (enum_cname != null) {
- en.set_cname (enum_cname);
+ Symbol sym;
+ if (error_domain) {
+ sym = new ErrorDomain (element_get_name (true), get_current_src ());
+ } else {
+ var en = new Enum (element_get_name (), get_current_src ());
+ if (element_name == "bitfield") {
+ en.is_flags = true;
+ }
+ sym = en;
}
+ sym.access = SymbolAccessibility.PUBLIC;
- next ();
-
+ string cname = reader.get_attribute ("c:type");
string common_prefix = null;
+
+ next ();
while (current_token == MarkupTokenType.START_ELEMENT) {
if (!push_metadata ()) {
@@ -1640,89 +1645,44 @@ public class Vala.GirParser : CodeVisitor {
}
if (reader.name == "member") {
- var ev = parse_enumeration_member ();
- en.add_value (ev);
- calculate_common_prefix (ref common_prefix, ev.get_cname ());
+ if (error_domain) {
+ ErrorCode ec = parse_error_member ();
+ ((ErrorDomain) sym).add_code (ec);
+ calculate_common_prefix (ref common_prefix, ec.get_cname ());
+ } else {
+ var ev = parse_enumeration_member ();
+ ((Enum) sym).add_value (ev);
+ calculate_common_prefix (ref common_prefix, ev.get_cname ());
+ }
} else {
// error
- Report.error (get_current_src (), "unknown child element `%s' in `enumaration'".printf (reader.name));
+ Report.error (get_current_src (), "unknown child element `%s' in `%s'".printf (reader.name, element_name));
skip_element ();
}
pop_metadata ();
}
- en.set_cprefix (common_prefix);
-
- end_element ("enumeration");
- return en;
- }
-
- ErrorDomain parse_error_domain () {
- start_element ("enumeration");
-
- var ed = new ErrorDomain (element_get_name (true), get_current_src ());
- ed.access = SymbolAccessibility.PUBLIC;
-
- string enum_cname = reader.get_attribute ("c:type");
- if (enum_cname != null) {
- ed.set_cname (enum_cname);
- }
-
- next ();
-
- string common_prefix = null;
-
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- continue;
- }
-
- if (reader.name == "member") {
- ErrorCode ec = parse_error_member ();
- ed.add_code (ec);
- calculate_common_prefix (ref common_prefix, ec.get_cname ());
+ if (cname != null) {
+ if (sym is Enum) {
+ ((Enum) sym).set_cname (cname);
+ ((Enum) sym).set_cprefix (common_prefix);
} else {
- // error
- Report.error (get_current_src (), "unknown child element `%s' in `enumeration'".printf (reader.name));
- skip_element ();
+ ((ErrorDomain) sym).set_cname (cname);
+ ((ErrorDomain) sym).set_cprefix (common_prefix);
}
-
- pop_metadata ();
}
- ed.set_cprefix (common_prefix);
+ end_element (element_name);
+ return sym;
+ }
- end_element ("enumeration");
- return ed;
+ ErrorDomain parse_error_domain () {
+ return parse_enumeration ("enumeration", true) as ErrorDomain;
}
Enum parse_bitfield () {
- start_element ("bitfield");
- var en = new Enum (reader.get_attribute ("name"), get_current_src ());
- en.access = SymbolAccessibility.PUBLIC;
- en.is_flags = true;
-
- next ();
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- continue;
- }
-
- if (reader.name == "member") {
- en.add_value (parse_enumeration_member ());
- } else {
- // error
- Report.error (get_current_src (), "unknown child element `%s' in `bitfield'".printf (reader.name));
- skip_element ();
- }
-
- pop_metadata ();
- }
- end_element ("bitfield");
- return en;
+ return parse_enumeration ("bitfield") as Enum;
}
EnumValue parse_enumeration_member () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]