1.1 --- a/simplify/ast.py Sun Jul 29 01:53:25 2007 +0200
1.2 +++ b/simplify/ast.py Sun Jul 29 20:33:09 2007 +0200
1.3 @@ -228,9 +228,7 @@
1.4 Raise(assert_,
1.5 expr=InvokeFunction(assert_,
1.6 expr=LoadName(name="AssertionError"),
1.7 - args=fail_args,
1.8 - star=None,
1.9 - dstar=None
1.10 + args=fail_args
1.11 )
1.12 )
1.13 ]
1.14 @@ -327,8 +325,6 @@
1.15 expr=InvokeFunction( # referenced below
1.16 augassign,
1.17 args=[expr],
1.18 - star=None,
1.19 - dstar=None,
1.20 expr=LoadAttr(
1.21 expr=self.dispatch(augassign.node),
1.22 name=self.augassign_methods[augassign.op]
1.23 @@ -359,7 +355,7 @@
1.24 StoreTemp(
1.25 expr=InvokeFunction( # referenced below
1.26 augassign,
1.27 - args=[expr], star=None, dstar=None,
1.28 + args=[expr],
1.29 expr=LoadAttr(
1.30 expr=LoadAttr(augassign.node, 1,
1.31 expr=LoadTemp(index="expr"),
1.32 @@ -404,7 +400,7 @@
1.33 StoreTemp(
1.34 expr=InvokeFunction( # referenced below
1.35 augassign,
1.36 - args=[expr], star=None, dstar=None,
1.37 + args=[expr],
1.38 expr=LoadAttr(
1.39 expr=self._visitSlice(
1.40 augassign.node,
1.41 @@ -446,7 +442,7 @@
1.42 StoreTemp(
1.43 expr=InvokeFunction( # referenced below
1.44 augassign,
1.45 - args=[expr], star=None, dstar=None,
1.46 + args=[expr],
1.47 expr=LoadAttr(
1.48 expr=self._visitSubscript(
1.49 augassign.node,
1.50 @@ -572,7 +568,7 @@
1.51 return result
1.52
1.53 def visitCallFunc(self, callfunc):
1.54 - result = InvokeFunction(callfunc, 1, star=None, dstar=None, args=self.dispatches(callfunc.args))
1.55 + result = InvokeFunction(callfunc, 1, args=self.dispatches(callfunc.args))
1.56 if callfunc.star_args is not None:
1.57 result.star = self.dispatch(callfunc.star_args)
1.58 if callfunc.dstar_args is not None:
1.59 @@ -692,9 +688,7 @@
1.60 invocation = InvokeFunction(
1.61 new_op, 1,
1.62 expr=LoadName(name="__is__"),
1.63 - args=[previous, expr],
1.64 - star=None,
1.65 - dstar=None)
1.66 + args=[previous, expr])
1.67
1.68 elif op_name == "is not":
1.69 invocation = Not(
1.70 @@ -702,9 +696,7 @@
1.71 expr=InvokeFunction(
1.72 new_op,
1.73 expr=LoadName(name="__is__"),
1.74 - args=[previous, expr],
1.75 - star=None,
1.76 - dstar=None)
1.77 + args=[previous, expr])
1.78 )
1.79
1.80 elif op_name == "in":
1.81 @@ -714,9 +706,7 @@
1.82 expr=previous,
1.83 name="__contains__"
1.84 ),
1.85 - args=[expr],
1.86 - star=None,
1.87 - dstar=None)
1.88 + args=[expr])
1.89
1.90 elif op_name == "not in":
1.91 invocation = Not(
1.92 @@ -727,9 +717,7 @@
1.93 expr=previous,
1.94 name="__contains__"
1.95 ),
1.96 - args=[expr],
1.97 - star=None,
1.98 - dstar=None)
1.99 + args=[expr])
1.100 )
1.101
1.102 else:
1.103 @@ -878,9 +866,8 @@
1.104 test=InvokeFunction(
1.105 node,
1.106 expr=LoadName(name="isinstance"),
1.107 - args=[LoadExc(), LoadName(name="StopIteration")],
1.108 - star=None,
1.109 - dstar=None),
1.110 + args=[LoadExc(), LoadName(name="StopIteration")]
1.111 + ),
1.112 body=else_stmt,
1.113 else_=[
1.114 Raise(
1.115 @@ -1022,7 +1009,7 @@
1.116 """
1.117
1.118 subprogram = Subprogram(function, name=function.name, module=self.module, structures=self.current_structures[:],
1.119 - internal=0, returns_value=1, star=None, dstar=None, is_method=self.within_class, original_def=function)
1.120 + internal=0, returns_value=1, star=None, dstar=None, is_method=self.within_class)
1.121
1.122 # Make nice annotations for the viewer.
1.123
1.124 @@ -1138,7 +1125,7 @@
1.125 # Make a subprogram for the function and record it outside the main
1.126 # tree.
1.127
1.128 - subprogram = Subprogram(lambda_, name=None, module=self.module, internal=0, returns_value=1, star=None, dstar=None, original_def=lambda_)
1.129 + subprogram = Subprogram(lambda_, name=None, module=self.module, internal=0, returns_value=1, star=None, dstar=None)
1.130
1.131 # Make nice annotations for the viewer.
1.132
1.133 @@ -1160,7 +1147,7 @@
1.134 # Make a subprogram for the list construction and record it outside the
1.135 # main tree.
1.136
1.137 - subprogram = Subprogram(list, name=None, module=self.module, internal=0, returns_value=1, star=None, dstar=None, original_def=list)
1.138 + subprogram = Subprogram(list, name=None, module=self.module, internal=0, returns_value=1, star=None, dstar=None)
1.139 self.current_subprograms.append(subprogram)
1.140
1.141 # Make nice annotations for the viewer.
1.142 @@ -1174,9 +1161,7 @@
1.143 expr=LoadName(
1.144 name="list"
1.145 ),
1.146 - args=[],
1.147 - star=None,
1.148 - dstar=None
1.149 + args=[]
1.150 )
1.151 )
1.152 ]
1.153 @@ -1189,9 +1174,7 @@
1.154 expr=LoadTemp(),
1.155 name="append"
1.156 ),
1.157 - args=[self.dispatch(node)],
1.158 - star=None,
1.159 - dstar=None
1.160 + args=[self.dispatch(node)]
1.161 )
1.162 )
1.163
1.164 @@ -1217,7 +1200,7 @@
1.165 # Make a subprogram for the list comprehension and record it outside the
1.166 # main tree.
1.167
1.168 - subprogram = Subprogram(listcomp, name=None, module=self.module, internal=1, returns_value=1, star=None, dstar=None, original_def=listcomp)
1.169 + subprogram = Subprogram(listcomp, name=None, module=self.module, internal=1, returns_value=1, star=None, dstar=None)
1.170 self.current_subprograms.append(subprogram)
1.171
1.172 # Make nice annotations for the viewer.
1.173 @@ -1233,9 +1216,7 @@
1.174 index="listcomp",
1.175 expr=InvokeFunction(
1.176 expr=LoadName(name="list"),
1.177 - args=[],
1.178 - star=None,
1.179 - dstar=None
1.180 + args=[]
1.181 )
1.182 )
1.183 ] + self._visitListCompFor(listcomp, listcomp.quals) + [
1.184 @@ -1299,9 +1280,7 @@
1.185 expr=LoadTemp(index="listcomp"),
1.186 name="append"
1.187 ),
1.188 - args=[self.dispatch(node.expr)],
1.189 - star=None,
1.190 - dstar=None
1.191 + args=[self.dispatch(node.expr)]
1.192 )
1.193 ]
1.194
1.195 @@ -1442,9 +1421,7 @@
1.196 InvokeFunction(
1.197 print_,
1.198 expr=LoadTemp(index="print"),
1.199 - args=[self.dispatch(node)],
1.200 - star=None,
1.201 - dstar=None
1.202 + args=[self.dispatch(node)]
1.203 )
1.204 )
1.205
1.206 @@ -1461,9 +1438,7 @@
1.207 InvokeFunction(
1.208 printnl,
1.209 expr=LoadTemp(index="print"),
1.210 - args=[self.dispatch(compiler.ast.Const("\n"))],
1.211 - star=None,
1.212 - dstar=None
1.213 + args=[self.dispatch(compiler.ast.Const("\n"))]
1.214 )
1.215 )
1.216 return result
1.217 @@ -1476,9 +1451,7 @@
1.218 result.expr = InvokeFunction(
1.219 raise_,
1.220 expr=self.dispatch(raise_.expr1),
1.221 - args=[self.dispatch(raise_.expr2)],
1.222 - star=None,
1.223 - dstar=None
1.224 + args=[self.dispatch(raise_.expr2)]
1.225 )
1.226 if raise_.expr3 is not None:
1.227 result.traceback = self.dispatch(raise_.expr3)
1.228 @@ -1499,8 +1472,6 @@
1.229 expr=expr,
1.230 name="__setslice__"
1.231 ),
1.232 - star=None,
1.233 - dstar=None,
1.234 args=[lower, upper, value]
1.235 )
1.236 elif flags == "OP_APPLY":
1.237 @@ -1510,8 +1481,6 @@
1.238 expr=expr,
1.239 name="__getslice__"
1.240 ),
1.241 - star=None,
1.242 - dstar=None,
1.243 args=[lower, upper]
1.244 )
1.245 elif flags == "OP_DELETE":
1.246 @@ -1521,8 +1490,6 @@
1.247 expr=expr,
1.248 name="__delslice__"
1.249 ),
1.250 - star=None,
1.251 - dstar=None,
1.252 args=[lower, upper]
1.253 )
1.254 else:
1.255 @@ -1537,9 +1504,7 @@
1.256 def visitSliceobj(self, sliceobj):
1.257 return InvokeFunction(sliceobj, 1,
1.258 expr=LoadName(name="slice"),
1.259 - args=self.dispatches(sliceobj.nodes),
1.260 - star=None,
1.261 - dstar=None
1.262 + args=self.dispatches(sliceobj.nodes)
1.263 )
1.264
1.265 def visitStmt(self, stmt):
1.266 @@ -1555,8 +1520,6 @@
1.267 expr=expr,
1.268 name="__setitem__"
1.269 ),
1.270 - star=None,
1.271 - dstar=None,
1.272 args=[subs, value]
1.273 )
1.274 elif flags == "OP_APPLY":
1.275 @@ -1566,8 +1529,6 @@
1.276 expr=expr,
1.277 name="__getitem__"
1.278 ),
1.279 - star=None,
1.280 - dstar=None,
1.281 args=[subs]
1.282 )
1.283 elif flags == "OP_DELETE":
1.284 @@ -1577,8 +1538,6 @@
1.285 expr=expr,
1.286 name="__delitem__"
1.287 ),
1.288 - star=None,
1.289 - dstar=None,
1.290 args=[subs]
1.291 )
1.292 else:
1.293 @@ -1592,9 +1551,7 @@
1.294 else:
1.295 return InvokeFunction(node, 1,
1.296 expr=LoadName(name="tuple"),
1.297 - args=self.dispatches(subs),
1.298 - star=None,
1.299 - dstar=None
1.300 + args=self.dispatches(subs)
1.301 )
1.302
1.303 def visitSubscript(self, subscript, element=None):
1.304 @@ -1826,9 +1783,8 @@
1.305 name=left_name),
1.306 args=[
1.307 LoadTemp(index="right")
1.308 - ],
1.309 - star=None,
1.310 - dstar=None)
1.311 + ]
1.312 + )
1.313 ),
1.314 Conditional(
1.315 isolate_test=1,
1.316 @@ -1845,9 +1801,8 @@
1.317 name=right_name),
1.318 args=[
1.319 LoadTemp(index="left")
1.320 - ],
1.321 - star=None,
1.322 - dstar=None)
1.323 + ]
1.324 + )
1.325 ),
1.326 Conditional(
1.327 isolate_test=1,
1.328 @@ -1927,9 +1882,8 @@
1.329 expr=InvokeFunction(
1.330 binary,
1.331 expr=LoadAttr(expr=LoadTemp(index="left"), name=left_name),
1.332 - args=[LoadTemp(index="right")],
1.333 - star=None,
1.334 - dstar=None)
1.335 + args=[LoadTemp(index="right")]
1.336 + )
1.337 )
1.338 ],
1.339 else_=[],
1.340 @@ -1942,9 +1896,8 @@
1.341 expr=InvokeFunction(
1.342 binary,
1.343 expr=LoadAttr(expr=LoadTemp(index="right"), name=right_name),
1.344 - args=[LoadTemp(index="left")],
1.345 - star=None,
1.346 - dstar=None)
1.347 + args=[LoadTemp(index="left")]
1.348 + )
1.349 )
1.350 ],
1.351 else_=[]
2.1 --- a/simplify/simplified/program.py Sun Jul 29 01:53:25 2007 +0200
2.2 +++ b/simplify/simplified/program.py Sun Jul 29 20:33:09 2007 +0200
2.3 @@ -366,11 +366,21 @@
2.4
2.5 "A function or method invocation."
2.6
2.7 - def __init__(self, *args, **kw):
2.8 - self.args = []
2.9 - self.star = None
2.10 - self.dstar = None
2.11 - Invoke.__init__(self, *args, **kw)
2.12 + def __init__(self, original=None, defining=0, expr=None, args=None, star=None, dstar=None, **kw):
2.13 +
2.14 + """
2.15 + Initialise the invocation with the following optional parameters:
2.16 +
2.17 + * The 'original' AST node represented by this invocation.
2.18 + * Whether this invocation is 'defining' (false by default).
2.19 + * The 'expr' or expression indicating the invoked subprogram.
2.20 + * The 'args' or arguments to be supplied, yielding the 'pos_args' and
2.21 + 'kw_args' attributes on this object.
2.22 + * The 'star' argument containing additional unlabelled arguments.
2.23 + * The 'dstar' argument containing keyword arguments.
2.24 + """
2.25 +
2.26 + Invoke.__init__(self, original, defining, expr=expr, args=(args or []), star=star, dstar=dstar, **kw)
2.27 self.set_args(self.args)
2.28 self.share_locals = 0
2.29
2.30 @@ -397,9 +407,21 @@
2.31
2.32 "A block or loop invocation."
2.33
2.34 - def __init__(self, *args, **kw):
2.35 - self.share_locals = 1
2.36 - Invoke.__init__(self, *args, **kw)
2.37 + def __init__(self, original=None, defining=0, ref=None, produces_result=1, share_locals=1, **kw):
2.38 +
2.39 + """
2.40 + Initialise the invocation with the following optional parameters:
2.41 +
2.42 + * The 'original' AST node represented by this invocation.
2.43 + * Whether this invocation is 'defining' (false by default).
2.44 + * The 'ref' indicating the subprogram to be invoked.
2.45 + * Whether a result is produced as indicated by 'produces_result' (true
2.46 + by default).
2.47 + * Whether the subprogram shares the locals of the caller as indicated
2.48 + by 'share_locals' (true by default).
2.49 + """
2.50 +
2.51 + Invoke.__init__(self, original, defining, ref=ref, produces_result=produces_result, share_locals=share_locals, **kw)
2.52
2.53 # Program structure nodes.
2.54
2.55 @@ -414,23 +436,37 @@
2.56
2.57 "A subprogram: functions, methods and loops."
2.58
2.59 - def __init__(self, *args, **kw):
2.60 - Node.__init__(self, *args, **kw)
2.61 + def __init__(self, original=None, defining=0, name=None, module=None, structure=None,
2.62 + structures=None, internal=0, returns_value=1, params=None, star=None,
2.63 + dstar=None, **kw):
2.64 +
2.65 + """
2.66 + Initialise the subprogram with the following optional parameters:
2.67 +
2.68 + * The 'original' AST node represented by this subprogram.
2.69 + * Whether this subprogram is 'defining' or not (false by default).
2.70 + * The 'name' of this subprogram which may be None.
2.71 + * The 'module' in which this subprogram is found.
2.72 + * The 'structure' initialised by this subprogram.
2.73 + * The 'structures' within which this subprogram resides.
2.74 + * The 'internal' status of this subprogram (false by default), which
2.75 + if true typically means that a loop or operation is being
2.76 + represented.
2.77 + * Whether a value is returned, as specified by 'returns_value' (true
2.78 + by default).
2.79 + * The 'params' (a parameter list which is empty by default).
2.80 + * The 'star' parameter which collects excess positional arguments.
2.81 + * The 'dstar' parameter which collects unmatched keyword arguments.
2.82 + """
2.83 +
2.84 + Node.__init__(self, original, defining, name=name, module=module, structure=structure,
2.85 + structures=structures, internal=internal, returns_value=returns_value,
2.86 + params=(params or []), star=star, dstar=dstar, **kw)
2.87 +
2.88 WithName.__init__(self)
2.89 self.raises = set()
2.90 self.returns = set()
2.91 self.return_locals = set()
2.92 self.namespace = Namespace() # NOTE: Temporary.
2.93
2.94 - # NOTE: Logic similar to that below is used in simplify.fixinstances to
2.95 - # NOTE: identify equivalent attributes which are subprograms.
2.96 -
2.97 - """
2.98 - def __eq__(self, other):
2.99 - return self is other or \
2.100 - not getattr(self, "internal", 0) and not getattr(other, "internal", 0) and \
2.101 - getattr(self, "copy_of", self) is getattr(other, "copy_of", other) and \
2.102 - getattr(self, "paramtypes", None) == getattr(other, "paramtypes", None)
2.103 - """
2.104 -
2.105 # vim: tabstop=4 expandtab shiftwidth=4