Bug 559706 - interface prequisites
authorColin Walters <walters@src.gnome.org>
Mon, 17 Nov 2008 00:27:37 +0000 (00:27 +0000)
committerColin Walters <walters@src.gnome.org>
Mon, 17 Nov 2008 00:27:37 +0000 (00:27 +0000)
svn path=/trunk/; revision=932

common.mk
girepository/gdump.c
girepository/girparser.c
giscanner/ast.py
giscanner/girwriter.py
giscanner/glibtransformer.py

index 7458e5f..3eeb193 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -7,4 +7,5 @@ SCANNER_ARGS = -v --add-include-path=$(top_builddir)/gir --add-include-path=.
 SCANNER = $(SCANNER_ENV) $(SCANNER_BIN) $(SCANNER_ARGS)
 SCANNER_LIBS = \
        $(top_srcdir)/giscanner/*.py \
-       $(top_builddir)/giscanner/libgiscanner.la
+       $(top_builddir)/giscanner/libgiscanner.la \
+       $(top_builddir)/girepository/libgirepository.la
index b26b0e8..a58e620 100644 (file)
@@ -186,7 +186,12 @@ dump_interface_type (GType type, const char *symbol, GOutputStream *out)
   for (i = 0; i < n_interfaces; i++)
     {
       GType itype = interfaces[i];
-      escaped_printf (out, "    <extends>%s</extends>\n",
+      if (itype == G_TYPE_OBJECT)
+       {
+         /* This is implicit */
+         continue;
+       }
+      escaped_printf (out, "    <prerequisite name=\"%s\"/>\n",
                      g_type_name (itype));
     }
   dump_properties (type, out);
index ecc2e10..43f3402 100644 (file)
@@ -54,7 +54,7 @@ typedef enum
   STATE_INTERFACE_PROPERTY,   /* 15 */
   STATE_INTERFACE_FIELD,
   STATE_IMPLEMENTS, 
-  STATE_REQUIRES,
+  STATE_PREREQUISITE,
   STATE_BOXED,  
   STATE_BOXED_FIELD, /* 20 */
   STATE_STRUCT,   
@@ -2338,25 +2338,6 @@ start_element_handler (GMarkupParseContext *context,
                            attribute_names, attribute_values,
                            ctx, error))
        goto out;
-      else if (strcmp (element_name, "class") == 0 &&
-              ctx->state == STATE_REQUIRES)
-       {
-         const gchar *name;
-
-         name = find_attribute ("name", attribute_names, attribute_values);
-
-         if (name == NULL)
-           MISSING_ATTRIBUTE (context, error, element_name, "name");
-         else
-           {  
-             GIrNodeInterface *iface;
-
-             iface = (GIrNodeInterface *)ctx->current_node;
-             iface ->prerequisites = g_list_append (iface->prerequisites, g_strdup (name));
-           }
-
-         goto out;
-       }
       break;
 
     case 'd':
@@ -2522,7 +2503,26 @@ start_element_handler (GMarkupParseContext *context,
                                attribute_names, attribute_values,
                                ctx, error))
        goto out;
+      else if (strcmp (element_name, "prerequisite") == 0 &&
+              ctx->state == STATE_INTERFACE)
+       {
+         const gchar *name;
 
+         name = find_attribute ("name", attribute_names, attribute_values);
+
+         state_switch (ctx, STATE_PREREQUISITE);
+
+         if (name == NULL)
+           MISSING_ATTRIBUTE (context, error, element_name, "name");
+         else
+           {  
+             GIrNodeInterface *iface;
+
+             iface = (GIrNodeInterface *)ctx->current_node;
+             iface ->prerequisites = g_list_append (iface->prerequisites, g_strdup (name));
+           }
+         goto out;
+       }
       break;
 
     case 'r':
@@ -2549,13 +2549,6 @@ start_element_handler (GMarkupParseContext *context,
                                   attribute_names, attribute_values,
                                   ctx, error))
        goto out;      
-      else if (strcmp (element_name, "requires") == 0 &&
-              ctx->state == STATE_INTERFACE)
-       {
-         state_switch (ctx, STATE_REQUIRES);
-         
-         goto out;
-       }
       else if (start_struct (context, element_name,
                             attribute_names, attribute_values,
                             ctx, error))
@@ -2893,8 +2886,8 @@ end_element_handler (GMarkupParseContext *context,
       if (require_end_element (context, ctx, "implements", element_name, error))
         state_switch (ctx, STATE_CLASS);
       break;
-    case STATE_REQUIRES:
-      if (require_end_element (context, ctx, "requires", element_name, error))
+    case STATE_PREREQUISITE:
+      if (require_end_element (context, ctx, "prerequisite", element_name, error))
         state_switch (ctx, STATE_INTERFACE);
       break;
     case STATE_NAMESPACE_CONSTANT:
index b4e8e9e..41587bc 100644 (file)
@@ -385,6 +385,7 @@ class Interface(Node):
         self.methods = []
         self.properties = []
         self.fields = []
+        self.prerequisites = []
 
     def __repr__(self):
         return '%s(%r, %r)' % (
index 030ea82..a5c50d9 100644 (file)
@@ -254,6 +254,9 @@ class GIRWriter(XMLWriter):
             if isinstance(node, GLibObject):
                 for iface in node.interfaces:
                     self.write_tag('implements', [('name', iface)])
+            if isinstance(node, Interface):
+                for iface in node.prerequisites:
+                    self.write_tag('prerequisite', [('name', iface)])
             if isinstance(node, Class):
                 for method in node.constructors:
                     self._write_constructor(method)
index 5f079ba..2edab36 100644 (file)
@@ -575,6 +575,10 @@ class GLibTransformer(object):
             type_name, xmlnode.attrib['get-type'])
         self._introspect_properties(node, xmlnode)
         self._introspect_signals(node, xmlnode)
+        for child in xmlnode.findall('prerequisite'):
+            name = child.attrib['name']
+            prereq = self._resolve_gtypename(name)
+            node.prerequisites.append(prereq)
         # GtkFileChooserEmbed is an example of a private interface, we
         # just filter them out
         if xmlnode.attrib['get-type'].startswith('_'):
@@ -728,6 +732,9 @@ class GLibTransformer(object):
         self._resolve_methods(node.methods)
         self._resolve_properties(node.properties, node)
         self._resolve_signals(node.signals)
+        node.prerequisites = filter(None,
+            [self._force_resolve(x, allow_unknown=True)
+             for x in node.prerequisites])
 
     def _resolve_glib_object(self, node):
         node.parent = self._force_resolve(node.parent)