cython
1from .Visitor import VisitorTransform2from .Nodes import StatListNode3
4
5class ExtractPxdCode(VisitorTransform):6"""7Finds nodes in a pxd file that should generate code, and
8returns them in a StatListNode.
9
10The result is a tuple (StatListNode, ModuleScope), i.e.
11everything that is needed from the pxd after it is processed.
12
13A purer approach would be to separately compile the pxd code,
14but the result would have to be slightly more sophisticated
15than pure strings (functions + wanted interned strings +
16wanted utility code + wanted cached objects) so for now this
17approach is taken.
18"""
19
20def __call__(self, root):21self.funcs = []22self.visitchildren(root)23return (StatListNode(root.pos, stats=self.funcs), root.scope)24
25def visit_FuncDefNode(self, node):26self.funcs.append(node)27# Do not visit children, nested funcdefnodes will28# also be moved by this action...29return node30
31def visit_Node(self, node):32self.visitchildren(node)33return node34