self._calculate_const(node)
return node
+ def visit_BoolBinopNode(self, node):
+ self._calculate_const(node)
+ if node.constant_result is ExprNodes.not_a_constant:
+ return node
+ if not node.operand1.is_literal or not node.operand2.is_literal:
+ # We calculate other constants to make them available to
+ # the compiler, but we only aggregate constant nodes
+ # recursively, so non-const nodes are straight out.
+ return node
+
+ if node.constant_result == node.operand1.constant_result and node.operand1.is_literal:
+ return node.operand1
+ elif node.constant_result == node.operand2.constant_result and node.operand2.is_literal:
+ return node.operand2
+ else:
+ # FIXME: we could do more ...
+ return node
+
def visit_BinopNode(self, node):
self._calculate_const(node)
if node.constant_result is ExprNodes.not_a_constant:
new_node = target_class(pos=node.pos, type = widest_type)
new_node.constant_result = node.constant_result
- new_node.value = str(node.constant_result)
+ if isinstance(node, ExprNodes.BoolNode):
+ new_node.value = node.constant_result
+ else:
+ new_node.value = str(node.constant_result)
#new_node = new_node.coerce_to(node.type, self.current_scope)
return new_node
+cimport cython
+
+@cython.test_fail_if_path_exists('//BoolBinopNode')
def or_literal_bint():
"""
>>> True or 5
"""
return True or 5
+@cython.test_fail_if_path_exists('//BoolBinopNode')
def and_literal_bint():
"""
>>> 5 and True
"""
return 5 and True
+@cython.test_fail_if_path_exists('//BoolBinopNode')
def False_and_True_or_0():
"""
>>> False and True or 0
"""
return False and True or 0
+@cython.test_fail_if_path_exists('//BoolBinopNode')
def True_and_True_or_0():
"""
>>> True and True or 0