def __fix_invalid_integral(self, func, arg): try: int(arg.default_value) return arg.default_value except: pass try: int(arg.default_value, 16) if 64 == utils.get_architecture(): # on 64 bit architecture, gccxml reports 0fffff, which is # valid number the problem is that in this case it is so # buggy so pygccxml can not fix it users will have to fix the # default value manually return arg.default_value default_value = arg.default_value.lower() found_hex = [ch for ch in default_value if ch in 'abcdef'] if found_hex and not default_value.startswith('0x'): int('0x' + default_value, 16) return '0x' + default_value except: pass # may be we deal with enum parent = func.parent while parent: found = self.__find_enum(parent, arg.default_value) if found: if declarations.is_fundamental(arg.type) and ' ' in \ arg.type.decl_string: template = '(%s)(%s)' else: template = '%s(%s)' return template % (arg.type.decl_string, self.__join_names(found.parent.decl_string, arg.default_value)) else: parent = parent.parent # check if we have an unqualified integral constant # only do patching in cases where we have a bare variable name c_var = re.compile("[a-z_][a-z0-9_]*", re.IGNORECASE) m = c_var.match(arg.default_value) if m: parent = func.parent while parent: try: found = parent.variable(arg.default_value, recursive=False) except declarations.matcher.declaration_not_found_t: # ignore exceptions if a match is not found found = None if found: if declarations.is_fundamental(arg.type): return "%s" % self.__join_names( found.parent.decl_string, arg.default_value) parent = parent.parent return arg.default_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.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 filter_decls(mb): mb.global_ns.exclude() fx_ns = mb.namespace( 'FX' ) fx_ns.include() fx_ns.decls( declarations_to_exclude.is_excluded ).exclude() fx_ns.decls( lambda decl: decl.name.startswith('FXIPCMsgHolder') ).exclude() fx_ns.namespace( 'Pol' ).exclude() fx_ns.decls( files_to_exclude.is_excluded ).exclude() fx_ns.class_( 'QValueList<FX::Pol::knowReferrers::ReferrerEntry>').exclude() try: fx_ns.variables( 'metaClass').exclude() except: pass try: fx_ns.class_( 'QPtrVector<FX::Generic::BoundFunctorV>').exclude() except: pass #Niall? wrapper for this function could not be compiled #TnFXSQLDBStatement = fx_ns.class_( 'TnFXSQLDBStatement' ) #TnFXSQLDBStatement.member_function( name='bind', arg_types=[None,None,None] ).exclude() for func in fx_ns.calldefs(): #I want to exclude all functions that returns pointer to pointer #and returns pointer to fundamental type if declarations.is_pointer( func.return_type ): temp = declarations.remove_pointer( func.return_type ) if declarations.is_fundamental( temp ) and not declarations.is_const(temp): func.exclude() temp = declarations.remove_cv( func.return_type ) temp = declarations.remove_pointer( temp ) if declarations.is_pointer( temp ): func.exclude()
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 suspicious_type( type_ ): if not declarations.is_reference( type_ ): return False type_no_ref = declarations.remove_reference( type_ ) return not declarations.is_const( type_no_ref ) \ and ( declarations.is_fundamental( type_no_ref ) or declarations.is_enum( type_no_ref ) )
def suspicious_type(type_): if not declarations.is_reference(type_): return False type_no_ref = declarations.remove_reference(type_) return not declarations.is_const(type_no_ref) and ( declarations.is_fundamental(type_no_ref) or declarations.is_enum(type_no_ref) )
def is_immutable( type_ ): """returns True, if type_ represents Python immutable type""" return declarations.is_fundamental( type_ ) \ or declarations.is_enum( type_ ) \ or declarations.is_std_string( type_ ) \ or declarations.is_std_wstring( type_ ) \ or declarations.smart_pointer_traits.is_smart_pointer( type_ )
def _exportable_impl_derived(self): if not declarations.is_fundamental( self.return_type) and not self.has_const: return messages.W1016 if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1017 return ''
def getTypePPA(ptype): if decls.is_pointer(ptype): return TypedefSeq(ptype) # specify return value elif decls.is_fundamental(ptype): return [] elif decls.is_class(ptype): return pyscope.CClass(ptype, pyresolvable.resolveNS(ptype)) # unknown / not yet implemented type. # This is treated as class => there may be some complications. else: print 'WARNING: unknown type:' + str(ptype) return pyscope.CClass(ptype, pyresolvable.resolveNS(ptype))
def getTypePPA(ptype): if decls.is_pointer(ptype): return TypedefSeq(ptype) # specify return value elif decls.is_fundamental(ptype): return [] elif decls.is_class(ptype): return pyscope.CClass(ptype, pyresolvable.resolveNS(ptype)) # unknown / not yet implemented type. # This is treated as class => there may be some complications. else: print "WARNING: unknown type:" + str(ptype) return pyscope.CClass(ptype, pyresolvable.resolveNS(ptype))
def wrapper_type( self ): tmpl = "%(namespace)s::%(constness)sarray_1_t< %(item_type)s, %(array_size)d>" item_type = declarations.array_item_type(self.declaration.decl_type) is_noncopyable = not declarations.is_fundamental(item_type) and \ declarations.is_noncopyable(item_type) constness = '' if declarations.is_const(self.declaration.decl_type) or is_noncopyable: constness = 'const_' result = tmpl % { 'namespace' : code_repository.array_1.namespace , 'constness' : constness , 'item_type' : declarations.array_item_type( self.declaration.decl_type ).decl_string , 'array_size': declarations.array_size( self.declaration.decl_type ) } return declarations.dummy_type_t( result )
def wrapper_type( self ): tmpl = "%(namespace)s::%(constness)sarray_1_t< %(item_type)s, %(array_size)d>" item_type = declarations.array_item_type(self.declaration.decl_type) is_noncopyable = not declarations.is_fundamental(item_type) and \ declarations.is_noncopyable(item_type) constness = '' if declarations.is_const(self.declaration.decl_type) or is_noncopyable: constness = 'const_' result = tmpl % { 'namespace' : code_repository.array_1.namespace , 'constness' : constness , 'item_type' : declarations.array_item_type( self.declaration.decl_type ).decl_string , 'array_size': declarations.array_size( self.declaration.decl_type ) } return declarations.dummy_type_t( result )
def _create_impl(self): templates = declarations.templates call_invocation = declarations.call_invocation ns_name = code_repository.array_1.namespace item_type = declarations.array_item_type(self.array_type) is_noncopyable = not declarations.is_fundamental(item_type) and declarations.is_noncopyable(item_type) if declarations.is_const(self.array_type) or is_noncopyable: fn_name = 'register_const_array_1' else: fn_name = 'register_array_1' fn_def_tmpl_args = [ declarations.array_item_type(self.array_type).decl_string , str( declarations.array_size(self.array_type) ) ] if not self.call_policies.is_default(): fn_def_tmpl_args.append( self.call_policies.create(self, call_policies.CREATION_POLICY.AS_TEMPLATE_ARGUMENT ) ) fn_def = templates.join( '::'.join( [ns_name, fn_name] ), fn_def_tmpl_args ) return call_invocation.join( fn_def, [ '"%s"' % self._create_name() ] ) + ';'
def __fix_invalid_integral(self, func, arg): try: int(arg.default_value) return arg.default_value except: pass try: int(arg.default_value, 16) if 64 == utils.get_architecture(): # on 64 bit architecture, gccxml reports 0fffff, which is # valid number the problem is that in this case it is so # buggy so pygccxml can not fix it users will have to fix the # default value manually return arg.default_value default_value = arg.default_value.lower() found_hex = [ch for ch in default_value if ch in 'abcdef'] if found_hex and not default_value.startswith('0x'): int('0x' + default_value, 16) return '0x' + default_value except: pass # may be we deal with enum parent = func.parent while parent: found = self.__find_enum(parent, arg.default_value) if found: if declarations.is_fundamental(arg.type) and ' ' in \ arg.type.decl_string: template = '(%s)(%s)' else: template = '%s(%s)' return template % (arg.type.decl_string, self.__join_names( found.parent.decl_string, arg.default_value)) else: parent = parent.parent return arg.default_value
def __fix_invalid_integral(self, func, arg): try: int(arg.default_value) return arg.default_value except: pass try: int(arg.default_value, 16) if 64 == utils.get_architecture(): # on 64 bit architecture, gccxml reports 0fffff, which is # valid number the problem is that in this case it is so # buggy so pygccxml can not fix it users will have to fix the # default value manually return arg.default_value default_value = arg.default_value.lower() found_hex = [ch for ch in default_value if ch in 'abcdef'] if found_hex and not default_value.startswith('0x'): int('0x' + default_value, 16) return '0x' + default_value except: pass # may be we deal with enum parent = func.parent while parent: found = self.__find_enum(parent, arg.default_value) if found: if declarations.is_fundamental(arg.type) and ' ' in \ arg.type.decl_string: template = '(%s)(%s)' else: template = '%s(%s)' return template % (arg.type.decl_string, self.__join_names(found.parent.decl_string, arg.default_value)) else: parent = parent.parent return arg.default_value
def _exportable_impl_derived(self): if not declarations.is_fundamental(self.return_type) and not self.has_const: return messages.W1016 if self.access_type != declarations.ACCESS_TYPES.PUBLIC: return messages.W1017 return ""
def getDeclType(arg): """Determines arg type""" if declarations.is_pointer(arg): return "Pointer" elif declarations.is_fundamental(arg): return "Fundamental" elif declarations.is_class(arg): return "Class" else: return "Unknown"
def customize_default_args(args): for arg in args: if arg.default_value: if not declarations.is_fundamental(arg.type): arg.default_value = "(" + arg.default_value + ")"
def __fix_invalid_integral(self, func, arg): try: int(arg.default_value) return arg.default_value except: pass try: int(arg.default_value, 16) if 64 == utils.get_architecture(): # on 64 bit architecture, gccxml reports 0fffff, which is # valid number the problem is that in this case it is so # buggy so pygccxml can not fix it users will have to fix the # default value manually return arg.default_value default_value = arg.default_value.lower() found_hex = [ch for ch in default_value if ch in 'abcdef'] if found_hex and not default_value.startswith('0x'): int('0x' + default_value, 16) return '0x' + default_value except: pass # may be we deal with enum # CastXML qualifies the enum value with enum type, so split the # argument and use only the enum value enum_value = arg.default_value.split('::')[-1] parent = func.parent while parent: found = self.__find_enum(parent, enum_value) if found: if declarations.is_fundamental(arg.type) and ' ' in \ arg.type.decl_string: template = '(%s)(%s)' else: template = '%s(%s)' if self.__cxx_std.is_cxx11_or_greater: qualifier_decl_string = found.decl_string else: qualifier_decl_string = found.parent.decl_string return template % (arg.type.decl_string, self.__join_names(qualifier_decl_string, enum_value)) else: parent = parent.parent # check if we have an unqualified integral constant # only do patching in cases where we have a bare variable name c_var = re.compile("[a-z_][a-z0-9_]*", re.IGNORECASE) m = c_var.match(arg.default_value) if m: parent = func.parent while parent: try: found = parent.variable(arg.default_value, recursive=False) except declarations.matcher.declaration_not_found_t: # ignore exceptions if a match is not found found = None if found: if declarations.is_fundamental(arg.type): return "%s" % self.__join_names( found.parent.decl_string, arg.default_value) parent = parent.parent return arg.default_value
def getDeclType(arg): """Determines arg type""" if declarations.is_pointer(arg): return "Pointer" elif declarations.is_fundamental(arg): return "Fundamental" elif declarations.is_class(arg): return "Class" else: return "Unknown"