Avoid searching aliases for basic types

* girepository/girparser.c: Don't search aliases
	for basic types.

svn path=/trunk/; revision=529
This commit is contained in:
Colin Walters 2008-08-29 20:06:10 +00:00
parent da9249d559
commit 63bb95c0db

View File

@ -218,16 +218,13 @@ state_switch (ParseContext *ctx, ParseState 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);
static GIrNodeType * typedef struct {
parse_type_internal (const gchar *str, char **next, gboolean in_glib)
{
gint i;
static struct {
const gchar *str; const gchar *str;
gint tag; gint tag;
gboolean pointer; gboolean pointer;
} basic[] = { } BasicTypeInfo;
static BasicTypeInfo basic_types[] = {
{ "none", GI_TYPE_TAG_VOID, 0 }, { "none", GI_TYPE_TAG_VOID, 0 },
{ "any", GI_TYPE_TAG_VOID, 1 }, { "any", GI_TYPE_TAG_VOID, 1 },
@ -293,19 +290,55 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
{ "gchar*", GI_TYPE_TAG_UTF8, 1 } { "gchar*", GI_TYPE_TAG_UTF8, 1 }
}; };
gint n_basic = G_N_ELEMENTS (basic); static const BasicTypeInfo *
parse_basic (const char *str)
{
gint i;
gint n_basic = G_N_ELEMENTS (basic_types);
gchar *temporary_type = NULL; gchar *temporary_type = NULL;
const gchar *start; const gchar *start;
const gchar *end; const gchar *end;
for (i = 0; i < n_basic; i++)
{
if (g_str_has_prefix (str, basic_types[i].str))
return &(basic_types[i]);
}
return NULL;
}
static GIrNodeType *
parse_type_internal (const gchar *str, char **next, gboolean in_glib)
{
const BasicTypeInfo *basic;
GIrNodeType *type; GIrNodeType *type;
char *temporary_type = NULL;
type = (GIrNodeType *)g_ir_node_new (G_IR_NODE_TYPE); type = (GIrNodeType *)g_ir_node_new (G_IR_NODE_TYPE);
type->unparsed = g_strdup (str); type->unparsed = g_strdup (str);
if (in_glib) basic = parse_basic (str);
if (basic != NULL)
{ {
type->is_basic = TRUE;
type->tag = basic->tag;
type->is_pointer = basic->pointer;
str += strlen(basic->str);
if (*str == '*' && !type->is_pointer)
{
type->is_pointer = TRUE;
(str)++;
}
}
else if (in_glib)
{
/* If we're inside GLib, handle "List" by prefixing it with
* "GLib." so the parsing code below doesn't have to get more
* special.
*/
if (g_str_has_prefix (str, "List<") || if (g_str_has_prefix (str, "List<") ||
strcmp (str, "List") == 0) strcmp (str, "List") == 0)
{ {
@ -332,25 +365,7 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
} }
} }
for (i = 0; i < n_basic; i++) if (basic != NULL)
{
if (g_str_has_prefix (str, basic[i].str))
{
type->is_basic = TRUE;
type->tag = basic[i].tag;
type->is_pointer = basic[i].pointer;
str += strlen(basic[i].str);
if (*str == '*' && !type->is_pointer)
{
type->is_pointer = TRUE;
str++;
}
break;
}
}
if (i < n_basic)
/* found a basic type */; /* found a basic type */;
else if (g_str_has_prefix (str, "GLib.List") || else if (g_str_has_prefix (str, "GLib.List") ||
g_str_has_prefix (str, "GLib.SList")) g_str_has_prefix (str, "GLib.SList"))
@ -440,7 +455,7 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
if (*str == '<') if (*str == '<')
{ {
(str)++; (str)++;
char *tmp; char *tmp, *end;
end = strchr (str, '>'); end = strchr (str, '>');
tmp = g_strndup (str, end - str); tmp = g_strndup (str, end - str);
@ -454,7 +469,7 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
{ {
type->tag = GI_TYPE_TAG_INTERFACE; type->tag = GI_TYPE_TAG_INTERFACE;
type->is_interface = TRUE; type->is_interface = TRUE;
start = str; const char *start = str;
/* must be an interface type */ /* must be an interface type */
while (g_ascii_isalnum (*str) || while (g_ascii_isalnum (*str) ||
@ -476,6 +491,7 @@ parse_type_internal (const gchar *str, char **next, gboolean in_glib)
if (g_str_has_prefix (str, "[")) if (g_str_has_prefix (str, "["))
{ {
GIrNodeType *array; GIrNodeType *array;
int i;
array = (GIrNodeType *)g_ir_node_new (G_IR_NODE_TYPE); array = (GIrNodeType *)g_ir_node_new (G_IR_NODE_TYPE);
@ -561,12 +577,17 @@ parse_type (ParseContext *ctx, const gchar *type)
{ {
gchar *str; gchar *str;
GIrNodeType *node; GIrNodeType *node;
const BasicTypeInfo *basic;
gboolean in_glib; gboolean in_glib;
gboolean matched_special = FALSE; gboolean matched_special = FALSE;
in_glib = strcmp (ctx->namespace, "GLib") == 0; in_glib = strcmp (ctx->namespace, "GLib") == 0;
/* Do not search aliases for basic types */
basic = parse_basic (type);
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);
if (node) if (node)
g_debug ("Parsed type: %s => %d", type, node->tag); g_debug ("Parsed type: %s => %d", type, node->tag);