Esempio n. 1
0
 def visitGenExpr(self, node):
     gen = GenExprCodeGenerator(node, self.scopes, self.class_name,
                                self.get_module())
     walk(node.code, gen)
     gen.finish()
     self.set_lineno(node)
     self._makeClosure(gen, 0)
     # precomputation of outmost iterable
     self.visit(node.code.quals[0].iter)
     self.emit('GET_ITER')
     self.emit('CALL_FUNCTION', 1)
Esempio n. 2
0
 def visitClass(self, node):
     gen = self.ClassGen(node, self.scopes,
                         self.get_module())
     walk(node.code, gen)
     gen.finish()
     self.set_lineno(node)
     self.emit('LOAD_CONST', node.name)
     for base in node.bases:
         self.visit(base)
     self.emit('BUILD_TUPLE', len(node.bases))
     self._makeClosure(gen, 0)
     self.emit('CALL_FUNCTION', 0)
     self.emit('BUILD_CLASS')
     self.storeName(node.name)
Esempio n. 3
0
    def __init__(self, func, scopes, isLambda, class_name, mod):
        self.class_name = class_name
        self.module = mod
        if isLambda:
            klass = FunctionCodeGenerator
            name = "<lambda.%d>" % klass.lambdaCount
            klass.lambdaCount = klass.lambdaCount + 1
        else:
            name = func.name

        args, hasTupleArg = generateArgList(func.argnames)
        self.graph = pyassem.PyFlowGraph(name, func.filename, args,
                                         optimized=1)
        self.isLambda = isLambda
        self.super_init()

        if not isLambda and func.doc:
            self.setDocstring(func.doc)

        lnf = walk(func.code, self.NameFinder(args), verbose=0)
        self.locals.push(lnf.getLocals())
        if func.varargs:
            self.graph.setFlag(CO_VARARGS)
        if func.kwargs:
            self.graph.setFlag(CO_VARKEYWORDS)
        self.set_lineno(func)
        if hasTupleArg:
            self.generateArgUnpack(func.argnames)
Esempio n. 4
0
    def _visitFuncOrLambda(self, node, isLambda=0):
        if not isLambda and node.decorators:
            for decorator in node.decorators.nodes:
                self.visit(decorator)
            ndecorators = len(node.decorators.nodes)
        else:
            ndecorators = 0

        gen = self.FunctionGen(node, self.scopes, isLambda,
                               self.class_name, self.get_module())
        walk(node.code, gen)
        gen.finish()
        self.set_lineno(node)
        for default in node.defaults:
            self.visit(default)
        self._makeClosure(gen, len(node.defaults))
        for i in range(ndecorators):
            self.emit('CALL_FUNCTION', 1)
Esempio n. 5
0
 def __init__(self, klass, scopes, module):
     self.class_name = klass.name
     self.module = module
     self.graph = pyassem.PyFlowGraph(klass.name, klass.filename,
                                        optimized=0, klass=1)
     self.super_init()
     lnf = walk(klass.code, self.NameFinder(), verbose=0)
     self.locals.push(lnf.getLocals())
     self.graph.setFlag(CO_NEWLOCALS)
     if klass.doc:
         self.setDocstring(klass.doc)
Esempio n. 6
0
 def visitModule(self, node):
     self.scopes = self.parseSymbols(node)
     self.scope = self.scopes[node]
     self.emit('SET_LINENO', 0)
     if node.doc:
         self.emit('LOAD_CONST', node.doc)
         self.storeName('__doc__')
     lnf = walk(node.node, self.NameFinder(), verbose=0)
     self.locals.push(lnf.getLocals())
     self.visit(node.node)
     self.emit('LOAD_CONST', None)
     self.emit('RETURN_VALUE')
Esempio n. 7
0
File: syntax.py Progetto: silky/oil
def check(tree, multi=None):
    v = SyntaxErrorChecker(multi)
    walk(tree, v)
    return v.errors
Esempio n. 8
0
 def parseSymbols(self, tree):
     s = symbols.SymbolVisitor()
     walk(tree, s)
     return s.scopes
Esempio n. 9
0
def findOp(node):
    """Find the op (DELETE, LOAD, STORE) in an AssTuple tree"""
    v = OpFinder()
    walk(node, v, verbose=0)
    return v.op
Esempio n. 10
0
 def __init__(self, tree):
     self.graph = pyassem.PyFlowGraph("<interactive>", tree.filename)
     self.__super_init()
     self.set_lineno(tree)
     walk(tree, self)
     self.emit('RETURN_VALUE')
Esempio n. 11
0
 def __init__(self, tree):
     self.graph = pyassem.PyFlowGraph("<expression>", tree.filename)
     self.__super_init()
     walk(tree, self)
Esempio n. 12
0
 def __init__(self, tree):
     self.graph = pyassem.PyFlowGraph("<module>", tree.filename)
     self.futures = future.find_futures(tree)
     self.__super_init()
     walk(tree, self)