-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoWIG.py
More file actions
123 lines (102 loc) · 5.56 KB
/
AutoWIG.py
File metadata and controls
123 lines (102 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import autowig
import os
import shutil
import sys
from path import Path
prefix = Path(sys.prefix).abspath()
root = Path('.')
inc_dir = root/'include'/'stat_tool'
if not inc_dir.exists():
os.makedirs(root/'include'/'stat_tool')
else:
for file in inc_dir.files('*.h*'):
file.remove()
for file in (root/'src'/'cpp').walkfiles('*.h*'):
file.copy(root/'include'/'stat_tool'/file.name)
headers = list(inc_dir.walkfiles('*.h'))
flags = ['-x', 'c++', '-std=c++11']
flags.append('-I' + str((prefix/'include').abspath()))
flags.append('-I' + str((root/'include').abspath()))
asg = autowig.AbstractSemanticGraph()
autowig.parser.plugin = 'clanglite'
asg = autowig.parser(asg, headers,
flags = flags,
bootstrap = 2)
def stat_tool_controller(asg):
for noncopyable in ['class ::std::basic_streambuf< char, struct ::std::char_traits< char > >',
'class ::std::codecvt< char, char, __mbstate_t >',
'class ::std::locale::facet',
'class ::std::locale::id',
'class ::std::ctype< char >',
'class ::std::ios_base',
'class ::std::basic_istream< char, struct ::std::char_traits< char > >',
'class ::std::basic_ostream< char, struct ::std::char_traits< char > >',
'class ::std::basic_ostringstream< char, struct ::std::char_traits< char >, class ::std::allocator< char > >',
'class ::std::basic_ios< char, struct ::std::char_traits< char > >',
'class ::std::basic_stringbuf< char, struct ::std::char_traits< char >, class ::std::allocator< char > >']:
if noncopyable in asg:
asg[noncopyable].is_copyable = False
for cls in asg.classes():
for fld in cls.fields(access='public'):
if fld.qualified_type.unqualified_type.globalname == 'class ::std::locale::id':
fld.boost_python_export = False
for specialization in asg['class ::std::reverse_iterator'].specializations():
specialization.boost_python_export = False
for m in ['class ::std::basic_string< char, struct ::std::char_traits< char >, class ::std::allocator< char > >',
'class ::std::basic_string< wchar_t, struct ::std::char_traits< wchar_t >, class ::std::allocator< wchar_t > >' ]:
#asg[m].boost_python_export = False # Try
for ctr in asg[m].constructors():
ctr.boost_python_export = False
for method in asg[m].methods():
method.boost_python_export = False
# if method.localname.startswith('__'):
# if isinstance(method.boost_python_export, bool):
# method.boost_python_export = False
# for exclude_method in ['append', 'assign', 'at', 'back', 'capacity', 'clear', 'compare',
# 'copy', 'c_str', 'data', 'empty', 'erase',
# 'find', 'front',
# 'get_allocator' , 'insert', 'operator[]', 'operator+=',
# 'pop', 'push', 'replace', 'reserve', 'resize', 'rfind',
# 'shrink_to_fit', 'substr', 'swap']:
# if method.localname.startswith(exclude_method):
# if isinstance(method.boost_python_export, bool):
# method.boost_python_export = False
asg['::std::ios_base::openmode'].qualified_type.boost_python_export = True
for cls in asg['class ::std::vector'].specializations(partial = False):
for method in cls.methods():
if method.localname in ['resize', 'shrink_to_fit', 'operator[]']:
if isinstance(method.boost_python_export, bool):
method.boost_python_export = False
for constructor in cls.constructors():
if not(constructor.nb_parameters == 0 or constructor.nb_parameters == 1 and constructor.parameters[0].qualified_type.unqualified_type == cls):
if isinstance(constructor.boost_python_export, bool):
constructor.boost_python_export = False
for cls in asg['class ::std::allocator'].specializations(partial = False):
cls.boost_python_export = False
if 'class ::std::reverse_iterator' in asg:
for cls in asg['class ::std::reverse_iterator'].specializations(partial = False):
cls.boost_python_export = False
if 'class ::std::initializer_list' in asg:
for cls in asg['class ::std::initializer_list'].specializations(partial = False):
cls.boost_python_export = False
if 'class ::std::default_delete' in asg:
for cls in asg['class ::std::default_delete'].specializations(partial = False):
cls.boost_python_export = False
for mtd in asg['::std::string'].qualified_type.desugared_type.unqualified_type.methods():
if mtd.localname in ['substr', 'compare']:
mtd.boost_python_export = False
return asg
autowig.controller['stat_tool'] = stat_tool_controller
autowig.controller.plugin = 'stat_tool'
asg = autowig.controller(asg)
autowig.generator.plugin = 'boost_python_internal'
wrappers = autowig.generator(asg,
module = root/'src'/'py'/'wrapper'/'_stat_tool.cpp',
decorator = root/'src'/'py'/'stat_tool'/'_stat_tool.py',
prefix = 'wrapper_')
wrappers.write()
# strange line
#shutil.rmtree('include')
import pickle
with open('ASG.pkl', 'w') as filehandler:
pickle.dump(asg, filehandler)