STATE_NAMESPACE_CONSTANT,
STATE_CLASS_CONSTANT,
STATE_INTERFACE_CONSTANT,
- STATE_ALIAS,
+ STATE_ALIAS, /* 30 */
STATE_TYPE,
STATE_ATTRIBUTE,
- STATE_UNKNOWN
+ STATE_PASSTHROUGH
} ParseState;
typedef struct _ParseContext ParseContext;
GHashTable *aliases;
GHashTable *disguised_structures;
+ const char *file_path;
const char *namespace;
const char *c_prefix;
GIrModule *current_module;
GSList *node_stack;
GIrNode *current_typed;
- gboolean is_varargs;
GList *type_stack;
GList *type_parameters;
int type_depth;
static void
state_switch (ParseContext *ctx, ParseState newstate)
{
- g_debug ("State: %d", newstate);
+ g_assert (ctx->state != newstate);
ctx->prev_state = ctx->state;
ctx->state = newstate;
}
static void
push_node (ParseContext *ctx, GIrNode *node)
{
+ g_assert (node != NULL);
g_debug ("pushing node %d %s", node->type, node->name);
ctx->node_stack = g_slist_prepend (ctx->node_stack, node);
}
return node;
}
+static gboolean
+introspectable_prelude (GMarkupParseContext *context,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ ParseContext *ctx,
+ ParseState new_state)
+{
+ const gchar *introspectable_arg;
+ gboolean introspectable;
+
+ g_assert (ctx->state != STATE_PASSTHROUGH);
+
+ introspectable_arg = find_attribute ("introspectable", attribute_names, attribute_values);
+ introspectable = !(introspectable_arg && atoi (introspectable_arg) == 0);
+
+ if (introspectable)
+ state_switch (ctx, new_state);
+ else
+ {
+ state_switch (ctx, STATE_PASSTHROUGH);
+ ctx->unknown_depth = 1;
+ }
+
+ return introspectable;
+}
+
static gboolean
start_glib_boxed (GMarkupParseContext *context,
const gchar *element_name,
ctx->state == STATE_NAMESPACE))
return FALSE;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_BOXED))
+ return TRUE;
+
name = find_attribute ("glib:name", attribute_names, attribute_values);
typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
ctx->current_module->entries =
g_list_append (ctx->current_module->entries, boxed);
- state_switch (ctx, STATE_BOXED);
-
return TRUE;
}
strcmp (element_name, "callback") == 0);
break;
case STATE_STRUCT_FIELD:
- ctx->in_embedded_type = TRUE;
found = (found || strcmp (element_name, "callback") == 0);
break;
default:
if (!found)
return FALSE;
+ if (ctx->state == STATE_STRUCT_FIELD)
+ ctx->in_embedded_type = TRUE;
+
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_FUNCTION))
+ return TRUE;
+
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);
}
push_node(ctx, (GIrNode *)function);
- state_switch (ctx, STATE_FUNCTION);
return TRUE;
}
ParseContext *ctx,
GError **error)
{
- if ((strcmp (element_name, "enumeration") == 0 && ctx->state == STATE_NAMESPACE) ||
- (strcmp (element_name, "bitfield") == 0 && ctx->state == STATE_NAMESPACE))
- {
- const gchar *name;
- const gchar *typename;
- const gchar *typeinit;
- const gchar *deprecated;
+ const gchar *name;
+ const gchar *typename;
+ const gchar *typeinit;
+ const gchar *deprecated;
+ GIrNodeEnum *enum_;
- name = find_attribute ("name", attribute_names, attribute_values);
- typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
- typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ if (!((strcmp (element_name, "enumeration") == 0 && ctx->state == STATE_NAMESPACE) ||
+ (strcmp (element_name, "bitfield") == 0 && ctx->state == STATE_NAMESPACE)))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeEnum *enum_;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_ENUM))
+ return TRUE;
- if (strcmp (element_name, "enumeration") == 0)
- enum_ = (GIrNodeEnum *) g_ir_node_new (G_IR_NODE_ENUM);
- else
- enum_ = (GIrNodeEnum *) g_ir_node_new (G_IR_NODE_FLAGS);
- ((GIrNode *)enum_)->name = g_strdup (name);
- enum_->gtype_name = g_strdup (typename);
- enum_->gtype_init = g_strdup (typeinit);
- if (deprecated)
- enum_->deprecated = TRUE;
- else
- enum_->deprecated = FALSE;
+ name = find_attribute ("name", attribute_names, attribute_values);
+ typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
+ typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- push_node (ctx, (GIrNode *) enum_);
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, enum_);
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
- state_switch (ctx, STATE_ENUM);
- }
+ if (strcmp (element_name, "enumeration") == 0)
+ enum_ = (GIrNodeEnum *) g_ir_node_new (G_IR_NODE_ENUM);
+ else
+ enum_ = (GIrNodeEnum *) g_ir_node_new (G_IR_NODE_FLAGS);
+ ((GIrNode *)enum_)->name = g_strdup (name);
+ enum_->gtype_name = g_strdup (typename);
+ enum_->gtype_init = g_strdup (typeinit);
+ if (deprecated)
+ enum_->deprecated = TRUE;
+ else
+ enum_->deprecated = FALSE;
- return TRUE;
- }
- return FALSE;
+ push_node (ctx, (GIrNode *) enum_);
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, enum_);
+
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "property") == 0 &&
- (ctx->state == STATE_CLASS ||
- ctx->state == STATE_INTERFACE))
- {
- const gchar *name;
- const gchar *readable;
- const gchar *writable;
- const gchar *construct;
- const gchar *construct_only;
- const gchar *transfer;
+ ParseState target_state;
+ const gchar *name;
+ const gchar *readable;
+ const gchar *writable;
+ const gchar *construct;
+ const gchar *construct_only;
+ const gchar *transfer;
+ GIrNodeProperty *property;
+ GIrNodeInterface *iface;
- name = find_attribute ("name", attribute_names, attribute_values);
- readable = find_attribute ("readable", attribute_names, attribute_values);
- writable = find_attribute ("writable", attribute_names, attribute_values);
- construct = find_attribute ("construct", attribute_names, attribute_values);
- construct_only = find_attribute ("construct-only", attribute_names, attribute_values);
- transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "property") == 0 &&
+ (ctx->state == STATE_CLASS ||
+ ctx->state == STATE_INTERFACE)))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeProperty *property;
- GIrNodeInterface *iface;
+ if (ctx->state == STATE_CLASS)
+ target_state = STATE_CLASS_PROPERTY;
+ else if (ctx->state == STATE_INTERFACE)
+ target_state = STATE_INTERFACE_PROPERTY;
+ else
+ g_assert_not_reached ();
- property = (GIrNodeProperty *) g_ir_node_new (G_IR_NODE_PROPERTY);
- ctx->current_typed = (GIrNode*) property;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, target_state))
+ return TRUE;
- ((GIrNode *)property)->name = g_strdup (name);
- /* Assume properties are readable */
- if (readable == NULL || strcmp (readable, "1") == 0)
- property->readable = TRUE;
- else
- property->readable = FALSE;
- if (writable && strcmp (writable, "1") == 0)
- property->writable = TRUE;
- else
- property->writable = FALSE;
- if (construct && strcmp (construct, "1") == 0)
- property->construct = TRUE;
- else
- property->construct = FALSE;
- if (construct_only && strcmp (construct_only, "1") == 0)
- property->construct_only = TRUE;
- else
- property->construct_only = FALSE;
+ name = find_attribute ("name", attribute_names, attribute_values);
+ readable = find_attribute ("readable", attribute_names, attribute_values);
+ writable = find_attribute ("writable", attribute_names, attribute_values);
+ construct = find_attribute ("construct", attribute_names, attribute_values);
+ construct_only = find_attribute ("construct-only", attribute_names, attribute_values);
+ transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
+
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
- parse_property_transfer (property, transfer, ctx);
+ property = (GIrNodeProperty *) g_ir_node_new (G_IR_NODE_PROPERTY);
+ ctx->current_typed = (GIrNode*) property;
- iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
- iface->members = g_list_append (iface->members, property);
+ ((GIrNode *)property)->name = g_strdup (name);
- if (ctx->state == STATE_CLASS)
- state_switch (ctx, STATE_CLASS_PROPERTY);
- else if (ctx->state == STATE_INTERFACE)
- state_switch (ctx, STATE_INTERFACE_PROPERTY);
- else
- g_assert_not_reached ();
- }
+ /* Assume properties are readable */
+ if (readable == NULL || strcmp (readable, "1") == 0)
+ property->readable = TRUE;
+ else
+ property->readable = FALSE;
+ if (writable && strcmp (writable, "1") == 0)
+ property->writable = TRUE;
+ else
+ property->writable = FALSE;
+ if (construct && strcmp (construct, "1") == 0)
+ property->construct = TRUE;
+ else
+ property->construct = FALSE;
+ if (construct_only && strcmp (construct_only, "1") == 0)
+ property->construct_only = TRUE;
+ else
+ property->construct_only = FALSE;
- return TRUE;
- }
- return FALSE;
+ parse_property_transfer (property, transfer, ctx);
+
+ iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
+ iface->members = g_list_append (iface->members, property);
+
+ return TRUE;
}
static gint
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "member") == 0 &&
- ctx->state == STATE_ENUM)
- {
- const gchar *name;
- const gchar *value;
- const gchar *deprecated;
+ const gchar *name;
+ const gchar *value;
+ const gchar *deprecated;
+ GIrNodeEnum *enum_;
+ GIrNodeValue *value_;
- name = find_attribute ("name", attribute_names, attribute_values);
- value = find_attribute ("value", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "member") == 0 &&
+ ctx->state == STATE_ENUM))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeEnum *enum_;
- GIrNodeValue *value_;
+ name = find_attribute ("name", attribute_names, attribute_values);
+ value = find_attribute ("value", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
- value_ = (GIrNodeValue *) g_ir_node_new (G_IR_NODE_VALUE);
+ value_ = (GIrNodeValue *) g_ir_node_new (G_IR_NODE_VALUE);
- ((GIrNode *)value_)->name = g_strdup (name);
+ ((GIrNode *)value_)->name = g_strdup (name);
- value_->value = parse_value (value);
+ value_->value = parse_value (value);
- if (deprecated)
- value_->deprecated = TRUE;
- else
- value_->deprecated = FALSE;
+ if (deprecated)
+ value_->deprecated = TRUE;
+ else
+ value_->deprecated = FALSE;
- enum_ = (GIrNodeEnum *)CURRENT_NODE (ctx);
- enum_->values = g_list_append (enum_->values, value_);
- }
+ enum_ = (GIrNodeEnum *)CURRENT_NODE (ctx);
+ enum_->values = g_list_append (enum_->values, value_);
- return TRUE;
- }
- return FALSE;
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "constant") == 0 &&
- (ctx->state == STATE_NAMESPACE ||
- ctx->state == STATE_CLASS ||
- ctx->state == STATE_INTERFACE))
+ ParseState prev_state;
+ ParseState target_state;
+ const gchar *name;
+ const gchar *value;
+ const gchar *deprecated;
+ GIrNodeConstant *constant;
+
+ if (!(strcmp (element_name, "constant") == 0 &&
+ (ctx->state == STATE_NAMESPACE ||
+ ctx->state == STATE_CLASS ||
+ ctx->state == STATE_INTERFACE)))
+ return FALSE;
+
+ switch (ctx->state)
{
- const gchar *name;
- const gchar *value;
- const gchar *deprecated;
+ case STATE_NAMESPACE:
+ target_state = STATE_NAMESPACE_CONSTANT;
+ break;
+ case STATE_CLASS:
+ target_state = STATE_CLASS_CONSTANT;
+ break;
+ case STATE_INTERFACE:
+ target_state = STATE_INTERFACE_CONSTANT;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
- name = find_attribute ("name", attribute_names, attribute_values);
- value = find_attribute ("value", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ prev_state = ctx->state;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else if (value == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "value");
- else
- {
- GIrNodeConstant *constant;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, target_state))
+ return TRUE;
- constant = (GIrNodeConstant *) g_ir_node_new (G_IR_NODE_CONSTANT);
+ name = find_attribute ("name", attribute_names, attribute_values);
+ value = find_attribute ("value", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- ((GIrNode *)constant)->name = g_strdup (name);
- constant->value = g_strdup (value);
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
+ else if (value == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "value");
+ return FALSE;
+ }
- ctx->current_typed = (GIrNode*) constant;
+ constant = (GIrNodeConstant *) g_ir_node_new (G_IR_NODE_CONSTANT);
- if (deprecated)
- constant->deprecated = TRUE;
- else
- constant->deprecated = FALSE;
+ ((GIrNode *)constant)->name = g_strdup (name);
+ constant->value = g_strdup (value);
- if (ctx->state == STATE_NAMESPACE)
- {
- push_node (ctx, (GIrNode *) constant);
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, constant);
- }
- else
- {
- GIrNodeInterface *iface;
+ ctx->current_typed = (GIrNode*) constant;
- iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
- iface->members = g_list_append (iface->members, constant);
- }
+ if (deprecated)
+ constant->deprecated = TRUE;
+ else
+ constant->deprecated = FALSE;
- switch (ctx->state)
- {
- case STATE_NAMESPACE:
- state_switch (ctx, STATE_NAMESPACE_CONSTANT);
- break;
- case STATE_CLASS:
- state_switch (ctx, STATE_CLASS_CONSTANT);
- break;
- case STATE_INTERFACE:
- state_switch (ctx, STATE_INTERFACE_CONSTANT);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }
+ if (prev_state == STATE_NAMESPACE)
+ {
+ push_node (ctx, (GIrNode *) constant);
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, constant);
+ }
+ else
+ {
+ GIrNodeInterface *iface;
- return TRUE;
+ iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
+ iface->members = g_list_append (iface->members, constant);
}
- return FALSE;
+
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "errordomain") == 0 &&
- ctx->state == STATE_NAMESPACE)
- {
- const gchar *name;
- const gchar *getquark;
- const gchar *codes;
- const gchar *deprecated;
+ const gchar *name;
+ const gchar *getquark;
+ const gchar *codes;
+ const gchar *deprecated;
+ GIrNodeErrorDomain *domain;
- name = find_attribute ("name", attribute_names, attribute_values);
- getquark = find_attribute ("get-quark", attribute_names, attribute_values);
- codes = find_attribute ("codes", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "errordomain") == 0 &&
+ ctx->state == STATE_NAMESPACE))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else if (getquark == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "getquark");
- else if (codes == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "codes");
- else
- {
- GIrNodeErrorDomain *domain;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_ERRORDOMAIN))
+ return TRUE;
- domain = (GIrNodeErrorDomain *) g_ir_node_new (G_IR_NODE_ERROR_DOMAIN);
- ((GIrNode *)domain)->name = g_strdup (name);
- domain->getquark = g_strdup (getquark);
- domain->codes = g_strdup (codes);
+ name = find_attribute ("name", attribute_names, attribute_values);
+ getquark = find_attribute ("get-quark", attribute_names, attribute_values);
+ codes = find_attribute ("codes", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- if (deprecated)
- domain->deprecated = TRUE;
- else
- domain->deprecated = FALSE;
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
+ else if (getquark == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "getquark");
+ return FALSE;
+ }
+ else if (codes == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "codes");
+ return FALSE;
+ }
- push_node (ctx, (GIrNode *) domain);
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, domain);
+ domain = (GIrNodeErrorDomain *) g_ir_node_new (G_IR_NODE_ERROR_DOMAIN);
- state_switch (ctx, STATE_ERRORDOMAIN);
- }
+ ((GIrNode *)domain)->name = g_strdup (name);
+ domain->getquark = g_strdup (getquark);
+ domain->codes = g_strdup (codes);
- return TRUE;
- }
- return FALSE;
+ if (deprecated)
+ domain->deprecated = TRUE;
+ else
+ domain->deprecated = FALSE;
+
+ push_node (ctx, (GIrNode *) domain);
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, domain);
+
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "interface") == 0 &&
- ctx->state == STATE_NAMESPACE)
- {
- const gchar *name;
- const gchar *typename;
- const gchar *typeinit;
- const gchar *deprecated;
- const gchar *glib_type_struct;
-
- name = find_attribute ("name", attribute_names, attribute_values);
- typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
- typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
- glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
-
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "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
- {
- GIrNodeInterface *iface;
-
- iface = (GIrNodeInterface *) g_ir_node_new (G_IR_NODE_INTERFACE);
- ((GIrNode *)iface)->name = g_strdup (name);
- iface->gtype_name = g_strdup (typename);
- iface->gtype_init = g_strdup (typeinit);
- iface->glib_type_struct = g_strdup (glib_type_struct);
- if (deprecated)
- iface->deprecated = TRUE;
- else
- iface->deprecated = FALSE;
+ const gchar *name;
+ const gchar *typename;
+ const gchar *typeinit;
+ const gchar *deprecated;
+ const gchar *glib_type_struct;
+ GIrNodeInterface *iface;
- push_node (ctx, (GIrNode *) iface);
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, iface);
+ if (!(strcmp (element_name, "interface") == 0 &&
+ ctx->state == STATE_NAMESPACE))
+ return FALSE;
- state_switch (ctx, STATE_INTERFACE);
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_INTERFACE))
+ return TRUE;
- }
+ name = find_attribute ("name", attribute_names, attribute_values);
+ typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
+ typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
+ glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- return TRUE;
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
}
- return FALSE;
-}
-
-static gboolean
+ 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;
+ }
+
+ iface = (GIrNodeInterface *) g_ir_node_new (G_IR_NODE_INTERFACE);
+ ((GIrNode *)iface)->name = g_strdup (name);
+ iface->gtype_name = g_strdup (typename);
+ iface->gtype_init = g_strdup (typeinit);
+ iface->glib_type_struct = g_strdup (glib_type_struct);
+ if (deprecated)
+ iface->deprecated = TRUE;
+ else
+ iface->deprecated = FALSE;
+
+ push_node (ctx, (GIrNode *) iface);
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, iface);
+
+ return TRUE;
+}
+
+static gboolean
start_class (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "class") == 0 &&
- ctx->state == STATE_NAMESPACE)
- {
- const gchar *name;
- const gchar *parent;
- const gchar *glib_type_struct;
- const gchar *typename;
- const gchar *typeinit;
- const gchar *deprecated;
- const gchar *abstract;
+ const gchar *name;
+ const gchar *parent;
+ const gchar *glib_type_struct;
+ const gchar *typename;
+ const gchar *typeinit;
+ const gchar *deprecated;
+ const gchar *abstract;
+ GIrNodeInterface *iface;
- name = find_attribute ("name", attribute_names, attribute_values);
- parent = find_attribute ("parent", attribute_names, attribute_values);
- glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
- typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
- typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- abstract = find_attribute ("abstract", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "class") == 0 &&
+ ctx->state == STATE_NAMESPACE))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else if (typename == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
- else if (typeinit == NULL && strcmp (typename, "GObject"))
- MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
- else
- {
- GIrNodeInterface *iface;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_CLASS))
+ return TRUE;
- iface = (GIrNodeInterface *) g_ir_node_new (G_IR_NODE_OBJECT);
- ((GIrNode *)iface)->name = g_strdup (name);
- iface->gtype_name = g_strdup (typename);
- iface->gtype_init = g_strdup (typeinit);
- iface->parent = g_strdup (parent);
- iface->glib_type_struct = g_strdup (glib_type_struct);
- if (deprecated)
- iface->deprecated = TRUE;
- else
- iface->deprecated = FALSE;
+ name = find_attribute ("name", attribute_names, attribute_values);
+ parent = find_attribute ("parent", attribute_names, attribute_values);
+ glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
+ typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
+ typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ abstract = find_attribute ("abstract", attribute_names, attribute_values);
- iface->abstract = abstract && strcmp (abstract, "1") == 0;
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
+ else if (typename == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
+ return FALSE;
+ }
+ else if (typeinit == NULL && strcmp (typename, "GObject"))
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
+ return FALSE;
+ }
- push_node (ctx, (GIrNode *) iface);
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, iface);
+ iface = (GIrNodeInterface *) g_ir_node_new (G_IR_NODE_OBJECT);
+ ((GIrNode *)iface)->name = g_strdup (name);
+ iface->gtype_name = g_strdup (typename);
+ iface->gtype_init = g_strdup (typeinit);
+ iface->parent = g_strdup (parent);
+ iface->glib_type_struct = g_strdup (glib_type_struct);
+ if (deprecated)
+ iface->deprecated = TRUE;
+ else
+ iface->deprecated = FALSE;
- state_switch (ctx, STATE_CLASS);
- }
+ iface->abstract = abstract && strcmp (abstract, "1") == 0;
- return TRUE;
- }
- return FALSE;
+ push_node (ctx, (GIrNode *) iface);
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, iface);
+
+ return TRUE;
}
static gboolean
{
state_switch (ctx, STATE_TYPE);
ctx->type_depth = 1;
- if (is_varargs)
- {
- switch (CURRENT_NODE (ctx)->type)
- {
- case G_IR_NODE_FUNCTION:
- case G_IR_NODE_CALLBACK:
- {
- GIrNodeFunction *func = (GIrNodeFunction *)CURRENT_NODE (ctx);
- func->is_varargs = TRUE;
- }
- break;
- case G_IR_NODE_VFUNC:
- {
- GIrNodeVFunc *vfunc = (GIrNodeVFunc *)CURRENT_NODE (ctx);
- vfunc->is_varargs = TRUE;
- }
- break;
- /* list others individually rather than with default: so that compiler
- * warns if new node types are added without adding them to the switch
- */
- case G_IR_NODE_INVALID:
- case G_IR_NODE_ENUM:
- case G_IR_NODE_FLAGS:
- case G_IR_NODE_CONSTANT:
- case G_IR_NODE_ERROR_DOMAIN:
- case G_IR_NODE_PARAM:
- case G_IR_NODE_TYPE:
- case G_IR_NODE_PROPERTY:
- case G_IR_NODE_SIGNAL:
- case G_IR_NODE_VALUE:
- case G_IR_NODE_FIELD:
- case G_IR_NODE_XREF:
- case G_IR_NODE_STRUCT:
- case G_IR_NODE_BOXED:
- case G_IR_NODE_OBJECT:
- case G_IR_NODE_INTERFACE:
- case G_IR_NODE_UNION:
- g_assert_not_reached ();
- break;
- }
- }
ctx->type_stack = NULL;
ctx->type_parameters = NULL;
}
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "return-value") == 0 &&
- ctx->state == STATE_FUNCTION)
- {
- GIrNodeParam *param;
- const gchar *transfer;
+ GIrNodeParam *param;
+ const gchar *transfer;
- param = (GIrNodeParam *)g_ir_node_new (G_IR_NODE_PARAM);
- param->in = FALSE;
- param->out = FALSE;
- param->retval = TRUE;
+ if (!(strcmp (element_name, "return-value") == 0 &&
+ ctx->state == STATE_FUNCTION))
+ return FALSE;
- ctx->current_typed = (GIrNode*) param;
+ param = (GIrNodeParam *)g_ir_node_new (G_IR_NODE_PARAM);
+ param->in = FALSE;
+ param->out = FALSE;
+ param->retval = TRUE;
- state_switch (ctx, STATE_FUNCTION_RETURN);
+ ctx->current_typed = (GIrNode*) param;
- transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
- parse_param_transfer (param, transfer, NULL);
+ state_switch (ctx, STATE_FUNCTION_RETURN);
- switch (CURRENT_NODE (ctx)->type)
- {
- case G_IR_NODE_FUNCTION:
- case G_IR_NODE_CALLBACK:
- {
- GIrNodeFunction *func = (GIrNodeFunction *)CURRENT_NODE (ctx);
- func->result = param;
- }
- break;
- case G_IR_NODE_SIGNAL:
- {
- GIrNodeSignal *signal = (GIrNodeSignal *)CURRENT_NODE (ctx);
- signal->result = param;
- }
- break;
- case G_IR_NODE_VFUNC:
- {
- GIrNodeVFunc *vfunc = (GIrNodeVFunc *)CURRENT_NODE (ctx);
- vfunc->result = param;
- }
- break;
- default:
- g_assert_not_reached ();
- }
+ transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
+ parse_param_transfer (param, transfer, NULL);
- return TRUE;
+ switch (CURRENT_NODE (ctx)->type)
+ {
+ case G_IR_NODE_FUNCTION:
+ case G_IR_NODE_CALLBACK:
+ {
+ GIrNodeFunction *func = (GIrNodeFunction *)CURRENT_NODE (ctx);
+ func->result = param;
+ }
+ break;
+ case G_IR_NODE_SIGNAL:
+ {
+ GIrNodeSignal *signal = (GIrNodeSignal *)CURRENT_NODE (ctx);
+ signal->result = param;
+ }
+ break;
+ case G_IR_NODE_VFUNC:
+ {
+ GIrNodeVFunc *vfunc = (GIrNodeVFunc *)CURRENT_NODE (ctx);
+ vfunc->result = param;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
- return FALSE;
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "glib:signal") == 0 &&
- (ctx->state == STATE_CLASS ||
- ctx->state == STATE_INTERFACE))
- {
- const gchar *name;
- const gchar *when;
- const gchar *no_recurse;
- const gchar *detailed;
- const gchar *action;
- const gchar *no_hooks;
- const gchar *has_class_closure;
+ const gchar *name;
+ const gchar *when;
+ const gchar *no_recurse;
+ const gchar *detailed;
+ const gchar *action;
+ const gchar *no_hooks;
+ const gchar *has_class_closure;
+ GIrNodeInterface *iface;
+ GIrNodeSignal *signal;
- name = find_attribute ("name", attribute_names, attribute_values);
- when = find_attribute ("when", attribute_names, attribute_values);
- no_recurse = find_attribute ("no-recurse", attribute_names, attribute_values);
- detailed = find_attribute ("detailed", attribute_names, attribute_values);
- action = find_attribute ("action", attribute_names, attribute_values);
- no_hooks = find_attribute ("no-hooks", attribute_names, attribute_values);
- has_class_closure = find_attribute ("has-class-closure", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "glib:signal") == 0 &&
+ (ctx->state == STATE_CLASS ||
+ ctx->state == STATE_INTERFACE)))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeInterface *iface;
- GIrNodeSignal *signal;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_FUNCTION))
+ return TRUE;
- signal = (GIrNodeSignal *)g_ir_node_new (G_IR_NODE_SIGNAL);
+ name = find_attribute ("name", attribute_names, attribute_values);
+ when = find_attribute ("when", attribute_names, attribute_values);
+ no_recurse = find_attribute ("no-recurse", attribute_names, attribute_values);
+ detailed = find_attribute ("detailed", attribute_names, attribute_values);
+ action = find_attribute ("action", attribute_names, attribute_values);
+ no_hooks = find_attribute ("no-hooks", attribute_names, attribute_values);
+ has_class_closure = find_attribute ("has-class-closure", attribute_names, attribute_values);
- ((GIrNode *)signal)->name = g_strdup (name);
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
+ signal = (GIrNodeSignal *)g_ir_node_new (G_IR_NODE_SIGNAL);
- signal->run_first = FALSE;
- signal->run_last = FALSE;
- signal->run_cleanup = FALSE;
- if (when == NULL || strcmp (when, "LAST") == 0)
- signal->run_last = TRUE;
- else if (strcmp (when, "FIRST") == 0)
- signal->run_first = TRUE;
- else
- signal->run_cleanup = TRUE;
+ ((GIrNode *)signal)->name = g_strdup (name);
- if (no_recurse && strcmp (no_recurse, "1") == 0)
- signal->no_recurse = TRUE;
- else
- signal->no_recurse = FALSE;
- if (detailed && strcmp (detailed, "1") == 0)
- signal->detailed = TRUE;
- else
- signal->detailed = FALSE;
- if (action && strcmp (action, "1") == 0)
- signal->action = TRUE;
- else
- signal->action = FALSE;
- if (no_hooks && strcmp (no_hooks, "1") == 0)
- signal->no_hooks = TRUE;
- else
- signal->no_hooks = FALSE;
- if (has_class_closure && strcmp (has_class_closure, "1") == 0)
- signal->has_class_closure = TRUE;
- else
- signal->has_class_closure = FALSE;
+ signal->run_first = FALSE;
+ signal->run_last = FALSE;
+ signal->run_cleanup = FALSE;
+ if (when == NULL || strcmp (when, "LAST") == 0)
+ signal->run_last = TRUE;
+ else if (strcmp (when, "FIRST") == 0)
+ signal->run_first = TRUE;
+ else
+ signal->run_cleanup = TRUE;
- iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
- iface->members = g_list_append (iface->members, signal);
+ if (no_recurse && strcmp (no_recurse, "1") == 0)
+ signal->no_recurse = TRUE;
+ else
+ signal->no_recurse = FALSE;
+ if (detailed && strcmp (detailed, "1") == 0)
+ signal->detailed = TRUE;
+ else
+ signal->detailed = FALSE;
+ if (action && strcmp (action, "1") == 0)
+ signal->action = TRUE;
+ else
+ signal->action = FALSE;
+ if (no_hooks && strcmp (no_hooks, "1") == 0)
+ signal->no_hooks = TRUE;
+ else
+ signal->no_hooks = FALSE;
+ if (has_class_closure && strcmp (has_class_closure, "1") == 0)
+ signal->has_class_closure = TRUE;
+ else
+ signal->has_class_closure = FALSE;
- push_node (ctx, (GIrNode *)signal);
- state_switch (ctx, STATE_FUNCTION);
- }
+ iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
+ iface->members = g_list_append (iface->members, signal);
- return TRUE;
- }
- return FALSE;
+ push_node (ctx, (GIrNode *)signal);
+
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "virtual-method") == 0 &&
- (ctx->state == STATE_CLASS ||
- ctx->state == STATE_INTERFACE))
- {
- const gchar *name;
- const gchar *must_chain_up;
- const gchar *override;
- const gchar *is_class_closure;
- const gchar *offset;
- const gchar *invoker;
+ const gchar *name;
+ const gchar *must_chain_up;
+ const gchar *override;
+ const gchar *is_class_closure;
+ const gchar *offset;
+ const gchar *invoker;
+ GIrNodeInterface *iface;
+ GIrNodeVFunc *vfunc;
- name = find_attribute ("name", attribute_names, attribute_values);
- must_chain_up = find_attribute ("must-chain-up", attribute_names, attribute_values);
- override = find_attribute ("override", attribute_names, attribute_values);
- is_class_closure = find_attribute ("is-class-closure", attribute_names, attribute_values);
- offset = find_attribute ("offset", attribute_names, attribute_values);
- invoker = find_attribute ("invoker", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "virtual-method") == 0 &&
+ (ctx->state == STATE_CLASS ||
+ ctx->state == STATE_INTERFACE)))
+ return FALSE;
- if (name == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeInterface *iface;
- GIrNodeVFunc *vfunc;
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_FUNCTION))
+ return TRUE;
- vfunc = (GIrNodeVFunc *)g_ir_node_new (G_IR_NODE_VFUNC);
+ name = find_attribute ("name", attribute_names, attribute_values);
+ must_chain_up = find_attribute ("must-chain-up", attribute_names, attribute_values);
+ override = find_attribute ("override", attribute_names, attribute_values);
+ is_class_closure = find_attribute ("is-class-closure", attribute_names, attribute_values);
+ offset = find_attribute ("offset", attribute_names, attribute_values);
+ invoker = find_attribute ("invoker", attribute_names, attribute_values);
- ((GIrNode *)vfunc)->name = g_strdup (name);
+ if (name == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
- if (must_chain_up && strcmp (must_chain_up, "1") == 0)
- vfunc->must_chain_up = TRUE;
- else
- vfunc->must_chain_up = FALSE;
+ vfunc = (GIrNodeVFunc *)g_ir_node_new (G_IR_NODE_VFUNC);
- if (override && strcmp (override, "always") == 0)
- {
- vfunc->must_be_implemented = TRUE;
- vfunc->must_not_be_implemented = FALSE;
- }
- else if (override && strcmp (override, "never") == 0)
- {
- vfunc->must_be_implemented = FALSE;
- vfunc->must_not_be_implemented = TRUE;
- }
- else
- {
- vfunc->must_be_implemented = FALSE;
- vfunc->must_not_be_implemented = FALSE;
- }
+ ((GIrNode *)vfunc)->name = g_strdup (name);
- if (is_class_closure && strcmp (is_class_closure, "1") == 0)
- vfunc->is_class_closure = TRUE;
- else
- vfunc->is_class_closure = FALSE;
+ if (must_chain_up && strcmp (must_chain_up, "1") == 0)
+ vfunc->must_chain_up = TRUE;
+ else
+ vfunc->must_chain_up = FALSE;
- if (offset)
- vfunc->offset = atoi (offset);
- else
- vfunc->offset = 0;
+ if (override && strcmp (override, "always") == 0)
+ {
+ vfunc->must_be_implemented = TRUE;
+ vfunc->must_not_be_implemented = FALSE;
+ }
+ else if (override && strcmp (override, "never") == 0)
+ {
+ vfunc->must_be_implemented = FALSE;
+ vfunc->must_not_be_implemented = TRUE;
+ }
+ else
+ {
+ vfunc->must_be_implemented = FALSE;
+ vfunc->must_not_be_implemented = FALSE;
+ }
- vfunc->invoker = g_strdup (invoker);
+ if (is_class_closure && strcmp (is_class_closure, "1") == 0)
+ vfunc->is_class_closure = TRUE;
+ else
+ vfunc->is_class_closure = FALSE;
- iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
- iface->members = g_list_append (iface->members, vfunc);
+ if (offset)
+ vfunc->offset = atoi (offset);
+ else
+ vfunc->offset = 0;
- push_node (ctx, (GIrNode *)vfunc);
- state_switch (ctx, STATE_FUNCTION);
- }
+ vfunc->invoker = g_strdup (invoker);
- return TRUE;
- }
- return FALSE;
-}
+ iface = (GIrNodeInterface *)CURRENT_NODE (ctx);
+ iface->members = g_list_append (iface->members, vfunc);
+
+ push_node (ctx, (GIrNode *)vfunc);
+ return TRUE;
+}
static gboolean
start_struct (GMarkupParseContext *context,
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "record") == 0 &&
- (ctx->state == STATE_NAMESPACE ||
- ctx->state == STATE_UNION ||
- ctx->state == STATE_STRUCT ||
- ctx->state == STATE_CLASS))
- {
- const gchar *name;
- const gchar *deprecated;
- const gchar *disguised;
- const gchar *gtype_name;
- const gchar *gtype_init;
- const gchar *gtype_struct;
- const gchar *foreign;
- GIrNodeStruct *struct_;
+ const gchar *name;
+ const gchar *deprecated;
+ const gchar *disguised;
+ const gchar *gtype_name;
+ const gchar *gtype_init;
+ const gchar *gtype_struct;
+ const gchar *foreign;
+ GIrNodeStruct *struct_;
+
+ if (!(strcmp (element_name, "record") == 0 &&
+ (ctx->state == STATE_NAMESPACE ||
+ ctx->state == STATE_UNION ||
+ ctx->state == STATE_STRUCT ||
+ ctx->state == STATE_CLASS)))
+ return FALSE;
- name = find_attribute ("name", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- disguised = find_attribute ("disguised", attribute_names, attribute_values);
- gtype_name = find_attribute ("glib:type-name", attribute_names, attribute_values);
- gtype_init = find_attribute ("glib:get-type", attribute_names, attribute_values);
- gtype_struct = find_attribute ("glib:is-gtype-struct-for", attribute_names, attribute_values);
- foreign = find_attribute ("foreign", attribute_names, attribute_values);
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_STRUCT))
+ return TRUE;
- if (name == NULL && ctx->node_stack == NULL)
- {
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- return FALSE;
- }
- if ((gtype_name == NULL && gtype_init != NULL))
- {
- MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
- return FALSE;
- }
- if ((gtype_name != NULL && gtype_init == NULL))
- {
- MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
- return FALSE;
- }
+ name = find_attribute ("name", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ disguised = find_attribute ("disguised", attribute_names, attribute_values);
+ gtype_name = find_attribute ("glib:type-name", attribute_names, attribute_values);
+ gtype_init = find_attribute ("glib:get-type", attribute_names, attribute_values);
+ gtype_struct = find_attribute ("glib:is-gtype-struct-for", attribute_names, attribute_values);
+ foreign = find_attribute ("foreign", attribute_names, attribute_values);
- struct_ = (GIrNodeStruct *) g_ir_node_new (G_IR_NODE_STRUCT);
+ if (name == NULL && ctx->node_stack == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
+ if ((gtype_name == NULL && gtype_init != NULL))
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "glib:type-name");
+ return FALSE;
+ }
+ if ((gtype_name != NULL && gtype_init == NULL))
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "glib:get-type");
+ return FALSE;
+ }
- ((GIrNode *)struct_)->name = g_strdup (name ? name : "");
- if (deprecated)
- struct_->deprecated = TRUE;
- else
- struct_->deprecated = FALSE;
+ struct_ = (GIrNodeStruct *) g_ir_node_new (G_IR_NODE_STRUCT);
- if (disguised && strcmp (disguised, "1") == 0)
- struct_->disguised = TRUE;
+ ((GIrNode *)struct_)->name = g_strdup (name ? name : "");
+ if (deprecated)
+ struct_->deprecated = TRUE;
+ else
+ struct_->deprecated = FALSE;
- struct_->is_gtype_struct = gtype_struct != NULL;
+ if (disguised && strcmp (disguised, "1") == 0)
+ struct_->disguised = TRUE;
- struct_->gtype_name = g_strdup (gtype_name);
- struct_->gtype_init = g_strdup (gtype_init);
+ struct_->is_gtype_struct = gtype_struct != NULL;
- struct_->foreign = (g_strcmp0 (foreign, "1") == 0);
+ struct_->gtype_name = g_strdup (gtype_name);
+ struct_->gtype_init = g_strdup (gtype_init);
- if (ctx->node_stack == NULL)
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, struct_);
- push_node (ctx, (GIrNode *)struct_);
+ struct_->foreign = (g_strcmp0 (foreign, "1") == 0);
- state_switch (ctx, STATE_STRUCT);
- return TRUE;
- }
- return FALSE;
+ if (ctx->node_stack == NULL)
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, struct_);
+ push_node (ctx, (GIrNode *)struct_);
+ return TRUE;
}
-
static gboolean
start_union (GMarkupParseContext *context,
const gchar *element_name,
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "union") == 0 &&
- (ctx->state == STATE_NAMESPACE ||
- ctx->state == STATE_UNION ||
- ctx->state == STATE_STRUCT ||
- ctx->state == STATE_CLASS))
- {
- const gchar *name;
- const gchar *deprecated;
- const gchar *typename;
- const gchar *typeinit;
+ const gchar *name;
+ const gchar *deprecated;
+ const gchar *typename;
+ const gchar *typeinit;
+ GIrNodeUnion *union_;
- name = find_attribute ("name", attribute_names, attribute_values);
- deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
- typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
- typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
+ if (!(strcmp (element_name, "union") == 0 &&
+ (ctx->state == STATE_NAMESPACE ||
+ ctx->state == STATE_UNION ||
+ ctx->state == STATE_STRUCT ||
+ ctx->state == STATE_CLASS)))
+ return FALSE;
+
+ if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_UNION))
+ return TRUE;
- if (name == NULL && ctx->node_stack == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "name");
- else
- {
- GIrNodeUnion *union_;
+ name = find_attribute ("name", attribute_names, attribute_values);
+ deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+ typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
+ typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
- union_ = (GIrNodeUnion *) g_ir_node_new (G_IR_NODE_UNION);
+ if (name == NULL && ctx->node_stack == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "name");
+ return FALSE;
+ }
- ((GIrNode *)union_)->name = g_strdup (name ? name : "");
- union_->gtype_name = g_strdup (typename);
- union_->gtype_init = g_strdup (typeinit);
- if (deprecated)
- union_->deprecated = TRUE;
- else
- union_->deprecated = FALSE;
+ union_ = (GIrNodeUnion *) g_ir_node_new (G_IR_NODE_UNION);
- if (ctx->node_stack == NULL)
- ctx->current_module->entries =
- g_list_append (ctx->current_module->entries, union_);
- push_node (ctx, (GIrNode *)union_);
+ ((GIrNode *)union_)->name = g_strdup (name ? name : "");
+ union_->gtype_name = g_strdup (typename);
+ union_->gtype_init = g_strdup (typeinit);
+ if (deprecated)
+ union_->deprecated = TRUE;
+ else
+ union_->deprecated = FALSE;
- state_switch (ctx, STATE_UNION);
- }
- return TRUE;
- }
- return FALSE;
+ if (ctx->node_stack == NULL)
+ ctx->current_module->entries =
+ g_list_append (ctx->current_module->entries, union_);
+ push_node (ctx, (GIrNode *)union_);
+ return TRUE;
}
static gboolean
ParseContext *ctx,
GError **error)
{
- if (strcmp (element_name, "discriminator") == 0 &&
- ctx->state == STATE_UNION)
- {
- const gchar *type;
- const gchar *offset;
-
- type = find_attribute ("type", attribute_names, attribute_values);
- offset = find_attribute ("offset", attribute_names, attribute_values);
- if (type == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "type");
- else if (offset == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "offset");
- {
- ((GIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_type
- = parse_type (ctx, type);
- ((GIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_offset
- = atoi (offset);
- }
+ const gchar *type;
+ const gchar *offset;
+ if (!(strcmp (element_name, "discriminator") == 0 &&
+ ctx->state == STATE_UNION))
+ return FALSE;
- return TRUE;
+ type = find_attribute ("type", attribute_names, attribute_values);
+ offset = find_attribute ("offset", attribute_names, attribute_values);
+ if (type == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "type");
+ return FALSE;
+ }
+ else if (offset == NULL)
+ {
+ MISSING_ATTRIBUTE (context, error, element_name, "offset");
+ return FALSE;
}
- return FALSE;
+ ((GIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_type
+ = parse_type (ctx, type);
+ ((GIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_offset
+ = atoi (offset);
+
+ return TRUE;
}
static gboolean
parse_include (GMarkupParseContext *context,
ParseContext *ctx,
const char *name,
- const char *version,
- GError **error)
+ const char *version)
{
+ GError *error = NULL;
gchar *buffer;
gsize length;
gchar *girpath, *girname;
- gboolean success = FALSE;
GList *modules;
GList *l;
}
else
{
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- "Module '%s' imported with conflicting versions '%s' and '%s'",
- name, m->version, version);
+ g_printerr ("Module '%s' imported with conflicting versions '%s' and '%s'\n",
+ name, m->version, version);
return FALSE;
}
}
if (girpath == NULL)
{
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- "Could not find GIR file '%s'; check XDG_DATA_DIRS or use --includedir",
+ g_printerr ("Could not find GIR file '%s'; check XDG_DATA_DIRS or use --includedir\n",
girname);
g_free (girname);
return FALSE;
g_debug ("Parsing include %s", girpath);
- if (!g_file_get_contents (girpath, &buffer, &length, error))
+ if (!g_file_get_contents (girpath, &buffer, &length, &error))
{
+ g_printerr ("%s: %s\n", girpath, error->message);
+ g_clear_error (&error);
g_free (girpath);
return FALSE;
}
- g_free (girpath);
- modules = g_ir_parser_parse_string (ctx->parser, name, buffer, length, error);
- success = error != NULL;
+ modules = g_ir_parser_parse_string (ctx->parser, name, girpath, buffer, length, &error);
+ g_free (buffer);
+ if (error != NULL)
+ {
+ int line_number, char_number;
+ g_markup_parse_context_get_position (context, &line_number, &char_number);
+ g_printerr ("%s:%d:%d: error: %s\n", girpath, line_number, char_number, error->message);
+ g_clear_error (&error);
+ g_free (girpath);
+ return FALSE;
+ }
+ g_free (girpath);
ctx->include_modules = g_list_concat (ctx->include_modules,
modules);
- g_free (buffer);
-
- return success;
+ return TRUE;
}
extern GLogLevelFlags logged_levels;
g_string_free (tags, TRUE);
}
+ if (ctx->state == STATE_PASSTHROUGH)
+ {
+ ctx->unknown_depth += 1;
+ return;
+ }
+
switch (element_name[0])
{
case 'a':
break;
}
- if (!parse_include (context, ctx, name, version, error))
- break;
+ if (!parse_include (context, ctx, name, version))
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "Failed to parse included gir %s-%s",
+ name,
+ version);
+ return;
+ }
ctx->dependencies = g_list_prepend (ctx->dependencies,
g_strdup_printf ("%s-%s", name, version));
break;
}
- if (ctx->state != STATE_UNKNOWN)
+ if (ctx->state != STATE_PASSTHROUGH)
{
- state_switch (ctx, STATE_UNKNOWN);
+ g_markup_parse_context_get_position (context, &line_number, &char_number);
+ if (!g_str_has_prefix (element_name, "c:"))
+ g_printerr ("%s:%d:%d: warning: dropping to PASSTHROUGH\n",
+ ctx->file_path, line_number, char_number);
+ state_switch (ctx, STATE_PASSTHROUGH);
ctx->unknown_depth = 1;
}
- else
- {
- ctx->unknown_depth += 1;
- }
out:
if (*error)
{
g_markup_parse_context_get_position (context, &line_number, &char_number);
- fprintf (stderr, "Error at line %d, character %d: %s\n", line_number, char_number, (*error)->message);
+ g_printerr ("%s:%d:%d: error: %s\n", ctx->file_path, line_number, char_number, (*error)->message);
backtrace_stderr ();
}
}
}
break;
- case STATE_UNKNOWN:
+ case STATE_PASSTHROUGH:
ctx->unknown_depth -= 1;
if (ctx->unknown_depth == 0)
state_switch (ctx, ctx->prev_state);
ctx->current_module = NULL;
}
-static GList *
-post_filter_toplevel_varargs_functions (GList *list,
- GList **varargs_callbacks_out)
-{
- GList *iter;
- GList *varargs_callbacks = *varargs_callbacks_out;
-
- iter = list;
- while (iter)
- {
- GList *link = iter;
- GIrNode *node = iter->data;
-
- iter = iter->next;
-
- if (node->type == G_IR_NODE_FUNCTION)
- {
- if (((GIrNodeFunction*)node)->is_varargs)
- {
- list = g_list_delete_link (list, link);
- }
- }
- if (node->type == G_IR_NODE_CALLBACK)
- {
- if (((GIrNodeFunction*)node)->is_varargs)
- {
- varargs_callbacks = g_list_append (varargs_callbacks,
- node);
- list = g_list_delete_link (list, link);
- }
- }
- }
-
- *varargs_callbacks_out = varargs_callbacks;
-
- return list;
-}
-
-static GList *
-post_filter_varargs_functions (GList *list, GList ** varargs_callbacks_out)
-{
- GList *iter;
- GList *varargs_callbacks;
-
- list = post_filter_toplevel_varargs_functions (list, varargs_callbacks_out);
-
- varargs_callbacks = *varargs_callbacks_out;
-
- iter = list;
- while (iter)
- {
- GList *link = iter;
- GIrNode *node = iter->data;
-
- iter = iter->next;
-
- if (node->type == G_IR_NODE_FUNCTION)
- {
- GList *param;
- gboolean function_done = FALSE;
-
- for (param = ((GIrNodeFunction *)node)->parameters;
- param;
- param = param->next)
- {
- GIrNodeParam *node = (GIrNodeParam *)param->data;
-
- if (function_done)
- break;
-
- if (node->type->is_interface)
- {
- GList *callback;
- for (callback = varargs_callbacks;
- callback;
- callback = callback->next)
- {
- if (!strcmp (node->type->interface,
- ((GIrNode *)varargs_callbacks->data)->name))
- {
- list = g_list_delete_link (list, link);
- function_done = TRUE;
- break;
- }
- }
- }
- }
- }
- }
-
- *varargs_callbacks_out = varargs_callbacks;
-
- return list;
-}
-
-static void
-post_filter (GIrModule *module)
-{
- GList *iter;
- GList *varargs_callbacks = NULL;
-
- module->entries = post_filter_varargs_functions (module->entries,
- &varargs_callbacks);
- iter = module->entries;
- while (iter)
- {
- GIrNode *node = iter->data;
-
- iter = iter->next;
-
- if (node->type == G_IR_NODE_OBJECT ||
- node->type == G_IR_NODE_INTERFACE)
- {
- GIrNodeInterface *iface = (GIrNodeInterface*)node;
- iface->members = post_filter_varargs_functions (iface->members,
- &varargs_callbacks);
- }
- else if (node->type == G_IR_NODE_BOXED)
- {
- GIrNodeBoxed *boxed = (GIrNodeBoxed*)node;
- boxed->members = post_filter_varargs_functions (boxed->members,
- &varargs_callbacks);
- }
- else if (node->type == G_IR_NODE_STRUCT)
- {
- GIrNodeStruct *iface = (GIrNodeStruct*)node;
- iface->members = post_filter_varargs_functions (iface->members,
- &varargs_callbacks);
- }
- else if (node->type == G_IR_NODE_UNION)
- {
- GIrNodeUnion *iface = (GIrNodeUnion*)node;
- iface->members = post_filter_varargs_functions (iface->members,
- &varargs_callbacks);
- }
- }
- g_list_free (varargs_callbacks);
-}
-
/**
* g_ir_parser_parse_string:
* @parser: a #GIrParser
* @namespace: the namespace of the string
+ * @filename: (allow-none): Path to parsed file, or %NULL
* @buffer: the data containing the XML
* @length: length of the data
* @error: return location for a #GError, or %NULL
GList *
g_ir_parser_parse_string (GIrParser *parser,
const gchar *namespace,
+ const gchar *filename,
const gchar *buffer,
gssize length,
GError **error)
ctx.parser = parser;
ctx.state = STATE_START;
+ ctx.file_path = filename;
ctx.namespace = namespace;
ctx.include_modules = NULL;
ctx.aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
gchar *buffer;
gsize length;
GList *modules;
- GList *iter;
const char *slash;
char *dash;
char *namespace;
if (!g_file_get_contents (filename, &buffer, &length, error))
return NULL;
- modules = g_ir_parser_parse_string (parser, namespace, buffer, length, error);
-
- for (iter = modules; iter; iter = iter->next)
- {
- post_filter ((GIrModule*)iter->data);
- }
+ modules = g_ir_parser_parse_string (parser, namespace, filename, buffer, length, error);
g_free (namespace);
import shutil
import subprocess
-from .ast import (Alias, Bitfield, Callback, Constant, Enum, Function, Member,
- Namespace, Parameter, Property, Record, Return, Type, Union,
- Field, VFunction, type_name_from_ctype,
- default_array_types, TYPE_UINT8, PARAM_TRANSFER_FULL, Array)
+from .ast import (Alias, Bitfield, Callable, Callback, Class, Constant, Enum,
+ Function, Interface, Member, Namespace, Node, Parameter,
+ Property, Record, Return, Type, TypeContainer, Union,
+ Field, VFunction, type_name_from_ctype, default_array_types,
+ TYPE_UINT8, PARAM_TRANSFER_FULL, Array, List,
+ Map, Varargs)
from .transformer import Names
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
# Public API
- def _print_statistics(self):
- nodes = list(self._names.names.itervalues())
-
- def count_type(otype):
- return len([x for x in nodes
- if isinstance(x[1], otype)])
- objectcount = count_type(GLibObject)
- ifacecount = count_type(GLibInterface)
- enumcount = count_type(GLibEnum)
- print " %d nodes; %d objects, %d interfaces, %d enums" \
- % (len(nodes), objectcount, ifacecount, enumcount)
-
def init_parse(self):
"""Do parsing steps that don't involve the introspection binary
try:
self._resolve_node(node)
except KeyError, e:
- #print "WARNING: DELETING node %s: %s" % (node.name, e)
+ self._transformer._log_node_warning(node,
+"""Unresolvable entry %r""" % (e, ))
self._remove_attribute(node.name)
# Another pass, since we need to have the methods parsed
# in order to correctly modify them after class/record
self._pair_class_record(node)
for (ns, alias) in self._names.aliases.itervalues():
self._resolve_alias(alias)
+
self._resolve_quarks()
- # Fourth pass: ensure all types are known
- if not self._noclosure:
- self._resolve_types(nodes)
- #self._validate(nodes)
+ # Our final pass replacing types
+ self._resolve_types(nodes)
# Create a new namespace with what we found
namespace = Namespace(self._namespace_name, self._namespace_version)
if enum is not None:
enum.error_quark = node.symbol
else:
- print "WARNING: " + \
- "Couldn't find corresponding enumeration for %s" % \
- (node.symbol, )
+ self._transformer._log_node_warning(node,
+"""Couldn't find corresponding enumeration""")
# Helper functions
'GType',
'GObject.Type',
'Gtk.Type']:
- print ("Warning: *_get_type function returns '%r'"
+ self._transformer.log_("Warning: *_get_type function returns '%r'"
", not GObject.Type") % (func.retval.type.name, )
return False
if matched_signal:
continue
vfunc = VFunction.from_callback(field)
+ vfunc.inherit_file_positions(field)
pair_class.virtual_methods.append(vfunc)
# Take the set of virtual methods we found, and try
self._remove_attribute(class_struct.name)
self._add_attribute(gclass_struct, True)
pair_class.glib_type_struct = gclass_struct
+ pair_class.inherit_file_positions(class_struct)
gclass_struct.is_gtype_struct_for = name
# Introspection
# (see also _pair_class_record and transformer.py)
field.writable = False
+ def _pair_boxed_type(self, boxed):
+ name = self._transformer.remove_prefix(boxed.type_name)
+ pair_node = self._get_attribute(name)
+ if not pair_node:
+ boxed_item = GLibBoxedOther(name, boxed.type_name,
+ boxed.get_type)
+ elif isinstance(pair_node, Record):
+ boxed_item = GLibBoxedStruct(pair_node.name, boxed.type_name,
+ boxed.get_type)
+ boxed_item.inherit_file_positions(pair_node)
+ boxed_item.fields = pair_node.fields
+ elif isinstance(pair_node, Union):
+ boxed_item = GLibBoxedUnion(pair_node.name, boxed.type_name,
+ boxed.get_type)
+ boxed_item.inherit_file_positions(pair_node)
+ boxed_item.fields = pair_node.fields
+ else:
+ return False
+ self._add_attribute(boxed_item, replace=True)
+
+ # Node walking
+
+ def _walk(self, node, callback, chain):
+ if not isinstance(node, Node):
+ return
+ if not callback(node, chain):
+ return
+ chain.append(node)
+ def _subwalk(subnode):
+ self._walk(subnode, callback, chain)
+ if isinstance(node, (Callback, Callable)):
+ _subwalk(node.retval)
+ for parameter in node.parameters:
+ _subwalk(parameter)
+ elif isinstance(node, (Array, List)):
+ _subwalk(node.element_type)
+ elif isinstance(node, Map):
+ _subwalk(node.key_type)
+ _subwalk(node.value_type)
+ elif isinstance(node, Bitfield):
+ pass
+ elif isinstance(node, Record):
+ for ctor in node.constructors:
+ _subwalk(ctor)
+ for func in node.methods:
+ _subwalk(func)
+ elif isinstance(node, Field):
+ _subwalk(node.type)
+ elif isinstance(node, Class):
+ for meth in node.methods:
+ _subwalk(meth)
+ for meth in node.virtual_methods:
+ _subwalk(meth)
+ for meth in node.static_methods:
+ _subwalk(meth)
+ for ctor in node.constructors:
+ _subwalk(ctor)
+ for prop in node.properties:
+ _subwalk(prop)
+ for field in node.fields:
+ _subwalk(field)
+ elif isinstance(node, Interface):
+ for meth in node.methods:
+ _subwalk(meth)
+ for meth in node.virtual_methods:
+ _subwalk(meth)
+ for prop in node.properties:
+ _subwalk(prop)
+ for field in node.fields:
+ _subwalk(field)
+ elif isinstance(node, Constant):
+ _subwalk(node.type)
+ elif isinstance(node, Union):
+ for ctor in node.constructors:
+ _subwalk(ctor)
+ for meth in node.methods:
+ _subwalk(meth)
+
+ if isinstance(node, (GLibObject, GLibInterface)):
+ for sig in node.signals:
+ _subwalk(sig)
+
+ chain.pop()
+
# Resolver
def _resolve_type_name(self, type_name, ctype=None):
return
self._resolve_function(func)
- def _pair_boxed_type(self, boxed):
- name = self._transformer.remove_prefix(boxed.type_name)
- pair_node = self._get_attribute(name)
- if not pair_node:
- boxed_item = GLibBoxedOther(name, boxed.type_name,
- boxed.get_type)
- elif isinstance(pair_node, Record):
- boxed_item = GLibBoxedStruct(pair_node.name, boxed.type_name,
- boxed.get_type)
- boxed_item.fields = pair_node.fields
- elif isinstance(pair_node, Union):
- boxed_item = GLibBoxedUnion(pair_node.name, boxed.type_name,
- boxed.get_type)
- boxed_item.fields = pair_node.fields
- else:
- return False
- self._add_attribute(boxed_item, replace=True)
-
def _resolve_record(self, node):
for field in node.fields:
self._resolve_field(field)
self._names)
except KeyError, e:
if allow_unknown:
- print "WARNING: Skipping unknown interface %s" % \
- (item.target, )
+ self._transformer._log_warning(
+"""Skipping unknown interface %s""" % (item.target, ))
return None
else:
raise
while True:
initlen = len(nodes)
- #print "Type resolution; pass=%d" % (i, )
nodes = list(self._names.names.itervalues())
for node in nodes:
try:
if len(nodes) == initlen:
break
i += 1
- self._print_statistics()
self._validating = False
# Validation
- def _validate_interface(self, iface):
- for vfunc in iface.virtual_methods:
- if not vfunc.invoker:
- print ("warning: Interface %r virtual function %r " + \
- "has no known invoker") % (iface.name, vfunc.name)
+ def _interface_vfunc_check(self, node, stack):
+ if isinstance(node, GLibInterface):
+ for vfunc in node.virtual_methods:
+ if not vfunc.invoker:
+ self._transformer._log_node_warning(vfunc,
+"""Virtual function %r has no known invoker""" % (vfunc.name, ),
+ context=node)
+
+ def _introspectable_analysis(self, node, stack):
+ if isinstance(node, TypeContainer):
+ parent = stack[-1]
+ if isinstance(node.type, Varargs):
+ parent.introspectable = False
+ elif not isinstance(node.type, List) and \
+ (node.type.name == 'GLib.List' or
+ (self._transformer._namespace.name == 'GLib'
+ and node.type.name == 'List')):
+ if isinstance(node, Parameter):
+ self._transformer._log_node_warning(parent,
+"""Missing (element-type) annotation on argument %r""" % (node.name, ),
+ context=parent)
+ else:
+ self._transformer._log_node_warning(parent,
+"""Missing (element-type) annotation on return value""", context=parent)
+ parent.introspectable = False
+
+ def _analyze_node(self, node, stack):
+ if node.skip:
+ return False
+ # Combine one-pass checks here
+ self._interface_vfunc_check(node, stack)
+ # Our first pass for scriptability
+ self._introspectable_analysis(node, stack)
+ return True
+
+ def _introspectable_pass2(self, node, stack):
+ if node.skip:
+ return False
+ # In the second introspectable pass, we propagate introspectablity;
+ # for example, a varargs callback as an argument to a function
+ # makes the whole function unintrospectable
+ if isinstance(node, TypeContainer):
+ parent = stack[-1]
+ target = self._lookup_node(node.type.name)
+ if target and not target.introspectable:
+ parent.introspectable = False
+ return True
# This function is called at the very end, before we hand back the
# completed namespace to the writer. Add static analysis checks here.
- def _validate(self, nodes):
- for (name, node) in nodes:
- if isinstance(node, GLibInterface):
- self._validate_interface(node)
+ def final_analyze(self):
+ for (ns, node) in self._names.names.itervalues():
+ self._walk(node, self._analyze_node, [])
+ for (ns, node) in self._names.names.itervalues():
+ self._walk(node, self._introspectable_pass2, [])