[vala] GIR writer: Support pointer types and generic types
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] GIR writer: Support pointer types and generic types
- Date: Thu, 30 Apr 2009 16:50:31 -0400 (EDT)
commit 43a74d2583ea54e7b0f72be50bc98a11711b89ad
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Fri Mar 20 19:32:26 2009 +0100
GIR writer: Support pointer types and generic types
Generate type correctly with adhoc c:type (pointer types and
parametered types).
Signed-off-by: Didier 'Ptitjes <ptitjes free fr>
---
gobject/valagirwriter.vala | 49 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 48 insertions(+), 1 deletions(-)
diff --git a/gobject/valagirwriter.vala b/gobject/valagirwriter.vala
index 095034a..fb0b58d 100644
--- a/gobject/valagirwriter.vala
+++ b/gobject/valagirwriter.vala
@@ -617,9 +617,56 @@ public class Vala.GIRWriter : CodeVisitor {
} else if (type is VoidType) {
write_indent ();
stream.printf ("<type name=\"none\"/>\n");
+ } else if (type is PointerType) {
+ write_indent ();
+ stream.printf ("<type name=\"any\" c:type=\"%s\"/>\n", type.get_cname ());
} else {
write_indent ();
- stream.printf ("<type name=\"%s\"/>\n", type.to_string ());
+ stream.printf ("<type name=\"%s\" c:type=\"%s\"", gi_type_name (type.data_type), type.get_cname ());
+
+ Gee.List<DataType> type_arguments = type.get_type_arguments ();
+ if (type_arguments.size == 0) {
+ stream.printf ("/>\n");
+ } else {
+ stream.printf (">\n");
+ indent++;
+
+ foreach (DataType type_argument in type_arguments) {
+ write_type (type_argument);
+ }
+
+ indent--;
+ write_indent ();
+ stream.printf ("</type>\n");
+ }
+ }
+ }
+
+ private string gi_type_name (TypeSymbol type_symbol) {
+ return vala_to_gi_type_name (type_symbol.get_full_name());
+ }
+
+ private string vala_to_gi_type_name (string name) {
+ if (name == "bool") {
+ return "boolean";
+ } else if (name == "string") {
+ return "utf8";
+ } else if (!name.contains (".")) {
+ return name;
+ } else {
+ string[] split_name = name.split (".");
+
+ StringBuilder type_name = new StringBuilder ();
+ type_name.append (split_name[0]);
+ type_name.append_unichar ('.');
+ for (int i = 1; i < split_name.length; i++) {
+ type_name.append (split_name[i]);
+ }
+
+ if (type_name.str == "GLib.Object") {
+ return "GObject.Object";
+ }
+ return type_name.str;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]