def __test_type_transformation(self, ns_name, transformer): ns_control = declarations.find_declaration( self.declarations, decl_type=declarations.namespace_t, name=ns_name) self.assertTrue(ns_control, "unable to find '%s' namespace" % ns_name) ns_before = declarations.find_declaration( ns_control, decl_type=declarations.namespace_t, name='before') self.assertTrue(ns_before, "unable to find 'before' namespace") ns_after = declarations.find_declaration( ns_control, decl_type=declarations.namespace_t, name='after') self.assertTrue(ns_after, "unable to find 'after' namespace") for tbefore in ns_before.declarations: tafter = declarations.find_declaration(ns_after, name=tbefore.name) self.assertTrue( tafter, "unable to find transformed type definition for type '%s'" % tbefore.decl_string) transformed = transformer(tbefore) self.assertTrue( declarations.is_same(transformed, tafter), ("there is a difference between expected type '{0}' " + "and result '{1}'. typedef name: {2}").format( declarations.remove_declarated(tafter).decl_string, declarations.remove_declarated(transformed).decl_string, tbefore.decl_string))
def __test_type_transformation(self, ns_name, transformer): ns_control = declarations.find_declaration( self.declarations, decl_type=declarations.namespace_t, name=ns_name) self.assertTrue(ns_control, "unable to find '%s' namespace" % ns_name) ns_before = declarations.find_declaration( ns_control, decl_type=declarations.namespace_t, name='before') self.assertTrue(ns_before, "unable to find 'before' namespace") ns_after = declarations.find_declaration( ns_control, decl_type=declarations.namespace_t, name='after') self.assertTrue(ns_after, "unable to find 'after' namespace") for tbefore in ns_before.declarations: tafter = declarations.find_declaration( ns_after, name=tbefore.name) self.assertTrue( tafter, "unable to find transformed type definition for type '%s'" % tbefore.decl_string) transformed = transformer(tbefore) self.assertTrue( declarations.is_same( transformed, tafter), ("there is a difference between expected type '{0}' " + "and result '{1}'. typedef name: {2}").format( declarations.remove_declarated(tafter).decl_string, declarations.remove_declarated(transformed).decl_string, tbefore.decl_string))
def customize(self, generator): items = generator.global_ns.typedef( 'items_t' ) items = declarations.remove_declarated( items.type ) items.alias = "items_t" fvector = generator.global_ns.typedef( 'fvector' ) fvector = declarations.remove_declarated( fvector.type ) fvector.indexing_suite.disable_method( 'extend' ) fvector.indexing_suite.disable_methods_group( 'reorder' ) #fvector.indexing_suite.call_policies = module_builder.call_policies.default_call_policies() items_ptr = generator.global_ns.typedefs( 'items_ptr_t' )[0] items_ptr = declarations.remove_declarated( items_ptr.type ) self.failUnless( items_ptr.indexing_suite.call_policies.__class__ is module_builder.call_policies.return_internal_reference().__class__ )
def customize(self, generator): items = generator.global_ns.typedef('items_t') items = declarations.remove_declarated(items.type) items.alias = "items_t" fvector = generator.global_ns.typedef('fvector') fvector = declarations.remove_declarated(fvector.type) fvector.indexing_suite.disable_method('extend') fvector.indexing_suite.disable_methods_group('reorder') #fvector.indexing_suite.call_policies = module_builder.call_policies.default_call_policies() items_ptr = generator.global_ns.typedefs('items_ptr_t')[0] items_ptr = declarations.remove_declarated(items_ptr.type) self.failUnless( items_ptr.indexing_suite.call_policies.__class__ is module_builder.call_policies.return_internal_reference().__class__)
def _update_containers_db( self, type_ ): #will return True is type was treated type_ = declarations.remove_alias( type_ ) type_ = declarations.remove_pointer( type_ ) type_ = declarations.remove_reference( type_ ) type_ = declarations.remove_cv( type_ ) type_ = declarations.remove_declarated( type_ ) class_traits = declarations.class_traits class_declaration_traits = declarations.class_declaration_traits if not class_traits.is_my_case( type_ ) and not class_declaration_traits.is_my_case( type_ ): return False if class_traits.is_my_case( type_ ): container_cls = class_traits.get_declaration( type_ ) else: container_cls = class_declaration_traits.get_declaration( type_ ) if None is container_cls.indexing_suite: return False try: #check extraction of element type from container container_cls.indexing_suite.element_type except RuntimeError: decls_logger = _logging_.loggers.declarations if not messages.filter_disabled_msgs([messages.W1042], container_cls.disabled_messages ): return #user disabled property warning decls_logger.warn( "%s;%s" % ( container_cls, messages.W1042 ) ) self.__containers.add( container_cls ) return True
def _update_containers_db(self, type_): #will return True is type was treated type_ = declarations.remove_alias(type_) type_ = declarations.remove_pointer(type_) type_ = declarations.remove_reference(type_) type_ = declarations.remove_cv(type_) type_ = declarations.remove_declarated(type_) class_traits = declarations.class_traits class_declaration_traits = declarations.class_declaration_traits if not class_traits.is_my_case( type_) and not class_declaration_traits.is_my_case(type_): return False if class_traits.is_my_case(type_): container_cls = class_traits.get_declaration(type_) else: container_cls = class_declaration_traits.get_declaration(type_) if None is container_cls.indexing_suite: return False try: #check extraction of element type from container container_cls.indexing_suite.element_type except RuntimeError: decls_logger = _logging_.loggers.declarations if not messages.filter_disabled_msgs( [messages.W1042], container_cls.disabled_messaged): return #user disabled property warning decls_logger.warn("%s;%s" % (container_cls, messages.W1042)) self.__containers.add(container_cls) return True
def __cmp_traits( self, typedef, expected, partial_name, key_type=None): if isinstance( typedef, str ): typedef = self.global_ns.typedef( typedef ) traits = declarations.find_container_traits( typedef ) self.failUnless( traits, 'container traits for "%s" not found' % str( typedef ) ) self.failUnless( traits is expected , 'container "%s", expected %s_traits, got %s_traits' % ( str(typedef), expected.name(), traits.name() ) ) cls = declarations.remove_declarated( typedef ) self.failUnless( cls.container_traits is expected ) self.failUnless( cls.partial_name == partial_name ) cls = traits.class_declaration( cls ) self.failUnless( traits.element_type( typedef ) ) self.failUnless( cls.cache.container_element_type, "For some reason cache was not updated" ) if key_type: self.failUnless( traits.is_mapping( typedef ) ) real_key_type = traits.key_type( typedef ) self.failUnless( real_key_type.decl_string == key_type , 'Error extracting key type. Expected type "%s", got "%s"' % ( key_type, real_key_type.decl_string ) ) self.failUnless( cls.cache.container_key_type, "For some reason cache was not updated" ) else: self.failUnless( traits.is_sequence( typedef ) )
def __cmp_traits(self, typedef, expected, partial_name, key_type=None): if utils.is_str(typedef): typedef = self.global_ns.typedef(typedef) traits = declarations.find_container_traits(typedef) self.assertTrue(traits, 'container traits for "%s" not found' % str(typedef)) self.assertTrue( traits is expected, 'container "%s", expected %s_traits, got %s_traits' % (str(typedef), expected.name(), traits.name())) cls = declarations.remove_declarated(typedef) self.assertTrue(declarations.find_container_traits(cls) is expected) self.assertTrue(cls.partial_name == partial_name) cls = traits.class_declaration(cls) self.assertTrue(traits.element_type(typedef)) self.assertTrue(cls.cache.container_element_type, "For some reason cache was not updated") if key_type: self.assertTrue(traits.is_mapping(typedef)) real_key_type = traits.key_type(typedef) self.assertTrue( real_key_type.decl_string == key_type, 'Error extracting key type. Expected type "%s", got "%s"' % (key_type, real_key_type.decl_string)) self.assertTrue(cls.cache.container_key_type, "For some reason cache was not updated") else: self.assertTrue(traits.is_sequence(typedef))
def customize( self, mb ): mb.global_ns.exclude() nm_t = declarations.remove_declarated( mb.global_ns.typedef( 'naive_matrix_t' ).type ) nm_t.include() exposed_db = utils.exposed_decls_db_t() exposed_db.register_decls( mb.global_ns, [] ) exposed_db.save( autoconfig.build_dir ) mb.register_module_dependency( autoconfig.build_dir ) sm = mb.global_ns.namespace( name='split_module' ) sm.include() sm.class_( 'op_struct' ).exclude() mb.free_function( 'check_overload' ).add_declaration_code( '//hello check_overload' ) mb.free_function( 'get_opaque' ).add_declaration_code( '//hello get_opaque' ) mb.calldefs( 'check_overload' ).use_overload_macro = True mb.calldefs( 'get_opaque' ).call_policies \ = call_policies.return_value_policy( call_policies.return_opaque_pointer ) mb.class_( 'op_struct' ).exclude() item = mb.class_( 'item_t' ) item.add_declaration_code( '//hello world' ) nested = item.class_( 'nested_t' ) nested.add_declaration_code( '//hello nested decl' ) nested.add_registration_code( '//hello nested reg', False ) mb.free_fun( 'create_empty_mapping' ).include()
def str_from_ostream(ns): """ Finds all free operators, then exposes only the ones with classes currently exposed then Py++ can do the rest. """ for oper in ns.free_operators('<<'): rtype = declarations.remove_declarated( declarations.remove_reference(oper.return_type)) type_or_decl = declarations.remove_declarated( declarations.remove_const( declarations.remove_reference(oper.arguments[1].type))) if not isinstance(type_or_decl, declarations.declaration_t): continue if type_or_decl.ignore == False: decl_logger.info("Exposing operator<<: " + str(oper)) oper.include()
def __configure_sealed(self, controller): w_arg = controller.find_wrapper_arg(self.arg.name) naked_type = declarations.remove_pointer(self.arg.type) naked_type = declarations.remove_declarated(naked_type) w_arg.type = declarations.dummy_type_t('std::auto_ptr< %s >' % naked_type.decl_string) controller.modify_arg_expression(self.arg_index, w_arg.name + '.release()')
def test( self ): buggy = self.global_ns.mem_fun( 'buggy' ) ExpressionError = self.global_ns.class_( 'ExpressionError' ) self.failUnless( len( buggy.exceptions ) == 1 ) err = buggy.exceptions[0] self.failUnless( declarations.is_reference( err ) ) err = declarations.remove_declarated( declarations.remove_reference( err ) ) self.failUnless( err is ExpressionError )
def str_from_ostream(ns): """ Finds all free operators, then exposes only the ones with classes currently exposed then Py++ can do the rest. """ for oper in ns.free_operators( '<<' ): rtype = declarations.remove_declarated( declarations.remove_reference( oper.return_type ) ) type_or_decl = declarations.remove_declarated( declarations.remove_const( declarations.remove_reference( oper.arguments[1].type))) if not isinstance( type_or_decl, declarations.declaration_t ): continue if type_or_decl.ignore == False: decl_logger.info("Exposing operator<<: " + str(oper)) oper.include()
def test(self): buggy = self.global_ns.member_function('buggy') expression_error = self.global_ns.class_('ExpressionError') self.assertTrue(len(buggy.exceptions) == 1) err = buggy.exceptions[0] self.assertTrue(declarations.is_reference(err)) err = declarations.remove_declarated( declarations.remove_reference(err)) self.assertTrue(err is expression_error)
def customize( self, mb ): mb.global_ns.exclude() mb.namespace( 'samples' ).include() do_smth = mb.free_fun( 'do_smth' ) v = declarations.remove_declarated( do_smth.return_type ) v.indexing_suite.disable_method( 'sort' ) v.indexing_suite.disable_method( 'count' ) v.indexing_suite.disable_method( 'index' ) v.indexing_suite.disable_method( 'contains' )
def test(self): buggy = self.global_ns.mem_fun('buggy') expression_error = self.global_ns.class_('ExpressionError') self.assertTrue(len(buggy.exceptions) == 1) err = buggy.exceptions[0] self.assertTrue(declarations.is_reference(err)) err = declarations.remove_declarated( declarations.remove_reference(err)) self.assertTrue(err is expression_error)
def customize(self, mb): mb.global_ns.exclude() mb.namespace('samples').include() do_smth = mb.free_fun('do_smth') v = declarations.remove_declarated(do_smth.return_type) v.indexing_suite.disable_method('sort') v.indexing_suite.disable_method('count') v.indexing_suite.disable_method('index') v.indexing_suite.disable_method('contains')
def __cmp_traits( self, typedef, expected, partial_name ): if isinstance( typedef, str ): typedef = self.global_ns.typedef( typedef ) traits = declarations.find_container_traits( typedef ) self.failUnless( traits, 'container traits for "%s" not found' % str( typedef ) ) self.failUnless( traits is expected , 'container "%s", expected %s, got %s' % ( str(typedef), expected.__name__, traits.__name__ ) ) cls = declarations.remove_declarated( typedef ) self.failUnless( cls.container_traits is expected ) self.failUnless( cls.partial_name == partial_name )
def __has_unexposed_dependency(self, exported_ids, depend_on_decl, dependency): sptr_traits = declarations.smart_pointer_traits if None is depend_on_decl: return if self.__is_std_decl(depend_on_decl): return if sptr_traits.is_smart_pointer(depend_on_decl): try: value_type = sptr_traits.value_type(depend_on_decl) if isinstance(value_type, declarations.type_t): value_type = declarations.remove_cv(value_type) value_type = declarations.remove_declarated(value_type) if isinstance(value_type, declarations.declaration_t): return self.__has_unexposed_dependency( exported_ids, value_type, dependency) except RuntimeError: pass if isinstance(depend_on_decl, decl_wrappers.decl_wrapper_t): if depend_on_decl.already_exposed: return if isinstance(depend_on_decl, declarations.class_types): if depend_on_decl.opaque: return if dependency.hint == "base class": return #base class for some class don't have to be exported if isinstance(depend_on_decl, declarations.variable_t): if not decl.expose_value: return if isinstance(dependency.decl, declarations.variable_t): #the only dependency of the variable is its type if not dependency.decl.expose_value: return if dependency.hint == "return type": #in this case we don't check, the return type but the function if isinstance(dependency.decl, declarations.calldef_t): if dependency.decl.return_type and dependency.decl.call_policies \ and decl_wrappers.is_return_opaque_pointer_policy( dependency.decl.call_policies ): return return id(depend_on_decl) not in exported_ids
def generate(module_builder, local_ns, global_ns): """ global_ns: is the module builder for the entire library local_ns: is the namespace that coresponds to the given namespace """ local_ns.include() # Free function which deals with a std::vector<boost::shared_ptr<T> > f = local_ns.free_fun( 'funcVectorShared' ) AList = declarations.remove_declarated(f.return_type) wrap.fix_shared_ptr_vector(AList) AList.alias = 'AList' # CodeInject Class CodeInject = local_ns.class_('CodeInject') # Return type only function CodeInject.add_declaration_code(""" int injectedFunc( samples::CodeInject& code ){ return code.getValue(); } """); CodeInject.add_registration_code( 'def( "injectedFunc", &::injectedFunc )', works_on_instance = True) # Return and set type function CodeInject.add_declaration_code(""" int otherInjectedFunc(samples::CodeInject& code, int value) { return code.setValue(value); } """); CodeInject.add_registration_code( 'def("otherInjectedFunc", (int (*)(samples::CodeInject&, int))(&::otherInjectedFunc))', works_on_instance = True) # This does not work, because its append with a ".bp..." # if it wasn't this would work perfectly #CodeInject.add_registration_code( # 'bp::implicitly_convertible< int, samples::CodeInject >()') wrap.add_needed_includes([CodeInject]) wrap.set_implicit_conversions([CodeInject], False) return ['include/SharedPtrVector.h']
def __has_unexposed_dependency( self, exported_ids, depend_on_decl, dependency ): sptr_traits = declarations.smart_pointer_traits if None is depend_on_decl: return if self.__is_std_decl( depend_on_decl ): return if sptr_traits.is_smart_pointer( depend_on_decl ): try: value_type = sptr_traits.value_type( depend_on_decl ) if isinstance( value_type, declarations.type_t ): value_type = declarations.remove_cv( value_type ) value_type = declarations.remove_declarated( value_type ) if isinstance( value_type, declarations.declaration_t ): return self.__has_unexposed_dependency( exported_ids, value_type, dependency ) except RuntimeError: pass if isinstance( depend_on_decl, decl_wrappers.decl_wrapper_t ): if depend_on_decl.already_exposed: return if isinstance( depend_on_decl, declarations.class_types ): if depend_on_decl.opaque: return if dependency.hint == "base class": return #base class for some class don't have to be exported if isinstance( depend_on_decl, declarations.variable_t ): if not depend_on_decl.expose_value: return if isinstance( dependency.declaration, declarations.variable_t ): #the only dependency of the variable is its type if not dependency.declaration.expose_value: return if dependency.hint == "return type": #in this case we don't check, the return type but the function if isinstance( dependency.declaration, declarations.calldef_t ): if dependency.declaration.return_type and dependency.declaration.call_policies \ and decl_wrappers.is_return_opaque_pointer_policy( dependency.declaration.call_policies ): return return id( depend_on_decl ) not in exported_ids
def generate(module_builder, local_ns, global_ns): """ global_ns: is the module builder for the entire library local_ns: is the namespace that coresponds to the given namespace """ local_ns.include() # Free function which deals with a std::vector<boost::shared_ptr<T> > f = local_ns.free_fun('funcVectorShared') AList = declarations.remove_declarated(f.return_type) wrap.fix_shared_ptr_vector(AList) AList.alias = 'AList' # CodeInject Class CodeInject = local_ns.class_('CodeInject') # Return type only function CodeInject.add_declaration_code(""" int injectedFunc( samples::CodeInject& code ){ return code.getValue(); } """) CodeInject.add_registration_code('def( "injectedFunc", &::injectedFunc )', works_on_instance=True) # Return and set type function CodeInject.add_declaration_code(""" int otherInjectedFunc(samples::CodeInject& code, int value) { return code.setValue(value); } """) CodeInject.add_registration_code( 'def("otherInjectedFunc", (int (*)(samples::CodeInject&, int))(&::otherInjectedFunc))', works_on_instance=True) # This does not work, because its append with a ".bp..." # if it wasn't this would work perfectly #CodeInject.add_registration_code( # 'bp::implicitly_convertible< int, samples::CodeInject >()') wrap.add_needed_includes([CodeInject]) wrap.set_implicit_conversions([CodeInject], False) return ['include/SharedPtrVector.h']
def check_args_exportable ( function, ns ): """ Look at each argument in the function and determine that we have exported it or it's a special. """ ret = True Specials = ['::Ogre::String'] for a in function.arguments: rawarg = declarations.remove_declarated( declarations.remove_const( declarations.remove_reference( declarations.remove_pointer ( a.type )))) ## now check if the arg is a fundemental type (int float etc), a void ## or a special .. if declarations.is_arithmetic (rawarg)\ or declarations.is_void(rawarg)\ or declarations.is_enum(rawarg): pass elif 'Ogre::' in a.type.decl_string: # assume it's a class and needs checking name = a.type.decl_string.split()[0] # let's grab the actual class name if name in Specials: # we know that the classes in specials DO exist pass else: try: tcls = ns.class_(name) if not tcls.exportable or tcls.ignore or type ( tcls.parent ) != decl_wrappers.namespace_wrapper.namespace_t: ## print "check_args_exportable: NOT EXPORTABLE:", tcls, tcls.exportable, tcls.ignore , type ( tcls.parent ) ret = False break else: pass # print name, "IS exportable" except: print "check_args_exportable: unable to find:", name ret = False else: print "check_args_exportable: NOT SURE...", a, a.type, type(a.type) return ret
def ManualFixes ( mb ): global_ns = mb.global_ns main_ns = global_ns funcs = [ '::ssgBranch::getByName' ,'::ssgBranch::getByPath' ,'::ssgEntity::getByName' ,'::ssgEntity::getByPath' ] # for f in funcs: # main_ns.member_functions(f).call_policies = call_policies.default_call_policies() # bug in Py++ where is uses the wrong call policies on a transformed function for fun in main_ns.member_functions(allow_empty=True): if fun.transformations: if declarations.is_pointer(fun.return_type ) : rawarg = declarations.remove_declarated( declarations.remove_const( declarations.remove_reference( declarations.remove_pointer ( fun.return_type )))) if not declarations.is_arithmetic (rawarg) and not declarations.is_void(rawarg): fun.call_policies = call_policies.default_call_policies() print "Changed call policies on ", fun
def test_element_type(self): do_nothing = self.global_ns.free_fun('do_nothing') v = declarations.remove_reference( declarations.remove_declarated(do_nothing.arguments[0].decl_type)) declarations.vector_traits.element_type(v)
def __configure_sealed( self, controller ): w_arg = controller.find_wrapper_arg( self.arg.name ) naked_type = declarations.remove_pointer( self.arg.type ) naked_type = declarations.remove_declarated( naked_type ) w_arg.type = declarations.dummy_type_t( 'std::auto_ptr< %s >' % naked_type.decl_string ) controller.modify_arg_expression(self.arg_index, w_arg.name + '.release()' )
def get_pointee( self, sp_instantiation ): #sp_instantiation - reference to SharedPtr<XXX> #returns reference to XXX type/declaration no_ptr = declarations.remove_pointer( sp_instantiation.variable ('pRep').type ) no_alias = declarations.remove_alias( no_ptr ) return declarations.remove_declarated( no_alias )
def customize(self, generator): fvector = generator.global_ns.typedef('foo_vector') fvector = declarations.remove_declarated(fvector.type) fvector.indexing_suite.call_policies \ = module_builder.call_policies.return_internal_reference()
def Auto_Functional_Transformation ( mb, ignore_funs=[], special_vars=[]): toprocess = [] aliases={} for fun in mb.member_functions(allow_empty=True): toprocess.append( fun ) for fun in mb.free_functions(allow_empty=True): toprocess.append( fun ) for fun in toprocess: fun_demangled = fun.demangled # need to check as extern functions don't have demangled name... if fun_demangled: # try: # ugly wrapping in a try :( fullname = fun.demangled.split('(')[0] if fullname not in ignore_funs and not fun.ignore: outputonly = False arg_position = 0 trans=[] desc="" ft_type = None ctypes_conversion = False for arg in fun.arguments: rawarg = declarations.remove_declarated( declarations.remove_const( declarations.remove_reference( declarations.remove_pointer ( arg.type )))) ## now check if the arg is a fundemental type (int float etc), a void ## or a special .. if declarations.is_arithmetic (rawarg)\ or declarations.is_void(rawarg)\ or arg.type.decl_string in special_vars: if declarations.is_pointer(arg.type): #we convert any pointers to unsigned int's # now look to see if it's a char * and if so we treat it as a string.. # # print "**" , declarations.remove_alias( rawarg ), declarations.type_traits.create_cv_types( declarations.cpptypes.char_t()) if declarations.remove_alias( rawarg ) in declarations.type_traits.create_cv_types( declarations.cpptypes.char_t() ): print ("MATCHED CString", fun) trans.append( ft.input_c_string(arg_position, 4096 ) ) desc = desc +"Argument: "+arg.name+ "( pos:" + str(arg_position) + " - " +\ arg.type.decl_string + " ) takes a python string. \\n" ctypes_conversion = True ctypes_arg = arg.type.decl_string.split()[0] ft_type = 'CTYPES' else: trans.append( ft.modify_type(arg_position,_ReturnUnsignedInt ) ) desc = desc +"Argument: "+arg.name+ "( pos:" + str(arg_position) + " - " +\ arg.type.decl_string + " ) takes a CTypes.addressof(xx). \\n" ctypes_conversion = True ctypes_arg = arg.type.decl_string.split()[0] ft_type = 'CTYPES' elif declarations.is_reference(arg.type)and not declarations.is_const(declarations.remove_reference( arg.type)): # seen functions passing const ref's trans.append( ft.inout(arg_position ) ) desc = desc + "Argument: "+arg.name+ "( pos:" + str(arg_position) + " - " +\ arg.type.decl_string + " ) converted to an input/output (change to return types).\\n" ft_type = 'INOUT' elif declarations.is_reference(arg.type): print ("Warning: - possible code change.", fun,arg," not wrapped as const reference to base type invalid") else: pass # it isn't a pointer or reference so doesn't need wrapping else: pass # it's not a var we need to handle arg_position += 1 if trans: const_return = False # declarations.is_const(fun) if fun.decl_string.endswith('const'): const_return=True simple_return = declarations.is_arithmetic(fun.return_type) or declarations.is_void(fun.return_type) nonpublic_destructor = declarations.is_class(fun.parent) and declarations.has_destructor(fun.parent) and\ not declarations.has_public_destructor(fun.parent) if fun.documentation or fun.transformations: # it's already be tweaked: print ("AUTOFT ERROR: Duplicate Tranforms.", fun, fun.documentation) # if the class has a protected destruction AND the return value is const or a non arithmatic value then exclude it. elif nonpublic_destructor and const_return: print ("AUTOFT ERROR Const: Parent has non public destructor and const return.", fun.parent.name, fun.return_type.decl_string, fun) fun.documentation="Python-Ogre Warning: function required transformation - not possible due to non public destructor and const return value.." elif nonpublic_destructor and not simple_return: print ("AUTOFT ERROR Const: Parent has non public destructor and complex return value.", fun.parent.name, fun.return_type.decl_string, fun) fun.documentation="Python-Ogre Warning: function required transformation - not possible due to non public destructor and complex return value.." else: new_alias = fun.name if ctypes_conversion: # only manage name changes if ctypes changing # now lets look for a duplicate function name with the same number arguments f= [None]*len(fun.arguments) s = mb.member_functions("::" + fullname, arg_types=f, allow_empty=True) if len (s) > 1: # there are duplicate names so need to create something unique ctypes_arg = ctypes_arg.replace("::", "_") # to clean up function names... new_alias = fun.name + ctypes_arg[0].upper() + ctypes_arg[1:] # now for REAL ugly code -- we have faked a new alias and it may not be unique # so we track previous alias + class name to ensure unique names are generated keyname = fullname + new_alias # we use the full class + function name + alias as the key if keyname in aliases: # already exists, need to fake another version.. new_alias = new_alias + "_" + str( aliases[keyname] ) aliases[keyname] = aliases[keyname] + 1 else: aliases[keyname] = 1 desc = desc + "\\\nWARNING FUNCTION NAME CHANGE - from "+fun.name + " -- " + fun.decl_string +" to " + new_alias + " \\n" print ("INFO: Adjusting Alias as multiple overlapping functions:", new_alias) print ("AUTOFT OK: Tranformed ", fun.return_type.decl_string, fun, "(",new_alias,")") fun.add_transformation ( * trans , **{"alias":new_alias} ) fun.documentation = docit ("Auto Modified Arguments:", desc, "...")
def test_element_type(self): do_nothing = self.global_ns.free_fun('do_nothing') v = declarations.remove_reference( declarations.remove_declarated( do_nothing.arguments[0].type)) declarations.vector_traits.element_type(v)
def customize(self, generator): fvector = generator.global_ns.typedef( 'foo_vector' ) fvector = declarations.remove_declarated( fvector.type ) fvector.indexing_suite.call_policies \ = module_builder.call_policies.return_internal_reference()