1.1 --- a/annotate.py Mon Dec 11 23:51:42 2006 +0100
1.2 +++ b/annotate.py Tue Dec 12 00:47:02 2006 +0100
1.3 @@ -573,7 +573,7 @@
1.4 elif isinstance(expr, LoadExc):
1.5 self.namespace.revoke_exception_type(attr)
1.6 elif isinstance(expr, LoadTemp):
1.7 - self.namespace.revoke_temp_type(expr.index, attr)
1.8 + self.namespace.revoke_temp_type(getattr(expr, "index", None), attr)
1.9
1.10 # LoadAttr cannot be pruned since this might unintentionally prune
1.11 # legitimate types from other applications of the referenced type, it
1.12 @@ -1066,7 +1066,7 @@
1.13 items.append((param, [])) # Annotation has not succeeded.
1.14 params = params[1:]
1.15
1.16 - dstar_args = kw_args.values()
1.17 + dstar_args = kw_args.items()
1.18
1.19 # Construct temporary objects.
1.20
1.21 @@ -1078,7 +1078,7 @@
1.22 star_types = None
1.23
1.24 if dstar_args:
1.25 - dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args) # NOTE: To be written!
1.26 + dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args)
1.27 self.dispatch(dstar_invocation)
1.28 dstar_types = dstar_invocation.types
1.29 else:
1.30 @@ -1178,6 +1178,91 @@
1.31
1.32 return invocation.stars[subprogram.full_name()]
1.33
1.34 + def make_dstar_args(self, invocation, subprogram, dstar_args):
1.35 +
1.36 + """
1.37 + Make a subprogram which initialises a dictionary built from the given
1.38 + 'dstar_args'.
1.39 + """
1.40 +
1.41 + if not hasattr(invocation, "dstars"):
1.42 + invocation.dstars = {}
1.43 +
1.44 + if not invocation.dstars.has_key(subprogram.full_name()):
1.45 + code=[
1.46 + StoreTemp(
1.47 + expr=InvokeFunction(
1.48 + expr=LoadAttr(
1.49 + expr=LoadRef(
1.50 + ref=self.builtins
1.51 + ),
1.52 + name="dict",
1.53 + nstype="module",
1.54 + )
1.55 + )
1.56 + )
1.57 + ]
1.58 +
1.59 + for arg, value in dstar_args:
1.60 +
1.61 + # NOTE: Constant not added to table.
1.62 +
1.63 + constant = Constant(name=repr(arg), value=arg, namespace=Namespace())
1.64 + code += [
1.65 + StoreTemp(
1.66 + expr=LoadRef(
1.67 + ref=constant
1.68 + ),
1.69 + index="const"
1.70 + ),
1.71 + StoreAttr(
1.72 + lvalue=LoadTemp(
1.73 + index="const"
1.74 + ),
1.75 + name="__class__",
1.76 + expr=LoadAttr(
1.77 + expr=LoadRef(
1.78 + ref=self.builtins
1.79 + ),
1.80 + name=constant.typename,
1.81 + nstype="module",
1.82 + )
1.83 + ),
1.84 + InvokeFunction(
1.85 + expr=LoadAttr(
1.86 + expr=LoadTemp(),
1.87 + name="__setitem__"
1.88 + ),
1.89 + args=[
1.90 + LoadTemp(
1.91 + index="const",
1.92 + release=1
1.93 + ),
1.94 + value
1.95 + ]
1.96 + )
1.97 + ]
1.98 +
1.99 + code += [
1.100 + Return(expr=LoadTemp(release=1))
1.101 + ]
1.102 +
1.103 + invocation.dstars[subprogram.full_name()] = InvokeBlock(
1.104 + produces_result=1,
1.105 + expr=LoadRef(
1.106 + ref=Subprogram(
1.107 + name=None,
1.108 + returns_value=1,
1.109 + params=[],
1.110 + star=None,
1.111 + dstar=None,
1.112 + code=code
1.113 + )
1.114 + )
1.115 + )
1.116 +
1.117 + return invocation.dstars[subprogram.full_name()]
1.118 +
1.119 # Namespace-related abstractions.
1.120
1.121 class Namespace: