Commit 9fc211eb authored by Stefan Behnel's avatar Stefan Behnel

improve constant folding for boolean expressions (and/or)

parent fd7ebea1
...@@ -3081,18 +3081,18 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3081,18 +3081,18 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
def visit_BoolBinopNode(self, node): def visit_BoolBinopNode(self, node):
self._calculate_const(node) self._calculate_const(node)
if node.constant_result is ExprNodes.not_a_constant: if node.operand1.constant_result is ExprNodes.not_a_constant:
return node
if not node.operand1.is_literal or not node.operand2.is_literal:
return node return node
elif node.operand1.constant_result:
if node.constant_result == node.operand1.constant_result and node.operand1.is_literal: if node.operator == 'and':
return node.operand1 return node.operand2
elif node.constant_result == node.operand2.constant_result and node.operand2.is_literal: else:
return node.operand2 return node.operand1
else: else:
# FIXME: we could do more ... if node.operator == 'and':
return node return node.operand1
else:
return node.operand2
def visit_BinopNode(self, node): def visit_BinopNode(self, node):
self._calculate_const(node) self._calculate_const(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