Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
## convert the return value
try:
return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
except (TypeLookupError, TypeConfigurationError) as ex:
warnings.warn_explicit("Return value '%s' error (used in %s): %r"
% (member.type.partial_decl_string, member, ex),
WrapperWarning, member.location.file_name, member.location.line)
continue
if member.type_qualifiers.has_static:
class_wrapper.add_static_attribute(member.name, return_type,
is_const=type_traits.is_const(member.type))
else:
class_wrapper.add_instance_attribute(member.name, return_type,
is_const=type_traits.is_const(member.type))
## TODO: invoke post_scan_hooks
elif isinstance(member, calldef.destructor_t):
pass
## gccxml 0.9, unlike 0.7, does not explicitly report inheritted trivial constructors
## thankfully pygccxml comes to the rescue!
if not have_trivial_constructor:
if type_traits.has_trivial_constructor(cls):
class_wrapper.add_constructor([])
pygen_sink.writeln("cls.add_constructor([])")
if not have_copy_constructor:
try: # pygccxml > 0.9
has_copy_constructor = type_traits.has_copy_constructor(cls)
except AttributeError: # pygccxml <= 0.9
has_copy_constructor = type_traits.has_trivial_copy(cls)
continue
if member.type_qualifiers.has_static:
class_wrapper.add_static_attribute(member.name, return_type,
is_const=type_traits.is_const(member.type))
else:
class_wrapper.add_instance_attribute(member.name, return_type,
is_const=type_traits.is_const(member.type))
## TODO: invoke post_scan_hooks
elif isinstance(member, calldef.destructor_t):
pass
## gccxml 0.9, unlike 0.7, does not explicitly report inheritted trivial constructors
## thankfully pygccxml comes to the rescue!
if not have_trivial_constructor:
if type_traits.has_trivial_constructor(cls):
class_wrapper.add_constructor([])
pygen_sink.writeln("cls.add_constructor([])")
if not have_copy_constructor:
try: # pygccxml > 0.9
has_copy_constructor = type_traits.has_copy_constructor(cls)
except AttributeError: # pygccxml <= 0.9
has_copy_constructor = type_traits.has_trivial_copy(cls)
if has_copy_constructor:
class_wrapper.add_copy_constructor()
pygen_sink.writeln("cls.add_copy_constructor()")
## TODO: invoke post_scan_hooks
elif isinstance(member, calldef.destructor_t):
pass
## gccxml 0.9, unlike 0.7, does not explicitly report inheritted trivial constructors
## thankfully pygccxml comes to the rescue!
if not have_trivial_constructor:
if type_traits.has_trivial_constructor(cls):
class_wrapper.add_constructor([])
pygen_sink.writeln("cls.add_constructor([])")
if not have_copy_constructor:
try: # pygccxml > 0.9
has_copy_constructor = type_traits.has_copy_constructor(cls)
except AttributeError: # pygccxml <= 0.9
has_copy_constructor = type_traits.has_trivial_copy(cls)
if has_copy_constructor:
class_wrapper.add_copy_constructor()
pygen_sink.writeln("cls.add_copy_constructor()")
if is_exception:
pygen_sink.writeln("module.add_exception(%s)" %
", ".join([repr(cls_name)] + _pygen_kwargs(kwargs)))
else:
pygen_sink.writeln("module.add_class(%s)" %
", ".join([repr(cls_name)] + _pygen_kwargs(kwargs)))
## detect use of unregistered container types: need to look at
## all parameters and return values of all functions in this namespace...
for member in cls.get_members(access='public'):
if member.name.startswith('__'):
continue
for dependency in member.i_depend_on_them(recursive=True):
type_info = dependency.depend_on_it
if type_traits.is_pointer(type_info):
type_info = type_traits.remove_pointer(type_info)
elif type_traits.is_reference(type_info):
type_info = type_traits.remove_reference(type_info)
if type_traits.is_const(type_info):
type_info = type_traits.remove_const(type_info)
traits = container_traits.find_container_traits(type_info)
if traits is None:
continue
name = normalize_name(type_info.partial_decl_string)
# now postpone container registration until after
# all classes are registered, because we may
# depend on one of those classes for the element
# type.
self._containers_to_register.append((traits, type_info, None, name))
if is_exception:
class_wrapper = module.add_exception(cls_name, **kwargs)
def get_container_or_none(self, type_):
"""
Returns reference to the class declaration or None.
"""
type_ = type_traits.remove_alias(type_)
type_ = type_traits.remove_cv(type_)
utils.loggers.queries_engine.debug(
"Container traits: cleaned up search %s", type_)
if isinstance(type_, cpptypes.declarated_t):
cls_declaration = type_traits.remove_alias(type_.declaration)
elif isinstance(type_, class_declaration.class_t):
cls_declaration = type_
elif isinstance(type_, class_declaration.class_declaration_t):
cls_declaration = type_
else:
utils.loggers.queries_engine.debug(
"Container traits: returning None, type not known\n")
return
if not cls_declaration.name.startswith(self.name() + '<'):
"except ImportError:\n"
" pass\n"
"else:\n"
" %s.register_types(module)\n"
% (section.local_customizations_module, section.local_customizations_module))
pygen_sink.writeln("root_module.end_section(%r)" % section.name)
## detect use of unregistered container types: need to look at
## all parameters and return values of all functions in this namespace...
for fun in module_namespace.free_functions(function=self.location_filter,
allow_empty=True, recursive=False):
if fun.name.startswith('__'):
continue
for dependency in fun.i_depend_on_them(recursive=True):
type_info = dependency.depend_on_it
if type_traits.is_pointer(type_info):
type_info = type_traits.remove_pointer(type_info)
elif type_traits.is_reference(type_info):
type_info = type_traits.remove_reference(type_info)
if type_traits.is_const(type_info):
type_info = type_traits.remove_const(type_info)
traits = container_traits.find_container_traits(type_info)
if traits is None:
continue
name = normalize_name(type_info.partial_decl_string)
#print >> sys.stderr, "** type: %s; ---> partial_decl_string: %r; name: %r" %\
# (type_info, type_info.partial_decl_string, name)
self._containers_to_register.append((traits, type_info, None, name))
## scan enumerations
if outer_class is None:
enums = module_namespace.enums(function=self.location_filter,
def remove_const_from_reference(type):
"Helper to avoid compile errors with const-reference-protected-destructor argument types"
if not type_traits.is_reference(type):
return type
nonref = declarations.remove_reference(type)
if not type_traits.is_const(nonref):
return type
nonconst = declarations.remove_const(nonref)
return cpptypes.reference_t(nonconst)
def visit_array(self):
for i in range(type_traits.array_size(self.type)):
dump_type(self.instance + '[%i]' % i, type_traits.base_type(self.type))
def remove_const_from_reference(type):
"Helper to avoid compile errors with const-reference-protected-destructor argument types"
if not type_traits.is_reference(type):
return type
nonref = declarations.remove_reference(type)
if not type_traits.is_const(nonref):
return type
nonconst = declarations.remove_const(nonref)
return cpptypes.reference_t(nonconst)
def _get_partial_name_impl(self):
if type_traits.is_std_string(self):
return 'string'
if type_traits.is_std_wstring(self):
return 'wstring'
return get_partial_name(self.name)