transforms: assume isinstance(expr, ast.Call) => isinstance(expr.func, ast.Name) after inline

This commit is contained in:
Sebastien Bourdeauducq 2014-11-15 15:36:26 -07:00
parent e02ca0b404
commit cbc629bd8c
3 changed files with 4 additions and 5 deletions

View File

@ -26,7 +26,7 @@ def _get_duration(stmt):
return 0 return 0
else: else:
return -1 return -1
elif isinstance(stmt, ast.Call) and isinstance(stmt.func, ast.Name): elif isinstance(stmt, ast.Call):
name = stmt.func.id name = stmt.func.id
if name == "delay": if name == "delay":
try: try:

View File

@ -19,7 +19,7 @@ from artiq.language.core import int64
class _TimeLowerer(ast.NodeTransformer): class _TimeLowerer(ast.NodeTransformer):
def visit_Call(self, node): def visit_Call(self, node):
if isinstance(node.func, ast.Name) and node.func.id == "now": if node.func.id == "now":
return ast.copy_location(ast.Name("now", ast.Load()), node) return ast.copy_location(ast.Name("now", ast.Load()), node)
else: else:
self.generic_visit(node) self.generic_visit(node)
@ -27,8 +27,7 @@ class _TimeLowerer(ast.NodeTransformer):
def visit_Expr(self, node): def visit_Expr(self, node):
r = node r = node
if (isinstance(node.value, ast.Call) if isinstance(node.value, ast.Call):
and isinstance(node.value.func, ast.Name)):
funcname = node.value.func.id funcname = node.value.func.id
if funcname == "delay": if funcname == "delay":
r = ast.copy_location( r = ast.copy_location(

View File

@ -102,7 +102,7 @@ def _is_ref_transparent(dependencies, expr):
and _is_ref_transparent(dependencies, expr.right)) and _is_ref_transparent(dependencies, expr.right))
elif isinstance(expr, ast.BoolOp): elif isinstance(expr, ast.BoolOp):
return all(_is_ref_transparent(dependencies, v) for v in expr.values) return all(_is_ref_transparent(dependencies, v) for v in expr.values)
elif isinstance(expr, ast.Call) and isinstance(expr.func, ast.Name): elif isinstance(expr, ast.Call):
return (expr.func.id in _replaceable_funcs and return (expr.func.id in _replaceable_funcs and
all(_is_ref_transparent(dependencies, arg) for arg in expr.args)) all(_is_ref_transparent(dependencies, arg) for arg in expr.args))
else: else: