mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
update function and enum generation
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user