summaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Compiler/CodeGeneration.py
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/tools/cython/Cython/Compiler/CodeGeneration.py
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/CodeGeneration.py')
-rw-r--r--contrib/tools/cython/Cython/Compiler/CodeGeneration.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/CodeGeneration.py b/contrib/tools/cython/Cython/Compiler/CodeGeneration.py
new file mode 100644
index 00000000000..e64049c7f5d
--- /dev/null
+++ b/contrib/tools/cython/Cython/Compiler/CodeGeneration.py
@@ -0,0 +1,35 @@
+from __future__ import absolute_import
+
+from .Visitor import VisitorTransform
+from .Nodes import StatListNode
+
+
+class ExtractPxdCode(VisitorTransform):
+ """
+ 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 separately 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
+
+ def visit_Node(self, node):
+ self.visitchildren(node)
+ return node