Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Modules/ThirdParty/pygccxml/src/pygccxml/declarations/calldef.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,24 @@ def does_throw(self, does_throw):

@property
def exceptions(self):
"""The list of exceptions.
@type: list of :class:`declaration_t`"""
"""
The list of exceptions.

Useless with c++17 and above as dynamich exceptions
are not allowed anymore:
https://developers.redhat.com/articles/2021/08/06/porting-your-code-c17-gcc-11#exception_specification_changes # noqa

@type: list of :class:`declaration_t`
"""
return self._exceptions

@exceptions.setter
def exceptions(self, exceptions):
"""
Useless with c++17 and above as dynamich exceptions
are not allowed anymore:
https://developers.redhat.com/articles/2021/08/06/porting-your-code-c17-gcc-11#exception_specification_changes # noqa
"""
self._exceptions = exceptions

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

std_namespaces = ('std', 'stdext', '__gnu_cxx')

# Take into account different equivalences (with or without spaces)
string_equivalences = type_traits.string_equivalences + \
type_traits.normalized_string_equivalences
string_equivalences = [
v for v in string_equivalences if not v == "std::string"]
wstring_equivalences = type_traits.wstring_equivalences + \
type_traits.normalized_wstring_equivalences
wstring_equivalences = [
v for v in wstring_equivalences if not v == "std::wstring"]


class defaults_eraser(object):

Expand All @@ -28,27 +38,17 @@ def __init__(self, unordered_maps_and_sets):
def normalize(self, type_str):
return type_str.replace(' ', '')

def replace_basic_string(self, cls_name):

# Take the lists of all possible string variations
# and clean them up by replacing ::std by std.
str_eq = [
v.replace("::std", "std") for v in
type_traits.string_equivalences]
wstr_eq = [
v.replace("::std", "std") for v in
type_traits.wstring_equivalences]

# Replace all the variations of strings by the smallest one.
@staticmethod
def replace_basic_string(cls_name):
strings = {
"std::string": [v for v in str_eq if not v == "std::string"],
"std::wstring": [v for v in wstr_eq if not v == "std::wstring"]}
"std::string": string_equivalences,
"std::wstring": wstring_equivalences
}

new_name = cls_name
for short_name, long_names in strings.items():
for lname in long_names:
new_name = new_name.replace(lname, short_name)

return new_name

def decorated_call_prefix(self, cls_name, text, doit):
Expand Down Expand Up @@ -99,13 +99,12 @@ def erase_recursive(self, cls_name):
return self.no_end_const(cls_name)

def erase_allocator(self, cls_name, default_allocator='std::allocator'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 2:
return
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $allocator<$value_type> >")
"$container<$value_type, $allocator<$value_type>>")
tmpl = tmpl.substitute(
container=c_name,
value_type=value_type,
Expand All @@ -116,24 +115,21 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
c_name, [self.erase_recursive(value_type)])

def erase_container(self, cls_name, default_container_name='std::deque'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 2:
return
value_type = c_args[0]
dc_no_defaults = self.erase_recursive(c_args[1])
if self.normalize(dc_no_defaults) != self.normalize(
if self.normalize(dc_no_defaults) == self.normalize(
templates.join(default_container_name, [value_type])):
return
return templates.join(
c_name, [self.erase_recursive(value_type)])
return templates.join(
c_name, [self.erase_recursive(value_type)])

def erase_container_compare(
self,
cls_name,
default_container_name='std::vector',
default_compare='std::less'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
Expand All @@ -153,14 +149,13 @@ def erase_compare_allocator(
cls_name,
default_compare='std::less',
default_allocator='std::allocator'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $compare<$value_type>, " +
"$allocator<$value_type> >")
"$container<$value_type, $compare<$value_type>, " +
"$allocator<$value_type>>")
tmpl = tmpl.substitute(
container=c_name,
value_type=value_type,
Expand All @@ -176,22 +171,21 @@ def erase_map_compare_allocator(
cls_name,
default_compare='std::less',
default_allocator='std::allocator'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 4:
return
key_type = c_args[0]
mapped_type = c_args[1]
tmpls = [
string.Template(
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
"$allocator< std::pair< const $key_type, $mapped_type> > >"),
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
"$allocator<std::pair<const $key_type, $mapped_type>>>"),
string.Template(
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
"$allocator< std::pair< $key_type const, $mapped_type> > >"),
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
"$allocator<std::pair< $key_type const, $mapped_type>>>"),
string.Template(
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
"$allocator< std::pair< $key_type, $mapped_type> > >")]
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
"$allocator<std::pair<$key_type, $mapped_type>>>")]
for tmpl in tmpls:
tmpl = tmpl.substitute(
container=c_name,
Expand All @@ -206,7 +200,6 @@ def erase_map_compare_allocator(
self.erase_recursive(mapped_type)])

def erase_hash_allocator(self, cls_name):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) < 3:
return
Expand All @@ -218,13 +211,13 @@ def erase_hash_allocator(self, cls_name):
if len(c_args) == 3:
default_hash = 'hash_compare'
tmpl = (
"$container< $value_type, $hash<$value_type, " +
"$less<$value_type> >, $allocator<$value_type> >")
"$container<$value_type, $hash<$value_type, " +
"$less<$value_type>>, $allocator<$value_type>>")
elif len(c_args) == 4:
default_hash = 'hash'
tmpl = (
"$container< $value_type, $hash<$value_type >, " +
"$equal_to<$value_type >, $allocator<$value_type> >")
"$container<$value_type, $hash<$value_type>, " +
"$equal_to<$value_type>, $allocator<$value_type>>")
else:
return

Expand All @@ -244,7 +237,6 @@ def erase_hash_allocator(self, cls_name):
c_name, [self.erase_recursive(value_type)])

def erase_hashmap_compare_allocator(self, cls_name):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)

if self.unordered_maps_and_sets:
Expand All @@ -263,14 +255,14 @@ def erase_hashmap_compare_allocator(self, cls_name):
if len(c_args) == 4:
default_hash = 'hash_compare'
tmpl = string.Template(
"$container< $key_type, $mapped_type, " +
"$hash<$key_type, $less<$key_type> >, " +
"$allocator< std::pair< const $key_type, $mapped_type> > >")
"$container<$key_type, $mapped_type, " +
"$hash<$key_type, $less<$key_type>>, " +
"$allocator<std::pair<const $key_type, $mapped_type>>>")
if key_type.startswith('const ') or key_type.endswith(' const'):
tmpl = string.Template(
"$container< $key_type, $mapped_type, $hash<$key_type, " +
"$less<$key_type> >, $allocator< std::pair< $key_type, " +
"$mapped_type> > >")
"$container<$key_type, $mapped_type, $hash<$key_type, " +
"$less<$key_type>>, $allocator<std::pair<$key_type, " +
"$mapped_type>>>")
elif len(c_args) == 5:
default_hash = 'hash'
if self.unordered_maps_and_sets:
Expand All @@ -279,31 +271,31 @@ def erase_hashmap_compare_allocator(self, cls_name):
"$hash<$key_type>, " +
"$equal_to<$key_type>, " +
"$allocator<std::pair<const$key_type, " +
"$mapped_type> > >")
"$mapped_type>>>")
if key_type.startswith('const ') or \
key_type.endswith(' const'):
tmpl = string.Template(
"$container<$key_type, $mapped_type, " +
"$hash<$key_type >, " +
"$equal_to<$key_type >, " +
"$hash<$key_type>, " +
"$equal_to<$key_type>, " +
"$allocator<std::pair<$key_type, " +
"$mapped_type> > >")
"$mapped_type>>>")
else:
tmpl = string.Template(
"$container< $key_type, $mapped_type, "
"$container<$key_type, $mapped_type, "
"$hash<$key_type >, " +
"$equal_to<$key_type>, "
"$allocator< $mapped_type> >")
"$allocator<$mapped_type>>")
if key_type.startswith('const ') or \
key_type.endswith(' const'):
# TODO: this template is the same than above.
# Make sure why this was needed and if this is
# tested. There may be a const missing somewhere.
tmpl = string.Template(
"$container< $key_type, $mapped_type, " +
"$hash<$key_type >, " +
"$container<$key_type, $mapped_type, " +
"$hash<$key_type>, " +
"$equal_to<$key_type>, " +
"$allocator< $mapped_type > >")
"$allocator<$mapped_type>>")
else:
return

Expand Down Expand Up @@ -524,6 +516,7 @@ def remove_defaults(self, type_or_string):
name = type_or_string
if not isinstance(type_or_string, str):
name = self.class_declaration(type_or_string).name
name = defaults_eraser.replace_basic_string(name)
if not self.remove_defaults_impl:
return name
no_defaults = self.remove_defaults_impl(name)
Expand Down Expand Up @@ -647,14 +640,14 @@ def remove_defaults(self, type_or_string):

unordered_set_traits = container_traits_impl_t(
'unordered_set',
1,
0,
'value_type',
'erase_hash_allocator',
unordered_maps_and_sets=True)

unordered_multiset_traits = container_traits_impl_t(
'unordered_multiset',
1,
0,
'value_type',
'erase_hash_allocator',
unordered_maps_and_sets=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from . import algorithms_cache
from . import byte_info
from . import elaborated_info


class type_t(byte_info.byte_info):
Expand Down Expand Up @@ -593,10 +594,10 @@ def __init__(self, base):
compound_t.__init__(self, base)

def build_decl_string(self, with_defaults=True):
if hasattr(self.base.declaration, "elaborated_type_specifier"):
prefix = ""
if isinstance(self.base, type(declarated_t)) and \
isinstance(self.base.declaration, type(elaborated_info)):
prefix = self.base.declaration.elaborated_type_specifier + " "
else:
prefix = ""
return prefix + self.base.build_decl_string(with_defaults)

def _clone_impl(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def join(self, name, args, arg_separator=None):
args = [_f for _f in args if _f]

if not args:
args_str = ' '
args_str = ''
elif len(args) == 1:
args_str = ' ' + args[0] + ' '
args_str = args[0]
else:
args_str = ' ' + arg_separator.join(args) + ' '
args_str = arg_separator.join(args)

return ''.join([name, self.__begin, args_str, self.__end])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,40 @@ def find_value_type(global_ns, value_type_str):
name=value_type_str,
function=lambda decl: not isinstance(decl, calldef.calldef_t),
allow_empty=True)
if not found:
no_global_ns_value_type_str = value_type_str[2:]
if no_global_ns_value_type_str in cpptypes.FUNDAMENTAL_TYPES:
return cpptypes.FUNDAMENTAL_TYPES[no_global_ns_value_type_str]
elif type_traits.is_std_string(value_type_str):
string_ = global_ns.typedef('::std::string')
return type_traits.remove_declarated(string_)
elif type_traits.is_std_wstring(value_type_str):
string_ = global_ns.typedef('::std::wstring')
return type_traits.remove_declarated(string_)

if len(found) == 1:
return found[0]

no_global_ns_value_type_str = value_type_str[2:]
if no_global_ns_value_type_str in cpptypes.FUNDAMENTAL_TYPES:
return cpptypes.FUNDAMENTAL_TYPES[no_global_ns_value_type_str]
elif type_traits.is_std_string(value_type_str):
string_ = global_ns.typedef('::std::string')
return type_traits.remove_declarated(string_)
elif type_traits.is_std_wstring(value_type_str):
string_ = global_ns.typedef('::std::wstring')
return type_traits.remove_declarated(string_)
else:
value_type_str = no_global_ns_value_type_str
has_const = value_type_str.startswith('const ')
if has_const:
value_type_str = value_type_str[len('const '):]
has_pointer = value_type_str.endswith('*')
if has_pointer:
value_type_str = value_type_str[:-1]
found = None
if has_const or has_pointer:
found = impl_details.find_value_type(
global_ns,
value_type_str)
if not found:
return None
else:
value_type_str = no_global_ns_value_type_str
has_const = value_type_str.startswith('const ')
if isinstance(found, class_declaration.class_types):
return cpptypes.declarated_t(found)
if has_const:
value_type_str = value_type_str[len('const '):]
has_pointer = value_type_str.endswith('*')
return cpptypes.const_t(found)
if has_pointer:
value_type_str = value_type_str[:-1]
found = None
if has_const or has_pointer:
found = impl_details.find_value_type(
global_ns,
value_type_str)
if not found:
return None
else:
if isinstance(found, class_declaration.class_types):
return cpptypes.declarated_t(found)
if has_const:
return cpptypes.const_t(found)
if has_pointer:
return cpptypes.pointer_t(found)
if len(found) == 1:
return found[0]
return cpptypes.pointer_t(found)

return None
Loading