[vala] vapigen: Support declaration of enum methods in -custom.vala
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] vapigen: Support declaration of enum methods in -custom.vala
- Date: Thu, 8 Apr 2010 07:11:05 +0000 (UTC)
commit a880ba827bc67edbd3a9f20cff8c081f049ad98b
Author: Jürg Billeter <j bitron ch>
Date: Thu Apr 8 09:09:42 2010 +0200
vapigen: Support declaration of enum methods in -custom.vala
Based on patch by Sebastian Drög, fixes bug 614543.
vala/valaenum.vala | 5 ++++
vapigen/valagidlparser.vala | 53 ++++++++++++++++++++++---------------------
2 files changed, 32 insertions(+), 26 deletions(-)
---
diff --git a/vala/valaenum.vala b/vala/valaenum.vala
index f5c2148..4e8c230 100644
--- a/vala/valaenum.vala
+++ b/vala/valaenum.vala
@@ -99,6 +99,11 @@ public class Vala.Enum : TypeSymbol {
return values;
}
+ // used by vapigen
+ public void remove_all_values () {
+ values.clear ();
+ }
+
/**
* Returns a copy of the list of methods.
*
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 6d3e03d..d2e739e 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -243,26 +243,9 @@ public class Vala.GIdlParser : CodeVisitor {
} else if (node.type == IdlNodeTypeId.BOXED) {
parse_boxed ((IdlNodeBoxed) node, ns, module);
} else if (node.type == IdlNodeTypeId.ENUM) {
- var en = parse_enum ((IdlNodeEnum) node);
- if (en == null) {
- continue;
- }
- en.name = fix_type_name (en.name, ns);
- if (en is ErrorDomain) {
- ns.add_error_domain (en as ErrorDomain);
- } else {
- ns.add_enum (en as Enum);
- }
- current_source_file.add_node (en);
+ parse_enum ((IdlNodeEnum) node, ns, module, false);
} else if (node.type == IdlNodeTypeId.FLAGS) {
- var en = parse_enum ((IdlNodeEnum) node) as Enum;
- if (en == null) {
- continue;
- }
- en.name = fix_type_name (en.name, ns);
- en.is_flags = true;
- ns.add_enum (en);
- current_source_file.add_node (en);
+ parse_enum ((IdlNodeEnum) node, ns, module, true);
} else if (node.type == IdlNodeTypeId.OBJECT) {
parse_object ((IdlNodeInterface) node, ns, module);
} else if (node.type == IdlNodeTypeId.INTERFACE) {
@@ -891,11 +874,22 @@ public class Vala.GIdlParser : CodeVisitor {
}
}
- private TypeSymbol? parse_enum (IdlNodeEnum en_node) {
+ private void parse_enum (IdlNodeEnum en_node, Namespace ns, IdlModule module, bool is_flags) {
weak IdlNode node = (IdlNode) en_node;
+ string name = fix_type_name (node.name, ns);
+ bool existing = true;
+
+ var en = ns.scope.lookup (name) as Enum;
+ if (en == null) {
+ en = new Enum (name, current_source_reference);
+ en.access = SymbolAccessibility.PUBLIC;
+ existing = false;
+ } else {
+ // ignore dummy enum values in -custom.vala files
+ // they exist for syntactical reasons
+ en.remove_all_values ();
+ }
- var en = new Enum (node.name, current_source_reference);
- en.access = SymbolAccessibility.PUBLIC;
en.has_type_id = (en_node.gtype_name != null && en_node.gtype_name != "");
string common_prefix = null;
@@ -949,7 +943,7 @@ public class Vala.GIdlParser : CodeVisitor {
en.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "hidden") {
if (eval (nv[1]) == "1") {
- return null;
+ return;
}
} else if (nv[0] == "rename_to") {
en.name = eval (nv[1]);
@@ -1002,10 +996,17 @@ public class Vala.GIdlParser : CodeVisitor {
ed.add_code (new ErrorCode (ev.name));
}
- return ed;
+ current_source_file.add_node (ed);
+ if (!existing) {
+ ns.add_error_domain (ed);
+ }
+ } else {
+ en.is_flags = is_flags;
+ current_source_file.add_node (en);
+ if (!existing) {
+ ns.add_enum (en);
+ }
}
-
- return en;
}
private void parse_object (IdlNodeInterface node, Namespace ns, IdlModule module) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]