mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 18:26:19 +01:00
Refactor a couple of parsing functions to be simpler to follow. Avoid huge
2008-08-24 Johan Dahlin <johan@gnome.org> * girepository/girparser.c (start_glib_boxed), (start_function), (start_field), (start_alias): Refactor a couple of parsing functions to be simpler to follow. Avoid huge ifs. svn path=/trunk/; revision=481
This commit is contained in:
parent
78f4434ef6
commit
ed13aae5f2
130
girparser.c
130
girparser.c
@ -480,13 +480,15 @@ start_glib_boxed (GMarkupParseContext *context,
|
||||
ParseContext *ctx,
|
||||
GError **error)
|
||||
{
|
||||
if (strcmp (element_name, "glib:boxed") == 0 &&
|
||||
ctx->state == STATE_NAMESPACE)
|
||||
{
|
||||
const gchar *name;
|
||||
const gchar *typename;
|
||||
const gchar *typeinit;
|
||||
const gchar *deprecated;
|
||||
GIrNodeBoxed *boxed;
|
||||
|
||||
if (!(strcmp (element_name, "glib:boxed") == 0 &&
|
||||
ctx->state == STATE_NAMESPACE))
|
||||
return FALSE;
|
||||
|
||||
name = find_attribute ("glib:name", attribute_names, attribute_values);
|
||||
typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
|
||||
@ -494,14 +496,20 @@ start_glib_boxed (GMarkupParseContext *context,
|
||||
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
|
||||
|
||||
if (name == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:name");
|
||||
else if (typename == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
|
||||
else if (typeinit == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
|
||||
else
|
||||
{
|
||||
GIrNodeBoxed *boxed;
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:name");
|
||||
return FALSE;
|
||||
}
|
||||
else if (typename == NULL)
|
||||
{
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
|
||||
return FALSE;
|
||||
}
|
||||
else if (typeinit == NULL)
|
||||
{
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
boxed = (GIrNodeBoxed *) g_ir_node_new (G_IR_NODE_BOXED);
|
||||
|
||||
@ -518,12 +526,8 @@ start_glib_boxed (GMarkupParseContext *context,
|
||||
g_list_append (ctx->current_module->entries, boxed);
|
||||
|
||||
state_switch (ctx, STATE_BOXED);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -534,35 +538,50 @@ start_function (GMarkupParseContext *context,
|
||||
ParseContext *ctx,
|
||||
GError **error)
|
||||
{
|
||||
if ((ctx->state == STATE_NAMESPACE &&
|
||||
(strcmp (element_name, "function") == 0 ||
|
||||
strcmp (element_name, "callback") == 0)) ||
|
||||
((ctx->state == STATE_CLASS ||
|
||||
ctx->state == STATE_INTERFACE ||
|
||||
ctx->state == STATE_BOXED ||
|
||||
ctx->state == STATE_UNION) &&
|
||||
(strcmp (element_name, "method") == 0 ||
|
||||
strcmp (element_name, "callback") == 0)) ||
|
||||
((ctx->state == STATE_CLASS ||
|
||||
ctx->state == STATE_BOXED) &&
|
||||
(strcmp (element_name, "constructor") == 0)) ||
|
||||
(ctx->state == STATE_STRUCT && strcmp (element_name, "callback") == 0))
|
||||
{
|
||||
const gchar *name;
|
||||
const gchar *symbol;
|
||||
const gchar *deprecated;
|
||||
GIrNodeFunction *function;
|
||||
gboolean found = FALSE;
|
||||
|
||||
switch (ctx->state)
|
||||
{
|
||||
case STATE_NAMESPACE:
|
||||
found = (strcmp (element_name, "function") == 0 ||
|
||||
strcmp (element_name, "callback") == 0);
|
||||
break;
|
||||
case STATE_CLASS:
|
||||
case STATE_BOXED:
|
||||
case STATE_STRUCT:
|
||||
case STATE_UNION:
|
||||
found = strcmp (element_name, "constructor") == 0;
|
||||
/* fallthrough */
|
||||
case STATE_INTERFACE:
|
||||
found = (found ||
|
||||
strcmp (element_name, "method") == 0 ||
|
||||
strcmp (element_name, "callback") == 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return FALSE;
|
||||
|
||||
name = find_attribute ("name", attribute_names, attribute_values);
|
||||
symbol = find_attribute ("c:identifier", attribute_names, attribute_values);
|
||||
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
|
||||
|
||||
if (name == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||
else if (strcmp (element_name, "callback") != 0 && symbol == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "c:identifier");
|
||||
else
|
||||
{
|
||||
GIrNodeFunction *function;
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||
return FALSE;
|
||||
}
|
||||
else if (strcmp (element_name, "callback") != 0 && symbol == NULL)
|
||||
{
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "c:identifier");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function = (GIrNodeFunction *) g_ir_node_new (G_IR_NODE_FUNCTION);
|
||||
|
||||
@ -642,10 +661,6 @@ start_function (GMarkupParseContext *context,
|
||||
state_switch (ctx, STATE_FUNCTION);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -793,19 +808,28 @@ start_field (GMarkupParseContext *context,
|
||||
ParseContext *ctx,
|
||||
GError **error)
|
||||
{
|
||||
if (strcmp (element_name, "field") == 0 &&
|
||||
(ctx->state == STATE_CLASS ||
|
||||
ctx->state == STATE_BOXED ||
|
||||
ctx->state == STATE_STRUCT ||
|
||||
ctx->state == STATE_UNION ||
|
||||
ctx->state == STATE_INTERFACE))
|
||||
{
|
||||
const gchar *name;
|
||||
const gchar *readable;
|
||||
const gchar *writable;
|
||||
const gchar *bits;
|
||||
const gchar *branch;
|
||||
const gchar *offset;
|
||||
GIrNodeField *field;
|
||||
|
||||
switch (ctx->state)
|
||||
{
|
||||
case STATE_CLASS:
|
||||
case STATE_BOXED:
|
||||
case STATE_STRUCT:
|
||||
case STATE_UNION:
|
||||
case STATE_INTERFACE:
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (strcmp (element_name, "field") != 0)
|
||||
return FALSE;
|
||||
|
||||
name = find_attribute ("name", attribute_names, attribute_values);
|
||||
readable = find_attribute ("readable", attribute_names, attribute_values);
|
||||
@ -815,10 +839,10 @@ start_field (GMarkupParseContext *context,
|
||||
offset = find_attribute ("offset", attribute_names, attribute_values);
|
||||
|
||||
if (name == NULL)
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||
else
|
||||
{
|
||||
GIrNodeField *field;
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
field = (GIrNodeField *)g_ir_node_new (G_IR_NODE_FIELD);
|
||||
ctx->current_typed = (GIrNode*) field;
|
||||
@ -905,11 +929,8 @@ start_field (GMarkupParseContext *context,
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -925,18 +946,21 @@ start_alias (GMarkupParseContext *context,
|
||||
const gchar *type;
|
||||
|
||||
name = find_attribute ("name", attribute_names, attribute_values);
|
||||
if (name == NULL) {
|
||||
if (name == NULL)
|
||||
{
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
target = find_attribute ("target", attribute_names, attribute_values);
|
||||
if (name == NULL) {
|
||||
if (name == NULL)
|
||||
{
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "target");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_hash_table_insert (ctx->aliases, g_strdup (name), g_strdup (target));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user