-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.py
executable file
·31 lines (27 loc) · 1.06 KB
/
test.py
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
import clang.cindex
index = clang.cindex.Index.create()
tu = index.parse("framework/include/bt_device.h", args=['-std=c99'])
for node in tu.cursor.walk_preorder():
if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
print('struct ' + node.spelling + '_s')
print('{')
if node.result_type.spelling == 'void *':
print(' ' + node.result_type.spelling + ' __ret;')
elif node.result_type.spelling != 'void':
print(' ' + node.result_type.spelling.replace("*","") + ' __ret;')
for arg in node.get_arguments():
print(' ' + arg.type.spelling.replace("*","") + ' ' + arg.spelling + ';')
print('};\n')
print(arg.type.spelling + ' ' + node.spelling + '(', end="")
first = True
for arg in node.get_arguments():
if first != True:
print(', ', end="")
first = False
print(arg.type.spelling + ' ' + arg.spelling, end="")
print(')')
print('{')
print('}\n')
for node in tu.cursor.walk_preorder():
if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
print(node.spelling.upper() + ',')