def __find_out_class_dependencies(self, class_): full_name = declarations.full_name #class depends on it's base classes i_depend_on_them = set( [full_name(base.related_class) for base in class_.bases]) #class depends on all classes that used in function as argument # types and those arguments have default value calldefs = [ decl for decl in declarations.make_flatten(class_) if isinstance(decl, declarations.calldef_t) ] for calldef in calldefs: for arg in calldef.arguments: if declarations.is_enum(arg.type): top_class_inst = self.__get_top_class_inst( declarations.enum_declaration(arg.type)) if top_class_inst: i_depend_on_them.add(full_name(top_class_inst)) continue if not arg.default_value: continue if declarations.is_pointer( arg.type) and arg.default_value == 0: continue base_type = declarations.base_type(arg.type) if not isinstance(base_type, declarations.declarated_t): continue top_class_inst = self.__get_top_class_inst( base_type.declaration) if top_class_inst: i_depend_on_them.add(full_name(top_class_inst)) if self.__include_vars: vars = [ decl for decl in declarations.make_flatten(class_) if isinstance(decl, declarations.variable_t) ] for var in vars: if declarations.is_pointer(var.type): continue base_type = declarations.base_type(var.type) if not isinstance(base_type, declarations.declarated_t): continue top_class_inst = self.__get_top_class_inst( base_type.declaration) if top_class_inst: i_depend_on_them.add(full_name(top_class_inst)) for internal_cls in class_.classes(allow_empty=True): internal_cls_dependencies = self.__find_out_class_dependencies( internal_cls) i_depend_on_them.update(internal_cls_dependencies) i_depend_on_them = list(i_depend_on_them) i_depend_on_them.sort() return i_depend_on_them
def __fix_constructor_call(self, func, arg): call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation(dv): return False base_type = declarations.base_type(arg.type) decl = base_type.declaration name, args = call_invocation.split(dv) if decl.name != name: # we have some alias to the class relevant_typedefs = [ typedef for typedef in decl.aliases if typedef.name == name] if 1 == len(relevant_typedefs): f_q_name = self.__join_names( declarations.full_name( relevant_typedefs[0].parent), name) else: # in this case we can not say which typedef user uses: f_q_name = self.__join_names( declarations.full_name( decl.parent), decl.name) else: f_q_name = self.__join_names( declarations.full_name( decl.parent), name) return call_invocation.join(f_q_name, args)
def __find_out_class_dependencies( self, class_ ): full_name = declarations.full_name #class depends on it's base classes i_depend_on_them = set( [ full_name( base.related_class ) for base in class_.bases ] ) #class depends on all classes that used in function as argument # types and those arguments have default value calldefs = filter( lambda decl: isinstance( decl, declarations.calldef_t ) , declarations.make_flatten( class_ )) for calldef in calldefs: for arg in calldef.arguments: if declarations.is_enum( arg.type ): top_class_inst = self.__get_top_class_inst( declarations.enum_declaration( arg.type ) ) if top_class_inst: i_depend_on_them.add( full_name( top_class_inst ) ) continue if not arg.default_value: continue if declarations.is_pointer( arg.type ) and arg.default_value == 0: continue base_type = declarations.base_type( arg.type ) if not isinstance( base_type, declarations.declarated_t ): continue top_class_inst = self.__get_top_class_inst( base_type.declaration ) if top_class_inst: i_depend_on_them.add( full_name( top_class_inst ) ) for internal_cls in class_.classes(allow_empty=True): internal_cls_dependencies = self.__find_out_class_dependencies( internal_cls ) i_depend_on_them.update( internal_cls_dependencies ) i_depend_on_them = list( i_depend_on_them ) i_depend_on_them.sort() return i_depend_on_them
def find_out_depend_on_declaration( self ): """if declaration depends on other declaration and not on some type this function will return reference to it. Otherwise None will be returned """ #prevent recursive import from pygccxml import declarations if isinstance( self.depend_on_it, declarations.declaration_t ): return self.depend_on_it base_type = declarations.base_type( declarations.remove_alias( self.depend_on_it ) ) if isinstance( base_type, cpptypes.declarated_t ): return base_type.declaration return None
def __is_constructor_call( self, func, arg ): call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation( dv ): return False name = call_invocation.name( dv ) base_type = declarations.base_type( arg.type ) if not isinstance( base_type, declarations.declarated_t ): return False decl = base_type.declaration return decl.name == name \ or ( isinstance( decl, declarations.class_t ) \ and name in map( lambda typedef: typedef.name, decl.aliases ) )
def __is_constructor_call( self, func, arg ): #if '0.9' in func.compiler: # return False call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation( dv ): return False name = call_invocation.name( dv ) base_type = declarations.base_type( arg.type ) if not isinstance( base_type, declarations.declarated_t ): return False decl = base_type.declaration return decl.name == name \ or ( isinstance( decl, declarations.class_t ) \ and name in map( lambda typedef: typedef.name, decl.aliases ) )
def __is_constructor_call(self, func, arg): # if '0.9' in utils.xml_generator: # return False call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation(dv): return False name = call_invocation.name(dv) base_type = declarations.base_type(arg.type) if not isinstance(base_type, declarations.declarated_t): return False decl = base_type.declaration return (decl.name == name or (isinstance(decl, declarations.class_t) and name in [typedef.name for typedef in decl.aliases]))
def __is_constructor_call( self, func, arg ): #if '0.9' in func.compiler: # return False call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation( dv ): return False name = call_invocation.name( dv ) base_type = declarations.base_type( arg.type ) if not isinstance( base_type, declarations.declarated_t ): return False decl = base_type.declaration return decl.name == name \ or ( isinstance( decl, declarations.class_t ) \ and name in [typedef.name for typedef in decl.aliases] )
def _update_db( self, db, type_ ): if self._update_containers_db( type_ ): return decl_string = self._normalize( declarations.base_type( type_ ).decl_string ) if not templates.is_instantiation( decl_string ): return if not self._is_relevant( decl_string ): return insts = [inst for inst in templates.split_recursive( decl_string ) if self._is_relevant_inst( inst[0], inst[1] )] for smart_ptr, args in insts: assert len( args ) == 1 pointee = self._normalize( args[0] ) if pointee not in db: db[ pointee ] = [] smart_ptr = self._normalize( smart_ptr ) if (smart_ptr, type_) not in db[pointee]: db[ pointee ].append( (smart_ptr, type_) )
def dig_declarations( depend_on_it ): #prevent recursive import from pygccxml import declarations if isinstance( depend_on_it, declarations.declaration_t ): return [depend_on_it] base_type = declarations.base_type( declarations.remove_alias( depend_on_it ) ) if isinstance( base_type, cpptypes.declarated_t ): return [base_type.declaration] elif isinstance( base_type, cpptypes.calldef_type_t ): result = [] result.extend( impl_details.dig_declarations( base_type.return_type ) ) for argtype in base_type.arguments_types: result.extend( impl_details.dig_declarations( argtype ) ) if isinstance( base_type, cpptypes.member_function_type_t ): result.extend( impl_details.dig_declarations( base_type.class_inst ) ) return result return []
def _update_db(self, db, type_): if self._update_containers_db(type_): return decl_string = self._normalize( declarations.base_type(type_).decl_string) if not templates.is_instantiation(decl_string): return if not self._is_relevant(decl_string): return insts = filter(lambda inst: self._is_relevant_inst(inst[0], inst[1]), templates.split_recursive(decl_string)) for smart_ptr, args in insts: assert len(args) == 1 pointee = self._normalize(args[0]) if not db.has_key(pointee): db[pointee] = [] smart_ptr = self._normalize(smart_ptr) if (smart_ptr, type_) not in db[pointee]: db[pointee].append((smart_ptr, type_))
def dig_declarations(depend_on_it): # prevent recursive import from pygccxml import declarations if isinstance(depend_on_it, declarations.declaration_t): return [depend_on_it] base_type = declarations.base_type( declarations.remove_alias(depend_on_it)) if isinstance(base_type, cpptypes.declarated_t): return [base_type.declaration] elif isinstance(base_type, cpptypes.calldef_type_t): result = [] result.extend(impl_details.dig_declarations(base_type.return_type)) for argtype in base_type.arguments_types: result.extend(impl_details.dig_declarations(argtype)) if isinstance(base_type, cpptypes.member_function_type_t): result.extend( impl_details.dig_declarations(base_type.class_inst)) return result return []
def __fix_constructor_call( self, func, arg ): call_invocation = declarations.call_invocation dv = arg.default_value if not call_invocation.is_call_invocation( dv ): return False base_type = declarations.base_type( arg.type ) decl = base_type.declaration name, args = call_invocation.split( dv ) if decl.name != name: #we have some alias to the class relevant_typedefs = filter( lambda typedef: typedef.name == name , decl.aliases ) if 1 == len( relevant_typedefs ): f_q_name = self.__join_names( declarations.full_name( relevant_typedefs[0].parent ) , name ) else:#in this case we can not say which typedef user uses: f_q_name = self.__join_names( declarations.full_name( decl.parent ) , decl.name ) else: f_q_name = self.__join_names( declarations.full_name( decl.parent ), name ) return call_invocation.join( f_q_name, args )