diff options
author | Colin Walters <walters@src.gnome.org> | 2008-10-02 13:25:46 +0000 |
---|---|---|
committer | Colin Walters <walters@src.gnome.org> | 2008-10-02 13:25:46 +0000 |
commit | ddb93b98b955bd5d3080835047abf7a641abf440 (patch) | |
tree | 5a94d5960badb5ed44a33f2da4153b775520f232 | |
parent | 1ab23b133ad9b48b9f67117f150026ff48daa927 (diff) | |
download | gobject-introspection-ddb93b98b955bd5d3080835047abf7a641abf440.tar.gz |
Bug 554632: Create type tag for GType
svn path=/trunk/; revision=641
-rw-r--r-- | docs/typelib-format.txt | 6 | ||||
-rw-r--r-- | girepository/girepository.c | 2 | ||||
-rw-r--r-- | girepository/girepository.h | 23 | ||||
-rw-r--r-- | girepository/girparser.c | 22 | ||||
-rw-r--r-- | giscanner/ast.py | 3 | ||||
-rw-r--r-- | giscanner/glibtransformer.py | 10 | ||||
-rw-r--r-- | tests/scanner/foo-expected.gir | 2 | ||||
-rw-r--r-- | tools/generate.c | 28 |
8 files changed, 48 insertions, 48 deletions
diff --git a/docs/typelib-format.txt b/docs/typelib-format.txt index 25174722..5279132f 100644 --- a/docs/typelib-format.txt +++ b/docs/typelib-format.txt @@ -473,9 +473,11 @@ tag: specifies what kind of type is described, as follows: 15 size_t 16 float 17 double - 18 utf8 (these are zero-terminated char[] and assumed to be + 18 time_t + 19 GType + 20 utf8 (these are zero-terminated char[] and assumed to be in UTF-8) - 19 filename (these are zero-terminated char[] and assumed to be + 21 filename (these are zero-terminated char[] and assumed to be in the GLib filename encoding) For utf8 and filename is_pointer will always be set. diff --git a/girepository/girepository.c b/girepository/girepository.c index 25170276..3bde15be 100644 --- a/girepository/girepository.c +++ b/girepository/girepository.c @@ -750,6 +750,8 @@ g_type_tag_to_string (GITypeTag type) return "double"; case GI_TYPE_TAG_TIME_T: return "time_t"; + case GI_TYPE_TAG_GTYPE: + return "GType"; case GI_TYPE_TAG_UTF8: return "utf8"; case GI_TYPE_TAG_FILENAME: diff --git a/girepository/girepository.h b/girepository/girepository.h index d3f68185..54baab4a 100644 --- a/girepository/girepository.h +++ b/girepository/girepository.h @@ -267,6 +267,7 @@ GITypeInfo * g_arg_info_get_type (GIArgInfo *info); /* GITypeInfo */ typedef enum { + /* Basic types */ GI_TYPE_TAG_VOID = 0, GI_TYPE_TAG_BOOLEAN = 1, GI_TYPE_TAG_INT8 = 2, @@ -286,16 +287,22 @@ typedef enum { GI_TYPE_TAG_FLOAT = 16, GI_TYPE_TAG_DOUBLE = 17, GI_TYPE_TAG_TIME_T = 18, - GI_TYPE_TAG_UTF8 = 19, - GI_TYPE_TAG_FILENAME = 20, - GI_TYPE_TAG_ARRAY = 21, - GI_TYPE_TAG_INTERFACE = 22, - GI_TYPE_TAG_GLIST = 23, - GI_TYPE_TAG_GSLIST = 24, - GI_TYPE_TAG_GHASH = 25, - GI_TYPE_TAG_ERROR = 26 + GI_TYPE_TAG_GTYPE = 19, + GI_TYPE_TAG_UTF8 = 20, + GI_TYPE_TAG_FILENAME = 21, + /* Non-basic types */ + GI_TYPE_TAG_ARRAY = 22, + GI_TYPE_TAG_INTERFACE = 23, + GI_TYPE_TAG_GLIST = 24, + GI_TYPE_TAG_GSLIST = 25, + GI_TYPE_TAG_GHASH = 26, + GI_TYPE_TAG_ERROR = 27 + /* Note - there is only room currently for 32 tags. + * See docs/typelib-format.txt SimpleTypeBlob definition */ } GITypeTag; +#define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY) + const gchar* g_type_tag_to_string (GITypeTag type); gboolean g_type_info_is_pointer (GITypeInfo *info); diff --git a/girepository/girparser.c b/girepository/girparser.c index fbdea587..52f2294c 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -222,7 +222,8 @@ state_switch (ParseContext *ctx, ParseState newstate) ctx->state = newstate; } -static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboolean in_glib); +static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboolean in_glib, + gboolean in_gobject); typedef struct { const gchar *str; @@ -255,6 +256,7 @@ static BasicTypeInfo basic_types[] = { { "float", GI_TYPE_TAG_FLOAT, 0 }, { "double", GI_TYPE_TAG_DOUBLE, 0 }, { "time_t", GI_TYPE_TAG_TIME_T, 0 }, + { "GType", GI_TYPE_TAG_GTYPE, 0 }, { "utf8", GI_TYPE_TAG_UTF8, 1 }, { "filename", GI_TYPE_TAG_FILENAME,1 }, }; @@ -277,7 +279,8 @@ parse_basic (const char *str) } static GIrNodeType * -parse_type_internal (const gchar *str, char **next, gboolean in_glib) +parse_type_internal (const gchar *str, char **next, gboolean in_glib, + gboolean in_gobject) { const BasicTypeInfo *basic; GIrNodeType *type; @@ -287,6 +290,13 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib) type->unparsed = g_strdup (str); + /* See comment below on GLib.List handling */ + if (in_gobject && strcmp (str, "Type") == 0) + { + temporary_type = g_strdup ("GLib.Type"); + str = temporary_type; + } + basic = parse_basic (str); if (basic != NULL) { @@ -298,11 +308,10 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib) } else if (in_glib) { - /* If we're inside GLib, handle "List" by prefixing it with + /* If we're inside GLib, handle "List" etc. by prefixing with * "GLib." so the parsing code below doesn't have to get more * special. */ - if (g_str_has_prefix (str, "List<") || strcmp (str, "List") == 0) { @@ -437,17 +446,18 @@ parse_type (ParseContext *ctx, const gchar *type) gchar *str; GIrNodeType *node; const BasicTypeInfo *basic; - gboolean in_glib; + gboolean in_glib, in_gobject; gboolean matched_special = FALSE; in_glib = strcmp (ctx->namespace, "GLib") == 0; + in_gobject = strcmp (ctx->namespace, "GObject") == 0; /* Do not search aliases for basic types */ basic = parse_basic (type); if (basic == NULL) type = resolve_aliases (ctx, type); - node = parse_type_internal (type, NULL, in_glib); + node = parse_type_internal (type, NULL, in_glib, in_gobject); if (node) g_debug ("Parsed type: %s => %d", type, node->tag); else diff --git a/giscanner/ast.py b/giscanner/ast.py index 93154d2c..7cd4fc6c 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -48,6 +48,7 @@ TYPE_ULONG = 'ulong' TYPE_SSIZET = 'ssize_t' TYPE_SIZET = 'size_t' TYPE_TIMET = 'time_t' +TYPE_GTYPE = 'GType' TYPE_FLOAT = 'float' TYPE_DOUBLE = 'double' TYPE_STRING = 'utf8' # requires zero-terminated @@ -57,7 +58,7 @@ BASIC_GIR_TYPES = [TYPE_BOOLEAN, TYPE_INT8, TYPE_UINT8, TYPE_INT16, TYPE_UINT16, TYPE_INT32, TYPE_UINT32, TYPE_INT64, TYPE_UINT64, TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_SSIZET, TYPE_SIZET, TYPE_FLOAT, - TYPE_DOUBLE, TYPE_TIMET] + TYPE_DOUBLE, TYPE_TIMET, TYPE_GTYPE] GIR_TYPES = [TYPE_NONE, TYPE_ANY] GIR_TYPES.extend(BASIC_GIR_TYPES) GIR_TYPES.extend([TYPE_STRING, TYPE_FILENAME]) diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py index 3916b773..dbe32ded 100644 --- a/giscanner/glibtransformer.py +++ b/giscanner/glibtransformer.py @@ -110,6 +110,11 @@ class GLibTransformer(object): for node in namespace.nodes: self._parse_node(node) + # We don't want an alias for this - it's handled specially in + # the typelib compiler. + if namespace.name == 'GObject': + del self._names.aliases['Type'] + # Introspection is done from within parsing # Second pass: pair boxed structures @@ -253,13 +258,10 @@ class GLibTransformer(object): # No GObjects in GLib return False # GType *_get_type(void) - # This is a bit fishy, why do we need all these aliases? if func.retval.type.name not in ['Type', 'GType', - 'Object.Type', 'GObject.Type', - 'Gtk.Type', - 'GObject.GType']: + 'Gtk.Type']: print ("Warning: *_get_type function returns '%r'" ", not GObject.Type") % (func.retval.type.name, ) return False diff --git a/tests/scanner/foo-expected.gir b/tests/scanner/foo-expected.gir index 81158550..8c6b8b5e 100644 --- a/tests/scanner/foo-expected.gir +++ b/tests/scanner/foo-expected.gir @@ -73,7 +73,7 @@ <type name="any" c:type="void*"/> </parameter> <parameter name="some_type"> - <type name="GObject.Type" c:type="GType"/> + <type name="GType" c:type="GType"/> </parameter> </parameters> </method> diff --git a/tools/generate.c b/tools/generate.c index dca2cdac..5f10d27c 100644 --- a/tools/generate.c +++ b/tools/generate.c @@ -64,30 +64,6 @@ write_type_info (const gchar *namespace, GITypeInfo *type; gboolean is_pointer; - const gchar* basic[] = { - "none", - "boolean", - "int8", - "uint8", - "int16", - "uint16", - "int32", - "uint32", - "int64", - "uint64", - "int", - "uint", - "long", - "ulong", - "ssize", - "size", - "float", - "double", - "time_t", - "utf8", - "filename" - }; - check_unresolved ((GIBaseInfo*)info); tag = g_type_info_get_tag (info); @@ -100,8 +76,8 @@ write_type_info (const gchar *namespace, else g_fprintf (file, "%s", "none"); } - else if (tag < GI_TYPE_TAG_ARRAY) - g_fprintf (file, "%s", basic[tag]); + else if (G_TYPE_TAG_IS_BASIC (tag)) + g_fprintf (file, "%s", g_type_tag_to_string (tag)); else if (tag == GI_TYPE_TAG_ARRAY) { gint length; |