[gobject-introspection] Namespace: fix appending of nodes



commit 9ff28e6abab52506933fb560de1360e16d8d3880
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Aug 28 02:46:23 2012 +0200

    Namespace: fix appending of nodes
    
    Traverse appended nodes for methods, so that namespace.symbols contains
    all known symbols and not just global functions.
    Also, ensure that all relevant nodes are appended when parsing GIRs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683046

 giscanner/ast.py       |   19 +++++++++++++++++++
 giscanner/girparser.py |   14 +++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 654c68e..be974a0 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -20,6 +20,7 @@
 #
 
 import copy
+from itertools import chain
 
 from . import message
 
@@ -399,6 +400,21 @@ but adds it to things like ctypes, symbols, and type_names.
             self.type_names[node.gtype_name] = node
         elif isinstance(node, Function):
             self.symbols[node.symbol] = node
+        if isinstance(node, (Compound, Class, Interface)):
+            for fn in chain(node.methods, node.static_methods, node.constructors):
+                if not isinstance(fn, Function):
+                    continue
+                fn.namespace = self
+                self.symbols[fn.symbol] = fn
+        if isinstance(node, (Class, Interface)):
+            for m in chain(node.signals, node.properties):
+                m.namespace = self
+        if isinstance(node, Enum) or isinstance(node, Bitfield):
+            for fn in node.static_methods:
+                if not isinstance(fn, Function):
+                    continue
+                fn.namespace = self
+                self.symbols[fn.symbol] = fn
         if hasattr(node, 'ctype'):
             self.ctypes[node.ctype] = node
 
@@ -990,6 +1006,9 @@ class Interface(Node, Registered):
         self.properties = []
         self.fields = []
         self.prerequisites = []
+        # Not used yet, exists just to avoid an exception in
+        # Namespace.append()
+        self.constructors = []
 
     def _walk(self, callback, chain):
         for meth in self.methods:
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index eb53a3c..34c9f3e 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -247,10 +247,11 @@ class GIRParser(object):
                             'set-value-func', 'get-value-func']:
                 func_name = node.attrib.get(_glibns(func_id))
                 obj.__dict__[func_id.replace('-', '_')] = func_name
-        self._namespace.append(obj)
 
         if self._types_only:
+            self._namespace.append(obj)
             return
+
         for iface in self._find_children(node, _corens('implements')):
             obj.interfaces.append(self._namespace.type_from_name(iface.attrib['name']))
         for iface in self._find_children(node, _corens('prerequisite')):
@@ -278,6 +279,8 @@ class GIRParser(object):
         for signal in self._find_children(node, _glibns('signal')):
             obj.signals.append(self._parse_function_common(signal, ast.Signal, obj))
 
+        self._namespace.append(obj)
+
     def _parse_callback(self, node):
         callback = self._parse_function_common(node, ast.Callback)
         self._namespace.append(callback)
@@ -480,9 +483,11 @@ class GIRParser(object):
                         get_type=node.attrib[_glibns('get-type')],
                         c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
         self._parse_generic_attribs(node, obj)
-        self._namespace.append(obj)
+
         if self._types_only:
+            self._namespace.append(obj)
             return
+
         for method in self._find_children(node, _corens('method')):
             func = self._parse_function_common(method, ast.Function, obj)
             func.is_method = True
@@ -493,6 +498,7 @@ class GIRParser(object):
         for callback in self._find_children(node, _corens('callback')):
             obj.fields.append(
                 self._parse_function_common(callback, ast.Callback, obj))
+        self._namespace.append(obj)
 
     def _parse_field(self, node):
         type_node = None
@@ -570,12 +576,14 @@ class GIRParser(object):
         obj.error_domain = glib_error_domain
         obj.ctype = ctype
         self._parse_generic_attribs(node, obj)
-        self._namespace.append(obj)
 
         if self._types_only:
+            self._namespace.append(obj)
             return
+
         for member in self._find_children(node, _corens('member')):
             members.append(self._parse_member(member))
         for func_node in self._find_children(node, _corens('function')):
             func = self._parse_function_common(func_node, ast.Function)
             obj.static_methods.append(func)
+        self._namespace.append(obj)



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