本文整理汇总了Python中pythran.metadata.visit函数的典型用法代码示例。如果您正苦于以下问题:Python visit函数的具体用法?Python visit怎么用?Python visit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了visit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_IfExp
def visit_IfExp(self, node):
md.visit(self, node)
swap = False
self.visit(node.test)
# if an identifier is first used in orelse and we are in a loop,
# we swap orelse and body
undef = self.passmanager.gather(ImportedIds, node.body, self.ctx)
if undef and self.in_loop:
node.body, node.orelse = node.orelse, node.body
swap = True
# body
old_node = {i: set(j) for i, j in self.current_node.iteritems()}
self.visit(node.body)
# orelse
new_node = self.current_node
self.current_node = old_node
self.visit(node.orelse)
if swap:
node.body, node.orelse = node.orelse, node.body
# merge result
self.merge_dict_set(self.current_node, new_node)
示例2: visit_Assign
def visit_Assign(self, node):
'''
Assignment creates aliasing between lhs and rhs
>>> from pythran import passmanager
>>> pm = passmanager.PassManager('demo')
>>> module = ast.parse('def foo(a): c = a ; d = e = c ; {c, d, e}')
>>> result = pm.gather(Aliases, module)
>>> Aliases.dump(result, filter=ast.Set)
{c, d, e} => ['|a|', '|a|', '|a|']
Everyone points to the formal parameter 'a' \o/
'''
md.visit(self, node)
value_aliases = self.visit(node.value)
for t in node.targets:
if isinstance(t, ast.Name):
self.aliases[t.id] = set(value_aliases) or {t}
for alias in list(value_aliases):
if isinstance(alias, ast.Name):
a_id = alias.id
self.aliases[a_id] = self.aliases[a_id].union((t,))
self.add(t, self.aliases[t.id])
else:
self.visit(t)
示例3: visit_TryExcept
def visit_TryExcept(self, node):
md.visit(self, node)
# body
all_node = dict()
for stmt in node.body:
self.visit(stmt)
for k, i in self.current_node.iteritems():
if k not in all_node:
all_node[k] = i
else:
all_node[k].update(i)
no_except = self.current_node
# except
for ex in node.handlers:
self.current_node = dict(all_node)
self.visit(ex)
# merge result
self.merge_dict_set(no_except, self.current_node)
self.current_node = no_except
if node.orelse:
err = ("orelse should have been removed in previous passes")
raise PythranSyntaxError(err, node)
示例4: visit_While
def visit_While(self, node):
md.visit(self, node)
self.visit(node.test)
self.visit_loop(node.body)
map(self.visit, node.orelse)
示例5: visit_Assign
def visit_Assign(self, node):
# order matter as an assignation
# is evaluated before being assigned
md.visit(self, node)
self.visit(node.value)
for target in node.targets:
self.visit(target)
示例6: visit_For
def visit_For(self, node):
self.expr_parent = node
self.result[node] = self.locals.copy()
md.visit(self, node)
self.visit(node.iter)
self.locals.add(node.target.id)
map(self.visit, node.body)
map(self.visit, node.orelse)
示例7: visit_Assign
def visit_Assign(self, node):
self.expr_parent = node
self.result[node] = self.locals.copy()
md.visit(self, node)
self.visit(node.value)
self.locals.update(t.id for t in node.targets
if isinstance(t, ast.Name))
map(self.visit, node.targets)
示例8: visit_While
def visit_While(self, node):
md.visit(self, node)
self.visit(node.test)
self.visit_loop(node.body)
for stmt in node.orelse:
self.visit(stmt)
示例9: visit_For
def visit_For(self, node):
self.expr_parent = node
self.result[node] = self.locals.copy()
md.visit(self, node)
self.visit(node.iter)
self.locals.add(node.target.id)
for stmt in node.body:
self.visit(stmt)
for stmt in node.orelse:
self.visit(stmt)
示例10: visit_Assign
def visit_Assign(self, node):
md.visit(self, node)
value_aliases = self.visit(node.value)
for t in node.targets:
if isinstance(t, ast.Name):
self.aliases[t.id] = value_aliases or {t}
for alias in list(value_aliases):
if isinstance(alias, ast.Name):
self.aliases[alias.id].add(t)
else:
self.visit(t)
示例11: visit_Call
def visit_Call(self, node):
"""
Compute use of variables in a function call.
Each arg is use once and function name too.
Information about modified arguments is forwarded to
func_args_lazyness.
"""
md.visit(self, node)
map(self.visit, node.args)
self.func_args_lazyness(node.func, node.args, node)
self.visit(node.func)
示例12: visit_For
def visit_For(self, node):
md.visit(self, node)
ids = self.passmanager.gather(Identifiers, node.iter, self.ctx)
if isinstance(node.target, ast.Name):
self.assign_to(node.target, ids, node.iter)
self.result[node.target.id] = LazynessAnalysis.INF
else:
err = "Assignation in for loop not to a Name"
raise PythranSyntaxError(err, node)
self.visit_loop(node.body)
map(self.visit, node.orelse)
示例13: visit_AugAssign
def visit_AugAssign(self, node):
md.visit(self, node)
self.visit(node.value)
self.visit(node.target)
var = node.target
while isinstance(var, ast.Subscript):
var = var.value
if isinstance(var, ast.Name):
var = var.id
else:
err = "AugAssign can't be used on {0}"
raise PythranSyntaxError(err.format(var), node)
last_node = self.current_node[var].pop()
self.result[var].node[last_node]['action'] = "UD"
self.current_node[var] = set([last_node])
示例14: visit_AugAssign
def visit_AugAssign(self, node):
md.visit(self, node)
# augassigned variable can't be lazy
self.visit(node.value)
if isinstance(node.target, ast.Name):
# variable is modified so other variables that use it dies
self.modify(node.target.id)
# and this variable can't be lazy
self.result[node.target.id] = LazynessAnalysis.INF
elif isinstance(node.target, ast.Subscript) or isattr(node.target):
var_name = get_variable(node.target)
# variable is modified so other variables that use it dies
self.modify(var_name.id)
# and this variable can't be lazy
self.result[var_name.id] = LazynessAnalysis.INF
else:
raise PythranSyntaxError("AugAssign to unknown node", node)
示例15: visit_Assign
def visit_Assign(self, node):
md.visit(self, node)
self.visit(node.value)
ids = self.passmanager.gather(Identifiers, node.value, self.ctx)
for target in node.targets:
if isinstance(target, ast.Name):
self.assign_to(target, ids, node.value)
if node.value not in self.pure_expressions:
self.result[target.id] = LazynessAnalysis.INF
elif isinstance(target, ast.Subscript):
# if we modify just a part of a variable, it can't be lazy
var_name = get_variable(target)
if isinstance(var_name, ast.Name):
# variable is modified so other variables that use it dies
self.modify(var_name.id, node.value)
# and this variable can't be lazy
self.result[var_name.id] = LazynessAnalysis.INF
else:
raise PythranSyntaxError("Assign to unknown node", node)