本文整理汇总了Python中pygccxml.declarations.is_const函数的典型用法代码示例。如果您正苦于以下问题:Python is_const函数的具体用法?Python is_const怎么用?Python is_const使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_const函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: is_supported
def is_supported(oper):
"""returns True if Boost.Python support the operator"""
if oper.symbol == "*" and len(oper.arguments) == 0:
# dereference does not make sense
return False
if oper.symbol != "<<":
return oper.symbol in operators_helper.all
args_len = len(oper.arguments)
if isinstance(oper, declarations.member_operator_t): # and args_len != 1:
return False # Boost.Python does not support member operator<< :-(
if isinstance(oper, declarations.free_operator_t) and args_len != 2:
return False
if not declarations.is_same(oper.return_type, oper.arguments[0].type):
return False
type_ = oper.return_type
if not declarations.is_reference(type_):
return False
type_ = declarations.remove_reference(type_)
if declarations.is_const(type_):
return False
if args_len == 2:
# second argument should has "T const &" type, otherwise the code will not compile
tmp = oper.arguments[1].type
if not declarations.is_reference(tmp):
return False
tmp = declarations.remove_reference(tmp)
if not declarations.is_const(tmp):
return False
return declarations.is_std_ostream(type_) or declarations.is_std_wostream(type_)
开发者ID:ISoirar,项目名称:pypp11,代码行数:30,代码来源:calldef_wrapper.py
示例2: suspicious_type
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)
)
开发者ID:ISoirar,项目名称:pypp11,代码行数:7,代码来源:calldef_wrapper.py
示例3: filter_decls
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()
开发者ID:ned14,项目名称:tnfox,代码行数:30,代码来源:create_tnfox.py
示例4: wrap_one_call_policy
def wrap_one_call_policy(fn):
rt = fn.return_type
if fn.return_type.decl_string == "char const *":
return # use default for strings
if fn.return_type.decl_string == "char *":
return # use default for strings
elif fn.return_type.decl_string == "void *":
return # use default for void pointers
elif fn.return_type.decl_string == "::GLvoid const *":
return # use default for void pointers
parent_ref = declarations.reference_t(declarations.declarated_t(fn.parent))
if declarations.is_reference(rt):
# Need type without reference for next type checks
nonref_rt = rt.base
if declarations.is_arithmetic(nonref_rt) or declarations.is_enum(nonref_rt):
# returning const& double can cause compile trouble if return_internal_reference is used
if declarations.is_const(nonref_rt):
fn.call_policies = return_value_policy(copy_const_reference)
return
# int& might need to be copy_non_const_reference...
else:
fn.call_policies = return_value_policy(copy_non_const_reference)
return
# Const string references should be copied to python strings
if declarations.is_std_string(nonref_rt) and declarations.is_const(nonref_rt):
fn.call_policies = return_value_policy(copy_const_reference)
return
# Returning reference to this same class looks like return_self() [does this always work?]
if declarations.is_same(parent_ref, rt):
fn.call_policies = return_self()
return
elif declarations.is_pointer(rt):
# Clone methods
if re.search(r'^clone', fn.name):
fn.call_policies = return_value_policy(reference_existing_object)
return
else:
return
# Everything else probably returns an internal reference
fn.call_policies = return_internal_reference()
return
开发者ID:cmbruns,项目名称:osgpyplusplus,代码行数:41,代码来源:wrap_helpers.py
示例5: wrapper_type
def wrapper_type( self ):
tmpl = "%(namespace)s::%(constness)sarray_1_t< %(item_type)s, %(array_size)d>"
constness = ''
if declarations.is_const( self.declaration.type ):
constness = 'const_'
result = tmpl % {
'namespace' : code_repository.array_1.namespace
, 'constness' : constness
, 'item_type' : declarations.array_item_type( self.declaration.type ).decl_string
, 'array_size': declarations.array_size( self.declaration.type )
}
return declarations.dummy_type_t( result )
开发者ID:CTrauma,项目名称:pypp11,代码行数:13,代码来源:member_variable.py
示例6: create_holder
def create_holder( self, class_decl ):
#holder should be created when we pass object created in python
#as parameter to function in C++ that takes the smart pointer by reference
found = self._find_smart_ptrs( self.__arguments_types, class_decl )
if not found:
return None#not found or ambiguty
held_type = None
for smart_ptr, type_ in found:
if declarations.is_reference( type_ ) and not declarations.is_const( type_.base ):
temp = code_creators.held_type_t( smart_ptr=smart_ptr )
if not held_type or 'shared_ptr' in smart_ptr:
held_type = temp
return held_type
开发者ID:CTrauma,项目名称:pypp11,代码行数:14,代码来源:types_database.py
示例7: create_default
def create_default(self):
cntrl = self.controller.default_controller
make_object = algorithm.create_identifier( self, 'pyplusplus::call_policies::make_object' )
make_tuple = algorithm.create_identifier( self, 'boost::python::make_tuple' )
tmpl_values = dict()
tmpl_values['unique_function_name'] = self.default_name()
tmpl_values['return_type'] = cntrl.wrapper_return_type.decl_string
tmpl_values['arg_declarations'] = self.args_default_declaration()
tmpl_values['wrapper_class'] = self.parent.wrapper_alias
tmpl_values['wrapped_class'] = declarations.full_name( self.declaration.parent )
tmpl_values['wrapped_inst'] = cntrl.inst_arg.name
tmpl_values['wrapped_inst_constness'] = ''
if declarations.is_const( declarations.remove_reference( cntrl.inst_arg.type ) ):
tmpl_values['wrapped_inst_constness'] = 'const'
decl_vars = cntrl.variables[:]
if not declarations.is_void( self.declaration.return_type ):
decl_vars.append( cntrl.result_variable )
tmpl_values['declare_variables'] \
= os.linesep + os.linesep.join( map( lambda var: self.indent( var.declare_var_string() )
, decl_vars ) )
tmpl_values['pre_call'] = os.linesep + self.indent( os.linesep.join( cntrl.pre_call ) )
tmpl_values['save_result'] = ''
if not declarations.is_void( self.declaration.return_type ):
tmpl_tmp = '%(result_var_name)s = '
if declarations.is_reference( self.declaration.return_type ):
tmpl_tmp = tmpl_tmp + '&'
tmpl_values['save_result'] = tmpl_tmp % dict( result_var_name=cntrl.result_variable.name )
tmpl_values['function_name'] = self.declaration.name
tmpl_values['arg_expressions'] = self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
return_stmt_creator = calldef_utils.return_stmt_creator_t( self
, cntrl
, cntrl.result_variable
, cntrl.return_variables )
tmpl_values['post_call'] = os.linesep + self.indent( os.linesep.join( cntrl.post_call ) )
if return_stmt_creator.pre_return_code:
tmpl_values['post_call'] \
= os.linesep.join([ tmpl_values['post_call']
, self.indent( return_stmt_creator.pre_return_code )])
tmpl_values['return'] = os.linesep + self.indent( return_stmt_creator.statement )
f_def = cntrl.template.substitute(tmpl_values)
return remove_duplicate_linesep( f_def )
开发者ID:CTrauma,项目名称:pypp11,代码行数:50,代码来源:calldef_transformed.py
示例8: test
def test(self):
"""
Test the find_noncopyable_vars function
"""
# The ptr1 variable in the holder struct can be copied,
# but not the ptr2 variable
holder = self.global_ns.class_("holder")
nc_vars = declarations.find_noncopyable_vars(holder)
self.assertEqual(len(nc_vars), 1)
self.assertEqual(nc_vars[0].name, "ptr2")
self.assertTrue(declarations.is_pointer(nc_vars[0].decl_type))
self.assertTrue(declarations.is_const(nc_vars[0].decl_type))
开发者ID:gccxml,项目名称:pygccxml,代码行数:14,代码来源:test_find_noncopyable_vars.py
示例9: _get_call_policies
def _get_call_policies(self):
if self.__call_policies:
return self.__call_policies
if self.container_traits not in declarations.sequential_container_traits:
# TODO: find out why map's don't like the policy
return self.__call_policies
element_type = None
try:
element_type = self.element_type
except:
return
if declarations.is_const(element_type):
element_type = declarations.remove_const(element_type)
if declarations.is_pointer(element_type):
self.__call_policies = call_policies.return_internal_reference()
return self.__call_policies
开发者ID:rhinton,项目名称:tce,代码行数:16,代码来源:indexing_suite2.py
示例10: wrapper_type
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 )
开发者ID:Sandern,项目名称:py-source-sdk-2013,代码行数:17,代码来源:member_variable.py
示例11: test5
def test5(self):
code = 'char const arr[4] = {};'
src_reader = parser.source_reader_t(self.config)
global_ns = declarations.get_global_namespace(
src_reader.read_string(code))
arr_type = global_ns.variable('arr').decl_type
if self.config.xml_generator == "gccxml":
self.assertTrue(
'char [4] const' == arr_type.decl_string,
arr_type.decl_string)
else:
self.assertTrue(
'char const [4]' == arr_type.decl_string,
arr_type.decl_string)
self.assertTrue(
declarations.is_array(arr_type))
self.assertTrue(
declarations.is_const(arr_type))
开发者ID:gccxml,项目名称:pygccxml,代码行数:18,代码来源:array_bug_tester.py
示例12: __call__
def __call__(self, calldef, hint=None):
if not isinstance( calldef, declarations.calldef_t ):
return None
if not isinstance( calldef, declarations.member_operator_t ):
return None
if calldef.symbol != '[]':
return None
return_type = declarations.remove_cv( calldef.return_type )
if declarations.is_reference( return_type ):
return_type = declarations.remove_reference( return_type )
if python_traits.is_immutable( return_type ):
if declarations.is_const( calldef.return_type ):
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.return_internal_reference()
开发者ID:alekob,项目名称:tce,代码行数:20,代码来源:call_policies_resolver.py
示例13: _get_has_setter
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
开发者ID:CTrauma,项目名称:pypp11,代码行数:21,代码来源:member_variable.py
示例14: Auto_Functional_Transformation
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)
#.........这里部分代码省略.........
开发者ID:holocronweaver,项目名称:python-ogre,代码行数:101,代码来源:__init__.py
示例15: has_setter
def has_setter( self ) :
return declarations.is_pointer( self.declaration.type ) \
and not declarations.is_const( self.declaration.type )
开发者ID:CTrauma,项目名称:pypp11,代码行数:3,代码来源:member_variable.py
示例16: wrapped_class_type
def wrapped_class_type( self ):
wrapped_cls_type = declarations.declarated_t( self.declaration.parent )
if declarations.is_const( self.declaration.type ):
wrapped_cls_type = declarations.const_t( wrapped_cls_type )
return declarations.reference_t( wrapped_cls_type )
开发者ID:CTrauma,项目名称:pypp11,代码行数:5,代码来源:member_variable.py
示例17: print
print("My type is: " + str(a.decl_type))
# > My type is: int const
# If we print real python type:
print("My type is : " + str(type(a.decl_type)))
# > My type is: <class 'pygccxml.declarations.cpptypes.const_t'>
# Types are nested in pygccxml. This means that you will get information
# about the first type only. You can access the "base" type by removing
# the const part:
print("My base type is: " + str(type(declarations.remove_const(a.decl_type))))
# > My base type is: <class 'pygccxml.declarations.cpptypes.int_t'>
# You use the is_const function to check for a type:
print("Is 'a' a const ?: " + str(declarations.is_const(a.decl_type)))
# > Is 'a' a const ?: True
# A more complex example with variable b:
b = ns.variables()[1]
print("My type is: " + str(type(b.decl_type)))
# > My type is: <class 'pygccxml.declarations.cpptypes.pointer_t'>
print("My type is: " + str(type(
declarations.remove_const(
declarations.remove_volatile(
declarations.remove_pointer(b.decl_type))))))
# > My type is: <class 'pygccxml.declarations.cpptypes.int_t'>
# The declarations module contains much more methods allowing you to
# navigate the nested types list.
开发者ID:gccxml,项目名称:pygccxml,代码行数:29,代码来源:example.py
注:本文中的pygccxml.declarations.is_const函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论