diff options
-rw-r--r-- | giscanner/ast.py | 34 | ||||
-rw-r--r-- | giscanner/girparser.py | 1 |
2 files changed, 22 insertions, 13 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py index 2e37db40..654c68e2 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 a59037da..eb53a3c4 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): |