fix FlattenInListTransform for the trivial case
authorStefan Behnel <scoder@users.berlios.de>
Tue, 2 Dec 2008 19:24:44 +0000 (20:24 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 2 Dec 2008 19:24:44 +0000 (20:24 +0100)
Cython/Compiler/Main.py
Cython/Compiler/Optimize.py

index 330e7554b475b15483d1a5510a18e9c31e063846..14cc6a63fc3ee72305af852cabf15f1b90c978c3 100644 (file)
@@ -114,7 +114,7 @@ class Context:
             _specific_post_parse,
             InterpretCompilerDirectives(self, self.pragma_overrides),
             _align_function_definitions,
-#            FlattenInListTransform(),
+            FlattenInListTransform(),
             WithTransform(self),
             DecoratorTransform(self),
             AnalyseDeclarationsTransform(self),
index a9021662bb1710d104299cb42b99b69f640c2539..f333d3ddc4757b7551ebdde47a5f31a4c0b8eac9 100644 (file)
@@ -311,27 +311,33 @@ class FlattenInListTransform(Visitor.VisitorTransform):
             args = node.operand2.args
             if len(args) == 0:
                 return ExprNodes.BoolNode(pos = node.pos, value = node.operator == 'not_in')
+
+            if node.operand1.is_temp or node.operand1.is_simple():
+                lhs = node.operand1
             else:
-                lhs = ExprNodes.PersistentNode(node.operand1, len(args))
-                conds = []
-                for arg in args:
-                    cond = ExprNodes.PrimaryCmpNode(
-                                        pos = node.pos,
-                                        operand1 = lhs,
-                                        operator = eq_or_neq,
-                                        operand2 = arg,
-                                        cascade = None)
-                    conds.append(ExprNodes.TypecastNode(
-                                        pos = node.pos, 
-                                        operand = cond,
-                                        type = PyrexTypes.c_bint_type))
-                def concat(left, right):
-                    return ExprNodes.BoolBinopNode(
-                                        pos = node.pos, 
-                                        operator = conjunction,
-                                        operand1 = left,
-                                        operand2 = right)
-                return reduce(concat, conds)
+                # FIXME: allocate temp for evaluated node.operand1
+                return node
+
+            conds = []
+            for arg in args:
+                cond = ExprNodes.PrimaryCmpNode(
+                                    pos = node.pos,
+                                    operand1 = lhs,
+                                    operator = eq_or_neq,
+                                    operand2 = arg,
+                                    cascade = None)
+                conds.append(ExprNodes.TypecastNode(
+                                    pos = node.pos, 
+                                    operand = cond,
+                                    type = PyrexTypes.c_bint_type))
+            def concat(left, right):
+                return ExprNodes.BoolBinopNode(
+                                    pos = node.pos, 
+                                    operator = conjunction,
+                                    operand1 = left,
+                                    operand2 = right)
+
+            return reduce(concat, conds)
         else:
             return node