simplify

Change of simplify.py

5:f5043236bf21
simplify.py
     1.1 --- a/simplify.py	Sun Jul 09 14:25:16 2006 +0200
     1.2 +++ b/simplify.py	Sun Jul 09 14:45:36 2006 +0200
     1.3 @@ -30,17 +30,16 @@
     1.4      """
     1.5      A simplifying visitor for AST nodes.
     1.6  
     1.7 -    Covered: AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
     1.8 +    Covered: And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break,
     1.9               CallFunc, Class, Const, Continue, Dict, Discard, For, From,
    1.10               Function, Getattr, Global, If, Import, Invert, Keyword, Lambda,
    1.11 -             List, Module, Name, Pass, Return, Stmt, TryExcept, TryFinally,
    1.12 -             Tuple, While, UnaryAdd, UnarySub.
    1.13 +             List, Module, Name, Not, Or, Pass, Raise, Return, Stmt, TryExcept,
    1.14 +             TryFinally, Tuple, While, UnaryAdd, UnarySub.
    1.15  
    1.16 -    Missing: Add, And, Assert, Backquote, Bitand, Bitor, Bitxor, Compare,
    1.17 -             Decorators, Div, Ellipsis, Exec, FloorDiv, LeftShift,
    1.18 -             ListComp, ListCompFor, ListCompIf, Mod, Mul, Not, Or, Power, Print,
    1.19 -             Printnl, Raise, RightShift, Slice, Sliceobj, Sub, Subscript,
    1.20 -             Yield.
    1.21 +    Missing: Add, Assert, Backquote, Bitand, Bitor, Bitxor, Compare, Decorators,
    1.22 +             Div, Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor,
    1.23 +             ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift,
    1.24 +             Slice, Sliceobj, Sub, Subscript, Yield.
    1.25      """
    1.26  
    1.27      def __init__(self):
    1.28 @@ -141,6 +140,14 @@
    1.29          result.expr = LoadRef(ref=self.current_subprograms[-1])
    1.30          return result
    1.31  
    1.32 +    def visitRaise(self, raise_):
    1.33 +        result = Raise(raise_, expr=self.dispatch(raise_.expr1), traceback=None)
    1.34 +        if raise_.expr2 is not None:
    1.35 +            result.args = [self.dispatch(raise_.expr2)]
    1.36 +        if raise_.expr3 is not None:
    1.37 +            result.traceback = self.dispatch(raise_.expr3)
    1.38 +        return result
    1.39 +
    1.40      def visitIf(self, if_):
    1.41          result = If(if_, else_=[])
    1.42          tests = []
    1.43 @@ -450,8 +457,13 @@
    1.44          handlers = []
    1.45          for spec, assign, stmt in tryexcept.handlers:
    1.46              get_exc = Assign()
    1.47 -            get_exc.code = [StoreTemp(expr=LoadExc()), self.dispatch(assign), ReleaseTemp()]
    1.48 -            handler = Except(spec=self.dispatch(spec))
    1.49 +            get_exc.code = [StoreTemp(expr=LoadExc())]
    1.50 +            if assign is not None:
    1.51 +                get_exc.code.append(self.dispatch(assign))
    1.52 +            get_exc.code.append(ReleaseTemp())
    1.53 +            handler = Except()
    1.54 +            if spec is not None:
    1.55 +                handler.spec = self.dispatch(spec)
    1.56              handler.code = [get_exc] + self.dispatch(stmt)
    1.57              handlers.append(handler)
    1.58          result.handlers = handlers