def keywords_args(self): if not self.__args: return '' boost_arg = self.__id_creator('::boost::python::arg') boost_obj = self.__id_creator('::boost::python::object') result = ['( '] for arg in self.__args: if 1 < len(result): result.append(self.PARAM_SEPARATOR) result.append(boost_arg) result.append('("%s")' % arg.name) if self.__decl.use_default_arguments and arg.default_value: if not declarations.is_pointer( arg.type) or arg.default_value != '0': arg_type_no_alias = declarations.remove_alias(arg.type) if declarations.is_fundamental( arg_type_no_alias ) \ and declarations.is_integral( arg_type_no_alias ) \ and not arg.default_value.startswith( arg_type_no_alias.decl_string ): result.append( '=(%s)(%s)' % (arg.type.partial_decl_string, arg.default_value)) elif self.__should_use_enum_wa(arg): #Work around for bug/missing functionality in boost.python. #registration order result.append('=(long)(%s)' % arg.default_value) else: result.append('=%s' % arg.default_value) else: result.append('=%s()' % boost_obj) result.append(' )') return ''.join(result)
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 bind_aliases(decls): """ This function binds between class and it's typedefs. :param decls: list of all declarations :rtype: None """ visited = set() typedefs = [ decl for decl in decls if isinstance(decl, declarations.typedef_t) ] for decl in typedefs: type_ = declarations.remove_alias(decl.decl_type) if not isinstance(type_, declarations.declarated_t): continue cls_inst = type_.declaration if not isinstance(cls_inst, declarations.class_types): continue if id(cls_inst) not in visited: visited.add(id(cls_inst)) del cls_inst.aliases[:] cls_inst.aliases.append(decl)
def call_traits( type_ ): """http://boost.org/libs/utility/call_traits.htm""" type_ = declarations.remove_alias( type_ ) if is_immutable( type_ ): return "%(arg)s" #pass by value elif declarations.is_reference( type_ ): no_ref = declarations.remove_reference( type_ ) if is_immutable( no_ref ): return "%(arg)s" #pass by value else: return "boost::ref(%(arg)s)" #pass by ref elif declarations.is_pointer( type_ ) \ and not is_immutable( type_.base ) \ and not declarations.is_pointer( type_.base ): base = type_.base while hasattr(base, 'base'): base = base.base if hasattr(base.declaration, 'custom_call_trait'): custom_call_trait = base.declaration.custom_call_trait call_trait = custom_call_trait(type_) if custom_call_trait else None if call_trait: return call_trait return "boost::python::ptr(%(arg)s)" #pass by ptr else: return "%(arg)s" #pass by value
def keywords_args(self): if not self.__args: return "" boost_arg = self.__id_creator("::boost::python::arg") boost_obj = self.__id_creator("::boost::python::object") result = ["( "] for arg in self.__args: if 1 < len(result): result.append(self.PARAM_SEPARATOR) result.append(boost_arg) result.append('("%s")' % arg.name) if self.__decl.use_default_arguments and arg.default_value: if not declarations.is_pointer(arg.type) or arg.default_value != "0": arg_type_no_alias = declarations.remove_alias(arg.type) if ( declarations.is_fundamental(arg_type_no_alias) and declarations.is_integral(arg_type_no_alias) and not arg.default_value.startswith(arg_type_no_alias.decl_string) ): result.append("=(%s)(%s)" % (arg_type_no_alias.partial_decl_string, arg.default_value)) elif self.__should_use_enum_wa(arg): # Work around for bug/missing functionality in boost.python. # registration order result.append("=(long)(%s)" % arg.default_value) else: result.append("=%s" % arg.default_value) else: result.append("=%s()" % boost_obj) result.append(" )") return "".join(result)
def call_traits(type_): """http://boost.org/libs/utility/call_traits.htm""" type_ = declarations.remove_alias(type_) if is_immutable(type_): return "%(arg)s" #pass by value elif declarations.is_reference(type_): no_ref = declarations.remove_reference(type_) if is_immutable(no_ref): return "%(arg)s" #pass by value else: return "boost::ref(%(arg)s)" #pass by ref elif declarations.is_pointer( type_ ) \ and not is_immutable( type_.base ) \ and not declarations.is_pointer( type_.base ): base = type_.base while hasattr(base, 'base'): base = base.base if hasattr(base.declaration, 'custom_call_trait'): custom_call_trait = base.declaration.custom_call_trait call_trait = custom_call_trait( type_) if custom_call_trait else None if call_trait: return call_trait return "boost::python::ptr(%(arg)s)" #pass by ptr else: return "%(arg)s" #pass by value
def _exportable_impl(self): if not self.name: return messages.W1033 if self.bits == 0 and self.name == "": return messages.W1034 if declarations.is_array( self.type) and declarations.array_size(self.type) < 1: return messages.W1045 type_ = declarations.remove_alias(self.type) type_ = declarations.remove_const(type_) if declarations.is_pointer(type_): if self.type_qualifiers.has_static: return messages.W1035 if python_traits.is_immutable(type_.base): return messages.W1036 units = declarations.decompose_type(type_) ptr2functions = filter( lambda unit: isinstance(unit, declarations.calldef_type_t), units) if ptr2functions: return messages.W1037 type_ = declarations.remove_pointer(type_) if declarations.class_traits.is_my_case(type_): cls = declarations.class_traits.get_declaration(type_) if not cls.name: return messages.W1038 if isinstance(self.parent, declarations.class_t): if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1039 return ''
def bind_aliases(decls): """ This function binds between class and it's typedefs. :param decls: list of all declarations :type all_classes: list of :class:`declarations.declaration_t` items :rtype: None """ visited = set() typedefs = [ decl for decl in decls if isinstance(decl, declarations.typedef_t)] for decl in typedefs: type_ = declarations.remove_alias(decl.type) if not isinstance(type_, declarations.declarated_t): continue cls_inst = type_.declaration if not isinstance(cls_inst, declarations.class_types): continue if id(cls_inst) not in visited: visited.add(id(cls_inst)) del cls_inst.aliases[:] cls_inst.aliases.append(decl)
def _exportable_impl( self ): if not self.name: return messages.W1033 if self.bits == 0 and self.name == "": return messages.W1034 if declarations.is_array( self.type ) and declarations.array_size( self.type ) < 1: return messages.W1045 type_ = declarations.remove_alias( self.type ) type_ = declarations.remove_const( type_ ) if declarations.is_pointer( type_ ): if self.type_qualifiers.has_static: return messages.W1035 if python_traits.is_immutable( type_.base ): return messages.W1036 units = declarations.decompose_type( type_ ) ptr2functions = filter( lambda unit: isinstance( unit, declarations.calldef_type_t ) , units ) if ptr2functions: return messages.W1037 type_ = declarations.remove_pointer( type_ ) if declarations.class_traits.is_my_case( type_ ): cls = declarations.class_traits.get_declaration( type_ ) if not cls.name: return messages.W1038 if isinstance( self.parent, declarations.class_t ): if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1039 return ''
def set_call_policies_pointee( mb ): # Set the default policy to deal with pointer/reference return types to reference_existing object # as this is the ogrenewt Default. ## NOTE AJM 1/1/07 -- this function not used as change to ref_existing_object.. from pyplusplus import module_creator mem_funs = mb.calldefs () mem_funs.create_with_signature = True #MSVC 7.1 if function has throw modifier. resolver = module_creator.built_in_resolver_t() for mem_fun in mem_funs: if mem_fun.call_policies: continue decl_call_policies = resolver( mem_fun ) if decl_call_policies: mem_fun.call_policies = decl_call_policies continue rtype = declarations.remove_alias( mem_fun.return_type ) if declarations.is_pointer(rtype) or declarations.is_reference(rtype): # mem_fun.call_policies \ # = call_policies.return_value_policy( call_policies.reference_existing_object ) mem_fun.call_policies \ = call_policies.return_value_policy( '::boost::python::return_pointee_value' ) ## now we fix a problem where the getSingleton policy isn't right mb.mem_funs( 'getSingleton' ).call_policies = call_policies.return_value_policy( call_policies.reference_existing_object )
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 _resolve_by_type( self, some_type ): temp_type = declarations.remove_alias( some_type ) temp_type = declarations.remove_cv( temp_type ) if isinstance( temp_type, declarations.fundamental_t ) \ or isinstance( temp_type, declarations.declarated_t ): return decl_wrappers.default_call_policies() if declarations.is_same( some_type, self.__const_char_pointer ): return decl_wrappers.default_call_policies() return None
def _resolve_by_type(self, some_type): temp_type = declarations.remove_alias(some_type) temp_type = declarations.remove_cv(temp_type) if isinstance( temp_type, declarations.fundamental_t ) \ or isinstance( temp_type, declarations.declarated_t ): return decl_wrappers.default_call_policies() if declarations.is_same(some_type, self.__const_char_pointer): return decl_wrappers.default_call_policies() return None
def __call__( self, calldef, hint=None ): if not isinstance( calldef, declarations.calldef_t ): return None if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) void_ptr = declarations.pointer_t( declarations.void_t() ) const_void_ptr = declarations.pointer_t( declarations.const_t( declarations.void_t() ) ) if declarations.is_same( return_type, void_ptr ) \ or declarations.is_same( return_type, const_void_ptr ): return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer ) return None
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 __should_be_exposed_by_address_only(self): type_ = declarations.remove_alias( self.decl_type ) type_ = declarations.remove_const( type_ ) type_ = declarations.remove_pointer( type_ ) if not declarations.class_traits.is_my_case( type_ ): return False cls = declarations.class_traits.get_declaration( type_ ) if cls.class_type == declarations.CLASS_TYPES.UNION: return True elif not cls.name: return True else: return False
def __should_be_exposed_by_address_only(self): type_ = declarations.remove_alias( self.type ) type_ = declarations.remove_const( type_ ) type_ = declarations.remove_pointer( type_ ) if not declarations.class_traits.is_my_case( type_ ): return False cls = declarations.class_traits.get_declaration( type_ ) if cls.class_type == declarations.CLASS_TYPES.UNION: return True elif not cls.name: return True else: return False
def _get_alias( self): if not self._alias or self.name == super( casting_operator_t, self )._get_alias(): return_type = declarations.remove_alias( self.return_type ) decl_string = return_type.decl_string for type_, alias in self.SPECIAL_CASES.items(): if isinstance( type_, declarations.type_t ): if declarations.is_same( return_type, type_ ): self._alias = alias break else: if decl_string == type_: self._alias = alias break else: self._alias = 'as_' + self._generate_valid_name(self.return_type.decl_string) return self._alias
def __format_type_as_undecorated( self, type_, is_argument, hint ): result = [] type_ = declarations.remove_alias( type_ ) if declarations.is_array( type_ ): result.append( declarations.array_item_type( type_ ).decl_string ) result.append( '*' ) if is_argument: result.append( 'const' ) else: result.append( self.__remove_leading_scope( type_.decl_string ) ) result = ' '.join( result ) if hint == 'nm': for x in ( '*', '&' ): result = result.replace( ' ' + x, x ) return result
def _get_alias(self): if not self._alias or self.name == super(casting_operator_t, self)._get_alias(): return_type = declarations.remove_alias(self.return_type) decl_string = return_type.decl_string for type_, alias in self.SPECIAL_CASES.items(): if isinstance(type_, declarations.type_t): if declarations.is_same(return_type, type_): self._alias = alias break else: if decl_string == type_: self._alias = alias break else: self._alias = "as_" + self._generate_valid_name(self.return_type.decl_string) return self._alias
def __format_type_as_undecorated(self, type_, is_argument, hint): result = [] type_ = declarations.remove_alias(type_) if declarations.is_array(type_): result.append(declarations.array_item_type(type_).decl_string) result.append('*') if is_argument: result.append('const') else: result.append(self.__remove_leading_scope(type_.decl_string)) result = ' '.join(result) if hint == 'nm': for x in ('*', '&'): result = result.replace(' ' + x, x) return result
def call_traits( type_ ): """http://boost.org/libs/utility/call_traits.htm""" type_ = declarations.remove_alias( type_ ) if is_immutable( type_ ): return "%s" #pass by value elif declarations.is_reference( type_ ): no_ref = declarations.remove_reference( type_ ) if is_immutable( no_ref ): return "%s" #pass by value else: return "boost::ref(%s)" #pass by ref elif declarations.is_pointer( type_ ) \ and not is_immutable( type_.base ) \ and not declarations.is_pointer( type_.base ): return "boost::python::ptr(%s)" #pass by ptr else: return "%s" #pass by value
def _exportable_impl(self): if not self.parent.name and self.is_wrapper_needed(): #return messages.W1057 % str( self ) return messages.W1058 % str(self) if not self.name: return messages.W1033 if self.bits == 0 and self.name == "": return messages.W1034 if not self.expose_address: if declarations.is_array( self.type) and declarations.array_size(self.type) < 1: return messages.W1045 type_ = declarations.remove_alias(self.type) type_ = declarations.remove_const(type_) if declarations.is_pointer(type_): if not self.expose_address and self.type_qualifiers.has_static: return messages.W1035 if not self.expose_address and python_traits.is_immutable( type_.base): return messages.W1036 units = declarations.decompose_type(type_) ptr2functions = [ unit for unit in units if isinstance(unit, declarations.calldef_type_t) ] if ptr2functions: return messages.W1037 type_ = declarations.remove_pointer(type_) if declarations.class_traits.is_my_case(type_): cls = declarations.class_traits.get_declaration(type_) if not cls.name: return messages.W1038 #if cls.class_type == declarations.CLASS_TYPES.UNION: # return messages.W1061 % ( str( self ), str( cls ) ) if isinstance(self.parent, declarations.class_t): if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1039 if declarations.is_array(type_): item_type = declarations.array_item_type(type_) if declarations.is_pointer(item_type): item_type_no_ptr = declarations.remove_pointer(item_type) if python_traits.is_immutable(item_type_no_ptr): return messages.W1056 return ''
def _convert_opaque_to_token(x): """ convert either a string from re or a value from pygccxml to a struct token """ if type(x) is str: return { "BOOL": "?", "UINT8_T": "B", "INT8_T": "b", "UINT16_T": "H", "INT16_T": "h", "UINT32_T": "I", "INT32_T": "i", "UINT64_T": "Q", "INT64_T": "q", "FLOAT": "f", "DOUBLE": "d" }[x.upper()] elif isinstance(x, declarations.declarated_t) and not declarations.is_enum(x): return _convert_opaque_to_token(declarations.remove_alias(x)) elif declarations.is_integral(x) or declarations.is_enum(x): basetoken = {1: "b", 2: "h", 4: "i", 8: "q"}[int(x.byte_size)] try: if "unsigned" in x.CPPNAME: basetoken = basetoken.upper() if "bool" in x.CPPNAME: basetoken = '?' except AttributeError: pass return basetoken elif declarations.is_floating_point(x): if isinstance(x, declarations.float_t): return "f" else: return "d" elif declarations.is_array(x): basetoken = _convert_opaque_to_token(declarations.array_item_type(x)) return basetoken * x.size else: raise ValueError("unknown instance: " + repr(x))
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 __call__(self, variable, hint=None): if not isinstance(variable, declarations.variable_t): return None assert hint in ('get', 'set') if not declarations.is_reference(variable.decl_type): return None no_ref = declarations.remove_reference(variable.decl_type) base_type = declarations.remove_const(no_ref) if python_traits.is_immutable(base_type): #the relevant code creator will generate code, that will return this member variable #by value return decl_wrappers.default_call_policies() if not isinstance(base_type, declarations.declarated_t): return None base_type = declarations.remove_alias(base_type) declaration = base_type.declaration if declarations.is_class_declaration(declaration): return None if declaration.is_abstract: return None if declarations.has_destructor( declaration ) and not declarations.has_public_destructor(declaration): return None if not declarations.has_copy_constructor(declaration): return None if hint == 'get': #if we rich this line, it means that we are able to create an obect using #copy constructor. if declarations.is_const(no_ref): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference) else: return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference) else: return decl_wrappers.default_call_policies()
def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) if isinstance( return_type, declarations.reference_t ) \ and isinstance( return_type.base, declarations.const_t ): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) if declarations.is_same( return_type, self.__const_wchar_pointer ): return decl_wrappers.return_value_policy( decl_wrappers.return_by_value ) if opaque_types_manager.find_out_opaque_decl( return_type, ensure_opaque_decl=True ): return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer ) return None
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 _exportable_impl( self ): if not self.parent.name and self.is_wrapper_needed(): #return messages.W1057 % str( self ) return messages.W1058 % str( self ) if not self.name: return messages.W1033 if self.bits == 0 and self.name == "": return messages.W1034 if not self.expose_address: if declarations.is_array( self.type ) and declarations.array_size( self.type ) < 1: return messages.W1045 type_ = declarations.remove_alias( self.type ) type_ = declarations.remove_const( type_ ) if declarations.is_pointer( type_ ): if not self.expose_address and self.type_qualifiers.has_static: return messages.W1035 if not self.expose_address and python_traits.is_immutable( type_.base ): return messages.W1036 units = declarations.decompose_type( type_ ) ptr2functions = filter( lambda unit: isinstance( unit, declarations.calldef_type_t ) , units ) if ptr2functions: return messages.W1037 type_ = declarations.remove_pointer( type_ ) if declarations.class_traits.is_my_case( type_ ): cls = declarations.class_traits.get_declaration( type_ ) if not cls.name: return messages.W1038 #if cls.class_type == declarations.CLASS_TYPES.UNION: # return messages.W1061 % ( str( self ), str( cls ) ) if isinstance( self.parent, declarations.class_t ): if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1039 if declarations.is_array( type_ ): item_type = declarations.array_item_type( type_ ) if declarations.is_pointer( item_type ): item_type_no_ptr = declarations.remove_pointer( item_type ) if python_traits.is_immutable( item_type_no_ptr ): return messages.W1056 return ''
def _get_has_setter( self ): if declarations.is_const( declarations.remove_reference( self.declaration.type ) ): return False elif python_traits.is_immutable( self._get_exported_var_type() ): return True else: pass no_ref = declarations.remove_reference( self.declaration.type ) no_const = declarations.remove_const( no_ref ) base_type = declarations.remove_alias( no_const ) if not isinstance( base_type, declarations.declarated_t ): return True #TODO ???? decl = base_type.declaration if decl.is_abstract: return False if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): return False if not declarations.has_copy_constructor(decl): return False return True
def __call__( self, variable, hint=None ): if not isinstance( variable, declarations.variable_t ): return None assert hint in ( 'get', 'set' ) if not declarations.is_reference( variable.type ): return None no_ref = declarations.remove_reference( variable.type ) base_type = declarations.remove_const( no_ref ) if python_traits.is_immutable( base_type ): #the relevant code creator will generate code, that will return this member variable #by value return decl_wrappers.default_call_policies() if not isinstance( base_type, declarations.declarated_t ): return None base_type = declarations.remove_alias( base_type ) decl = base_type.declaration if declarations.is_class_declaration( decl ): return None if decl.is_abstract: return None if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): return None if not declarations.has_copy_constructor(decl): return None if hint == 'get': #if we rich this line, it means that we are able to create an obect using #copy constructor. if declarations.is_const( no_ref ): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) else: return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) else: return decl_wrappers.default_call_policies()
def _create_member_list(struct_info): new_type_members = [] for i in struct_info.variables(): if i.type_qualifiers.has_static: continue bitfield = None enumer = None if declarations.is_integral(i.decl_type): try: for enumerator in struct_info.enumerations(): if enumerator.byte_size != declarations.remove_alias( i.decl_type).byte_size: continue elif enumerator.name != snake_to_camel(i.name): continue else: bitfield = enumerator.get_name2value_dict() break except RuntimeError: bitfield = None elif declarations.is_enum(i.decl_type): try: enumer = global_namespace.enumeration( i.decl_type.decl_string).get_name2value_dict() except RuntimeError: enumer = {} if declarations.is_class(i.decl_type): new_type_members.append( DeclaredMemberStruct( i.name, _create_member_list(i.decl_type.declaration))) else: new_type_members.append( DeclaredMember(i.name, _convert_opaque_to_token(i.decl_type), bitfield=bitfield, enumer=enumer)) return new_type_members
def __find_out_is_read_only(self): type_ = declarations.remove_alias( self.type ) if isinstance( type_, declarations.const_t ): return True if declarations.is_pointer( type_ ): type_ = declarations.remove_pointer( type_ ) if declarations.is_reference( type_ ): type_ = declarations.remove_reference( type_ ) if isinstance( type_, declarations.const_t ): return True if self.apply_smart_ptr_wa: return False #all smart pointers has assign operator if isinstance( type_, declarations.declarated_t ) \ and isinstance( type_.declaration, declarations.class_t ) \ and not declarations.has_public_assign( type_.declaration ): return True return False
def __find_out_is_read_only(self): type_ = declarations.remove_alias( self.decl_type ) if isinstance( type_, declarations.const_t ): return True if declarations.is_pointer( type_ ): type_ = declarations.remove_pointer( type_ ) if declarations.is_reference( type_ ): type_ = declarations.remove_reference( type_ ) if isinstance( type_, declarations.const_t ): return True if self.apply_smart_ptr_wa: return False #all smart pointers has assign operator if isinstance( type_, declarations.declarated_t ) \ and isinstance( type_.declaration, declarations.class_t ) \ and not declarations.has_public_assign( type_.declaration ): return True return False
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 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 set_array_item_type_as_size_t(klass, member_name): _D.remove_cv(_D.remove_alias( klass.var(member_name).type)).base = size_t_t()
def set_array_item_type_as_size_t(klass, member_name): _D.remove_cv(_D.remove_alias(klass.var(member_name).type)).base = size_t_t()