Ejemplo n.º 1
0
def block(lst, withResult, prepend=None):
    if len(lst) == 0:
        if withResult:
            return ast.Const(None)
        else:
            return ast.Pass()

    def stm(x):
        if hasResult(x):
            dis = ast.Discard(topy(x))
            dis.lineno = getmeta(x, 'lineno')
            return dis
        else:
            return topy(x)

    if withResult:
        stms = [stm(s) for s in lst[:-1]]
        last = lst[-1]
        lastpy = topy(last)

        if hasResult(last):
            # Insert a pass so pycodegen emits a SET_LINENO
            p = ast.Pass()
            p.lineno = getmeta(last, 'lineno')
        
            statements = stms + [p, lastpy]
        else:
            statements = stms + [lastpy, ast.Const(None)]
    else:
        statements = [stm(s) for s in lst]

    if prepend:
        return ast.Stmt(prepend + statements)
    else:
        return ast.Stmt(statements)
Ejemplo n.º 2
0
def block(lst, withResult, prepend=None):
    if len(lst) == 0:
        if withResult:
            return ast.Const(None)
        else:
            return ast.Pass()

    def stm(x):
        if hasResult(x):
            dis = ast.Discard(topy(x))
            dis.lineno = getattr(x, 'lineno', None)
            return dis
        else:
            return topy(x)

    if withResult:
        stms = [stm(s) for s in lst[:-1]]
        last = lst[-1]
        lastpy = topy(last)

        if hasResult(last):
            # Insert a pass so pycodegen emits a SET_LINENO
            p = ast.Pass()
            p.lineno = getattr(last, "lineno", None)
        
            statements = stms + [p, lastpy]
        else:
            statements = stms + [lastpy, ast.Const(None)]
    else:
        statements = [stm(s) for s in lst]

    # HACK: No lineno info was emitted for "del a[0]" statements
    # (insert a Pass to fix that)
    s2 = []
    for s in statements:
        if isinstance(s, ast.Subscript) and s.flags == "OP_DELETE" and hasattr(s, "lineno"):
            p = ast.Pass()
            p.lineno = s.lineno
            s2.append(p)
        s2.append(s)

    if prepend:
        return ast.Stmt(prepend + s2)
    else:
        return ast.Stmt(s2)
Ejemplo n.º 3
0
 def _do_PassStatement(self, node):
     return ast.Pass()
Ejemplo n.º 4
0
def p_pass_stmt(p):
    "pass_stmt : PASS"
    p[0] = ast.Pass()