本文整理汇总了Python中pyc_vis.visit函数的典型用法代码示例。如果您正苦于以下问题:Python visit函数的具体用法?Python visit怎么用?Python visit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了visit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: visit_If
def visit_If(self, node, **kwargs):
print >>self.io, "%sif (%s): %s" % (
self.tab_str(**kwargs),
pyc_vis.visit(self, node.test),
self.lineno(node)
)
self.tab_depth += 1
for n in node.body:
pyc_vis.visit(self, n, **kwargs)
self.tab_depth -= 1
if len(node.orelse) > 0:
print >>self.io, "%selse: %s" % (
self.tab_str(**kwargs),
self.lineno_str(node.orelse_lineno)
)
self.tab_depth += 1
for n in node.orelse:
pyc_vis.visit(self, n, **kwargs)
self.tab_depth -= 1
#print >>self.io, ""
return ""
开发者ID:0xcc,项目名称:pyc,代码行数:25,代码来源:pyc_sir_to_py.py
示例2: visit_If
def visit_If(self, node):
(test_name, test_sir_list) = pyc_vis.visit(self, node.test)
if_lineno = self.next_lineno()
body_sir_list = []
for x in node.body:
(dummy1, sl) = pyc_vis.visit(self, x)
body_sir_list += sl
#increment to account for the 'else:' line
els_lineno = self.next_lineno() if len(node.orelse) > 0 else None
els_sir_list = []
for x in node.orelse:
(dummy2, sl) = pyc_vis.visit(self, x)
els_sir_list += sl
ifnode = ast.If(
test = test_name,
body = body_sir_list,
orelse = els_sir_list,
lineno = if_lineno
)
if els_lineno:
ifnode.orelse_lineno = els_lineno
return (
None,
test_sir_list + [ifnode]
)
开发者ID:0xcc,项目名称:pyc,代码行数:30,代码来源:pyc_sir.py
示例3: visit_BlocDef
def visit_BlocDef(self, node):
sir_body = []
bloc_lineno = self.next_lineno()
sir_body.extend([
make_assign(
var_set('False'),
InjectFromBool(arg=ast.Num(n=0)),
lineno = self.next_lineno()
),
make_assign(
var_set('True'),
InjectFromBool(arg=ast.Num(n=1)),
lineno = self.next_lineno()
)
])
for n in node.body:
(name, sir_list) = pyc_vis.visit(self, n)
sir_body += sir_list
return (
BlocDef(
name = node.name,
body = sir_body,
lineno = bloc_lineno,
params = [pyc_vis.visit(self, n)[0] for n in node.params]
),
[]
)
开发者ID:0xcc,项目名称:pyc,代码行数:30,代码来源:pyc_sir.py
示例4: visit_Call
def visit_Call(self, node, **kwargs):
return "%s(%s)" % (
pyc_vis.visit(self, node.func),
self.format_args(
[pyc_vis.visit(self, arg) for arg in node.args]
)
)
开发者ID:0xcc,项目名称:pyc,代码行数:7,代码来源:pyc_sir_to_py.py
示例5: default
def default(self, node, *args, **kwargs):
result = self.default_accumulator()
if isinstance(node, ast.AST):
result = self.default_accumulate(result, self.default_ast(node, *args, **kwargs))
for (fld, value) in ast.iter_fields(node):
#print "%s => %s" % (fld, value.__class__.__name__)
if isinstance(value, list):
for i in range(0, len(value) ):
if self.pass_fields:
kwargs["field"] = fld + ("[%d]" % i)
result = self.default_accumulate(
result,
pyc_vis.visit(self, value[i], *args, **kwargs)
)
else:
if self.pass_fields:
kwargs["field"] = fld
result = self.default_accumulate(
result,
pyc_vis.visit(self, value, *args, **kwargs)
)
else:
#print "non ast:"
result = self.default_non_ast(node, *args, **kwargs)
return result
开发者ID:0xcc,项目名称:pyc,代码行数:32,代码来源:pyc_astvisitor.py
示例6: visit_HasAttr
def visit_HasAttr(self, node):
return InjectFromBool(
arg = HasAttr(
obj = pyc_vis.visit(self, node.obj),
attr = pyc_vis.visit(self, node.attr)
)
)
开发者ID:0xcc,项目名称:pyc,代码行数:7,代码来源:pyc_ir.py
示例7: visit_IfExp
def visit_IfExp(self, node):
result_name = self.gen_name()
(test_name, test_sir_list) = pyc_vis.visit(self, node.test)
if_lineno = self.next_lineno()
(body_name, body_sir_list) = pyc_vis.visit(self, node.body)
body_sir_list += [self.make_assign(
var_set(result_name),
body_name
)]
els_lineno = self.next_lineno() #increment to account for the 'else:' line
(els_name, els_sir_list) = pyc_vis.visit(self, node.orelse)
els_sir_list += [self.make_assign(
var_set(result_name),
els_name
)]
return (
var_ref(result_name),
test_sir_list + [
ast.If(
test = test_name,
body = body_sir_list,
orelse = els_sir_list,
lineno = if_lineno,
orelse_lineno = els_lineno
)
]
)
开发者ID:0xcc,项目名称:pyc,代码行数:31,代码来源:pyc_sir.py
示例8: visit_Assign
def visit_Assign(self, node, **kwargs):
print >>self.io, "%s%s = %s %s" % (
self.tab_str(**kwargs),
pyc_vis.visit(self, node.targets[0]),
pyc_vis.visit(self, node.value),
self.lineno(node)
)
return ""
开发者ID:0xcc,项目名称:pyc,代码行数:8,代码来源:pyc_sir_to_py.py
示例9: visit_CreateClosure
def visit_CreateClosure(self, node, **kwargs):
return self.visit_func_like(
node,
[
pyc_vis.visit(self, node.name),
pyc_vis.visit(self, node.free_vars)
]
)
开发者ID:0xcc,项目名称:pyc,代码行数:8,代码来源:pyc_sir_to_py.py
示例10: visit_Assign
def visit_Assign(self, node):
if len(node.targets) != 1:
raise BadAss("expected singleton assign list")
if isinstance(node.targets[0], ast.Name):
return self.sattr(node.targets[0].id, pyc_vis.visit(self, node.value))
return make_assign(pyc_vis.visit(self, node.targets[0]), pyc_vis.visit(self, node.value))
开发者ID:cantora,项目名称:pyc,代码行数:8,代码来源:pyc_declassify.py
示例11: visit_Lambda
def visit_Lambda(self, node):
return Bloc(
args = pyc_vis.visit(self, node.args),
body = [ast.Return(
value = pyc_vis.visit(self, node.body)
)],
klass = ast.Lambda
)
开发者ID:0xcc,项目名称:pyc,代码行数:8,代码来源:pyc_ir.py
示例12: visit_Compare
def visit_Compare(self, node):
if len(node.ops) != 1:
raise BadAss("expected 1 compare op: %s" % dump(node) )
elif not isinstance(node.ops[0], ast.Eq) \
and not isinstance(node.ops[0], ast.NotEq) \
and not isinstance(node.ops[0], ast.Is):
raise BadAss("unexpected compare context: %s" % dump(node) )
elif len(node.comparators) != 1:
raise BadAss("expected 1 comparator: %s" % dump(node) )
class IsPolySwitch(PolySwitch):
def no_match(self, name_typ_list):
return ast.Num(0)
def int_int(self, l, r):
return simple_compare(ProjectToInt(arg=l), ProjectToInt(arg=r))
def bool_bool(self, l, r):
return simple_compare(ProjectToBool(arg=l), ProjectToBool(arg=r))
def big_big(self, l, r):
return simple_compare(ProjectToBig(arg=l), ProjectToBig(arg=r))
#end IsPolySwitch
class CmpPolySwitch(IsPolySwitch):
def int_bool(self, l, r):
return simple_compare(ProjectToInt(arg=l), ProjectToBool(arg=r))
def bool_int(self, l, r):
return simple_compare(ProjectToBool(arg=l), ProjectToInt(arg=r))
def big_big(self, l, r):
return make_call(
'equal',
[ ProjectToBig(arg=l), ProjectToBig(arg=r) ]
)
l_name = self.gen_name()
comp_name = self.gen_name()
ps = IsPolySwitch() if isinstance(node.ops[0], ast.Is) else CmpPolySwitch()
result = let_env(
self.gen_name,
lambda names: InjectFromBool(arg=polyswitch(ps, var_ref(names[0]), var_ref(names[1]))),
pyc_vis.visit(self, node.left),
pyc_vis.visit(self, node.comparators[0])
)
if isinstance(node.ops[0], ast.NotEq):
return InjectFromBool(arg=ast.UnaryOp(
op = ast.Not(),
operand = IsTrue(arg=result)
))
return result
开发者ID:0xcc,项目名称:pyc,代码行数:58,代码来源:pyc_ir.py
示例13: vis_fn
def vis_fn(visitor, node, name, scope):
locs = locals(node)
fnscope = locs | scope
return ast.FunctionDef(
name=name,
args=pyc_vis.visit(visitor, node.args, fnscope),
body=[pyc_vis.visit(visitor, n, fnscope) for n in node.body],
)
开发者ID:cantora,项目名称:pyc,代码行数:9,代码来源:pyc_declassify.py
示例14: visit_FunctionDef
def visit_FunctionDef(self, node):
return make_assign(
var_set(node.name),
Bloc(
args = pyc_vis.visit(self, node.args),
body = [pyc_vis.visit(self, n) for n in node.body],
klass = ast.FunctionDef
)
)
开发者ID:0xcc,项目名称:pyc,代码行数:9,代码来源:pyc_ir.py
示例15: visit_BinOp_Add
def visit_BinOp_Add(self, dummy, node):
class AddPolySwitch(PolySwitch):
def no_match(self, name_typ_list):
return make_error(
"cant add %s to %s" % (
name_typ_list[1][1],
name_typ_list[0][1]
)
)
def add_bools_or_ints(self, l, r):
return ast.BinOp(left = l, op = ast.Add(), right = r)
#int, bool => int, cast(bool, int)
def int_int(self, l, r):
return InjectFromInt(
arg = self.add_bools_or_ints(ProjectToInt(arg=l), ProjectToInt(arg=r))
)
def int_bool(self, l, r):
return InjectFromInt(
arg = self.add_bools_or_ints(ProjectToInt(arg=l), CastBoolToInt(arg=ProjectToBool(arg=r)))
)
def bool_bool(self, l, r):
return InjectFromInt(
arg = self.add_bools_or_ints(
CastBoolToInt(arg=ProjectToBool(arg=l)),
CastBoolToInt(arg=ProjectToBool(arg=r))
)
)
def bool_int(self, l, r):
return InjectFromInt(
arg = self.add_bools_or_ints(
CastBoolToInt(arg=ProjectToBool(arg=l)),
ProjectToInt(arg=r)
)
)
def big_big(self, l, r):
return InjectFromBig(
arg = make_call(
"add",
[ProjectToBig(arg=l), ProjectToBig(arg=r)]
)
)
#AddPolyswitch
return let_env(
self.gen_name,
lambda names: polyswitch(AddPolySwitch(), var_ref(names[0]), var_ref(names[1])),
pyc_vis.visit(self, node.left),
pyc_vis.visit(self, node.right)
)
开发者ID:0xcc,项目名称:pyc,代码行数:57,代码来源:pyc_ir.py
示例16: visit_If
def visit_If(self, node):
return ast.If(
test = let(
name_gen = self.gen_name,
rhs = pyc_vis.visit(self, node.test),
body = lambda name: make_is_true(name)
),
body = [pyc_vis.visit(self, x) for x in node.body],
orelse = [pyc_vis.visit(self, x) for x in node.orelse]
)
开发者ID:0xcc,项目名称:pyc,代码行数:10,代码来源:pyc_ir.py
示例17: visit_BlocDef
def visit_BlocDef(self, node, **kwargs):
print >>self.io, "def %s(%s): %s" % (
node.name,
self.format_args([n.id for n in node.params]),
self.lineno(node)
)
for n in node.body:
pyc_vis.visit(self, n, **kwargs)
return ""
开发者ID:0xcc,项目名称:pyc,代码行数:10,代码来源:pyc_sir_to_py.py
示例18: visit_IfExp
def visit_IfExp(self, node):
return ast.IfExp(
test = let(
name_gen = self.gen_name,
rhs = pyc_vis.visit(self, node.test),
body = lambda name: make_is_true(name)
),
body = pyc_vis.visit(self, node.body),
orelse = pyc_vis.visit(self, node.orelse)
)
开发者ID:0xcc,项目名称:pyc,代码行数:10,代码来源:pyc_ir.py
示例19: visit_Let
def visit_Let(self, node):
(rhs_name, rhs_sir_list) = pyc_vis.visit(self, node.rhs)
assign = self.make_assign(
var_set(node.name.id),
rhs_name
)
(body_name, body_sir_list) = pyc_vis.visit(self, node.body)
return (
body_name,
rhs_sir_list + [assign] + body_sir_list
)
开发者ID:0xcc,项目名称:pyc,代码行数:11,代码来源:pyc_sir.py
示例20: visit_Assign
def visit_Assign(self, node):
if len(node.targets) != 1:
raise InvalidP1("assign expected to have only one target: %r" % node)
elif node.targets[0].__class__ not in set([ast.Name, ast.Subscript, ast.Attribute]):
raise BadAss("assumed all targets were names, subs or attrs: %r" % ast.dump(node))
elif not isinstance(node.targets[0].ctx, ast.Store):
raise BadAss("why isnt the target context store?: %r" % node)
return ast.Assign(
targets = [pyc_vis.visit(self, node.targets[0])],
value = pyc_vis.visit(self, node.value)
)
开发者ID:0xcc,项目名称:pyc,代码行数:12,代码来源:pyc_ir.py
注:本文中的pyc_vis.visit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论