cython

Форк
0
/
CodeGeneration.py 
33 строки · 1.0 Кб
1
from .Visitor import VisitorTransform
2
from .Nodes import StatListNode
3

4

5
class ExtractPxdCode(VisitorTransform):
6
    """
7
    Finds nodes in a pxd file that should generate code, and
8
    returns them in a StatListNode.
9

10
    The result is a tuple (StatListNode, ModuleScope), i.e.
11
    everything that is needed from the pxd after it is processed.
12

13
    A purer approach would be to separately compile the pxd code,
14
    but the result would have to be slightly more sophisticated
15
    than pure strings (functions + wanted interned strings +
16
    wanted utility code + wanted cached objects) so for now this
17
    approach is taken.
18
    """
19

20
    def __call__(self, root):
21
        self.funcs = []
22
        self.visitchildren(root)
23
        return (StatListNode(root.pos, stats=self.funcs), root.scope)
24

25
    def visit_FuncDefNode(self, node):
26
        self.funcs.append(node)
27
        # Do not visit children, nested funcdefnodes will
28
        # also be moved by this action...
29
        return node
30

31
    def visit_Node(self, node):
32
        self.visitchildren(node)
33
        return node
34

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.