Whoops, missing file in pxd-compilation commits
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 1 Aug 2008 22:20:57 +0000 (00:20 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 1 Aug 2008 22:20:57 +0000 (00:20 +0200)
Cython/Compiler/CodeGeneration.py [new file with mode: 0644]

diff --git a/Cython/Compiler/CodeGeneration.py b/Cython/Compiler/CodeGeneration.py
new file mode 100644 (file)
index 0000000..9d9d555
--- /dev/null
@@ -0,0 +1,30 @@
+from Cython.Compiler.Visitor import VisitorTransform, temp_name_handle, CythonTransform
+from Cython.Compiler.ModuleNode import ModuleNode
+from Cython.Compiler.Nodes import *
+from Cython.Compiler.ExprNodes import *
+
+class ExtractPxdCode(CythonTransform):
+    """
+    Finds nodes in a pxd file that should generate code, and
+    returns them in a StatListNode.
+
+    The result is a tuple (StatListNode, ModuleScope), i.e.
+    everything that is needed from the pxd after it is processed.
+
+    A purer approach would be to seperately compile the pxd code,
+    but the result would have to be slightly more sophisticated
+    than pure strings (functions + wanted interned strings +
+    wanted utility code + wanted cached objects) so for now this
+    approach is taken.
+    """
+
+    def __call__(self, root):
+        self.funcs = []
+        self.visitchildren(root)
+        return (StatListNode(root.pos, stats=self.funcs), root.scope)
+
+    def visit_FuncDefNode(self, node):
+        self.funcs.append(node)
+        # Do not visit children, nested funcdefnodes will
+        # also be moved by this action...
+        return node