1.1 --- a/annotate.py Mon Aug 21 00:55:12 2006 +0200
1.2 +++ b/annotate.py Fri Aug 25 01:23:43 2006 +0200
1.3 @@ -205,6 +205,7 @@
1.4 return Visitor.dispatch(self, node, *args)
1.5 except:
1.6 print "Failed using node", node
1.7 + #print "Original AST node", getattr(node, "original", None)
1.8 raise
1.9
1.10 def visitLoadRef(self, loadref):
1.11 @@ -309,32 +310,7 @@
1.12 invoke.expr = self.dispatch(invoke.expr)
1.13 invocation_types = self.namespace.types
1.14
1.15 - # NOTE: Consider initialiser invocation for classes.
1.16 -
1.17 - types = []
1.18 - args = []
1.19 -
1.20 - # Get type information for regular arguments.
1.21 -
1.22 - for arg in invoke.args:
1.23 - args.append(self.dispatch(arg))
1.24 - types.append(self.namespace.types)
1.25 -
1.26 - # Get type information for star and dstar arguments.
1.27 -
1.28 - if invoke.star is not None:
1.29 - param, default = invoke.star
1.30 - default = self.dispatch(default)
1.31 - invoke.star = param, default
1.32 - types.append(default.types)
1.33 -
1.34 - if invoke.dstar is not None:
1.35 - param, default = invoke.dstar
1.36 - default = self.dispatch(default)
1.37 - invoke.dstar = param, default
1.38 - types.append(default.types)
1.39 -
1.40 - invoke.args = args
1.41 + self.process_args(invoke)
1.42
1.43 # Now locate and invoke the subprogram. This can be complicated because
1.44 # the target may be a class or object, and there may be many different
1.45 @@ -381,7 +357,6 @@
1.46 instance = Instance()
1.47 instance.namespace = Namespace()
1.48 instance.namespace.store("__class__", [attr.type])
1.49 - instance = Attribute(None, instance)
1.50
1.51 # For instantiations, switch the context.
1.52
1.53 @@ -404,7 +379,7 @@
1.54
1.55 # Associate the instance with the result of this invocation.
1.56
1.57 - self.namespace.set_types([instance])
1.58 + self.namespace.set_types([Attribute(None, instance)])
1.59 self.annotate(invoke)
1.60
1.61 invoke.invocations = invocations
1.62 @@ -424,16 +399,14 @@
1.63 if hasattr(invoke, "syscount") and invoke.syscount == self.system.count:
1.64 return
1.65
1.66 - # Test for context information.
1.67 + # Test for context information, making it into a real attribute.
1.68
1.69 - if hasattr(subprogram, "context"):
1.70 - context = subprogram.context
1.71 + if subprogram.context is not None:
1.72 + context = Attribute(None, subprogram.context)
1.73 target = subprogram.type
1.74 else:
1.75 context = None
1.76 - target = subprogram
1.77 -
1.78 - print subprogram, "->", context, target
1.79 + target = subprogram.type
1.80
1.81 # Provide the correct namespace for the invocation.
1.82
1.83 @@ -462,6 +435,35 @@
1.84
1.85 invoke.syscount = self.system.count
1.86
1.87 + def process_args(self, invoke):
1.88 +
1.89 + # NOTE: Consider initialiser invocation for classes.
1.90 +
1.91 + types = []
1.92 + args = []
1.93 +
1.94 + # Get type information for regular arguments.
1.95 +
1.96 + for arg in invoke.args:
1.97 + args.append(self.dispatch(arg))
1.98 + types.append(self.namespace.types)
1.99 +
1.100 + # Get type information for star and dstar arguments.
1.101 +
1.102 + if invoke.star is not None:
1.103 + param, default = invoke.star
1.104 + default = self.dispatch(default)
1.105 + invoke.star = param, default
1.106 + types.append(default.types)
1.107 +
1.108 + if invoke.dstar is not None:
1.109 + param, default = invoke.dstar
1.110 + default = self.dispatch(default)
1.111 + invoke.dstar = param, default
1.112 + types.append(default.types)
1.113 +
1.114 + invoke.args = args
1.115 +
1.116 def make_items(self, invocation, subprogram, context):
1.117
1.118 """
1.119 @@ -487,7 +489,7 @@
1.120 elif params:
1.121 param, default = params[0]
1.122 if arg is None:
1.123 - arg = self.dispatch(default)
1.124 + arg = default
1.125 else:
1.126 raise TypeError, "Invocation has too many arguments."
1.127 items.append((param, arg.types))
1.128 @@ -500,7 +502,7 @@
1.129 if keywords.has_key(param):
1.130 arg = keywords[param]
1.131 else:
1.132 - arg = self.dispatch(default)
1.133 + arg = self.dispatch(default) # NOTE: Review reprocessing.
1.134 items.append((param, arg.types))
1.135 params = params[1:]
1.136
1.137 @@ -514,7 +516,8 @@
1.138 raise TypeError, "Invocation provides unwanted *args."
1.139 elif subprogram.star is not None:
1.140 param, default = subprogram.star
1.141 - items.append((param, self.dispatch(default)))
1.142 + arg = self.dispatch(default) # NOTE: Review reprocessing.
1.143 + items.append((param, arg.types))
1.144
1.145 if invocation.dstar is not None:
1.146 if subprogram.dstar is not None:
1.147 @@ -524,7 +527,8 @@
1.148 raise TypeError, "Invocation provides unwanted **args."
1.149 elif subprogram.dstar is not None:
1.150 param, default = subprogram.dstar
1.151 - items.append((param, self.dispatch(default)))
1.152 + arg = self.dispatch(default) # NOTE: Review reprocessing.
1.153 + items.append((param, arg.types))
1.154
1.155 return items
1.156
1.157 @@ -608,7 +612,7 @@
1.158 return hasattr(other, "type") and other.type == self.type or other == self.type
1.159
1.160 def __repr__(self):
1.161 - return "Attribute of type %s (context %s)" % (self.type, self.context)
1.162 + return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
1.163
1.164 class Self:
1.165 def __init__(self, attribute):