[pypy-svn] r66599 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test tools

benjamin at codespeak.net benjamin at codespeak.net
Fri Jul 24 18:05:37 CEST 2009


Author: benjamin
Date: Fri Jul 24 18:05:33 2009
New Revision: 66599

Added:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/ast.py   (contents, props changed)
Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/assemble.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/asthelpers.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/optimize.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
Log:
move ast2.py to ast.py and add it the repo

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/assemble.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/assemble.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/assemble.py	Fri Jul 24 18:05:33 2009
@@ -2,7 +2,7 @@
 Python control flow graph generation and bytecode assembly.
 """
 
-from pypy.interpreter.astcompiler import ast2 as ast, symtable
+from pypy.interpreter.astcompiler import ast, symtable
 from pypy.interpreter import pycode
 from pypy.tool import stdlib_opcode as ops
 

Added: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/ast.py
==============================================================================
--- (empty file)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/ast.py	Fri Jul 24 18:05:33 2009
@@ -0,0 +1,1448 @@
+# Generated by tools/asdl_py.py
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter import typedef
+from pypy.tool.pairtype import extendabletype
+
+class AST(Wrappable):
+
+    __slots__ = ()
+
+    __metaclass__ = extendabletype
+
+    def walkabout(self, visitor):
+        raise AssertionError("walkabout() implementation not provided")
+
+    def mutate_over(self, visitor):
+        raise AssertionError("mutate_over() implementation not provided")
+
+class NodeVisitorNotImplemented(Exception):
+    pass
+
+class mod(AST):
+
+    __slots__ = ()
+
+class Module(mod):
+
+    __slots__ = ('body')
+
+    def __init__(self, body):
+        self.body = body
+
+    def walkabout(self, visitor):
+        visitor.visit_Module(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        return visitor.visit_Module(self)
+
+class Interactive(mod):
+
+    __slots__ = ('body')
+
+    def __init__(self, body):
+        self.body = body
+
+    def walkabout(self, visitor):
+        visitor.visit_Interactive(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        return visitor.visit_Interactive(self)
+
+class Expression(mod):
+
+    __slots__ = ('body')
+
+    def __init__(self, body):
+        self.body = body
+
+    def walkabout(self, visitor):
+        visitor.visit_Expression(self)
+
+    def mutate_over(self, visitor):
+        self.body = self.body.mutate_over(visitor)
+        return visitor.visit_Expression(self)
+
+class Suite(mod):
+
+    __slots__ = ('body')
+
+    def __init__(self, body):
+        self.body = body
+
+    def walkabout(self, visitor):
+        visitor.visit_Suite(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        return visitor.visit_Suite(self)
+
+class stmt(AST):
+
+    __slots__ = ('lineno', 'col_offset')
+
+class FunctionDef(stmt):
+
+    __slots__ = ('name', 'args', 'body', 'decorators')
+
+    def __init__(self, name, args, body, decorators, lineno, col_offset):
+        self.name = name
+        self.args = args
+        self.body = body
+        self.decorators = decorators
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_FunctionDef(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.decorators:
+            visitor._mutate_sequence(self.decorators)
+        return visitor.visit_FunctionDef(self)
+
+class ClassDef(stmt):
+
+    __slots__ = ('name', 'bases', 'body')
+
+    def __init__(self, name, bases, body, lineno, col_offset):
+        self.name = name
+        self.bases = bases
+        self.body = body
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_ClassDef(self)
+
+    def mutate_over(self, visitor):
+        if self.bases:
+            visitor._mutate_sequence(self.bases)
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        return visitor.visit_ClassDef(self)
+
+class Return(stmt):
+
+    __slots__ = ('value')
+
+    def __init__(self, value, lineno, col_offset):
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Return(self)
+
+    def mutate_over(self, visitor):
+        if self.value:
+            self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Return(self)
+
+class Delete(stmt):
+
+    __slots__ = ('targets')
+
+    def __init__(self, targets, lineno, col_offset):
+        self.targets = targets
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Delete(self)
+
+    def mutate_over(self, visitor):
+        if self.targets:
+            visitor._mutate_sequence(self.targets)
+        return visitor.visit_Delete(self)
+
+class Assign(stmt):
+
+    __slots__ = ('targets', 'value')
+
+    def __init__(self, targets, value, lineno, col_offset):
+        self.targets = targets
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Assign(self)
+
+    def mutate_over(self, visitor):
+        if self.targets:
+            visitor._mutate_sequence(self.targets)
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Assign(self)
+
+class AugAssign(stmt):
+
+    __slots__ = ('target', 'op', 'value')
+
+    def __init__(self, target, op, value, lineno, col_offset):
+        self.target = target
+        self.op = op
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_AugAssign(self)
+
+    def mutate_over(self, visitor):
+        self.target = self.target.mutate_over(visitor)
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_AugAssign(self)
+
+class Print(stmt):
+
+    __slots__ = ('dest', 'values', 'nl')
+
+    def __init__(self, dest, values, nl, lineno, col_offset):
+        self.dest = dest
+        self.values = values
+        self.nl = nl
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Print(self)
+
+    def mutate_over(self, visitor):
+        if self.dest:
+            self.dest = self.dest.mutate_over(visitor)
+        if self.values:
+            visitor._mutate_sequence(self.values)
+        return visitor.visit_Print(self)
+
+class For(stmt):
+
+    __slots__ = ('target', 'iter', 'body', 'orelse')
+
+    def __init__(self, target, iter, body, orelse, lineno, col_offset):
+        self.target = target
+        self.iter = iter
+        self.body = body
+        self.orelse = orelse
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_For(self)
+
+    def mutate_over(self, visitor):
+        self.target = self.target.mutate_over(visitor)
+        self.iter = self.iter.mutate_over(visitor)
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.orelse:
+            visitor._mutate_sequence(self.orelse)
+        return visitor.visit_For(self)
+
+class While(stmt):
+
+    __slots__ = ('test', 'body', 'orelse')
+
+    def __init__(self, test, body, orelse, lineno, col_offset):
+        self.test = test
+        self.body = body
+        self.orelse = orelse
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_While(self)
+
+    def mutate_over(self, visitor):
+        self.test = self.test.mutate_over(visitor)
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.orelse:
+            visitor._mutate_sequence(self.orelse)
+        return visitor.visit_While(self)
+
+class If(stmt):
+
+    __slots__ = ('test', 'body', 'orelse')
+
+    def __init__(self, test, body, orelse, lineno, col_offset):
+        self.test = test
+        self.body = body
+        self.orelse = orelse
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_If(self)
+
+    def mutate_over(self, visitor):
+        self.test = self.test.mutate_over(visitor)
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.orelse:
+            visitor._mutate_sequence(self.orelse)
+        return visitor.visit_If(self)
+
+class With(stmt):
+
+    __slots__ = ('context_expr', 'optional_vars', 'body')
+
+    def __init__(self, context_expr, optional_vars, body, lineno, col_offset):
+        self.context_expr = context_expr
+        self.optional_vars = optional_vars
+        self.body = body
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_With(self)
+
+    def mutate_over(self, visitor):
+        self.context_expr = self.context_expr.mutate_over(visitor)
+        if self.optional_vars:
+            self.optional_vars = self.optional_vars.mutate_over(visitor)
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        return visitor.visit_With(self)
+
+class Raise(stmt):
+
+    __slots__ = ('type', 'inst', 'tback')
+
+    def __init__(self, type, inst, tback, lineno, col_offset):
+        self.type = type
+        self.inst = inst
+        self.tback = tback
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Raise(self)
+
+    def mutate_over(self, visitor):
+        if self.type:
+            self.type = self.type.mutate_over(visitor)
+        if self.inst:
+            self.inst = self.inst.mutate_over(visitor)
+        if self.tback:
+            self.tback = self.tback.mutate_over(visitor)
+        return visitor.visit_Raise(self)
+
+class TryExcept(stmt):
+
+    __slots__ = ('body', 'handlers', 'orelse')
+
+    def __init__(self, body, handlers, orelse, lineno, col_offset):
+        self.body = body
+        self.handlers = handlers
+        self.orelse = orelse
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_TryExcept(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.orelse:
+            visitor._mutate_sequence(self.orelse)
+        return visitor.visit_TryExcept(self)
+
+class TryFinally(stmt):
+
+    __slots__ = ('body', 'finalbody')
+
+    def __init__(self, body, finalbody, lineno, col_offset):
+        self.body = body
+        self.finalbody = finalbody
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_TryFinally(self)
+
+    def mutate_over(self, visitor):
+        if self.body:
+            visitor._mutate_sequence(self.body)
+        if self.finalbody:
+            visitor._mutate_sequence(self.finalbody)
+        return visitor.visit_TryFinally(self)
+
+class Assert(stmt):
+
+    __slots__ = ('test', 'msg')
+
+    def __init__(self, test, msg, lineno, col_offset):
+        self.test = test
+        self.msg = msg
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Assert(self)
+
+    def mutate_over(self, visitor):
+        self.test = self.test.mutate_over(visitor)
+        if self.msg:
+            self.msg = self.msg.mutate_over(visitor)
+        return visitor.visit_Assert(self)
+
+class Import(stmt):
+
+    __slots__ = ('names')
+
+    def __init__(self, names, lineno, col_offset):
+        self.names = names
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Import(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Import(self)
+
+class ImportFrom(stmt):
+
+    __slots__ = ('module', 'names', 'level')
+
+    def __init__(self, module, names, level, lineno, col_offset):
+        self.module = module
+        self.names = names
+        self.level = level
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_ImportFrom(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_ImportFrom(self)
+
+class Exec(stmt):
+
+    __slots__ = ('body', 'globals', 'locals')
+
+    def __init__(self, body, globals, locals, lineno, col_offset):
+        self.body = body
+        self.globals = globals
+        self.locals = locals
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Exec(self)
+
+    def mutate_over(self, visitor):
+        self.body = self.body.mutate_over(visitor)
+        if self.globals:
+            self.globals = self.globals.mutate_over(visitor)
+        if self.locals:
+            self.locals = self.locals.mutate_over(visitor)
+        return visitor.visit_Exec(self)
+
+class Global(stmt):
+
+    __slots__ = ('names')
+
+    def __init__(self, names, lineno, col_offset):
+        self.names = names
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Global(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Global(self)
+
+class Expr(stmt):
+
+    __slots__ = ('value')
+
+    def __init__(self, value, lineno, col_offset):
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Expr(self)
+
+    def mutate_over(self, visitor):
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Expr(self)
+
+class Pass(stmt):
+
+    __slots__ = ()
+
+    def __init__(self, lineno, col_offset):
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Pass(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Pass(self)
+
+class Break(stmt):
+
+    __slots__ = ()
+
+    def __init__(self, lineno, col_offset):
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Break(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Break(self)
+
+class Continue(stmt):
+
+    __slots__ = ()
+
+    def __init__(self, lineno, col_offset):
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Continue(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Continue(self)
+
+class expr(AST):
+
+    __slots__ = ('lineno', 'col_offset')
+
+class BoolOp(expr):
+
+    __slots__ = ('op', 'values')
+
+    def __init__(self, op, values, lineno, col_offset):
+        self.op = op
+        self.values = values
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_BoolOp(self)
+
+    def mutate_over(self, visitor):
+        if self.values:
+            visitor._mutate_sequence(self.values)
+        return visitor.visit_BoolOp(self)
+
+class BinOp(expr):
+
+    __slots__ = ('left', 'op', 'right')
+
+    def __init__(self, left, op, right, lineno, col_offset):
+        self.left = left
+        self.op = op
+        self.right = right
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_BinOp(self)
+
+    def mutate_over(self, visitor):
+        self.left = self.left.mutate_over(visitor)
+        self.right = self.right.mutate_over(visitor)
+        return visitor.visit_BinOp(self)
+
+class UnaryOp(expr):
+
+    __slots__ = ('op', 'operand')
+
+    def __init__(self, op, operand, lineno, col_offset):
+        self.op = op
+        self.operand = operand
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_UnaryOp(self)
+
+    def mutate_over(self, visitor):
+        self.operand = self.operand.mutate_over(visitor)
+        return visitor.visit_UnaryOp(self)
+
+class Lambda(expr):
+
+    __slots__ = ('args', 'body')
+
+    def __init__(self, args, body, lineno, col_offset):
+        self.args = args
+        self.body = body
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Lambda(self)
+
+    def mutate_over(self, visitor):
+        self.body = self.body.mutate_over(visitor)
+        return visitor.visit_Lambda(self)
+
+class IfExp(expr):
+
+    __slots__ = ('test', 'body', 'orelse')
+
+    def __init__(self, test, body, orelse, lineno, col_offset):
+        self.test = test
+        self.body = body
+        self.orelse = orelse
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_IfExp(self)
+
+    def mutate_over(self, visitor):
+        self.test = self.test.mutate_over(visitor)
+        self.body = self.body.mutate_over(visitor)
+        self.orelse = self.orelse.mutate_over(visitor)
+        return visitor.visit_IfExp(self)
+
+class Dict(expr):
+
+    __slots__ = ('keys', 'values')
+
+    def __init__(self, keys, values, lineno, col_offset):
+        self.keys = keys
+        self.values = values
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Dict(self)
+
+    def mutate_over(self, visitor):
+        if self.keys:
+            visitor._mutate_sequence(self.keys)
+        if self.values:
+            visitor._mutate_sequence(self.values)
+        return visitor.visit_Dict(self)
+
+class ListComp(expr):
+
+    __slots__ = ('elt', 'generators')
+
+    def __init__(self, elt, generators, lineno, col_offset):
+        self.elt = elt
+        self.generators = generators
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_ListComp(self)
+
+    def mutate_over(self, visitor):
+        self.elt = self.elt.mutate_over(visitor)
+        return visitor.visit_ListComp(self)
+
+class GeneratorExp(expr):
+
+    __slots__ = ('elt', 'generators')
+
+    def __init__(self, elt, generators, lineno, col_offset):
+        self.elt = elt
+        self.generators = generators
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_GeneratorExp(self)
+
+    def mutate_over(self, visitor):
+        self.elt = self.elt.mutate_over(visitor)
+        return visitor.visit_GeneratorExp(self)
+
+class Yield(expr):
+
+    __slots__ = ('value')
+
+    def __init__(self, value, lineno, col_offset):
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Yield(self)
+
+    def mutate_over(self, visitor):
+        if self.value:
+            self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Yield(self)
+
+class Compare(expr):
+
+    __slots__ = ('left', 'ops', 'comparators')
+
+    def __init__(self, left, ops, comparators, lineno, col_offset):
+        self.left = left
+        self.ops = ops
+        self.comparators = comparators
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Compare(self)
+
+    def mutate_over(self, visitor):
+        self.left = self.left.mutate_over(visitor)
+        if self.comparators:
+            visitor._mutate_sequence(self.comparators)
+        return visitor.visit_Compare(self)
+
+class Call(expr):
+
+    __slots__ = ('func', 'args', 'keywords', 'starargs', 'kwargs')
+
+    def __init__(self, func, args, keywords, starargs, kwargs, lineno, col_offset):
+        self.func = func
+        self.args = args
+        self.keywords = keywords
+        self.starargs = starargs
+        self.kwargs = kwargs
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Call(self)
+
+    def mutate_over(self, visitor):
+        self.func = self.func.mutate_over(visitor)
+        if self.args:
+            visitor._mutate_sequence(self.args)
+        if self.starargs:
+            self.starargs = self.starargs.mutate_over(visitor)
+        if self.kwargs:
+            self.kwargs = self.kwargs.mutate_over(visitor)
+        return visitor.visit_Call(self)
+
+class Repr(expr):
+
+    __slots__ = ('value')
+
+    def __init__(self, value, lineno, col_offset):
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Repr(self)
+
+    def mutate_over(self, visitor):
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Repr(self)
+
+class Num(expr):
+
+    __slots__ = ('n')
+
+    def __init__(self, n, lineno, col_offset):
+        self.n = n
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Num(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Num(self)
+
+class Str(expr):
+
+    __slots__ = ('s')
+
+    def __init__(self, s, lineno, col_offset):
+        self.s = s
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Str(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Str(self)
+
+class Attribute(expr):
+
+    __slots__ = ('value', 'attr', 'ctx')
+
+    def __init__(self, value, attr, ctx, lineno, col_offset):
+        self.value = value
+        self.attr = attr
+        self.ctx = ctx
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Attribute(self)
+
+    def mutate_over(self, visitor):
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Attribute(self)
+
+class Subscript(expr):
+
+    __slots__ = ('value', 'slice', 'ctx')
+
+    def __init__(self, value, slice, ctx, lineno, col_offset):
+        self.value = value
+        self.slice = slice
+        self.ctx = ctx
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Subscript(self)
+
+    def mutate_over(self, visitor):
+        self.value = self.value.mutate_over(visitor)
+        self.slice = self.slice.mutate_over(visitor)
+        return visitor.visit_Subscript(self)
+
+class Name(expr):
+
+    __slots__ = ('id', 'ctx')
+
+    def __init__(self, id, ctx, lineno, col_offset):
+        self.id = id
+        self.ctx = ctx
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Name(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Name(self)
+
+class List(expr):
+
+    __slots__ = ('elts', 'ctx')
+
+    def __init__(self, elts, ctx, lineno, col_offset):
+        self.elts = elts
+        self.ctx = ctx
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_List(self)
+
+    def mutate_over(self, visitor):
+        if self.elts:
+            visitor._mutate_sequence(self.elts)
+        return visitor.visit_List(self)
+
+class Tuple(expr):
+
+    __slots__ = ('elts', 'ctx')
+
+    def __init__(self, elts, ctx, lineno, col_offset):
+        self.elts = elts
+        self.ctx = ctx
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Tuple(self)
+
+    def mutate_over(self, visitor):
+        if self.elts:
+            visitor._mutate_sequence(self.elts)
+        return visitor.visit_Tuple(self)
+
+class Const(expr):
+
+    __slots__ = ('value')
+
+    def __init__(self, value, lineno, col_offset):
+        self.value = value
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_Const(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Const(self)
+
+Load = 1
+Store = 2
+Del = 3
+AugLoad = 4
+AugStore = 5
+Param = 6
+
+class slice(AST):
+
+    __slots__ = ()
+
+class Ellipsis(slice):
+
+    __slots__ = ()
+
+    def __init__(self):
+        pass
+
+    def walkabout(self, visitor):
+        visitor.visit_Ellipsis(self)
+
+    def mutate_over(self, visitor):
+        return visitor.visit_Ellipsis(self)
+
+class Slice(slice):
+
+    __slots__ = ('lower', 'upper', 'step')
+
+    def __init__(self, lower, upper, step):
+        self.lower = lower
+        self.upper = upper
+        self.step = step
+
+    def walkabout(self, visitor):
+        visitor.visit_Slice(self)
+
+    def mutate_over(self, visitor):
+        if self.lower:
+            self.lower = self.lower.mutate_over(visitor)
+        if self.upper:
+            self.upper = self.upper.mutate_over(visitor)
+        if self.step:
+            self.step = self.step.mutate_over(visitor)
+        return visitor.visit_Slice(self)
+
+class ExtSlice(slice):
+
+    __slots__ = ('dims')
+
+    def __init__(self, dims):
+        self.dims = dims
+
+    def walkabout(self, visitor):
+        visitor.visit_ExtSlice(self)
+
+    def mutate_over(self, visitor):
+        if self.dims:
+            visitor._mutate_sequence(self.dims)
+        return visitor.visit_ExtSlice(self)
+
+class Index(slice):
+
+    __slots__ = ('value')
+
+    def __init__(self, value):
+        self.value = value
+
+    def walkabout(self, visitor):
+        visitor.visit_Index(self)
+
+    def mutate_over(self, visitor):
+        self.value = self.value.mutate_over(visitor)
+        return visitor.visit_Index(self)
+
+And = 1
+Or = 2
+
+Add = 1
+Sub = 2
+Mult = 3
+Div = 4
+Mod = 5
+Pow = 6
+LShift = 7
+RShift = 8
+BitOr = 9
+BitXor = 10
+BitAnd = 11
+FloorDiv = 12
+
+Invert = 1
+Not = 2
+UAdd = 3
+USub = 4
+
+Eq = 1
+NotEq = 2
+Lt = 3
+LtE = 4
+Gt = 5
+GtE = 6
+Is = 7
+IsNot = 8
+In = 9
+NotIn = 10
+
+class comprehension(AST):
+
+    __slots__ = ('target', 'iter', 'ifs')
+
+    def __init__(self, target, iter, ifs):
+        self.target = target
+        self.iter = iter
+        self.ifs = ifs
+
+    def walkabout(self, visitor):
+        visitor.visit_comprehension(self)
+
+class excepthandler(AST):
+
+    __slots__ = ('type', 'name', 'body', 'lineno', 'col_offset')
+
+    def __init__(self, type, name, body, lineno, col_offset):
+        self.type = type
+        self.name = name
+        self.body = body
+        self.lineno = lineno
+        self.col_offset = col_offset
+
+    def walkabout(self, visitor):
+        visitor.visit_excepthandler(self)
+
+class arguments(AST):
+
+    __slots__ = ('args', 'vararg', 'kwarg', 'defaults')
+
+    def __init__(self, args, vararg, kwarg, defaults):
+        self.args = args
+        self.vararg = vararg
+        self.kwarg = kwarg
+        self.defaults = defaults
+
+    def walkabout(self, visitor):
+        visitor.visit_arguments(self)
+
+class keyword(AST):
+
+    __slots__ = ('arg', 'value')
+
+    def __init__(self, arg, value):
+        self.arg = arg
+        self.value = value
+
+    def walkabout(self, visitor):
+        visitor.visit_keyword(self)
+
+class alias(AST):
+
+    __slots__ = ('name', 'asname')
+
+    def __init__(self, name, asname):
+        self.name = name
+        self.asname = asname
+
+    def walkabout(self, visitor):
+        visitor.visit_alias(self)
+
+class ASTVisitor(object):
+
+    def visit_sequence(self, seq):
+        for node in seq:
+            node.walkabout(self)
+
+    def default_visitor(self, node):
+        raise NodeVisitorNotImplemented
+
+    def _mutate_sequence(self, seq):
+        for i in range(len(seq)):
+            seq[i] = seq[i].mutate_over(self)
+
+    def visit_Module(self, node):
+        return self.default_visitor(node)
+    def visit_Interactive(self, node):
+        return self.default_visitor(node)
+    def visit_Expression(self, node):
+        return self.default_visitor(node)
+    def visit_Suite(self, node):
+        return self.default_visitor(node)
+    def visit_FunctionDef(self, node):
+        return self.default_visitor(node)
+    def visit_ClassDef(self, node):
+        return self.default_visitor(node)
+    def visit_Return(self, node):
+        return self.default_visitor(node)
+    def visit_Delete(self, node):
+        return self.default_visitor(node)
+    def visit_Assign(self, node):
+        return self.default_visitor(node)
+    def visit_AugAssign(self, node):
+        return self.default_visitor(node)
+    def visit_Print(self, node):
+        return self.default_visitor(node)
+    def visit_For(self, node):
+        return self.default_visitor(node)
+    def visit_While(self, node):
+        return self.default_visitor(node)
+    def visit_If(self, node):
+        return self.default_visitor(node)
+    def visit_With(self, node):
+        return self.default_visitor(node)
+    def visit_Raise(self, node):
+        return self.default_visitor(node)
+    def visit_TryExcept(self, node):
+        return self.default_visitor(node)
+    def visit_TryFinally(self, node):
+        return self.default_visitor(node)
+    def visit_Assert(self, node):
+        return self.default_visitor(node)
+    def visit_Import(self, node):
+        return self.default_visitor(node)
+    def visit_ImportFrom(self, node):
+        return self.default_visitor(node)
+    def visit_Exec(self, node):
+        return self.default_visitor(node)
+    def visit_Global(self, node):
+        return self.default_visitor(node)
+    def visit_Expr(self, node):
+        return self.default_visitor(node)
+    def visit_Pass(self, node):
+        return self.default_visitor(node)
+    def visit_Break(self, node):
+        return self.default_visitor(node)
+    def visit_Continue(self, node):
+        return self.default_visitor(node)
+    def visit_BoolOp(self, node):
+        return self.default_visitor(node)
+    def visit_BinOp(self, node):
+        return self.default_visitor(node)
+    def visit_UnaryOp(self, node):
+        return self.default_visitor(node)
+    def visit_Lambda(self, node):
+        return self.default_visitor(node)
+    def visit_IfExp(self, node):
+        return self.default_visitor(node)
+    def visit_Dict(self, node):
+        return self.default_visitor(node)
+    def visit_ListComp(self, node):
+        return self.default_visitor(node)
+    def visit_GeneratorExp(self, node):
+        return self.default_visitor(node)
+    def visit_Yield(self, node):
+        return self.default_visitor(node)
+    def visit_Compare(self, node):
+        return self.default_visitor(node)
+    def visit_Call(self, node):
+        return self.default_visitor(node)
+    def visit_Repr(self, node):
+        return self.default_visitor(node)
+    def visit_Num(self, node):
+        return self.default_visitor(node)
+    def visit_Str(self, node):
+        return self.default_visitor(node)
+    def visit_Attribute(self, node):
+        return self.default_visitor(node)
+    def visit_Subscript(self, node):
+        return self.default_visitor(node)
+    def visit_Name(self, node):
+        return self.default_visitor(node)
+    def visit_List(self, node):
+        return self.default_visitor(node)
+    def visit_Tuple(self, node):
+        return self.default_visitor(node)
+    def visit_Const(self, node):
+        return self.default_visitor(node)
+    def visit_Ellipsis(self, node):
+        return self.default_visitor(node)
+    def visit_Slice(self, node):
+        return self.default_visitor(node)
+    def visit_ExtSlice(self, node):
+        return self.default_visitor(node)
+    def visit_Index(self, node):
+        return self.default_visitor(node)
+    def visit_comprehension(self, node):
+        return self.default_visitor(node)
+    def visit_excepthandler(self, node):
+        return self.default_visitor(node)
+    def visit_arguments(self, node):
+        return self.default_visitor(node)
+    def visit_keyword(self, node):
+        return self.default_visitor(node)
+    def visit_alias(self, node):
+        return self.default_visitor(node)
+
+class GenericASTVisitor(ASTVisitor):
+
+    def visit_Module(self, node):
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_Interactive(self, node):
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_Expression(self, node):
+        node.body.walkabout(self)
+
+    def visit_Suite(self, node):
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_FunctionDef(self, node):
+        node.args.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.decorators:
+            self.visit_sequence(node.decorators)
+
+    def visit_ClassDef(self, node):
+        if node.bases:
+            self.visit_sequence(node.bases)
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_Return(self, node):
+        if node.value:
+            node.value.walkabout(self)
+
+    def visit_Delete(self, node):
+        if node.targets:
+            self.visit_sequence(node.targets)
+
+    def visit_Assign(self, node):
+        if node.targets:
+            self.visit_sequence(node.targets)
+        node.value.walkabout(self)
+
+    def visit_AugAssign(self, node):
+        node.target.walkabout(self)
+        node.value.walkabout(self)
+
+    def visit_Print(self, node):
+        if node.dest:
+            node.dest.walkabout(self)
+        if node.values:
+            self.visit_sequence(node.values)
+
+    def visit_For(self, node):
+        node.target.walkabout(self)
+        node.iter.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.orelse:
+            self.visit_sequence(node.orelse)
+
+    def visit_While(self, node):
+        node.test.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.orelse:
+            self.visit_sequence(node.orelse)
+
+    def visit_If(self, node):
+        node.test.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.orelse:
+            self.visit_sequence(node.orelse)
+
+    def visit_With(self, node):
+        node.context_expr.walkabout(self)
+        if node.optional_vars:
+            node.optional_vars.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_Raise(self, node):
+        if node.type:
+            node.type.walkabout(self)
+        if node.inst:
+            node.inst.walkabout(self)
+        if node.tback:
+            node.tback.walkabout(self)
+
+    def visit_TryExcept(self, node):
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.handlers:
+            self.visit_sequence(node.handlers)
+        if node.orelse:
+            self.visit_sequence(node.orelse)
+
+    def visit_TryFinally(self, node):
+        if node.body:
+            self.visit_sequence(node.body)
+        if node.finalbody:
+            self.visit_sequence(node.finalbody)
+
+    def visit_Assert(self, node):
+        node.test.walkabout(self)
+        if node.msg:
+            node.msg.walkabout(self)
+
+    def visit_Import(self, node):
+        if node.names:
+            self.visit_sequence(node.names)
+
+    def visit_ImportFrom(self, node):
+        if node.names:
+            self.visit_sequence(node.names)
+
+    def visit_Exec(self, node):
+        node.body.walkabout(self)
+        if node.globals:
+            node.globals.walkabout(self)
+        if node.locals:
+            node.locals.walkabout(self)
+
+    def visit_Global(self, node):
+        pass
+
+    def visit_Expr(self, node):
+        node.value.walkabout(self)
+
+    def visit_Pass(self, node):
+        pass
+
+    def visit_Break(self, node):
+        pass
+
+    def visit_Continue(self, node):
+        pass
+
+    def visit_BoolOp(self, node):
+        if node.values:
+            self.visit_sequence(node.values)
+
+    def visit_BinOp(self, node):
+        node.left.walkabout(self)
+        node.right.walkabout(self)
+
+    def visit_UnaryOp(self, node):
+        node.operand.walkabout(self)
+
+    def visit_Lambda(self, node):
+        node.args.walkabout(self)
+        node.body.walkabout(self)
+
+    def visit_IfExp(self, node):
+        node.test.walkabout(self)
+        node.body.walkabout(self)
+        node.orelse.walkabout(self)
+
+    def visit_Dict(self, node):
+        if node.keys:
+            self.visit_sequence(node.keys)
+        if node.values:
+            self.visit_sequence(node.values)
+
+    def visit_ListComp(self, node):
+        node.elt.walkabout(self)
+        if node.generators:
+            self.visit_sequence(node.generators)
+
+    def visit_GeneratorExp(self, node):
+        node.elt.walkabout(self)
+        if node.generators:
+            self.visit_sequence(node.generators)
+
+    def visit_Yield(self, node):
+        if node.value:
+            node.value.walkabout(self)
+
+    def visit_Compare(self, node):
+        node.left.walkabout(self)
+        if node.comparators:
+            self.visit_sequence(node.comparators)
+
+    def visit_Call(self, node):
+        node.func.walkabout(self)
+        if node.args:
+            self.visit_sequence(node.args)
+        if node.keywords:
+            self.visit_sequence(node.keywords)
+        if node.starargs:
+            node.starargs.walkabout(self)
+        if node.kwargs:
+            node.kwargs.walkabout(self)
+
+    def visit_Repr(self, node):
+        node.value.walkabout(self)
+
+    def visit_Num(self, node):
+        pass
+
+    def visit_Str(self, node):
+        pass
+
+    def visit_Attribute(self, node):
+        node.value.walkabout(self)
+
+    def visit_Subscript(self, node):
+        node.value.walkabout(self)
+        node.slice.walkabout(self)
+
+    def visit_Name(self, node):
+        pass
+
+    def visit_List(self, node):
+        if node.elts:
+            self.visit_sequence(node.elts)
+
+    def visit_Tuple(self, node):
+        if node.elts:
+            self.visit_sequence(node.elts)
+
+    def visit_Const(self, node):
+        pass
+
+    def visit_Ellipsis(self, node):
+        pass
+
+    def visit_Slice(self, node):
+        if node.lower:
+            node.lower.walkabout(self)
+        if node.upper:
+            node.upper.walkabout(self)
+        if node.step:
+            node.step.walkabout(self)
+
+    def visit_ExtSlice(self, node):
+        if node.dims:
+            self.visit_sequence(node.dims)
+
+    def visit_Index(self, node):
+        node.value.walkabout(self)
+
+    def visit_comprehension(self, node):
+        node.target.walkabout(self)
+        node.iter.walkabout(self)
+        if node.ifs:
+            self.visit_sequence(node.ifs)
+
+    def visit_excepthandler(self, node):
+        if node.type:
+            node.type.walkabout(self)
+        if node.name:
+            node.name.walkabout(self)
+        if node.body:
+            self.visit_sequence(node.body)
+
+    def visit_arguments(self, node):
+        if node.args:
+            self.visit_sequence(node.args)
+        if node.defaults:
+            self.visit_sequence(node.defaults)
+
+    def visit_keyword(self, node):
+        node.value.walkabout(self)
+
+    def visit_alias(self, node):
+        pass
+
+

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py	Fri Jul 24 18:05:33 2009
@@ -1,4 +1,4 @@
-from pypy.interpreter.astcompiler import ast2 as ast, misc
+from pypy.interpreter.astcompiler import ast, misc
 from pypy.interpreter import error
 from pypy.interpreter.pyparser.pygram import syms, tokens
 from pypy.interpreter.pyparser.error import SyntaxError

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/asthelpers.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/asthelpers.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/asthelpers.py	Fri Jul 24 18:05:33 2009
@@ -1,4 +1,4 @@
-from pypy.interpreter.astcompiler import ast2 as ast
+from pypy.interpreter.astcompiler import ast
 from pypy.interpreter.error import OperationError
 
 

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/codegen.py	Fri Jul 24 18:05:33 2009
@@ -7,8 +7,7 @@
 # you figure out a way to remove them, great, but try a translation first,
 # please.
 
-from pypy.interpreter.astcompiler import (ast2 as ast, assemble, symtable,
-                                          consts, misc)
+from pypy.interpreter.astcompiler import ast, assemble, symtable, consts, misc
 from pypy.interpreter.astcompiler import optimize, asthelpers # For side effects
 from pypy.interpreter.pyparser.error import SyntaxError
 from pypy.tool import stdlib_opcode as ops

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/misc.py	Fri Jul 24 18:05:33 2009
@@ -1,5 +1,5 @@
 from pypy.interpreter import gateway
-from pypy.interpreter.astcompiler import ast2 as ast
+from pypy.interpreter.astcompiler import ast
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
 

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/optimize.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/optimize.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/optimize.py	Fri Jul 24 18:05:33 2009
@@ -2,7 +2,7 @@
 import sys
 import itertools
 
-from pypy.interpreter.astcompiler import ast2 as ast, consts, misc
+from pypy.interpreter.astcompiler import ast, consts, misc
 from pypy.tool import stdlib_opcode as ops
 from pypy.interpreter.error import OperationError
 from pypy.rlib.unroll import unrolling_iterable

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py	Fri Jul 24 18:05:33 2009
@@ -2,7 +2,7 @@
 Symbol tabling building.
 """
 
-from pypy.interpreter.astcompiler import ast2 as ast, misc
+from pypy.interpreter.astcompiler import ast, misc
 from pypy.interpreter.pyparser.error import SyntaxError
 
 # These are for internal use only:

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	Fri Jul 24 18:05:33 2009
@@ -7,7 +7,7 @@
 from pypy.interpreter.pyparser import pyparse
 from pypy.interpreter.pyparser.error import SyntaxError
 from pypy.interpreter.astcompiler.astbuilder import ast_from_node
-from pypy.interpreter.astcompiler import ast2 as ast, consts
+from pypy.interpreter.astcompiler import ast, consts
 
 
 class TestAstBuilder:

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	Fri Jul 24 18:05:33 2009
@@ -247,7 +247,7 @@
         print "Assuming default values of Python.asdl and ast.py"
         here = os.path.dirname(__file__)
         def_file = os.path.join(here, "Python.asdl")
-        out_file = os.path.join(here, "..", "ast2.py")
+        out_file = os.path.join(here, "..", "ast.py")
     else:
         print >> sys.stderr, "invalid arguments"
         return 2



More information about the Pypy-commit mailing list