[gobject-introspection/wip/transformer] Correctly parse anonymous struct/union



commit 25b256ade2ce75e18c8357ce5680dd4e06c66b2a
Author: Colin Walters <walters verbum org>
Date:   Thu Jul 22 21:18:41 2010 -0400

    Correctly parse anonymous struct/union
    
    We now pass through GLib-2.0.gir

 giscanner/girparser.py |   27 ++++++++++++++++++---------
 giscanner/girwriter.py |    6 +-----
 2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 67ab800..18344ef 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -312,7 +312,7 @@ class GIRParser(object):
 
         return func
 
-    def _parse_record(self, node):
+    def _parse_record(self, node, anonymous=False):
         if _glibns('type-name') in node.attrib:
             struct = GLibBoxedStruct(node.attrib['name'],
                                      node.attrib[_glibns('type-name')],
@@ -331,7 +331,8 @@ class GIRParser(object):
         if node.attrib.get('foreign') == '1':
             struct.foreign = True
         self._parse_generic_attribs(node, struct)
-        self._namespace.append(struct)
+        if not anonymous:
+            self._namespace.append(struct)
 
         for field in self._find_children(node, _corens('field')):
             fieldobj = self._parse_field(field) 
@@ -339,11 +340,15 @@ class GIRParser(object):
         for method in self._find_children(node, _corens('method')):
             struct.methods.append(
                 self._parse_function_common(method, Function))
+        for func in self._find_children(node, _corens('function')):
+            struct.static_methods.append(
+                self._parse_function_common(func, Function))
         for ctor in self._find_children(node, _corens('constructor')):
             struct.constructors.append(
                 self._parse_function_common(ctor, Function))
+        return struct
 
-    def _parse_union(self, node):
+    def _parse_union(self, node, anonymous=False):
         if _glibns('type-name') in node.attrib:
             union = GLibBoxedUnion(node.attrib['name'],
                                     node.attrib[_glibns('type-name')],
@@ -352,7 +357,8 @@ class GIRParser(object):
         else:
             union = Union(node.attrib['name'],
                           node.attrib.get(_cns('type')))
-        self._namespace.append(union)
+        if not anonymous:
+            self._namespace.append(union)
 
         for callback in self._find_children(node, _corens('callback')):
             union.fields.append(
@@ -365,6 +371,7 @@ class GIRParser(object):
         for ctor in self._find_children(node, _corens('constructor')):
             union.constructors.append(
                 self._parse_function_common(ctor, Function))
+        return union
 
     def _parse_type(self, node):
         # Fields can contain inline callbacks
@@ -441,12 +448,14 @@ class GIRParser(object):
             if anonymous_elt:
                 break
         if anonymous_elt:
-            if anonymous_elt.tag == 'callback':
+            if anonymous_elt.tag == _corens('callback'):
                 anonymous_node = self._parse_function_common(anonymous_elt, Callback)
-            elif anonymous_elt.tag == 'record':
-                anonymous_node = self._parse_record(anonymous_elt)
-            elif anonymous_elt.tag == 'union':
-                anonymous_node = self._parse_union(anonymous_elt)
+            elif anonymous_elt.tag == _corens('record'):
+                anonymous_node = self._parse_record(anonymous_elt, anonymous=True)
+            elif anonymous_elt.tag == _corens('union'):
+                anonymous_node = self._parse_union(anonymous_elt, anonymous=True)
+            else:
+                assert False, anonymous_elt.tag
         else:
             type_node = self._parse_type(node)
         field = Field(node.attrib['name'],
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index e547f2a..b9c55a7 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -240,7 +240,7 @@ and/or use gtk-doc annotations. ''')
         return typeval.target_giname
 
     def _write_type(self, ntype, relation=None):
-        assert isinstance(ntype, Type)
+        assert isinstance(ntype, Type), ntype
         attrs = []
         if ntype.ctype:
             attrs.append(('c:type', ntype.ctype))
@@ -501,10 +501,6 @@ and/or use gtk-doc annotations. ''')
                 else:
                     raise AssertionError("Unknown field anonymous: %r" \
                                              % (field.anonymous_node, ))
-        elif isinstance(field, Record):
-            self._write_record(field)
-        elif isinstance(field, Union):
-            self._write_union(field)
         else:
             attrs = [('name', field.name)]
             # Fields are assumed to be read-only



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]