Bug 554632: Create type tag for GType

svn path=/trunk/; revision=641
This commit is contained in:
Colin Walters 2008-10-02 13:25:46 +00:00
parent 9893df46cb
commit b26d8d2dce
3 changed files with 33 additions and 14 deletions

View File

@ -750,6 +750,8 @@ g_type_tag_to_string (GITypeTag type)
return "double"; return "double";
case GI_TYPE_TAG_TIME_T: case GI_TYPE_TAG_TIME_T:
return "time_t"; return "time_t";
case GI_TYPE_TAG_GTYPE:
return "GType";
case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_UTF8:
return "utf8"; return "utf8";
case GI_TYPE_TAG_FILENAME: case GI_TYPE_TAG_FILENAME:

View File

@ -267,6 +267,7 @@ GITypeInfo * g_arg_info_get_type (GIArgInfo *info);
/* GITypeInfo */ /* GITypeInfo */
typedef enum { typedef enum {
/* Basic types */
GI_TYPE_TAG_VOID = 0, GI_TYPE_TAG_VOID = 0,
GI_TYPE_TAG_BOOLEAN = 1, GI_TYPE_TAG_BOOLEAN = 1,
GI_TYPE_TAG_INT8 = 2, GI_TYPE_TAG_INT8 = 2,
@ -286,16 +287,22 @@ typedef enum {
GI_TYPE_TAG_FLOAT = 16, GI_TYPE_TAG_FLOAT = 16,
GI_TYPE_TAG_DOUBLE = 17, GI_TYPE_TAG_DOUBLE = 17,
GI_TYPE_TAG_TIME_T = 18, GI_TYPE_TAG_TIME_T = 18,
GI_TYPE_TAG_UTF8 = 19, GI_TYPE_TAG_GTYPE = 19,
GI_TYPE_TAG_FILENAME = 20, GI_TYPE_TAG_UTF8 = 20,
GI_TYPE_TAG_ARRAY = 21, GI_TYPE_TAG_FILENAME = 21,
GI_TYPE_TAG_INTERFACE = 22, /* Non-basic types */
GI_TYPE_TAG_GLIST = 23, GI_TYPE_TAG_ARRAY = 22,
GI_TYPE_TAG_GSLIST = 24, GI_TYPE_TAG_INTERFACE = 23,
GI_TYPE_TAG_GHASH = 25, GI_TYPE_TAG_GLIST = 24,
GI_TYPE_TAG_ERROR = 26 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; } GITypeTag;
#define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY)
const gchar* g_type_tag_to_string (GITypeTag type); const gchar* g_type_tag_to_string (GITypeTag type);
gboolean g_type_info_is_pointer (GITypeInfo *info); gboolean g_type_info_is_pointer (GITypeInfo *info);

View File

@ -222,7 +222,8 @@ state_switch (ParseContext *ctx, ParseState newstate)
ctx->state = 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 { typedef struct {
const gchar *str; const gchar *str;
@ -255,6 +256,7 @@ static BasicTypeInfo basic_types[] = {
{ "float", GI_TYPE_TAG_FLOAT, 0 }, { "float", GI_TYPE_TAG_FLOAT, 0 },
{ "double", GI_TYPE_TAG_DOUBLE, 0 }, { "double", GI_TYPE_TAG_DOUBLE, 0 },
{ "time_t", GI_TYPE_TAG_TIME_T, 0 }, { "time_t", GI_TYPE_TAG_TIME_T, 0 },
{ "GType", GI_TYPE_TAG_GTYPE, 0 },
{ "utf8", GI_TYPE_TAG_UTF8, 1 }, { "utf8", GI_TYPE_TAG_UTF8, 1 },
{ "filename", GI_TYPE_TAG_FILENAME,1 }, { "filename", GI_TYPE_TAG_FILENAME,1 },
}; };
@ -277,7 +279,8 @@ parse_basic (const char *str)
} }
static GIrNodeType * 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; const BasicTypeInfo *basic;
GIrNodeType *type; GIrNodeType *type;
@ -287,6 +290,13 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
type->unparsed = g_strdup (str); 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); basic = parse_basic (str);
if (basic != NULL) if (basic != NULL)
{ {
@ -298,11 +308,10 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
} }
else if (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 * "GLib." so the parsing code below doesn't have to get more
* special. * special.
*/ */
if (g_str_has_prefix (str, "List<") || if (g_str_has_prefix (str, "List<") ||
strcmp (str, "List") == 0) strcmp (str, "List") == 0)
{ {
@ -437,17 +446,18 @@ parse_type (ParseContext *ctx, const gchar *type)
gchar *str; gchar *str;
GIrNodeType *node; GIrNodeType *node;
const BasicTypeInfo *basic; const BasicTypeInfo *basic;
gboolean in_glib; gboolean in_glib, in_gobject;
gboolean matched_special = FALSE; gboolean matched_special = FALSE;
in_glib = strcmp (ctx->namespace, "GLib") == 0; in_glib = strcmp (ctx->namespace, "GLib") == 0;
in_gobject = strcmp (ctx->namespace, "GObject") == 0;
/* Do not search aliases for basic types */ /* Do not search aliases for basic types */
basic = parse_basic (type); basic = parse_basic (type);
if (basic == NULL) if (basic == NULL)
type = resolve_aliases (ctx, type); 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) if (node)
g_debug ("Parsed type: %s => %d", type, node->tag); g_debug ("Parsed type: %s => %d", type, node->tag);
else else