本文整理汇总了Python中pythran.metadata.visit函数的典型用法代码示例。如果您正苦于以下问题:Python visit函数的具体用法?Python visit怎么用?Python visit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了visit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:pythran-travis,项目名称:pythran,代码行数:26,代码来源:use_def_chain.py
示例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)
开发者ID:jfinkels,项目名称:pythran,代码行数:25,代码来源:aliases.py
示例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)
开发者ID:pythran-travis,项目名称:pythran,代码行数:28,代码来源:use_def_chain.py
示例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)
开发者ID:Pikalchemist,项目名称:pythran,代码行数:7,代码来源:lazyness_analysis.py
示例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)
开发者ID:serge-sans-paille,项目名称:pythran,代码行数:7,代码来源:imported_ids.py
示例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)
开发者ID:baoboa,项目名称:pythran,代码行数:8,代码来源:locals_analysis.py
示例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)
开发者ID:baoboa,项目名称:pythran,代码行数:8,代码来源:locals_analysis.py
示例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)
开发者ID:serge-sans-paille,项目名称:pythran,代码行数:8,代码来源:lazyness_analysis.py
示例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)
开发者ID:serge-sans-paille,项目名称:pythran,代码行数:10,代码来源:locals_analysis.py
示例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)
开发者ID:baoboa,项目名称:pythran,代码行数:11,代码来源:aliases.py
示例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)
开发者ID:Pikalchemist,项目名称:pythran,代码行数:12,代码来源:lazyness_analysis.py
示例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)
开发者ID:Pikalchemist,项目名称:pythran,代码行数:13,代码来源:lazyness_analysis.py
示例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])
开发者ID:pythran-travis,项目名称:pythran,代码行数:15,代码来源:use_def_chain.py
示例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)
开发者ID:serge-sans-paille,项目名称:pythran,代码行数:17,代码来源:lazyness_analysis.py
示例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)
开发者ID:LuisBL,项目名称:pythran,代码行数:19,代码来源:lazyness_analysis.py
示例16: visit_If
def visit_If(self, node):
md.visit(self, node)
self.visit(node.test)
old_count = dict(self.name_count)
old_dead = set(self.dead)
old_deps = {a: set(b) for a, b in self.use.items()}
# wrap body in a list if we come from an ifExp
body = node.body if isinstance(node.body, list) else [node.body]
for stmt in body:
self.visit(stmt)
mid_count = self.name_count
mid_dead = self.dead
mid_deps = self.use
self.name_count = old_count
self.dead = old_dead
self.use = old_deps
# wrap orelse in a list if we come from an ifExp
orelse = (node.orelse if isinstance(node.orelse, list)
else [node.orelse])
for stmt in orelse:
self.visit(stmt)
# merge use variable
for key in self.use:
if key in mid_deps:
self.use[key].update(mid_deps[key])
for key in mid_deps:
if key not in self.use:
self.use[key] = set(mid_deps[key])
# value is the worse case of both branches
names = set(self.name_count.keys()).union(mid_count.keys())
for name in names:
val_body = mid_count.get(name, 0)
val_else = self.name_count.get(name, 0)
self.name_count[name] = max(val_body, val_else)
# dead var are still dead
self.dead.update(mid_dead)
开发者ID:serge-sans-paille,项目名称:pythran,代码行数:43,代码来源:lazyness_analysis.py
示例17: visit_While
def visit_While(self, node):
md.visit(self, node)
prev_node = {i: set(j) for i, j in self.current_node.iteritems()}
self.visit(node.test)
# body
self.in_loop = True
old_node = {i: set(j) for i, j in self.current_node.iteritems()}
map(self.visit, node.body)
self.add_loop_edges(prev_node)
self.in_loop = False
# orelse
new_node = self.current_node
self.merge_dict_set(self.current_node, old_node)
map(self.visit, node.orelse)
# merge result
self.merge_dict_set(self.current_node, new_node)
self.merge_dict_set(self.current_node, self.break_)
self.break_ = dict()
开发者ID:pythran-travis,项目名称:pythran,代码行数:20,代码来源:use_def_chain.py
示例18: visit_For
def visit_For(self, node):
md.visit(self, node)
self.visit(node.iter)
# body
self.in_loop = True
old_node = {i: set(j) for i, j in self.current_node.items()}
self.visit(node.target)
list(map(self.visit, node.body))
self.add_loop_edges(old_node)
self.in_loop = False
# orelse
new_node = self.current_node
self.merge_dict_set(self.current_node, old_node)
list(map(self.visit, node.orelse))
# merge result
self.merge_dict_set(self.current_node, new_node)
self.merge_dict_set(self.current_node, self.break_)
self.break_ = dict()
开发者ID:xmar,项目名称:pythran,代码行数:21,代码来源:use_def_chain.py
示例19: visit_If
def visit_If(self, node):
md.visit(self, node)
self.visit(node.test)
old_count = dict(self.name_count)
old_dead = set(self.dead)
old_deps = {a: set(b) for a, b in self.use.iteritems()}
if isinstance(node.body, list):
map(self.visit, node.body)
else:
self.visit(node.body)
mid_count = self.name_count
mid_dead = self.dead
mid_deps = self.use
self.name_count = old_count
self.dead = old_dead
self.use = old_deps
if isinstance(node.orelse, list):
map(self.visit, node.orelse)
else:
self.visit(node.orelse)
# merge use variable
for key in self.use:
if key in mid_deps:
self.use[key].update(mid_deps[key])
for key in mid_deps:
if key not in self.use:
self.use[key] = set(mid_deps[key])
# value is the worse case of both branches
names = set(self.name_count.keys() + mid_count.keys())
for name in names:
val_body = mid_count.get(name, 0)
val_else = self.name_count.get(name, 0)
self.name_count[name] = max(val_body, val_else)
# dead var are still dead
self.dead.update(mid_dead)
开发者ID:Pikalchemist,项目名称:pythran,代码行数:40,代码来源:lazyness_analysis.py
示例20: visit_If
def visit_If(self, node):
md.visit(self, node)
self.visit(node.test)
false_aliases = {k: v.copy() for k, v in self.aliases.iteritems()}
try: # first try the true branch
map(self.visit, node.body)
true_aliases, self.aliases = self.aliases, false_aliases
except PythranSyntaxError: # it failed, try the false branch
map(self.visit, node.orelse)
raise # but still throw the exception, maybe we are in a For
try: # then try the false branch
map(self.visit, node.orelse)
except PythranSyntaxError: # it failed
# we still get some info from the true branch, validate them
self.aliases = true_aliases
raise # and let other visit_ handle the issue
for k, v in true_aliases.iteritems():
if k in self.aliases:
self.aliases[k].update(v)
else:
assert isinstance(v, set)
self.aliases[k] = v
开发者ID:baoboa,项目名称:pythran,代码行数:22,代码来源:aliases.py
注:本文中的pythran.metadata.visit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论