Enhance symbol prettifying function

This commit is contained in:
Christophe Bedard 2019-07-09 14:59:05 +02:00
parent 24c1c503d5
commit 5d63977fa2

View file

@ -43,26 +43,55 @@ class DataModelUtil():
""" """
Process symbol to make it more readable. Process symbol to make it more readable.
Processing will depend on the kind of symbol: * remove std::allocator
* bind object: remove placeholder and allocator info * remove std::default_delete
* function pointer: no processing * bind object: remove placeholder
* lambda: (TODO)
* timer: (TODO)
:param original: the original symbol :param original: the original symbol
:return: the prettified symbol :return: the prettified symbol
""" """
pretty = original pretty = original
pretty = pretty.replace('_<std::allocator<void> > ', '') # remove spaces
if pretty.startswith('std::_Bind<'): pretty = pretty.replace(' ', '')
# bind # allocator
STD_ALLOCATOR = '_<std::allocator<void>>'
pretty = pretty.replace(STD_ALLOCATOR, '')
# default_delete
STD_DEFAULTDELETE = 'std::default_delete'
if STD_DEFAULTDELETE in pretty:
dd_start = pretty.find(STD_DEFAULTDELETE)
template_param_open = dd_start + len(STD_DEFAULTDELETE)
# find index of matching/closing GT sign
template_param_close = template_param_open
level = 0
done = False
while not done:
template_param_close += 1
if pretty[template_param_close] == '<':
level += 1
elif pretty[template_param_close] == '>':
if level == 0:
done = True
else:
level -= 1
pretty = pretty[:dd_start] + pretty[(template_param_close + 1):]
# bind
STD_BIND = 'std::_Bind<'
if pretty.startswith(STD_BIND):
# remove bind<> # remove bind<>
pretty = pretty.replace('std::_Bind<', '') pretty = pretty.replace(STD_BIND, '')
pretty = pretty[:-1] pretty = pretty[:-1]
# remove placeholder stuff # remove placeholder stuff
placeholder_from = pretty.find('*') placeholder_from = pretty.find('*')
placeholder_to = pretty.find(')', placeholder_from) placeholder_to = pretty.find(')', placeholder_from)
pretty = pretty[:placeholder_from] + '?' + pretty[(placeholder_to + 1):] pretty = pretty[:placeholder_from] + '?' + pretty[(placeholder_to + 1):]
# remove dangling comma
pretty = pretty.replace(',>', '>')
# restore meaningful spaces
if pretty.startswith('void'):
pretty = 'void' + ' ' + pretty[len('void'):]
if pretty.endswith('const'):
pretty = pretty[:(len(pretty) - len('const'))] + ' ' + 'const'
return pretty return pretty
def get_callback_symbols(self) -> Mapping[int, str]: def get_callback_symbols(self) -> Mapping[int, str]: