1 from Cython
.Compiler
.Visitor
import VisitorTransform
2 from Cython
.Compiler
.Nodes
import StatListNode
4 class ExtractPxdCode(VisitorTransform
):
6 Finds nodes in a pxd file that should generate code, and
7 returns them in a StatListNode.
9 The result is a tuple (StatListNode, ModuleScope), i.e.
10 everything that is needed from the pxd after it is processed.
12 A purer approach would be to seperately compile the pxd code,
13 but the result would have to be slightly more sophisticated
14 than pure strings (functions + wanted interned strings +
15 wanted utility code + wanted cached objects) so for now this
19 def __call__(self
, root
):
21 self
.visitchildren(root
)
22 return (StatListNode(root
.pos
, stats
=self
.funcs
), root
.scope
)
24 def visit_FuncDefNode(self
, node
):
25 self
.funcs
.append(node
)
26 # Do not visit children, nested funcdefnodes will
27 # also be moved by this action...
30 def visit_Node(self
, node
):
31 self
.visitchildren(node
)