summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--girepository/girparser.c69
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/object.gir50
-rw-r--r--tests/object.test10
-rw-r--r--tools/generate.c53
6 files changed, 129 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index b056ec64..39a86028 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2008-08-14 Johan Dahlin <johan@gnome.org>
+ * girepository/girparser.c (start_field), (start_constant),
+ (start_type), (end_element_handler):
+ Clear up constant parsing
+
+ * tests/object.gir:
+ Update
+
+ * tools/generate.c (write_callable_info), (write_function_info),
+ (write_callback_info), (write_constant_info), (write_signal_info),
+ (write_vfunc_info), (write_property_info), (write_object_info),
+ (write_interface_info):
+ Constants/Signals are handled now.
+
+2008-08-14 Johan Dahlin <johan@gnome.org>
+
* girepository/girparser.c (start_type):
Don't require c:type.
* tests/Makefile.am:
diff --git a/girepository/girparser.c b/girepository/girparser.c
index 6b7942e9..07fff0a7 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -53,8 +53,10 @@ typedef enum
STATE_STRUCT_FIELD,
STATE_ERRORDOMAIN,
STATE_UNION,
- STATE_CONSTANT,
- STATE_ALIAS, /* 25 */
+ STATE_NAMESPACE_CONSTANT,
+ STATE_CLASS_CONSTANT, /* 25 */
+ STATE_INTERFACE_CONSTANT,
+ STATE_ALIAS
} ParseState;
typedef struct _ParseContext ParseContext;
@@ -776,7 +778,6 @@ start_field (GMarkupParseContext *context,
ctx->state == STATE_INTERFACE))
{
const gchar *name;
- const gchar *type;
const gchar *readable;
const gchar *writable;
const gchar *bits;
@@ -784,7 +785,6 @@ start_field (GMarkupParseContext *context,
const gchar *offset;
name = find_attribute ("name", attribute_names, attribute_values);
- type = find_attribute ("c:type", attribute_names, attribute_values);
readable = find_attribute ("readable", attribute_names, attribute_values);
writable = find_attribute ("writable", attribute_names, attribute_values);
bits = find_attribute ("bits", attribute_names, attribute_values);
@@ -1119,19 +1119,15 @@ start_constant (GMarkupParseContext *context,
ctx->state == STATE_INTERFACE))
{
const gchar *name;
- const gchar *type;
const gchar *value;
const gchar *deprecated;
name = find_attribute ("name", attribute_names, attribute_values);
- type = find_attribute ("c:type", 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");
- else if (type == NULL)
- MISSING_ATTRIBUTE (context, error, element_name, "c:type");
else if (value == NULL)
MISSING_ATTRIBUTE (context, error, element_name, "value");
else
@@ -1142,8 +1138,8 @@ start_constant (GMarkupParseContext *context,
((GIrNode *)constant)->name = g_strdup (name);
constant->value = g_strdup (value);
-
- constant->type = parse_type (ctx, type);
+
+ ctx->current_typed = (GIrNode*) constant;
if (deprecated && strcmp (deprecated, "1") == 0)
constant->deprecated = TRUE;
@@ -1163,7 +1159,22 @@ start_constant (GMarkupParseContext *context,
iface = (GIrNodeInterface *)ctx->current_node;
iface->members = g_list_append (iface->members, constant);
}
- state_switch (ctx, STATE_CONSTANT);
+
+ 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;
+ }
}
return TRUE;
@@ -1351,7 +1362,10 @@ start_type (GMarkupParseContext *context,
ctx->state == STATE_CLASS_FIELD ||
ctx->state == STATE_INTERFACE_FIELD ||
ctx->state == STATE_INTERFACE_PROPERTY ||
- ctx->state == STATE_BOXED_FIELD
+ ctx->state == STATE_BOXED_FIELD ||
+ ctx->state == STATE_NAMESPACE_CONSTANT ||
+ ctx->state == STATE_CLASS_CONSTANT ||
+ ctx->state == STATE_INTERFACE_CONSTANT
))
return FALSE;
@@ -1373,8 +1387,7 @@ start_type (GMarkupParseContext *context,
{
case G_IR_NODE_PARAM:
{
- GIrNodeParam *param;
- param = (GIrNodeParam *)ctx->current_typed;
+ GIrNodeParam *param = (GIrNodeParam *)ctx->current_typed;
param->type = parse_type (ctx, name);
}
break;
@@ -1390,6 +1403,12 @@ start_type (GMarkupParseContext *context,
property->type = parse_type (ctx, name);
}
break;
+ case G_IR_NODE_CONSTANT:
+ {
+ GIrNodeConstant *constant = (GIrNodeConstant *)ctx->current_typed;
+ constant->type = parse_type (ctx, name);
+ }
+ break;
default:
g_printerr("current node is %d\n", ctx->current_node->type);
g_assert_not_reached ();
@@ -2308,11 +2327,29 @@ end_element_handler (GMarkupParseContext *context,
if (require_end_element (context, ctx, "requires", element_name, error))
state_switch (ctx, STATE_INTERFACE);
break;
- case STATE_CONSTANT:
+ case STATE_NAMESPACE_CONSTANT:
+ case STATE_CLASS_CONSTANT:
+ case STATE_INTERFACE_CONSTANT:
+ if (strcmp ("type", element_name) == 0)
+ break;
if (require_end_element (context, ctx, "constant", element_name, error))
{
ctx->current_node = NULL;
- state_switch (ctx, STATE_NAMESPACE);
+ switch (ctx->state)
+ {
+ case STATE_NAMESPACE_CONSTANT:
+ state_switch (ctx, STATE_NAMESPACE);
+ break;
+ case STATE_CLASS_CONSTANT:
+ state_switch (ctx, STATE_CLASS);
+ break;
+ case STATE_INTERFACE_CONSTANT:
+ state_switch (ctx, STATE_INTERFACE);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
}
break;
default:
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 479a30a7..69e6952f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,8 @@ EXTRA_DIST = \
xref2.gir
GIRTESTS = \
- boxed.gir.test
+ boxed.gir.test \
+ object.gir.test
%.gir.test: %.gir
@echo Testing $<:
diff --git a/tests/object.gir b/tests/object.gir
index dfaf732b..99ca0c3b 100644
--- a/tests/object.gir
+++ b/tests/object.gir
@@ -9,50 +9,52 @@
<interface name="Iface1" />
</implements>
<property name="prop1" readable="0" writable="0">
- <type name="int" c:type="gint"/>
+ <type name="int"/>
</property>
<glib:signal name="signal1" when="LAST">
- <return-value>
- <type name="boolean" c:type="gboolean"/>
+ <return-value>
+ <type name="boolean"/>
</return-value>
<parameters>
- <parameter name="obj" transfer="full" direction="in">
- <type name="Object1" c:type="Object1*"/>
- </parameter>
+ <parameter name="obj" direction="in">
+ <type name="Object1"/>
+ </parameter>
</parameters>
</glib:signal>
<glib:signal name="signal2" when="FIRST" no-recurse="1" detailed="1" action="1" no-hooks="1">
- <return-value>
- <type name="void" c:type="void"/>
+ <return-value>
+ <type name="none"/>
</return-value>
<parameters>
- <parameter name="obj" transfer="full" direction="in">
- <type name="Object1" c:type="Object1*"/>
- </parameter>
+ <parameter name="obj" direction="in">
+ <type name="Object1"/>
+ </parameter>
</parameters>
</glib:signal>
- <vfunc name="vfunc1" offset="20">
- <return-value>
- <type name="Object2" c:type="Object2*"/>
+ <vfunc name="vfunc1" offset="20" transfer="none">
+ <return-value>
+ <type name="Object2*"/>
</return-value>
<parameters>
- <parameter name="param1" transfer="full" direction="in">
- <type name="Object1" c:type="Object1*"/>
- </parameter>
+ <parameter name="param1" direction="in">
+ <type name="Object1"/>
+ </parameter>
</parameters>
</vfunc>
- <vfunc name="vfunc2" offset="24">
- <return-value>
- <type name="Object2" c:type="Object2*"/>
+ <vfunc name="vfunc2" offset="24" transfer="none">
+ <return-value>
+ <type name="Object2*"/>
</return-value>
<parameters>
- <parameter name="param1" transfer="full" direction="in">
- <type name="Object1" c:type="Object1*"/>
- </parameter>
+ <parameter name="param1" direction="in">
+ <type name="Object1"/>
+ </parameter>
</parameters>
</vfunc>
</class>
- <constant name="constant1" c:type="gint" value="42" />
+ <constant name="constant1" value="42">
+ <type name="int"/>
+ </constant>
<interface name="Iface1" glib:type-name="Iface1" glib:get-type="iface1_get_type">
</interface>
<class name="Object2" parent="GObject.GObject" glib:type-name="Object2" glib:get-type="object2_get_type">
diff --git a/tests/object.test1 b/tests/object.test1
deleted file mode 100644
index e69de29b..00000000
--- a/tests/object.test1
+++ /dev/null
diff --git a/tools/generate.c b/tools/generate.c
index 1292c3d7..226f1ac1 100644
--- a/tools/generate.c
+++ b/tools/generate.c
@@ -242,8 +242,6 @@ write_callable_info (const gchar *namespace,
GITypeInfo *type;
gint i;
- g_fprintf (file, "%*s <return-value>\n", indent, "");
-
type = g_callable_info_get_return_type (info);
if (g_type_info_is_pointer (type))
@@ -263,6 +261,11 @@ write_callable_info (const gchar *namespace,
g_assert_not_reached ();
}
}
+
+ g_fprintf (file, ">\n");
+
+ g_fprintf (file, "%*s <return-value>\n", indent, "");
+
g_base_info_unref ((GIBaseInfo *)type);
if (g_callable_info_may_return_null (info))
g_fprintf (file, " null-ok=\"1\"");
@@ -384,7 +387,6 @@ write_function_info (const gchar *namespace,
if (deprecated)
g_fprintf (file, " deprecated=\"1\"");
- g_fprintf (file, ">\n");
write_callable_info (namespace, (GICallableInfo*)info, file, indent);
g_fprintf (file, "%*s</%s>\n", indent, "", tag);
}
@@ -406,7 +408,6 @@ write_callback_info (const gchar *namespace,
if (deprecated)
g_fprintf (file, " deprecated=\"1\"");
- g_fprintf (file, ">\n");
write_callable_info (namespace, (GICallableInfo*)info, file, indent);
g_fprintf (file, "%*s</callback>\n", indent, "");
}
@@ -563,15 +564,22 @@ write_constant_info (const gchar *namespace,
name = g_base_info_get_name ((GIBaseInfo *)info);
deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info);
- g_fprintf (file, "%*s<constant name=\"%s\" type=\"", indent, "", name);
+ g_fprintf (file, "%*s<constant name=\"%s\"", indent, "", name);
type = g_constant_info_get_type (info);
- write_type_info (namespace, type, file);
- g_fprintf (file, "\" value=\"");
+ g_fprintf (file, " value=\"");
g_constant_info_get_value (info, &value);
write_constant_value (namespace, type, &value, file);
- g_fprintf (file, "\" />\n");
+ g_fprintf (file, "\">\n");
+
+ g_fprintf (file, "%*s<type name=\"", indent + 2, "");
+
+ write_type_info (namespace, type, file);
+
+ g_fprintf (file, "\"/>\n");
+
+ g_fprintf (file, "%*s</constant>\n", indent, "");
g_base_info_unref ((GIBaseInfo *)type);
}
@@ -634,7 +642,7 @@ write_signal_info (const gchar *namespace,
flags = g_signal_info_get_flags (info);
deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info);
- g_fprintf (file, " <signal name=\"%s\"", name);
+ g_fprintf (file, " <glib:signal name=\"%s\"", name);
if (deprecated)
g_fprintf (file, " deprecated=\"1\"");
@@ -658,10 +666,9 @@ write_signal_info (const gchar *namespace,
if (flags & G_SIGNAL_NO_HOOKS)
g_fprintf (file, " no-hooks=\"1\"");
- g_fprintf (file, ">\n");
-
write_callable_info (namespace, (GICallableInfo*)info, file, 6);
- g_fprintf (file, " </signal>\n");
+
+ g_fprintf (file, " </glib:signal>\n");
}
static void
@@ -693,9 +700,9 @@ write_vfunc_info (const gchar *namespace,
g_fprintf (file, " override=\"never\"");
g_fprintf (file, " offset=\"%d\"", offset);
- g_fprintf (file, ">\n");
write_callable_info (namespace, (GICallableInfo*)info, file, 6);
+
g_fprintf (file, " </vfunc>\n");
}
@@ -735,11 +742,17 @@ write_property_info (const gchar *namespace,
g_fprintf (file, " construct-only=\"1\"");
type = g_property_info_get_type (info);
- g_fprintf (file, " type=\"");
+
+ g_fprintf (file, ">\n");
+
+ g_fprintf (file, " <type name=\"", name);
+
write_type_info (namespace, type, file);
- g_fprintf (file, "\"");
- g_fprintf (file, " />\n");
+ g_fprintf (file, "\"/>\n");
+
+ g_fprintf (file, " </property>\n");
+
}
static void
@@ -759,7 +772,7 @@ write_object_info (const gchar *namespace,
type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info);
- g_fprintf (file, " <object name=\"%s\"", name);
+ g_fprintf (file, " <class name=\"%s\"", name);
pnode = g_object_info_get_parent (info);
if (pnode)
@@ -770,7 +783,7 @@ write_object_info (const gchar *namespace,
g_base_info_unref ((GIBaseInfo *)pnode);
}
- g_fprintf (file, " type-name=\"%s\" get-type=\"%s\"", type_name, type_init);
+ g_fprintf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init);
if (deprecated)
g_fprintf (file, " deprecated=\"1\"");
@@ -833,7 +846,7 @@ write_object_info (const gchar *namespace,
g_base_info_unref ((GIBaseInfo *)constant);
}
- g_fprintf (file, " </object>\n");
+ g_fprintf (file, " </class>\n");
}
static void
@@ -852,7 +865,7 @@ write_interface_info (const gchar *namespace,
type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info);
- g_fprintf (file, " <interface name=\"%s\" type-name=\"%s\" get-type=\"%s\"",
+ g_fprintf (file, " <interface name=\"%s\" glib:type-name=\"%s\" glib:get-type=\"%s\"",
name, type_name, type_init);
if (deprecated)