Commit 8e3915f6 authored by Stefan Behnel's avatar Stefan Behnel

code cleanup for if-const dead code removal

parent e80d0678
......@@ -2582,23 +2582,21 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
self.visitchildren(node)
# eliminate dead code based on constant condition results
if_clauses = []
condition_result = None
for if_clause in node.if_clauses:
condition_result = if_clause.get_constant_condition_result()
# condition_result is True, False or None (unknown)
if condition_result != False:
if condition_result is None:
# unknown result => normal runtime evaluation
if_clauses.append(if_clause)
if condition_result == True:
# other conditions can no longer apply
node.else_clause = None
break
elif condition_result == True:
# subsequent clauses can safely be dropped
node.else_clause = if_clause.body
break
else:
assert condition_result == False
if not if_clauses:
return node.else_clause # if None, deletes the node completely
elif len(if_clauses) == 1 and condition_result == True:
return if_clauses[0].body
else:
node.if_clauses = if_clauses
return node
return node.else_clause
node.if_clauses = if_clauses
return node
# in the future, other nodes can have their own handler method here
# that can replace them with a constant result node
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment