# HG changeset patch # User paulb@jeremy # Date 1156461823 -7200 # Node ID f322e252ad11935be9ff1507b7a8bfd83f1d311c # Parent 5c21b2a7220a03802dcc54d1d853c9b0c9e9f7b7 Attempted to get invocations closer to working correctly. Added a dict class to the builtins in order to support dstar parameter defaults. diff -r 5c21b2a7220a -r f322e252ad11 annotate.py --- a/annotate.py Mon Aug 21 00:55:12 2006 +0200 +++ b/annotate.py Fri Aug 25 01:23:43 2006 +0200 @@ -205,6 +205,7 @@ return Visitor.dispatch(self, node, *args) except: print "Failed using node", node + #print "Original AST node", getattr(node, "original", None) raise def visitLoadRef(self, loadref): @@ -309,32 +310,7 @@ invoke.expr = self.dispatch(invoke.expr) invocation_types = self.namespace.types - # NOTE: Consider initialiser invocation for classes. - - types = [] - args = [] - - # Get type information for regular arguments. - - for arg in invoke.args: - args.append(self.dispatch(arg)) - types.append(self.namespace.types) - - # Get type information for star and dstar arguments. - - if invoke.star is not None: - param, default = invoke.star - default = self.dispatch(default) - invoke.star = param, default - types.append(default.types) - - if invoke.dstar is not None: - param, default = invoke.dstar - default = self.dispatch(default) - invoke.dstar = param, default - types.append(default.types) - - invoke.args = args + self.process_args(invoke) # Now locate and invoke the subprogram. This can be complicated because # the target may be a class or object, and there may be many different @@ -381,7 +357,6 @@ instance = Instance() instance.namespace = Namespace() instance.namespace.store("__class__", [attr.type]) - instance = Attribute(None, instance) # For instantiations, switch the context. @@ -404,7 +379,7 @@ # Associate the instance with the result of this invocation. - self.namespace.set_types([instance]) + self.namespace.set_types([Attribute(None, instance)]) self.annotate(invoke) invoke.invocations = invocations @@ -424,16 +399,14 @@ if hasattr(invoke, "syscount") and invoke.syscount == self.system.count: return - # Test for context information. + # Test for context information, making it into a real attribute. - if hasattr(subprogram, "context"): - context = subprogram.context + if subprogram.context is not None: + context = Attribute(None, subprogram.context) target = subprogram.type else: context = None - target = subprogram - - print subprogram, "->", context, target + target = subprogram.type # Provide the correct namespace for the invocation. @@ -462,6 +435,35 @@ invoke.syscount = self.system.count + def process_args(self, invoke): + + # NOTE: Consider initialiser invocation for classes. + + types = [] + args = [] + + # Get type information for regular arguments. + + for arg in invoke.args: + args.append(self.dispatch(arg)) + types.append(self.namespace.types) + + # Get type information for star and dstar arguments. + + if invoke.star is not None: + param, default = invoke.star + default = self.dispatch(default) + invoke.star = param, default + types.append(default.types) + + if invoke.dstar is not None: + param, default = invoke.dstar + default = self.dispatch(default) + invoke.dstar = param, default + types.append(default.types) + + invoke.args = args + def make_items(self, invocation, subprogram, context): """ @@ -487,7 +489,7 @@ elif params: param, default = params[0] if arg is None: - arg = self.dispatch(default) + arg = default else: raise TypeError, "Invocation has too many arguments." items.append((param, arg.types)) @@ -500,7 +502,7 @@ if keywords.has_key(param): arg = keywords[param] else: - arg = self.dispatch(default) + arg = self.dispatch(default) # NOTE: Review reprocessing. items.append((param, arg.types)) params = params[1:] @@ -514,7 +516,8 @@ raise TypeError, "Invocation provides unwanted *args." elif subprogram.star is not None: param, default = subprogram.star - items.append((param, self.dispatch(default))) + arg = self.dispatch(default) # NOTE: Review reprocessing. + items.append((param, arg.types)) if invocation.dstar is not None: if subprogram.dstar is not None: @@ -524,7 +527,8 @@ raise TypeError, "Invocation provides unwanted **args." elif subprogram.dstar is not None: param, default = subprogram.dstar - items.append((param, self.dispatch(default))) + arg = self.dispatch(default) # NOTE: Review reprocessing. + items.append((param, arg.types)) return items @@ -608,7 +612,7 @@ return hasattr(other, "type") and other.type == self.type or other == self.type def __repr__(self): - return "Attribute of type %s (context %s)" % (self.type, self.context) + return "Attribute(%s, %s)" % (repr(self.context), repr(self.type)) class Self: def __init__(self, attribute): diff -r 5c21b2a7220a -r f322e252ad11 lib/builtins.py --- a/lib/builtins.py Mon Aug 21 00:55:12 2006 +0200 +++ b/lib/builtins.py Fri Aug 25 01:23:43 2006 +0200 @@ -1000,6 +1000,9 @@ """ return boolean() +class dict: + pass + class Exception: pass