fix constant folding for nonsense code like '-False'
authorStefan Behnel <scoder@users.berlios.de>
Tue, 23 Nov 2010 19:03:45 +0000 (20:03 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 23 Nov 2010 19:03:45 +0000 (20:03 +0100)
Cython/Compiler/Optimize.py

index 62d29e3142757fd035f4a8afcacf4ef12498cf58..c8abd0d4d606f00e929cf579d7c9fff09182fa24 100644 (file)
@@ -2979,6 +2979,11 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
             # this is a safe operation
             return ExprNodes.FloatNode(node.pos, value = '-' + node.operand.value,
                                        constant_result = node.constant_result)
+        if isinstance(node.operand, ExprNodes.BoolNode):
+            # not important at all, but simplifies the code below
+            return ExprNodes.IntNode(node.pos, value = str(node.constant_result),
+                                     type = PyrexTypes.c_int_type,
+                                     constant_result = node.constant_result)
         node_type = node.operand.type
         if node_type.is_int and node_type.signed or \
                isinstance(node.operand, ExprNodes.IntNode) and node_type.is_pyobject: