forked from M-Labs/artiq
1
0
Fork 0

transforms/remove_dead_code: bugfixes

This commit is contained in:
Sebastien Bourdeauducq 2014-10-31 23:17:54 +08:00
parent 97329b7fc9
commit b12fd1d566
1 changed files with 4 additions and 2 deletions

View File

@ -19,8 +19,8 @@ class _DeadCodeRemover(ast.NodeTransformer):
def visit_Assign(self, node): def visit_Assign(self, node):
new_targets = [] new_targets = []
for target in node.targets: for target in node.targets:
if not (isinstance(target, ast.Name) if (not isinstance(target, ast.Name)
and target.id not in self.kept_targets): or target.id in self.kept_targets):
new_targets.append(target) new_targets.append(target)
if not new_targets and is_replaceable(node.value): if not new_targets and is_replaceable(node.value):
return None return None
@ -36,6 +36,7 @@ class _DeadCodeRemover(ast.NodeTransformer):
return node return node
def visit_If(self, node): def visit_If(self, node):
self.generic_visit(node)
if isinstance(node.test, ast.NameConstant): if isinstance(node.test, ast.NameConstant):
if node.test.value: if node.test.value:
return node.body return node.body
@ -45,6 +46,7 @@ class _DeadCodeRemover(ast.NodeTransformer):
return node return node
def visit_While(self, node): def visit_While(self, node):
self.generic_visit(node)
if isinstance(node.test, ast.NameConstant) and not node.test.value: if isinstance(node.test, ast.NameConstant) and not node.test.value:
return node.orelse return node.orelse
else: else: