Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visit_class(self):
self.__link_members()
# GCC-XML sometimes generates constructors with names that does not
# match class name. I think this is because those constructors are
# compiler generated. I need to find out more about this and to talk
# with Brad
new_name = self.__inst._name
if declarations.templates.is_instantiation(new_name):
new_name = declarations.templates.name(new_name)
for decl in self.__inst.declarations:
if not isinstance(decl, declarations.constructor_t):
continue
if '.' in decl._name or '$' in decl._name:
decl._name = new_name
bases = self.__inst.bases.split()
self.__inst.bases = []
for base in bases:
# it could be "_5" or "protected:_5"
data = base.split(':')
base_decl = self.__decls[data[-1]]
access = declarations.ACCESS_TYPES.PUBLIC
if len(data) == 2:
if self.__opt_is_tmpl_inst:
if not self.__opt_is_full_name:
if self.name != templates.normalize_name(decl) \
and self.name != templates.normalize_partial_name(decl):
return False
else:
if self.name != templates.normalize_full_name_true(decl) and \
self.name != templates.normalize_full_name_false(decl):
return False
else:
if not self.__opt_is_full_name:
if self.name != decl.name and self.name != decl.partial_name:
return False
else:
if self.name != templates.normalize_full_name_true(decl) and \
self.name != templates.normalize_full_name_false(decl):
return False
return True
## cause needless changes, since the generated python files are
## kept under version control.
#global_annotations['pygen_comment'] = "%s:%i: %s" % \
# (ns3_header, pygccxml_definition.location.line, pygccxml_definition)
global_annotations['pygen_comment'] = "%s (module %r): %s" % \
(ns3_header, definition_module, pygccxml_definition)
## handle ns3::Object::GetObject (left to its own devices,
## pybindgen will generate a mangled name containing the template
## argument type name).
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Object' \
and pygccxml_definition.name == 'GetObject':
template_args = templates.args(pygccxml_definition.demangled_name)
if template_args == ['ns3::Object']:
global_annotations['template_instance_names'] = 'ns3::Object=>GetObject'
## Don't wrap Simulator::Schedule* (manually wrapped)
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Simulator' \
and pygccxml_definition.name.startswith('Schedule'):
global_annotations['ignore'] = None
# manually wrapped
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Simulator' \
and pygccxml_definition.name == 'Run':
global_annotations['ignore'] = True
## http://www.gccxml.org/Bug/view.php?id=9915
result = []
is_mem_fun = isinstance( calldef, declarations.member_calldef_t )
if is_mem_fun and calldef.virtuality != declarations.VIRTUALITY_TYPES.NOT_VIRTUAL:
result.append( 'virtual ' )
if is_mem_fun and calldef.has_static:
result.append( 'static ' )
if calldef_type.return_type:
result.append( self.__format_type_as_undecorated( calldef.return_type, False ) )
result.append( ' ' )
if is_mem_fun:
result.append( self.__remove_leading_scope( calldef.parent.decl_string ) + '::')
result.append( calldef.name )
if isinstance( calldef, ( declarations.constructor_t, declarations.destructor_t) ) \
and declarations.templates.is_instantiation( calldef.parent.name ):
result.append( '<%s>' % ','.join( declarations.templates.args( calldef.parent.name ) ) )
result.append( '(%s)' % self.undecorate_argtypes( calldef_type.arguments_types ) )
if is_mem_fun and calldef.has_const:
result.append( 'const' )
return ''.join( result )
## cause needless changes, since the generated python files are
## kept under version control.
#global_annotations['pygen_comment'] = "%s:%i: %s" % \
# (ns3_header, pygccxml_definition.location.line, pygccxml_definition)
global_annotations['pygen_comment'] = "%s (module %r): %s" % \
(ns3_header, definition_module, pygccxml_definition)
## handle ns3::Object::GetObject (left to its own devices,
## pybindgen will generate a mangled name containing the template
## argument type name).
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Object' \
and pygccxml_definition.name == 'GetObject':
template_args = templates.args(pygccxml_definition.demangled_name)
if template_args == ['ns3::Object']:
global_annotations['template_instance_names'] = 'ns3::Object=>GetObject'
## Don't wrap Simulator::Schedule* (manually wrapped)
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Simulator' \
and pygccxml_definition.name.startswith('Schedule'):
global_annotations['ignore'] = None
# manually wrapped
if isinstance(pygccxml_definition, member_function_t) \
and pygccxml_definition.parent.name == 'Simulator' \
and pygccxml_definition.name == 'Run':
global_annotations['ignore'] = True
## http://www.gccxml.org/Bug/view.php?id=9915
def find_container_traits(cls_or_string):
"""
Find the container traits type of a declaration.
Args:
cls_or_string (str | declarations.declaration_t): a string
Returns:
declarations.container_traits: a container traits
"""
if utils.is_str(cls_or_string):
if not templates.is_instantiation(cls_or_string):
return None
name = templates.name(cls_or_string)
if name.startswith('std::'):
name = name[len('std::'):]
if name.startswith('std::tr1::'):
name = name[len('std::tr1::'):]
for cls_traits in all_container_traits:
if cls_traits.name() == name:
return cls_traits
else:
if isinstance(cls_or_string, class_declaration.class_types):
# Look in the cache.
if cls_or_string.cache.container_traits is not None:
return cls_or_string.cache.container_traits
# Look for a container traits
for cls_traits in all_container_traits:
result.append('static ')
if hint == 'msvc' and calldef_type.return_type:
# nm doesn't dump return type information
result.append(
self.__format_type_as_undecorated(
calldef.return_type, False, hint))
result.append(' ')
if is_mem_fun:
result.append(
self.__remove_leading_scope(
calldef.parent.decl_string) + '::')
result.append(calldef.name)
if isinstance(
calldef, (declarations.constructor_t, declarations.destructor_t)) \
and declarations.templates.is_instantiation(calldef.parent.name):
if hint == 'msvc':
result.append('<%s>' % ','.join(
declarations.templates.args(calldef.parent.name)))
result.append('(%s)' % self.format_argtypes(
calldef_type.arguments_types, hint))
if is_mem_fun and calldef.has_const:
if hint == 'nm':
result.append(' ')
result.append('const')
return ''.join(result)