[vala] GIR parser: Handle anonymous unions and structs inside unions
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] GIR parser: Handle anonymous unions and structs inside unions
- Date: Tue, 15 Sep 2009 06:35:36 +0000 (UTC)
commit 10cdf90fec549bc0afe25abd9233f8cfe363ebf1
Author: Sebastian Dröge <sebastian droege collabora co uk>
Date: Tue Sep 15 07:43:38 2009 +0200
GIR parser: Handle anonymous unions and structs inside unions
Fixes bug 594228.
vala/valastruct.vala | 7 ++++++-
vapigen/valagirparser.vala | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 2676322..95e8bf0 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -298,7 +298,12 @@ public class Vala.Struct : TypeSymbol {
* @return the name to be used in C code by default
*/
public string get_default_cname () {
- return "%s%s".printf (parent_symbol.get_cprefix (), name);
+ // parent_symbol may be null in GIR parser
+ if (parent_symbol != null) {
+ return "%s%s".printf (parent_symbol.get_cprefix (), name);
+ } else {
+ return name;
+ }
}
private void set_const_cname (string cname) {
diff --git a/vapigen/valagirparser.vala b/vapigen/valagirparser.vala
index 3a60e46..dfecae1 100644
--- a/vapigen/valagirparser.vala
+++ b/vapigen/valagirparser.vala
@@ -521,6 +521,14 @@ public class Vala.GirParser : CodeVisitor {
parse_constructor ();
} else if (reader.name == "method") {
st.add_method (parse_method ("method"));
+ } else if (reader.name == "union") {
+ Struct s = parse_union ();
+ var s_fields = s.get_fields ();
+ foreach (var f in s_fields) {
+ f.set_cname (s.get_cname () + "." + f.get_cname ());
+ f.name = s.name + "_" + f.name;
+ st.add_field (f);
+ }
} else {
// error
Report.error (get_current_src (), "unknown child element `%s' in `record'".printf (reader.name));
@@ -597,6 +605,14 @@ public class Vala.GirParser : CodeVisitor {
methods.add (parse_method ("method"));
} else if (reader.name == "virtual-method") {
vmethods.add (parse_method ("virtual-method"));
+ } else if (reader.name == "union") {
+ Struct s = parse_union ();
+ var s_fields = s.get_fields ();
+ foreach (var f in s_fields) {
+ f.set_cname (s.get_cname () + "." + f.get_cname ());
+ f.name = s.name + "_" + f.name;
+ fields.add (f);
+ }
} else if (reader.name == "glib:signal") {
signals.add (parse_signal ());
} else {
@@ -1042,6 +1058,14 @@ public class Vala.GirParser : CodeVisitor {
parse_constructor ();
} else if (reader.name == "method") {
st.add_method (parse_method ("method"));
+ } else if (reader.name == "record") {
+ Struct s = parse_record ();
+ var fs = s.get_fields ();
+ foreach (var f in fs) {
+ f.set_cname (s.get_cname () + "." + f.get_cname ());
+ f.name = s.name + "_" + f.name;
+ st.add_field (f);
+ }
} else {
// error
Report.error (get_current_src (), "unknown child element `%s' in `union'".printf (reader.name));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]