mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-23 07:39:17 +02: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
@ -479,14 +479,16 @@ start_glib_boxed (GMarkupParseContext *context,
|
|||||||
const gchar **attribute_values,
|
const gchar **attribute_values,
|
||||||
ParseContext *ctx,
|
ParseContext *ctx,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
|
||||||
if (strcmp (element_name, "glib:boxed") == 0 &&
|
|
||||||
ctx->state == STATE_NAMESPACE)
|
|
||||||
{
|
{
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
const gchar *typename;
|
const gchar *typename;
|
||||||
const gchar *typeinit;
|
const gchar *typeinit;
|
||||||
const gchar *deprecated;
|
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);
|
name = find_attribute ("glib:name", attribute_names, attribute_values);
|
||||||
typename = find_attribute ("glib:type-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);
|
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
|
||||||
|
|
||||||
if (name == NULL)
|
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);
|
boxed = (GIrNodeBoxed *) g_ir_node_new (G_IR_NODE_BOXED);
|
||||||
|
|
||||||
@ -518,14 +526,10 @@ start_glib_boxed (GMarkupParseContext *context,
|
|||||||
g_list_append (ctx->current_module->entries, boxed);
|
g_list_append (ctx->current_module->entries, boxed);
|
||||||
|
|
||||||
state_switch (ctx, STATE_BOXED);
|
state_switch (ctx, STATE_BOXED);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
start_function (GMarkupParseContext *context,
|
start_function (GMarkupParseContext *context,
|
||||||
const gchar *element_name,
|
const gchar *element_name,
|
||||||
@ -533,36 +537,51 @@ start_function (GMarkupParseContext *context,
|
|||||||
const gchar **attribute_values,
|
const gchar **attribute_values,
|
||||||
ParseContext *ctx,
|
ParseContext *ctx,
|
||||||
GError **error)
|
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 *name;
|
||||||
const gchar *symbol;
|
const gchar *symbol;
|
||||||
const gchar *deprecated;
|
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);
|
name = find_attribute ("name", attribute_names, attribute_values);
|
||||||
symbol = find_attribute ("c:identifier", attribute_names, attribute_values);
|
symbol = find_attribute ("c:identifier", attribute_names, attribute_values);
|
||||||
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
|
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
|
||||||
|
|
||||||
if (name == NULL)
|
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);
|
function = (GIrNodeFunction *) g_ir_node_new (G_IR_NODE_FUNCTION);
|
||||||
|
|
||||||
@ -643,10 +662,6 @@ start_function (GMarkupParseContext *context,
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
start_parameter (GMarkupParseContext *context,
|
start_parameter (GMarkupParseContext *context,
|
||||||
@ -792,13 +807,6 @@ start_field (GMarkupParseContext *context,
|
|||||||
const gchar **attribute_values,
|
const gchar **attribute_values,
|
||||||
ParseContext *ctx,
|
ParseContext *ctx,
|
||||||
GError **error)
|
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 *name;
|
||||||
const gchar *readable;
|
const gchar *readable;
|
||||||
@ -806,6 +814,22 @@ start_field (GMarkupParseContext *context,
|
|||||||
const gchar *bits;
|
const gchar *bits;
|
||||||
const gchar *branch;
|
const gchar *branch;
|
||||||
const gchar *offset;
|
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);
|
name = find_attribute ("name", attribute_names, attribute_values);
|
||||||
readable = find_attribute ("readable", 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);
|
offset = find_attribute ("offset", attribute_names, attribute_values);
|
||||||
|
|
||||||
if (name == NULL)
|
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);
|
field = (GIrNodeField *)g_ir_node_new (G_IR_NODE_FIELD);
|
||||||
ctx->current_typed = (GIrNode*) field;
|
ctx->current_typed = (GIrNode*) field;
|
||||||
@ -905,11 +929,8 @@ start_field (GMarkupParseContext *context,
|
|||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -925,18 +946,21 @@ start_alias (GMarkupParseContext *context,
|
|||||||
const gchar *type;
|
const gchar *type;
|
||||||
|
|
||||||
name = find_attribute ("name", attribute_names, attribute_values);
|
name = find_attribute ("name", attribute_names, attribute_values);
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
|
{
|
||||||
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
MISSING_ATTRIBUTE (context, error, element_name, "name");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
target = find_attribute ("target", attribute_names, attribute_values);
|
target = find_attribute ("target", attribute_names, attribute_values);
|
||||||
if (name == NULL) {
|
if (name == NULL)
|
||||||
|
{
|
||||||
MISSING_ATTRIBUTE (context, error, element_name, "target");
|
MISSING_ATTRIBUTE (context, error, element_name, "target");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_insert (ctx->aliases, g_strdup (name), g_strdup (target));
|
g_hash_table_insert (ctx->aliases, g_strdup (name), g_strdup (target));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user