# HG changeset patch # User paulb@jeremy # Date 1153861454 -7200 # Node ID f42f9f25d1120208b363e9c1904f074fa93c2f45 # Parent 6c70feca6247e74599b4e7ff62cba6bf3b5a4b37 Added elementary support for Return nodes, base classes and tentative support for invocations. diff -r 6c70feca6247 -r f42f9f25d112 annotate.py --- a/annotate.py Tue Jul 25 23:03:33 2006 +0200 +++ b/annotate.py Tue Jul 25 23:04:14 2006 +0200 @@ -135,6 +135,10 @@ self.types = None self.temp = {} + # Satisfy visitor issues. + + self.visitor = self + def process(self, node, locals=None, globals=None): """ @@ -154,14 +158,26 @@ self.global_namespace = globals or self.namespace # NOTE: Improve this. node.namespace = self.namespace + # Remember return values. + + self.returns = [] + # Add namespace details to any structure involved. if hasattr(node, "structure") and node.structure is not None: node.structure.namespace = self.namespace - # Satisfy visitor issues and then dispatch. + # Initialise bases where appropriate. - self.visitor = self + if hasattr(node.structure, "bases"): + base_refs = [] + for base in node.structure.bases: + self.dispatch(base) + base_refs.append(self.types) + node.structure.base_refs = base_refs + + # Dispatch to the code itself. + result = self.dispatch(node) return result @@ -275,6 +291,12 @@ ref.namespace.store(storeattr.name, expr) return storeattr + def visitReturn(self, return_): + if hasattr(return_, "expr"): + return_.expr = self.dispatch(return_.expr) + self.returns += self.types + return return_ + def visitInvoke(self, invoke): invoke.expr = self.dispatch(invoke.expr) expr = self.types @@ -310,6 +332,10 @@ # NOTE: Now locate and invoke the subprogram. for subprogram in expr: + + # NOTE: Deal with class invocations by providing instance objects, + # NOTE: and with object invocations by using __call__ methods. + if hasattr(invoke, "same_frame") and invoke.same_frame: namespace = self.namespace else: @@ -320,6 +346,11 @@ annotator.process(subprogram, namespace, self.global_namespace) # NOTE: Annotate the node with invocation details. + # NOTE: This should really be as part of a table of alternatives. + + if hasattr(subprogram, "returns_value") and subprogram.returns_value: + self.types = annotator.returns + self.annotate(invoke) return invoke