Ast: Add parent to Fields
authorGiovanni Campagna <gcampagna@src.gnome.org>
Tue, 28 Aug 2012 00:55:52 +0000 (02:55 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 28 Oct 2012 17:41:04 +0000 (18:41 +0100)
Properties have it, there is no reason for Field not to, and in this
way mallard docs can treat a field almost like a property.

https://bugzilla.gnome.org/show_bug.cgi?id=683046

giscanner/ast.py
giscanner/girparser.py

index be974a09aadba088a3dd785793819a4e9088b2bd..e5c403e1a091c4242610994844c47072a4a309c7 100644 (file)
@@ -857,6 +857,7 @@ class Field(Annotated):
         self.bits = bits
         self.anonymous_node = anonymous_node
         self.private = False
+        self.parent = None # a compound
 
     def __cmp__(self, other):
         return cmp(self.name, other.name)
index 34c9f3e4ad4cf985a6c2d99e476fd8b3692b4c6f..479eb549d6b4ce6d852211e2193ed8724f23263d 100644 (file)
@@ -273,7 +273,7 @@ class GIRParser(object):
             func = self._parse_function_common(ctor, ast.Function, obj)
             func.is_constructor = True
             obj.constructors.append(func)
-        obj.fields.extend(self._parse_fields(node))
+        obj.fields.extend(self._parse_fields(node, obj))
         for prop in self._find_children(node, _corens('property')):
             obj.properties.append(self._parse_property(prop, obj))
         for signal in self._find_children(node, _glibns('signal')):
@@ -359,12 +359,12 @@ class GIRParser(object):
         self._namespace.track(func)
         return func
 
-    def _parse_fields(self, node):
+    def _parse_fields(self, node, obj):
         res = []
         names = (_corens('field'), _corens('record'), _corens('union'), _corens('callback'))
         for child in node.getchildren():
             if child.tag in names:
-                fieldobj = self._parse_field(child)
+                fieldobj = self._parse_field(child, obj)
                 res.append(fieldobj)
         return res
 
@@ -379,16 +379,18 @@ class GIRParser(object):
             compound.foreign = True
         self._parse_generic_attribs(node, compound)
         if not self._types_only:
-            compound.fields.extend(self._parse_fields(node))
+            compound.fields.extend(self._parse_fields(node, compound))
             for method in self._find_children(node, _corens('method')):
-                compound.methods.append(
-                    self._parse_function_common(method, ast.Function, compound))
+                func = self._parse_function_common(method, ast.Function, compound)
+                func.is_method = True
+                compound.methods.append(func)
             for func in self._find_children(node, _corens('function')):
                 compound.static_methods.append(
                     self._parse_function_common(func, ast.Function, compound))
             for ctor in self._find_children(node, _corens('constructor')):
-                compound.constructors.append(
-                    self._parse_function_common(ctor, ast.Function, compound))
+                func = self._parse_function_common(ctor, ast.Function, compound)
+                func.is_constructor = True
+                compound.constructors.append(func)
         return compound
 
     def _parse_record(self, node, anonymous=False):
@@ -500,7 +502,7 @@ class GIRParser(object):
                 self._parse_function_common(callback, ast.Callback, obj))
         self._namespace.append(obj)
 
-    def _parse_field(self, node):
+    def _parse_field(self, node, parent):
         type_node = None
         anonymous_node = None
         if node.tag in map(_corens, ('record', 'union')):
@@ -526,6 +528,7 @@ class GIRParser(object):
                       node.attrib.get('bits'),
                       anonymous_node=anonymous_node)
         field.private = node.attrib.get('private') == '1'
+        field.parent = parent
         self._parse_generic_attribs(node, field)
         return field