From: Evan Nemerson Date: Mon, 6 Sep 2010 22:40:03 +0000 (-0700) Subject: Write GIR version 1.2 instead of version 1.1 X-Git-Tag: 0.10.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=275ca104ce9d7787aac3eda953426a4e3b0ed6ba;p=thirdparty%2Fvala.git Write GIR version 1.2 instead of version 1.1 Fixes bug 628927. --- diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index e1899deec..4890aa650 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -94,7 +94,7 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf ("\n"); - stream.printf ("\n"); indent++; write_indent (); - buffer.append_printf ("\n", cl.get_cname ()); + buffer.append_printf ("\n", cl.name, cl.get_cname ()); indent--; write_indent (); buffer.append_printf("\n"); @@ -286,6 +286,9 @@ public class Vala.GIRWriter : CodeVisitor { indent--; write_indent (); buffer.append_printf ("\n"); + + write_indent (); + buffer.append_printf ("\n", cl.name, cl.get_cname ()); } else { write_indent (); buffer.append_printf (" 0) { - write_indent (); - buffer.append_printf ("\n"); - indent++; - foreach (DataType base_type in iface.get_prerequisites ()) { - var object_type = (ObjectType) base_type; - if (object_type.type_symbol is Class) { - write_indent (); - buffer.append_printf ("\n", gi_type_name (object_type.type_symbol)); - } else if (object_type.type_symbol is Interface) { - write_indent (); - buffer.append_printf ("\n", gi_type_name (object_type.type_symbol)); - } else { - assert_not_reached (); - } + write_indent (); + buffer.append_printf ("\n", gi_type_name (((ObjectType) base_type).type_symbol)); } - - indent--; - write_indent (); - buffer.append_printf ("\n"); } write_annotations (iface); - iface.accept_children (this); indent--; @@ -569,7 +555,7 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n", index); indent++; write_indent (); - buffer.append_printf ("\n"); + buffer.append_printf ("\n"); indent--; write_indent (); buffer.append_printf ("\n"); @@ -858,7 +844,7 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); } else if (type is PointerType) { write_indent (); - buffer.append_printf ("\n", type.get_cname ()); + buffer.append_printf ("\n", type.get_cname ()); } else if (type.data_type != null) { write_indent (); buffer.append_printf ("\n"); + buffer.append ("\n"); } else { write_indent (); buffer.append_printf ("\n", type.to_string ()); @@ -913,40 +899,20 @@ public class Vala.GIRWriter : CodeVisitor { Symbol parent = type_symbol.parent_symbol; if (parent is Namespace) { Namespace ns = parent as Namespace; - if (ns.name != null) { + if (ns.gir_name != null) { if (type_symbol.source_reference.file.gir_namespace != null) { GIRNamespace external = GIRNamespace (type_symbol.source_reference.file.gir_namespace, type_symbol.source_reference.file.gir_version); if (!externals.contains (external)) { externals.add (external); } - return "%s.%s".printf (type_symbol.source_reference.file.gir_namespace, type_symbol.name); + return "%s.%s".printf (type_symbol.source_reference.file.gir_namespace, type_symbol.gir_name); } else { unannotated_namespaces.add(ns); } } } - 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]); - } - return type_name.str; - } + return type_symbol.get_full_gir_name(); } private string? literal_expression_to_value_string (Expression literal) { diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 0380acb76..06cc7eaba 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -627,6 +627,12 @@ public class Vala.Class : ObjectTypeSymbol { public override bool is_reference_type () { return true; } + + private void process_gir_attribute (Attribute a) { + if (a.has_argument ("name")) { + gir_name = a.get_string ("name"); + } + } private void process_ccode_attribute (Attribute a) { if (a.has_argument ("ref_function")) { @@ -703,6 +709,8 @@ public class Vala.Class : ObjectTypeSymbol { is_immutable = true; } else if (a.name == "Deprecated") { process_deprecated_attribute (a); + } else if (a.name == "GIR") { + process_gir_attribute (a); } } } diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 2f5411972..93aac1e53 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -407,6 +407,12 @@ public class Vala.Struct : TypeSymbol { this.rank = rank; } + private void process_gir_attribute (Attribute a) { + if (a.has_argument ("name")) { + gir_name = a.get_string ("name"); + } + } + private void process_ccode_attribute (Attribute a) { if (a.has_argument ("const_cname")) { set_const_cname (a.get_string ("const_cname")); @@ -499,6 +505,8 @@ public class Vala.Struct : TypeSymbol { is_immutable = true; } else if (a.name == "Deprecated") { process_deprecated_attribute (a); + } else if (a.name == "GIR") { + process_gir_attribute (a); } } } diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala index a935bcb76..fd74c6ce7 100644 --- a/vala/valasymbol.vala +++ b/vala/valasymbol.vala @@ -51,7 +51,19 @@ public abstract class Vala.Symbol : CodeNode { _scope.parent_scope = value; } } - + + /** + * The GIR name. + */ + public string? gir_name { + get { + return _gir_name == null ? name : _gir_name; + } + set { + _gir_name = value; + } + } + /** * The symbol name. */ @@ -162,6 +174,7 @@ public abstract class Vala.Symbol : CodeNode { private weak Scope _owner; private Scope _scope; + private string? _gir_name = null; public Symbol (string? name, SourceReference? source_reference, Comment? comment = null) { this.name = name; @@ -170,6 +183,31 @@ public abstract class Vala.Symbol : CodeNode { _scope = new Scope (this); } + /** + * Returns the fully expanded GIR name of this symbol + * + * @return full GIR name + */ + public string get_full_gir_name () { + if (parent_symbol == null) { + return gir_name; + } + + if (name == null) { + return parent_symbol.get_full_gir_name (); + } + + if (parent_symbol.get_full_gir_name () == null) { + return gir_name; + } + + if (name.has_prefix (".")) { + return "%s%s".printf (parent_symbol.get_full_gir_name (), gir_name); + } else { + return "%s.%s".printf (parent_symbol.get_full_gir_name (), gir_name); + } + } + /** * Returns the fully expanded name of this symbol for use in * human-readable messages. diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 11d77f2ae..4cf2bfc0d 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -29,6 +29,7 @@ */ [SimpleType] +[GIR (name = "gboolean")] [CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE", type_signature = "b")] [BooleanType] public struct bool { @@ -87,6 +88,7 @@ public struct uchar { } [SimpleType] +[GIR (name = "gint")] [CCode (cname = "gint", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", type_signature = "i")] [IntegerType (rank = 6)] public struct int { @@ -123,6 +125,7 @@ public struct int { } [SimpleType] +[GIR (name = "guint")] [CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")] [IntegerType (rank = 7)] public struct uint { @@ -156,6 +159,7 @@ public struct uint { } [SimpleType] +[GIR (name = "gshort")] [CCode (cname = "gshort", cheader_filename = "glib.h", has_type_id = false, default_value = "0", type_signature = "n")] [IntegerType (rank = 4, min = -32768, max = 32767)] public struct short { @@ -176,6 +180,7 @@ public struct short { } [SimpleType] +[GIR (name = "gushort")] [CCode (cname = "gushort", cheader_filename = "glib.h", has_type_id = false, default_value = "0U", type_signature = "q")] [IntegerType (rank = 5, min = 0, max = 65535)] public struct ushort { @@ -196,6 +201,7 @@ public struct ushort { } [SimpleType] +[GIR (name = "glong")] [CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")] [IntegerType (rank = 8)] public struct long { @@ -228,6 +234,7 @@ public struct long { } [SimpleType] +[GIR (name = "gulong")] [CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")] [IntegerType (rank = 9)] public struct ulong { @@ -311,6 +318,7 @@ public struct ssize_t { } [SimpleType] +[GIR (name = "gint8")] [CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0", type_signature = "y")] [IntegerType (rank = 1, min = -128, max = 127)] public struct int8 { @@ -331,6 +339,7 @@ public struct int8 { } [SimpleType] +[GIR (name = "guint8")] [CCode (cname = "guint8", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "0U", type_signature = "y")] [IntegerType (rank = 3, min = 0, max = 255)] public struct uint8 { @@ -351,6 +360,7 @@ public struct uint8 { } [SimpleType] +[GIR (name = "gint16")] [CCode (cname = "gint16", cheader_filename = "glib.h", default_value = "0", type_signature = "n", has_type_id = false)] [IntegerType (rank = 4, min = -32768, max = 32767)] public struct int16 { @@ -386,6 +396,7 @@ public struct int16 { } [SimpleType] +[GIR (name = "guint16")] [CCode (cname = "guint16", cheader_filename = "glib.h", default_value = "0U", type_signature = "q", has_type_id = false)] [IntegerType (rank = 5, min = 0, max = 65535)] public struct uint16 { @@ -428,6 +439,7 @@ public struct uint16 { } [SimpleType] +[GIR (name = "gint32")] [CCode (cname = "gint32", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", type_signature = "i")] [IntegerType (rank = 6)] public struct int32 { @@ -463,6 +475,7 @@ public struct int32 { } [SimpleType] +[GIR (name = "guint32")] [CCode (cname = "guint32", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")] [IntegerType (rank = 7)] public struct uint32 { @@ -505,6 +518,7 @@ public struct uint32 { } [SimpleType] +[GIR (name = "gint64")] [CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64", default_value = "0LL", type_signature = "x")] [IntegerType (rank = 10)] public struct int64 { @@ -545,6 +559,7 @@ public struct int64 { } [SimpleType] +[GIR (name = "guint64")] [CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64", default_value = "0ULL", type_signature = "t")] [IntegerType (rank = 11)] public struct uint64 { @@ -580,6 +595,7 @@ public struct uint64 { } [SimpleType] +[GIR (name = "gfloat")] [CCode (cname = "float", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float", default_value = "0.0F")] [FloatingType (rank = 1)] public struct float { @@ -631,6 +647,7 @@ public struct float { } [SimpleType] +[GIR (name = "gdouble")] [CCode (cname = "double", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double", default_value = "0.0", type_signature = "d")] [FloatingType (rank = 2)] public struct double { @@ -689,6 +706,7 @@ public struct double { } } +[GIR (name = "glong")] [CCode (cheader_filename = "time.h", has_type_id = false)] [IntegerType (rank = 8)] public struct time_t { @@ -708,6 +726,7 @@ public struct va_list { } [SimpleType] +[GIR (name = "gunichar")] [CCode (cname = "gunichar", cprefix = "g_unichar_", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")] [IntegerType (rank = 7)] public struct unichar { @@ -929,6 +948,7 @@ public enum NormalizeMode { [Compact] [Immutable] +[GIR (name = "utf8")] [CCode (cname = "char", const_cname = "const char", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", param_spec_function = "g_param_spec_string", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", take_value_function = "g_value_take_string", type_signature = "s")] public class string { [CCode (cname = "strstr")] @@ -3599,6 +3619,7 @@ namespace GLib { /* Strings */ [Compact] + [GIR (name = "String")] [CCode (cname = "GString", cprefix = "g_string_", free_function = "g_string_free", type_id = "G_TYPE_GSTRING")] public class StringBuilder { public StringBuilder (string init = "");