update function and enum generation

This commit is contained in:
Erik Frojdh
2020-05-26 11:26:24 +02:00
parent 37cb0bb1c0
commit f4ba46c19b
5 changed files with 295 additions and 232 deletions

View File

@ -11,6 +11,10 @@ import subprocess
from parse import remove_comments
def single_line_enum(line):
sub = line[line.find('{')+1:line.find('}')]
return sub.strip().split(',')
def extract_enums(lines):
line_iter = iter(lines)
enums = {}
@ -18,19 +22,26 @@ def extract_enums(lines):
m = re.search("(?<=enum )\w+(?= {)", line)
if m:
enum_name = m.group()
# print(enum_name)
print(enum_name)
# print(line)
fields = []
while True:
l = next(line_iter)
if '};' in l:
break
m = re.search("\w+", l)
try:
# print('\t', m.group())
fields.append(m.group())
except:
pass
#deal with single line enums
if '};' in line:
fields = single_line_enum(line)
else:
#deal with multi line enums
while True:
l = next(line_iter)
if '};' in l:
break
m = re.search("\w+", l)
try:
# print('\t', m.group())
fields.append(m.group())
except:
pass
enums[enum_name] = fields
return enums

View File

@ -47,6 +47,8 @@ lines = []
ag2 = []
cn = []
def get_arguments(node):
args = [a.type.spelling for a in node.get_arguments()]
args = [
@ -66,8 +68,12 @@ def get_fdec(node):
else:
return_type = 'void'
if node.is_const_method():
const = 'const'
else:
const = ''
args = ", ".join(args)
args = f'({return_type}(Detector::*)({args}))'
args = f'({return_type}(Detector::*)({args}){const})'
return args
@ -85,6 +91,7 @@ def visit(node):
lines.append(
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'
)
cn.append(child)
for child in node.get_children():
visit(child)