From c370f9420486cda5297b0d315d64839c4bd6d293 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Sat, 2 Aug 2008 00:20:57 +0200 Subject: [PATCH] Whoops, missing file in pxd-compilation commits --- Cython/Compiler/CodeGeneration.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Cython/Compiler/CodeGeneration.py diff --git a/Cython/Compiler/CodeGeneration.py b/Cython/Compiler/CodeGeneration.py new file mode 100644 index 00000000..9d9d555d --- /dev/null +++ b/Cython/Compiler/CodeGeneration.py @@ -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 -- 2.26.2