remove unused ComprehensionTransform class (which doesn't work anyway)
authorStefan Behnel <scoder@users.berlios.de>
Fri, 15 May 2009 18:24:43 +0000 (20:24 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 15 May 2009 18:24:43 +0000 (20:24 +0200)
Cython/Compiler/Main.py
Cython/Compiler/ParseTreeTransforms.py

index a2cb780c06e99e4c580fcbfd457997db8976fb37..7b8b7efd4a96ff8baf08588aca22504b836005a7 100644 (file)
@@ -80,7 +80,7 @@ class Context(object):
         from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
         from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
         from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
-        from ParseTreeTransforms import ComprehensionTransform, AlignFunctionDefinitions
+        from ParseTreeTransforms import AlignFunctionDefinitions
         from AutoDocTransforms import EmbedSignature
         from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
         from Optimize import FlattenBuiltinTypeCreation, ConstantFolding, FinalOptimizePhase
@@ -125,7 +125,6 @@ class Context(object):
             AnalyseExpressionsTransform(self),
             FlattenBuiltinTypeCreation(),
             ConstantFolding(),
-#            ComprehensionTransform(),
             IterationTransform(),
             SwitchTransform(),
             FinalOptimizePhase(self),
index eb76005cdf6423d654199f8a57291a5fc3d3a184..c0961ef37b232a724f8f689d22d31960038cadc8 100644 (file)
@@ -589,62 +589,6 @@ class WithTransform(CythonTransform, SkipDeclarations):
         return node
         
 
-class ComprehensionTransform(VisitorTransform):
-    """Prevent the target of list/set/dict comprehensions from leaking by
-    moving it into a temp variable.  This mimics the behaviour of all
-    comprehensions in Py3 and of generator expressions in Py2.x.
-
-    This must run before the IterationTransform, which might replace
-    for-loops with while-loops.  We only handle for-loops here.
-    """
-    def visit_ModuleNode(self, node):
-        self.comprehension_targets = {}
-        self.visitchildren(node)
-        return node
-
-    visit_Node = VisitorTransform.recurse_to_children
-
-    def visit_ComprehensionNode(self, node):
-        if type(node.loop) not in (Nodes.ForInStatNode,
-                                   Nodes.ForFromStatNode):
-            # this should not happen!
-            self.visitchildren(node)
-            return node
-
-        outer_comprehension_targets = self.comprehension_targets
-        self.comprehension_targets = outer_comprehension_targets.copy()
-
-        # find all NameNodes in the loop target
-        target_name_collector = NameNodeCollector()
-        target_name_collector.visit(node.loop.target)
-        targets = target_name_collector.name_nodes
-
-        # create a temp variable for each target name
-        temps = []
-        for target in targets:
-            handle = TempHandle(target.type)
-            temps.append(handle)
-            self.comprehension_targets[target.entry.cname] = handle.ref(node.pos)
-
-        # replace name references in the loop code by their temp node
-        self.visitchildren(node, ['loop'])
-
-        loop = node.loop
-        if type(loop) is Nodes.ForFromStatNode and loop.target.type.is_numeric:
-            loop.loopvar_node = loop.target
-
-        node.loop = TempsBlockNode(node.pos, body=node.loop, temps=temps)
-        self.comprehension_targets = outer_comprehension_targets
-        return node
-
-    def visit_NameNode(self, node):
-        if node.entry:
-            replacement = self.comprehension_targets.get(node.entry.cname)
-            if replacement is not None:
-                return replacement
-        return node
-
-
 class DecoratorTransform(CythonTransform, SkipDeclarations):
 
     def visit_DefNode(self, func_node):