2.1 --- a/simplify.py Sun Jul 09 14:25:16 2006 +0200
2.2 +++ b/simplify.py Sun Jul 09 14:45:36 2006 +0200
2.3 @@ -30,17 +30,16 @@
2.4 """
2.5 A simplifying visitor for AST nodes.
2.6
2.7 - Covered: AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
2.8 + Covered: And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
2.9 CallFunc, Class, Const, Continue, Dict, Discard, For, From,
2.10 Function, Getattr, Global, If, Import, Invert, Keyword, Lambda,
2.11 - List, Module, Name, Pass, Return, Stmt, TryExcept, TryFinally,
2.12 - Tuple, While, UnaryAdd, UnarySub.
2.13 + List, Module, Name, Not, Or, Pass, Raise, Return, Stmt, TryExcept,
2.14 + TryFinally, Tuple, While, UnaryAdd, UnarySub.
2.15
2.16 - Missing: Add, And, Assert, Backquote, Bitand, Bitor, Bitxor, Compare,
2.17 - Decorators, Div, Ellipsis, Exec, FloorDiv, LeftShift,
2.18 - ListComp, ListCompFor, ListCompIf, Mod, Mul, Not, Or, Power, Print,
2.19 - Printnl, Raise, RightShift, Slice, Sliceobj, Sub, Subscript,
2.20 - Yield.
2.21 + Missing: Add, Assert, Backquote, Bitand, Bitor, Bitxor, Compare, Decorators,
2.22 + Div, Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor,
2.23 + ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift,
2.24 + Slice, Sliceobj, Sub, Subscript, Yield.
2.25 """
2.26
2.27 def __init__(self):
2.28 @@ -141,6 +140,14 @@
2.29 result.expr = LoadRef(ref=self.current_subprograms[-1])
2.30 return result
2.31
2.32 + def visitRaise(self, raise_):
2.33 + result = Raise(raise_, expr=self.dispatch(raise_.expr1), traceback=None)
2.34 + if raise_.expr2 is not None:
2.35 + result.args = [self.dispatch(raise_.expr2)]
2.36 + if raise_.expr3 is not None:
2.37 + result.traceback = self.dispatch(raise_.expr3)
2.38 + return result
2.39 +
2.40 def visitIf(self, if_):
2.41 result = If(if_, else_=[])
2.42 tests = []
2.43 @@ -450,8 +457,13 @@
2.44 handlers = []
2.45 for spec, assign, stmt in tryexcept.handlers:
2.46 get_exc = Assign()
2.47 - get_exc.code = [StoreTemp(expr=LoadExc()), self.dispatch(assign), ReleaseTemp()]
2.48 - handler = Except(spec=self.dispatch(spec))
2.49 + get_exc.code = [StoreTemp(expr=LoadExc())]
2.50 + if assign is not None:
2.51 + get_exc.code.append(self.dispatch(assign))
2.52 + get_exc.code.append(ReleaseTemp())
2.53 + handler = Except()
2.54 + if spec is not None:
2.55 + handler.spec = self.dispatch(spec)
2.56 handler.code = [get_exc] + self.dispatch(stmt)
2.57 handlers.append(handler)
2.58 result.handlers = handlers