(path)
| 1 | from __future__ import print_function |
| 2 | |
| 3 | def parse_pxd_file(path): |
| 4 | |
| 5 | import os |
| 6 | |
| 7 | from Cython.Compiler.CmdLine import parse_command_line |
| 8 | from Cython.Compiler.Main import create_default_resultobj, CompilationSource |
| 9 | from Cython.Compiler import Pipeline |
| 10 | from Cython.Compiler.Scanning import FileSourceDescriptor |
| 11 | from Cython.Compiler.Nodes import CEnumDefNode, CppClassNode, CTypeDefNode, CVarDefNode, CImportStatNode, CDefExternNode |
| 12 | # from Cython.Compiler.ExprNodes import * |
| 13 | |
| 14 | |
| 15 | options, sources = parse_command_line(["--cplus", path]) |
| 16 | |
| 17 | path = os.path.abspath(path) |
| 18 | basename = os.path.basename(path) |
| 19 | name, ext = os.path.splitext(basename) |
| 20 | |
| 21 | source_desc = FileSourceDescriptor(path, basename) |
| 22 | source = CompilationSource(source_desc, name, os.getcwd()) |
| 23 | result = create_default_resultobj(source, options) |
| 24 | |
| 25 | context = options.create_context() |
| 26 | pipeline = Pipeline.create_pyx_pipeline(context, options, result) |
| 27 | context.setup_errors(options, result) |
| 28 | root = pipeline[0](source) # only parser |
| 29 | |
| 30 | def iter_bodies(tree): |
| 31 | try: |
| 32 | for n in tree.body.stats[0].stats: |
| 33 | # cimports at head of file |
| 34 | yield n |
| 35 | except Exception: |
| 36 | pass |
| 37 | if hasattr(tree.body, "stats"): |
| 38 | for s in tree.body.stats: |
| 39 | if isinstance(s, CDefExternNode): |
| 40 | body = s.body |
| 41 | if hasattr(body, "stats"): |
| 42 | for node in body.stats: |
| 43 | yield node |
| 44 | else: |
| 45 | yield body |
| 46 | elif hasattr(tree.body, "body"): |
| 47 | body = tree.body.body |
| 48 | yield body |
| 49 | else: |
| 50 | raise Exception("parse_pxd_file failed: no valied .pxd file !") |
| 51 | |
| 52 | lines = open(path).readlines() |
| 53 | |
| 54 | def cimport(b, _, __): |
| 55 | print ("cimport", b.module_name, "as", b.as_name) |
| 56 | |
| 57 | handlers = { CEnumDefNode : "", |
| 58 | CppClassNode : "", |
| 59 | CTypeDefNode : "", |
| 60 | CVarDefNode : "", |
no test coverage detected