Debian Codegraph @

tests/c-hello/hellomodulegen.py

raw symbols SCIP
1 #! /usr/bin/env python
2
3 import sys
4 import re
5
6 import pybindgen
7 from pybindgen import FileCodeSink
8
9
10 constructor_rx = re.compile("hello_foo_new(_.*)?")
11 method_rx = re.compile("hello_foo(_.*)?")
12
13 def pre_scan_hook(dummy_module_parser,
14 pygccxml_definition,
15 global_annotations,
16 parameter_annotations):
17 if pygccxml_definition.name == "_HelloFoo":
18 global_annotations['free_function'] = 'hello_foo_unref'
19 global_annotations['incref_function'] = 'hello_foo_ref'
20 global_annotations['decref_function'] = 'hello_foo_unref'
21 global_annotations['custom_name'] = 'Foo'
22
23 ## constructor?
24 m = constructor_rx.match(pygccxml_definition.name)
25 if m:
26 global_annotations['is_constructor_of'] = 'HelloFoo'
27 return
28
29 ## method?
30 m = method_rx.match(pygccxml_definition.name)
31 if m:
32 method_name = m.group(1)[1:]
33 if method_name in ['ref', 'unref']:
34 global_annotations['ignore'] = 'true'
35 return
36 global_annotations['as_method'] = m.group(1)[1:]
37 global_annotations['of_class'] = 'HelloFoo'
38 parameter_annotations['foo'] = {'transfer_ownership': 'false'}
39
40
41
42 def my_module_gen(out_file, pygccxml_mode):
43 if pygccxml_mode == 'castxml':
44 from pybindgen.castxmlparser import ModuleParser
45 else:
46 from pybindgen.gccxmlparser import ModuleParser
47
48 out = FileCodeSink(out_file)
49 #pybindgen.write_preamble(out)
50 out.writeln("#include \"hello.h\"")
51 module_parser = ModuleParser('hello')
52 module_parser.add_pre_scan_hook(pre_scan_hook)
53 module = module_parser.parse(sys.argv[2:])
54 module.generate(out)
55
56
57 if __name__ == '__main__':
58 try:
59 import cProfile as profile
60 except ImportError:
61 my_module_gen(sys.stdout, sys.argv[1])
62 else:
63 sys.stderr.write("** running under profiler\n")
64 profile.run('my_module_gen(sys.stdout, sys.argv[1])', 'hellomodulegen.pstat')