[vala/wip/attributes: 120/121] Fix gidl parser
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 120/121] Fix gidl parser
- Date: Mon, 4 Jul 2011 17:18:50 +0000 (UTC)
commit ecc0b5514158c63af26cb436edc3feec1d421bd2
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Jul 4 15:11:07 2011 +0200
Fix gidl parser
vala/valacodewriter.vala | 10 +++++-
vapigen/valagidlparser.vala | 70 ++++++++++++++++++++++++++++++++++--------
2 files changed, 64 insertions(+), 16 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 251f430..ecfa8c9 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -1543,7 +1543,9 @@ public class Vala.CodeWriter : CodeVisitor {
return;
}
foreach (Attribute attr in node.attributes.get_values ()) {
- write_indent ();
+ if (!(node is Parameter)) {
+ write_indent ();
+ }
stream.printf ("[%s", attr.name);
var keys = attr.args.get_keys ();
@@ -1563,7 +1565,11 @@ public class Vala.CodeWriter : CodeVisitor {
stream.printf (")");
}
stream.printf ("]");
- write_newline ();
+ if (node is Parameter) {
+ write_string (" ");
+ } else {
+ write_newline ();
+ }
}
}
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index a7849c6..6aa7dde 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -183,15 +183,39 @@ public class Vala.GIdlParser : CodeVisitor {
return const_name;
}
- private string get_cname (Symbol sym) {
+ private string get_cheader_filename (Symbol sym) {
+ var cheader_filename = sym.get_attribute_string ("CCode", "cheader_filename");
+ if (cheader_filename != null) {
+ return cheader_filename;
+ }
+ if (sym.parent_symbol != null) {
+ return get_cheader_filename (sym.parent_symbol);
+ } else if (sym.source_reference != null) {
+ return sym.source_reference.file.get_cinclude_filename ();
+ }
+ return "";
+ }
+
+ private string get_cname (Symbol sym, Symbol? container = null) {
+ if (container == null) {
+ container = sym.parent_symbol;
+ }
var cname = sym.get_attribute_string ("CCode", "cname");
if (cname != null) {
return cname;
}
if (sym is Method) {
- return "%s%s".printf (get_lower_case_cprefix (sym.parent_symbol), sym.name);
+ var name = sym.name;
+ if (sym is CreationMethod) {
+ if (name == null) {
+ name = "new";
+ } else {
+ name = "new_"+name;
+ }
+ }
+ return "%s%s".printf (get_lower_case_cprefix (container), name);
} else {
- return "%s%s".printf (get_cprefix (sym.parent_symbol), sym.name);
+ return "%s%s".printf (get_cprefix (container), sym.name);
}
}
@@ -236,7 +260,6 @@ public class Vala.GIdlParser : CodeVisitor {
if (cprefix != null) {
return cprefix;
}
-
return get_lower_case_cname (sym) + "_";
}
@@ -280,13 +303,6 @@ public class Vala.GIdlParser : CodeVisitor {
}
private void add_symbol_to_container (Symbol container, Symbol sym) {
- if (sym is Method) {
- var cname = sym.get_attribute_string ("CCode", "cname");
- if (cname != null && cname == "%s%s".printf (get_lower_case_cprefix (container), sym.name)) {
- // same as default, remove the argument
- sym.remove_attribute_argument ("CCode", "cname");
- }
- }
if (container is Class) {
unowned Class cl = (Class) container;
@@ -376,6 +392,11 @@ public class Vala.GIdlParser : CodeVisitor {
st.add_property ((Property) sym);
}
}
+
+ if (container is Namespace) {
+ // set C headers
+ sym.set_attribute_string ("CCode", "cheader_filename", get_cheader_filename (sym));
+ }
}
private void parse_node (IdlNode node, IdlModule module, Symbol container) {
@@ -421,13 +442,15 @@ public class Vala.GIdlParser : CodeVisitor {
private Symbol? get_container_from_name (string name) {
var path = name.split (".");
Symbol? cp = current_namespace;
+ if (cp.parent_symbol != context.root) {
+ cp = cp.parent_symbol;
+ }
Symbol? cc = null;
foreach ( unowned string tok in path ) {
cc = cp.scope.lookup (tok) as Symbol;
if ( cc == null ) {
cc = new Namespace (tok, current_source_reference);
- cc.set_attribute_string ("CCode", "cprefix", get_cprefix (cp) + tok);
add_symbol_to_container (cp, cc);
}
cp = cc;
@@ -463,8 +486,10 @@ public class Vala.GIdlParser : CodeVisitor {
ns.set_attribute_string ("CCode", "lower_case_cprefix", eval (nv[1]));
} else if (nv[0] == "gir_namespace") {
ns.source_reference.file.gir_namespace = eval (nv[1]);
+ ns.set_attribute_string ("CCode", "gir_namespace", eval (nv[1]));
} else if (nv[0] == "gir_version") {
ns.source_reference.file.gir_version = eval (nv[1]);
+ ns.set_attribute_string ("CCode", "gir_version", eval (nv[1]));
}
}
}
@@ -501,7 +526,14 @@ public class Vala.GIdlParser : CodeVisitor {
}
}
+ if (container is Namespace) {
+ current_namespace = (Namespace) container;
+ } else {
+ current_data_type = (TypeSymbol) container;
+ }
parse_node (node, module, container);
+ current_namespace = ns;
+ current_data_type = null;
}
current_namespace = null;
@@ -1921,6 +1953,8 @@ public class Vala.GIdlParser : CodeVisitor {
if (n.has_prefix (current_namespace.name)) {
type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.substring (current_namespace.name.length));
+ } else if (current_namespace.parent_symbol != context.root && n.has_prefix (current_namespace.parent_symbol.name)) {
+ type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.parent_symbol.name), n.substring (current_namespace.parent_symbol.name.length));
} else if (n.has_prefix ("G")) {
type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), n.substring (1));
} else {
@@ -2222,7 +2256,15 @@ public class Vala.GIdlParser : CodeVisitor {
}
}
- m.set_attribute_string ("CCode", "cname", symbol);
+ if (container == null) {
+ container = current_data_type;
+ if (container == null) {
+ container = current_namespace;
+ }
+ }
+ if (symbol != get_cname (m, container)) {
+ m.set_attribute_string ("CCode", "cname", symbol);
+ }
bool first = true;
Parameter last_param = null;
@@ -2790,7 +2832,7 @@ public class Vala.GIdlParser : CodeVisitor {
if (array_length_type != null) {
field.set_attribute_string ("CCode", "array_length_type", array_length_type);
}
- } else {
+ } else if (field.variable_type is ArrayType) {
field.set_attribute_bool ("CCode", "array_length", false);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]