Commit 08c1d574 authored by Stefan Behnel's avatar Stefan Behnel

simplify some code

parent 60428dd9
......@@ -5328,12 +5328,6 @@ class IfClauseNode(Node):
self.body = self.body.analyse_expressions(env)
return self
def get_constant_condition_result(self):
if self.condition.has_constant_result():
return bool(self.condition.constant_result)
else:
return None
def generate_execution_code(self, code, end_label):
self.condition.generate_evaluation_code(code)
code.putln(
......
......@@ -3306,17 +3306,16 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
# eliminate dead code based on constant condition results
if_clauses = []
for if_clause in node.if_clauses:
condition_result = if_clause.get_constant_condition_result()
if condition_result is None:
# unknown result => normal runtime evaluation
if_clauses.append(if_clause)
elif condition_result == True:
# subsequent clauses can safely be dropped
condition = if_clause.condition
if condition.has_constant_result():
if condition.constant_result:
# always true => subsequent clauses can safely be dropped
node.else_clause = if_clause.body
break
# else: false => drop clause
else:
# False clauses can safely be deleted
assert condition_result == False
# unknown result => normal runtime evaluation
if_clauses.append(if_clause)
if if_clauses:
node.if_clauses = if_clauses
return 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