本文整理汇总了Python中pythran.passmanager.Transformation.generic_visit方法的典型用法代码示例。如果您正苦于以下问题:Python Transformation.generic_visit方法的具体用法?Python Transformation.generic_visit怎么用?Python Transformation.generic_visit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pythran.passmanager.Transformation
的用法示例。
在下文中一共展示了Transformation.generic_visit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generic_visit
# 需要导入模块: from pythran.passmanager import Transformation [as 别名]
# 或者: from pythran.passmanager.Transformation import generic_visit [as 别名]
def generic_visit(self, node):
if node in self.constant_expressions:
try:
fake_node = ast.Expression(node.value if isinstance(node, ast.Index) else node)
code = compile(fake_node, "<constant folding>", "eval")
value = eval(code, self.env)
new_node = self.to_ast(value)
if isinstance(node, ast.Index) and not isinstance(new_node, ast.Index):
new_node = ast.Index(new_node)
return new_node
except ConstantFolding.ConversionError as e:
print ast.dump(node)
print "error in constant folding: ", e
raise
except ConstantFolding.ToNotEval:
return Transformation.generic_visit(self, node)
except AttributeError as e:
# FIXME union_ function is not handle by constant folding
if "union_" in e.args[0]:
return Transformation.generic_visit(self, node)
raise
except NameError as e:
# FIXME dispatched function are not processed by constant
# folding
if "__dispatch__" in e.args[0]:
return Transformation.generic_visit(self, node)
raise
else:
return Transformation.generic_visit(self, node)
示例2: generic_visit
# 需要导入模块: from pythran.passmanager import Transformation [as 别名]
# 或者: from pythran.passmanager.Transformation import generic_visit [as 别名]
def generic_visit(self, node):
if node in self.constant_expressions:
try:
fake_node = ast.Expression(
node.value if isinstance(node, ast.Index) else node)
code = compile(fake_node, '<constant folding>', 'eval')
value = eval(code, self.env)
new_node = self.to_ast(value)
if (isinstance(node, ast.Index)
and not isinstance(new_node, ast.Index)):
new_node = ast.Index(new_node)
return new_node
except Exception: # as e:
#print ast.dump(node)
#print 'error in constant folding: ', e
return Transformation.generic_visit(self, node)
else:
return Transformation.generic_visit(self, node)
示例3: generic_visit
# 需要导入模块: from pythran.passmanager import Transformation [as 别名]
# 或者: from pythran.passmanager.Transformation import generic_visit [as 别名]
def generic_visit(self, node):
if node in self.constant_expressions:
try:
fake_node = ast.Expression(
node.value if isinstance(node, ast.Index) else node)
code = compile(fake_node, '<constant folding>', 'eval')
value = eval(code, self.env)
new_node = to_ast(value)
if(isinstance(node, ast.Index) and
not isinstance(new_node, ast.Index)):
new_node = ast.Index(new_node)
try:
if not ASTMatcher(node).search(new_node):
self.update = True
except DamnTooLongPattern as e:
print "W: ", e, " Assume no update happened."
return new_node
except ConversionError as e:
print ast.dump(node)
print 'error in constant folding: ', e
raise
except ToNotEval:
return Transformation.generic_visit(self, node)
except AttributeError as e:
# FIXME union_ function is not handle by constant folding
if "union_" in e.args[0]:
return Transformation.generic_visit(self, node)
elif "pythran" in e.args[0]:
# FIXME: Can be fix giving a Python implementation for
# these functions.
return Transformation.generic_visit(self, node)
raise
except NameError as e:
# FIXME dispatched function are not processed by constant
# folding
if "__dispatch__" in e.args[0]:
return Transformation.generic_visit(self, node)
raise
else:
return Transformation.generic_visit(self, node)