summaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Compiler/CodeGeneration.py
diff options
context:
space:
mode:
authoralexv-smirnov <[email protected]>2023-06-13 11:05:01 +0300
committeralexv-smirnov <[email protected]>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /contrib/tools/cython/Cython/Compiler/CodeGeneration.py
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
add ymake export to ydb
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