def visit_class(self ): if self.curr_decl.indexing_suite: self.__types_db.update_containers( self.curr_decl ) return #it will be exposed later, using other code creators self.__dependencies_manager.add_exported( self.curr_decl ) cls_decl = self.curr_decl cls_parent_cc = self.curr_code_creator exportable_members = self.curr_decl.get_exportable_members(sort_algorithms.sort) wrapper = None cls_cc = None if cls_decl.introduces_new_scope: cls_cc = code_creators.class_t( class_inst=self.curr_decl ) else: cls_cc = self.curr_code_creator if self.curr_decl.is_wrapper_needed(): wrapper = code_creators.class_wrapper_t( declaration=self.curr_decl , class_creator=cls_cc ) cls_cc.wrapper = wrapper cls_cc.associated_decl_creators.append( wrapper ) #insert wrapper before module body if isinstance( self.curr_decl.parent, declarations.class_t ): #we deal with internal class self.curr_code_creator.wrapper.adopt_creator( wrapper ) else: self.__extmodule.adopt_declaration_creator( wrapper ) #next constructors are not present in code, but compiler generated #Boost.Python requiers them to be declared in the wrapper class noncopyable_vars = self.curr_decl.find_noncopyable_vars() copy_constr = self.curr_decl.find_copy_constructor() if not self.curr_decl.noncopyable and copy_constr and copy_constr.is_artificial: cccc = code_creators.copy_constructor_wrapper_t( constructor=copy_constr) wrapper.adopt_creator( cccc ) trivial_constr = self.curr_decl.find_trivial_constructor() if trivial_constr and trivial_constr.is_artificial and not noncopyable_vars: tcons = code_creators.null_constructor_wrapper_t( constructor=trivial_constr ) wrapper.adopt_creator( tcons ) exposed = self.expose_overloaded_mem_fun_using_macro( cls_decl, cls_cc ) if cls_decl.introduces_new_scope: cls_parent_cc.adopt_creator( cls_cc ) self.curr_code_creator = cls_cc if cls_decl.expose_this: cls_cc.adopt_creator( code_creators.expose_this_t( cls_decl ) ) if cls_decl.expose_sizeof: cls_cc.adopt_creator( code_creators.expose_sizeof_t( cls_decl ) ) for decl in exportable_members: if decl in exposed: continue self.curr_decl = decl declarations.apply_visitor( self, decl ) for redefined_func in cls_decl.redefined_funcs(): if isinstance( redefined_func, declarations.operator_t ): continue self.curr_decl = redefined_func declarations.apply_visitor( self, redefined_func ) #all static_methods_t should be moved to the end #better approach is to move them after last def of relevant function static_methods = [creator for creator in cls_cc.creators if isinstance( creator, code_creators.static_method_t )] for static_method in static_methods: cls_cc.remove_creator( static_method ) cls_cc.adopt_creator( static_method ) if cls_decl.exception_translation_code: translator = code_creators.exception_translator_t( cls_decl ) self.__extmodule.adopt_declaration_creator( translator ) cls_cc.associated_decl_creators.append( translator ) translator_register \ = code_creators.exception_translator_register_t( cls_decl, translator ) cls_cc.adopt_creator( translator_register ) for property_def in cls_decl.properties: cls_cc.adopt_creator( code_creators.property_t(property_def) ) if wrapper and cls_decl.destructor_code: destructor = code_creators.destructor_wrapper_t( class_=cls_decl ) wrapper.adopt_creator( destructor ) for fc in cls_decl.fake_constructors: if self.__fc_manager.should_generate_code( fc ): self.__dependencies_manager.add_exported( fc ) cls_cc.adopt_creator( code_creators.make_constructor_t( fc ) ) self.curr_decl = cls_decl self.curr_code_creator = cls_parent_cc
def visit_class(self ): self.__dependencies_manager.add_exported( self.curr_decl ) cls_decl = self.curr_decl cls_parent_cc = self.curr_code_creator exportable_members = self.curr_decl.get_exportable_members(sort_algorithms.sort) wrapper = None cls_cc = code_creators.class_t( class_inst=self.curr_decl ) if self.curr_decl.is_wrapper_needed(): wrapper = code_creators.class_wrapper_t( declaration=self.curr_decl , class_creator=cls_cc ) cls_cc.wrapper = wrapper cls_cc.associated_decl_creators.append( wrapper ) #insert wrapper before module body if isinstance( self.curr_decl.parent, declarations.class_t ): #we deal with internal class self.curr_code_creator.wrapper.adopt_creator( wrapper ) else: self.__extmodule.adopt_declaration_creator( wrapper ) #next constructors are not present in code, but compiler generated #Boost.Python requiers them to be declared in the wrapper class if '0.9' in self.curr_decl.compiler: copy_constr = self.curr_decl.find_copy_constructor() add_to_wrapper = False if declarations.has_copy_constructor( self.curr_decl ): #find out whether user or compiler defined it if self.curr_decl.noncopyable: add_to_wrapper = False elif not copy_constr: add_to_wrapper = True #compiler defined will not be exposed manually later elif copy_constr.is_artificial: add_to_wrapper = True #compiler defined will not be exposed manually later if add_to_wrapper: cccc = code_creators.copy_constructor_wrapper_t( class_=self.curr_decl) wrapper.adopt_creator( cccc ) trivial_constr = self.curr_decl.find_trivial_constructor() add_to_wrapper = False if declarations.has_trivial_constructor( self.curr_decl ): if not trivial_constr: add_to_wrapper = True elif trivial_constr.is_artificial: add_to_wrapper = True if add_to_wrapper: tcons = code_creators.null_constructor_wrapper_t( class_=self.curr_decl ) wrapper.adopt_creator( tcons ) else: if declarations.has_copy_constructor( self.curr_decl ): copy_constr = self.curr_decl.find_copy_constructor() if not self.curr_decl.noncopyable and copy_constr.is_artificial: cccc = code_creators.copy_constructor_wrapper_t( class_=self.curr_decl) wrapper.adopt_creator( cccc ) null_constr = self.curr_decl.find_trivial_constructor() if null_constr and null_constr.is_artificial: #this constructor is not going to be exposed tcons = code_creators.null_constructor_wrapper_t( class_=self.curr_decl ) wrapper.adopt_creator( tcons ) exposed = self.expose_overloaded_mem_fun_using_macro( cls_decl, cls_cc ) cls_parent_cc.adopt_creator( cls_cc ) self.curr_code_creator = cls_cc for decl in exportable_members: if decl in exposed: continue self.curr_decl = decl declarations.apply_visitor( self, decl ) for redefined_func in cls_decl.redefined_funcs(): if isinstance( redefined_func, declarations.operator_t ): continue self.curr_decl = redefined_func declarations.apply_visitor( self, redefined_func ) #all static_methods_t should be moved to the end #better approach is to move them after last def of relevant function static_methods = filter( lambda creator: isinstance( creator, code_creators.static_method_t ) , cls_cc.creators ) for static_method in static_methods: cls_cc.remove_creator( static_method ) cls_cc.adopt_creator( static_method ) if cls_decl.exception_translation_code: translator = code_creators.exception_translator_t( cls_decl ) self.__extmodule.adopt_declaration_creator( translator ) cls_cc.associated_decl_creators.append( translator ) translator_register \ = code_creators.exception_translator_register_t( cls_decl, translator ) cls_cc.adopt_creator( translator_register ) for property_def in cls_decl.properties: cls_cc.adopt_creator( code_creators.property_t(property_def) ) self.curr_decl = cls_decl self.curr_code_creator = cls_parent_cc