[gobject-introspection] girparser: Track methods/constructors by symbol



commit 4f6f32dcb1942063508fa002fd0bc83a362c96b6
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Aug 29 06:06:55 2012 -0300

    girparser: Track methods/constructors by symbol
    
    In order to be able to linkify a constructor/method, we need
    to first track it by symbol.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682969

 giscanner/ast.py       |   34 +++++++++++++++++++++-------------
 giscanner/girparser.py |    1 +
 2 files changed, 22 insertions(+), 13 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 2e37db4..654c68e 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -384,37 +384,45 @@ returned."""
             target = '%s.%s' % (self.name, name)
         return Type(target_giname=target, ctype=ctype)
 
-    def append(self, node, replace=False):
-        previous = self.names.get(node.name)
-        if previous is not None:
-            if not replace:
-                raise ValueError("Namespace conflict: %r" % (node, ))
-            self.remove(previous)
-        # A layering violation...but oh well.
+    def track(self, node):
+        """Doesn't directly append the function to our own namespace,
+but adds it to things like ctypes, symbols, and type_names.
+"""
+        assert isinstance(node, Node)
+        if node.namespace is self:
+            return
+        assert node.namespace is None
+        node.namespace = self
         if isinstance(node, Alias):
             self.aliases[node.name] = node
         elif isinstance(node, Registered) and node.gtype_name is not None:
             self.type_names[node.gtype_name] = node
         elif isinstance(node, Function):
             self.symbols[node.symbol] = node
-        assert isinstance(node, Node)
-        assert node.namespace is None
-        node.namespace = self
-        self.names[node.name] = node
         if hasattr(node, 'ctype'):
             self.ctypes[node.ctype] = node
 
+    def append(self, node, replace=False):
+        previous = self.names.get(node.name)
+        if previous is not None:
+            if not replace:
+                raise ValueError("Namespace conflict: %r" % (node, ))
+            self.remove(previous)
+
+        self.track(node)
+        self.names[node.name] = node
+
     def remove(self, node):
         if isinstance(node, Alias):
             del self.aliases[node.name]
         elif isinstance(node, Registered) and node.gtype_name is not None:
             del self.type_names[node.gtype_name]
-        del self.names[node.name]
-        node.namespace = None
         if hasattr(node, 'ctype'):
             del self.ctypes[node.ctype]
         if isinstance(node, Function):
             del self.symbols[node.symbol]
+        node.namespace = None
+        self.names.pop(node.name, None)
 
     def float(self, node):
         """Like remove(), but doesn't unset the node's namespace
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index a59037d..eb53a3c 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -353,6 +353,7 @@ class GIRParser(object):
 
         self._parse_generic_attribs(node, func)
 
+        self._namespace.track(func)
         return func
 
     def _parse_fields(self, node):



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