def _generate_constructor(self): result = [] result.append( '(' ) result.append( ' "%s"' % self.alias ) if self.documentation: result.append( ', %s' % self.documentation ) used_init = None inits = filter( lambda x: isinstance( x, calldef.constructor_t ), self.creators ) if ( self.declaration.is_abstract \ or not declarations.has_any_non_copyconstructor(self.declaration) ) \ and not self.wrapper \ or ( declarations.has_destructor( self.declaration ) and not declarations.has_public_destructor( self.declaration ) ): #TODO: or self.declaration has public constructor and destructor result.append( ", " ) result.append( algorithm.create_identifier( self, '::boost::python::no_init' ) ) elif not declarations.has_trivial_constructor( self.declaration ): if inits: used_init = inits[0] result.append( ", " ) result.append( used_init.create_init_code() ) elif self.declaration.indexing_suite: pass #in this case all constructors are exposed by indexing suite else:#it is possible to class to have public accessed constructor #that could not be exported by boost.python library #for example constructor takes as argument pointer to function result.append( ", " ) result.append( algorithm.create_identifier( self, '::boost::python::no_init' ) ) else: pass result.append( ' )' ) return ( ''.join( result ), used_init )
def _generate_constructor(self): result = [] result.append('(') result.append(' "%s"' % self.alias) if self.documentation: result.append(', %s' % self.documentation) used_init = None inits = filter(lambda x: isinstance(x, calldef.constructor_t), self.creators) if ( self.declaration.is_abstract \ or not declarations.has_any_non_copyconstructor(self.declaration) ) \ and not self.wrapper \ or ( declarations.has_destructor( self.declaration ) and not declarations.has_public_destructor( self.declaration ) ): #TODO: or self.declaration has public constructor and destructor result.append(", ") result.append( algorithm.create_identifier(self, '::boost::python::no_init')) elif not declarations.has_trivial_constructor(self.declaration): if inits: used_init = inits[0] result.append(", ") result.append(used_init.create_init_code()) elif self.declaration.indexing_suite: pass #in this case all constructors are exposed by indexing suite else: #it is possible to class to have public accessed constructor #that could not be exported by boost.python library #for example constructor takes as argument pointer to function result.append(", ") result.append( algorithm.create_identifier(self, '::boost::python::no_init')) else: pass result.append(' )') return (''.join(result), used_init)
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