1.1 --- a/annotate.py Sun Nov 26 21:28:11 2006 +0100
1.2 +++ b/annotate.py Mon Nov 27 01:06:38 2006 +0100
1.3 @@ -361,7 +361,6 @@
1.4 choice_types += self.namespace.types
1.5 for expr_type in expr_types:
1.6 if expr_type.type.get_class() not in choice_types:
1.7 - print "CheckExc", expr_type, "should be revoked!"
1.8 self._prune_non_accesses(checkexc.expr, expr_type)
1.9 return checkexc
1.10
1.11 @@ -686,7 +685,7 @@
1.12
1.13 if getattr(invoke, "share_locals", 0):
1.14 namespace = Namespace()
1.15 - namespace.merge_namespace(self.namespace, no_return_locals=1)
1.16 + namespace.merge_namespace(self.namespace, everything=0)
1.17 using_module_namespace = self.namespace is self.module.namespace
1.18 elif getattr(target, "structure", None):
1.19 namespace = Namespace()
1.20 @@ -720,7 +719,7 @@
1.21 if getattr(invoke, "share_locals", 0):
1.22 self.namespace.reset()
1.23 for locals in self.returned_locals:
1.24 - self.namespace.merge_namespace(locals, no_return_locals=1)
1.25 + self.namespace.merge_namespace(locals, everything=0)
1.26
1.27 # Incorporate any raised exceptions.
1.28
1.29 @@ -970,14 +969,17 @@
1.30 def revoke_exception_type(self, type):
1.31 self.raises.remove(type)
1.32
1.33 - def merge_namespace(self, namespace, no_return_locals=0):
1.34 + def merge_namespace(self, namespace, everything=1):
1.35 self.merge_items(namespace.names.items())
1.36 - combine(self.returns, namespace.returns)
1.37 - if not no_return_locals:
1.38 + if everything:
1.39 + combine(self.returns, namespace.returns)
1.40 combine(self.return_locals, namespace.return_locals)
1.41 combine(self.raises, namespace.raises)
1.42 - self.temp = {}
1.43 - self.temp.update(namespace.temp)
1.44 + for name, values in namespace.temp.items():
1.45 + if values:
1.46 + if not self.temp.has_key(name) or not self.temp[name]:
1.47 + self.temp[name] = [[]]
1.48 + combine(self.temp[name][-1], values[-1])
1.49
1.50 def merge_items(self, items):
1.51 for name, types in items:
2.1 --- a/simplify.py Sun Nov 26 21:28:11 2006 +0100
2.2 +++ b/simplify.py Mon Nov 27 01:06:38 2006 +0100
2.3 @@ -47,14 +47,14 @@
2.4 """
2.5 A simplifying visitor for AST nodes.
2.6
2.7 - Covered: And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
2.8 - CallFunc, Class, Compare, Const, Continue, Dict, Discard, For,
2.9 - From, Function, Getattr, Global, If, Import, Invert, Keyword,
2.10 + Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
2.11 + Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
2.12 + For, From, Function, Getattr, Global, If, Import, Invert, Keyword,
2.13 Lambda, List, Module, Name, Not, Or, Pass, Raise, Return, Slice,
2.14 Stmt, Subscript, TryExcept, TryFinally, Tuple, While, UnaryAdd,
2.15 UnarySub.
2.16
2.17 - Missing: Add, Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
2.18 + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
2.19 Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor,
2.20 ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift, Sliceobj,
2.21 Sub, Yield.
2.22 @@ -348,8 +348,7 @@
2.23 nodes += self.dispatch(stmt)
2.24 catch_all = 1
2.25
2.26 - # Produce something like...
2.27 - # isinstance(<exc>, <spec>)
2.28 + # Produce an exception value check.
2.29
2.30 else:
2.31 test = Conditional(
2.32 @@ -689,42 +688,50 @@
2.33 """
2.34 Emulate the current mechanisms by producing nodes as follows:
2.35
2.36 - Try (body) -> x.__add__(y)
2.37 - (else)
2.38 - (handler) -> Conditional (test) -> isinstance(exc, TypeError)
2.39 - (body) -> y.__radd__(x)
2.40 - (else)
2.41 + InvokeBlock -> Subprogram -> Try (body) -> Return (expr) -> x.__add__(y)
2.42 + (else)
2.43 + (handler) -> Conditional (test) -> CheckExc (expr) -> LoadExc
2.44 + (choices) -> LoadName TypeError
2.45 + (body) -> Return (expr) -> y.__radd__(x)
2.46 + (else)
2.47 """
2.48
2.49 - result = Try(add, 1,
2.50 - body=[
2.51 - InvokeFunction(
2.52 - expr=LoadAttr(expr=self.dispatch(add.left), name="__add__"),
2.53 - args=[self.dispatch(add.right)],
2.54 - star=None,
2.55 - dstar=None)
2.56 - ],
2.57 - else_=[],
2.58 - finally_=[],
2.59 - handler=[
2.60 - Conditional(
2.61 - test=InvokeFunction(
2.62 - expr=LoadName(name="isinstance"),
2.63 - args=[LoadExc(), LoadName(name="TypeError")],
2.64 - star=None,
2.65 - dstar=None),
2.66 - body=[
2.67 - InvokeFunction(
2.68 - expr=LoadAttr(expr=self.dispatch(add.right), name="__radd__"),
2.69 - args=[self.dispatch(add.left)],
2.70 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=1, params=[], star=None, dstar=None)
2.71 + self.current_subprograms.append(subprogram)
2.72 +
2.73 + subprogram.code = [
2.74 + Try(add, 1,
2.75 + body=[
2.76 + Return(
2.77 + expr=InvokeFunction(
2.78 + expr=LoadAttr(expr=self.dispatch(add.left), name="__add__"),
2.79 + args=[self.dispatch(add.right)],
2.80 star=None,
2.81 dstar=None)
2.82 - ],
2.83 - else_=[]
2.84 - )
2.85 - ]
2.86 - )
2.87 + )
2.88 + ],
2.89 + else_=[],
2.90 + finally_=[],
2.91 + handler=[
2.92 + Conditional(
2.93 + test=CheckExc(expr=LoadExc(), choices=[LoadName(name="TypeError")]),
2.94 + body=[
2.95 + Return(
2.96 + expr=InvokeFunction(
2.97 + expr=LoadAttr(expr=self.dispatch(add.right), name="__radd__"),
2.98 + args=[self.dispatch(add.left)],
2.99 + star=None,
2.100 + dstar=None)
2.101 + )
2.102 + ],
2.103 + else_=[]
2.104 + )
2.105 + ]
2.106 + )
2.107 + ]
2.108
2.109 + result = InvokeBlock(produces_result=1)
2.110 + result.expr = LoadRef(ref=subprogram)
2.111 return result
2.112
2.113 # Assignments.
3.1 --- a/viewer.py Sun Nov 26 21:28:11 2006 +0100
3.2 +++ b/viewer.py Mon Nov 27 01:06:38 2006 +0100
3.3 @@ -151,7 +151,8 @@
3.4 .op,
3.5 .name,
3.6 .attr,
3.7 - .conditional
3.8 + .conditional,
3.9 + .operator
3.10 {
3.11 position: relative;
3.12 }
3.13 @@ -159,7 +160,8 @@
3.14 .op:hover > .popup,
3.15 .name:hover > .popup,
3.16 .attr:hover > .popup,
3.17 - .conditional:hover > .popup
3.18 + .conditional:hover > .popup,
3.19 + .operator:hover > .popup
3.20 {
3.21 display: block;
3.22 }
3.23 @@ -180,16 +182,16 @@
3.24 """
3.25 A browsing visitor for AST nodes.
3.26
3.27 - Covered: And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
3.28 - CallFunc, Class, Compare, Const, Continue, Dict, Discard, For,
3.29 - Function, Getattr, If, Keyword, Lambda, List, Module, Name, Not,
3.30 - Or, Pass, Raise, Return, Slice, Stmt, Subscript, Tuple, While.
3.31 + Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
3.32 + Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
3.33 + For, Function, Getattr, If, Keyword, Lambda, List, Module, Name,
3.34 + Not, Or, Pass, Raise, Return, Slice, Stmt, Subscript, TryExcept,
3.35 + TryFinally, Tuple, While.
3.36
3.37 - Missing: Add, Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
3.38 + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
3.39 Ellipsis, Exec, FloorDiv, From, Global, Import, Invert, LeftShift,
3.40 ListComp, ListCompFor, ListCompIf, Mod, Mul, Not, Or, Power, Print,
3.41 - Printnl, RightShift, Sliceobj, Sub, TryExcept, TryFinally,
3.42 - UnaryAdd, UnarySub, Yield.
3.43 + Printnl, RightShift, Sliceobj, Sub, UnaryAdd, UnarySub, Yield.
3.44 """
3.45
3.46 def __init__(self, stream):
3.47 @@ -474,6 +476,21 @@
3.48
3.49 # Expressions.
3.50
3.51 + def visitAdd(self, node):
3.52 + self.stream.write("<span class='add'>\n")
3.53 + self.dispatch(node.left)
3.54 + self.stream.write("<span class='operator'>\n")
3.55 + self.stream.write("+")
3.56 + self._popup_start()
3.57 + self.stream.write("<div class='invocations'>\n")
3.58 + self._invocations_list(node._node.body[0].expr) # NOTE: See visitAdd in simplify.
3.59 + self._invocations_list(node._node.handler[0].body[0].expr) # NOTE: See visitAdd in simplify.
3.60 + self.stream.write("</div>\n")
3.61 + self._popup_end()
3.62 + self.stream.write("</span>\n")
3.63 + self.dispatch(node.right)
3.64 + self.stream.write("</span>")
3.65 +
3.66 def visitAnd(self, node):
3.67 self.stream.write("<span class='and'>\n")
3.68 first = 1
3.69 @@ -738,22 +755,22 @@
3.70 self._invocations(op)
3.71
3.72 def _invocations(self, node):
3.73 - if hasattr(node, "invocations"):
3.74 - self._invocations_list(node.invocations)
3.75 + self.stream.write("<div class='invocations'>\n")
3.76 + self._invocations_list(node)
3.77 + self.stream.write("</div>\n")
3.78
3.79 - def _invocations_list(self, invocations):
3.80 - self.stream.write("<div class='invocations'>\n")
3.81 - for invocation in invocations:
3.82 - fn = invocation.full_name()
3.83 - module = invocation.module.name
3.84 - name = invocation.name
3.85 - structures = [x.name for x in invocation.structures]
3.86 - self.stream.write("<div class='invocation'>")
3.87 - self.stream.write("<a href='%s.html#%s'>" % (self._url(module), self._url(fn)))
3.88 - self.stream.write(self._text(".".join([module] + structures + [name])))
3.89 - self.stream.write("</a>")
3.90 - self.stream.write("</div>\n")
3.91 - self.stream.write("</div>\n")
3.92 + def _invocations_list(self, node):
3.93 + if hasattr(node, "invocations"):
3.94 + for invocation in node.invocations:
3.95 + fn = invocation.full_name()
3.96 + module = invocation.module.name
3.97 + name = invocation.name
3.98 + structures = [x.name for x in invocation.structures]
3.99 + self.stream.write("<div class='invocation'>")
3.100 + self.stream.write("<a href='%s.html#%s'>" % (self._url(module), self._url(fn)))
3.101 + self.stream.write(self._text(".".join([module] + structures + [name])))
3.102 + self.stream.write("</a>")
3.103 + self.stream.write("</div>\n")
3.104
3.105 def _types(self, node):
3.106 if hasattr(node, "types"):