def __test_trivial( self, source, target ):
     if not ( source and target ):
         return False
     if is_same( source, target ):
         return True #X => X
     if is_const( target ) and is_same( source, target.base ):
         return True #X => const X
     if is_reference( target ) and is_same( source, target.base ):
         return True #X => X&
     if is_reference( target ) and is_const( target.base ) and is_same( source, target.base.base ):
         return True #X => const X&
     if is_same( target, cpptypes.pointer_t( cpptypes.void_t() ) ):
         if is_integral( source ) or is_enum( source ):
             return False
         else:
             return True #X => void*
     if is_pointer( source ) and is_pointer( target ):
         if is_const( target.base ) and is_same( source.base, target.base.base ):
             return True#X* => const X*
     if is_reference( source ) and is_reference( target ):
         if is_const( target.base ) and is_same( source.base, target.base.base ):
             return True#X& => const X&
     if not is_const( source ) and is_array( source ) and is_pointer( target ):
         if is_same( base_type(source), target.base ):
             return True#X[2] => X*
     if is_array( source ) and is_pointer( target ) and is_const( target.base ):
         if is_same( base_type(source), target.base.base ):
             return True
Esempio n. 2
0
 def __test_trivial( self, source, target ):
     if not ( source and target ):
         return False
     if is_same( source, target ):
         return True #X => X
     if is_const( target ) and is_same( source, target.base ):
         return True #X => const X
     if is_reference( target ) and is_same( source, target.base ):
         return True #X => X&
     if is_reference( target ) and is_const( target.base ) and is_same( source, target.base.base ):
         return True #X => const X&
     if is_same( target, cpptypes.pointer_t( cpptypes.void_t() ) ):
         if is_integral( source ) or is_enum( source ):
             return False
         else:
             return True #X => void*
     if is_pointer( source ) and is_pointer( target ):
         if is_const( target.base ) and is_same( source.base, target.base.base ):
             return True#X* => const X*
     if is_reference( source ) and is_reference( target ):
         if is_const( target.base ) and is_same( source.base, target.base.base ):
             return True#X& => const X&
     if not is_const( source ) and is_array( source ) and is_pointer( target ):
         if is_same( base_type(source), target.base ):
             return True#X[2] => X*
     if is_array( source ) and is_pointer( target ) and is_const( target.base ):
         if is_same( base_type(source), target.base.base ):
             return True
Esempio n. 3
0
 def find_value_type(global_ns, value_type_str):
     """implementation details"""
     if not value_type_str.startswith('::'):
         value_type_str = '::' + value_type_str
     found = global_ns.decls(
         name=value_type_str,
         function=lambda decl: not isinstance(decl, calldef.calldef_t),
         allow_empty=True)
     if not found:
         no_global_ns_value_type_str = value_type_str[2:]
         if cpptypes.FUNDAMENTAL_TYPES.has_key(no_global_ns_value_type_str):
             return cpptypes.FUNDAMENTAL_TYPES[no_global_ns_value_type_str]
         elif is_std_string(value_type_str):
             string_ = global_ns.typedef('::std::string')
             return remove_declarated(string_)
         elif is_std_wstring(value_type_str):
             string_ = global_ns.typedef('::std::wstring')
             return remove_declarated(string_)
         else:
             value_type_str = no_global_ns_value_type_str
             has_const = value_type_str.startswith('const ')
             if has_const:
                 value_type_str = value_type_str[len('const '):]
             has_pointer = value_type_str.endswith('*')
             if has_pointer:
                 value_type_str = value_type_str[:-1]
             found = None
             if has_const or has_pointer:
                 found = impl_details.find_value_type(
                     global_ns, value_type_str)
             if not found:
                 return None
             else:
                 if isinstance(found, class_declaration.class_types):
                     found = cpptypes.declarated_t(found)
                 if has_const:
                     found = cpptypes.const_t(found)
                 if has_pointer:
                     found = cpptypes.pointer_t(found)
                 return found
     if len(found) == 1:
         return found[0]
     else:
         return None
 def find_value_type( global_ns, value_type_str ):
     """implementation details"""
     if not value_type_str.startswith( '::' ):
         value_type_str = '::' + value_type_str
     found = global_ns.decls( name=value_type_str
                              , function=lambda decl: not isinstance( decl, calldef.calldef_t )
                              ,  allow_empty=True )
     if not found:
         no_global_ns_value_type_str = value_type_str[2:]
         if cpptypes.FUNDAMENTAL_TYPES.has_key( no_global_ns_value_type_str ):
             return cpptypes.FUNDAMENTAL_TYPES[ no_global_ns_value_type_str ]
         elif is_std_string( value_type_str ):
             string_ = global_ns.typedef( '::std::string' )
             return remove_declarated( string_ )
         elif is_std_wstring( value_type_str ):
             string_ = global_ns.typedef( '::std::wstring' )
             return remove_declarated( string_ )
         else:
             value_type_str = no_global_ns_value_type_str
             has_const = value_type_str.startswith( 'const ' )
             if has_const:
                 value_type_str = value_type_str[ len('const '): ]
             has_pointer = value_type_str.endswith( '*' )
             if has_pointer:
                 value_type_str = value_type_str[:-1]
             found = None
             if has_const or has_pointer:
                 found = impl_details.find_value_type( global_ns, value_type_str )
             if not found:
                 return None
             else:
                 if isinstance( found, class_declaration.class_types ):
                     found = cpptypes.declarated_t( found )
                 if has_const:
                     found = cpptypes.const_t( found )
                 if has_pointer:
                     found = cpptypes.pointer_t( found )
                 return found
     if len( found ) == 1:
         return found[0]
     else:
         return None
def is_void_pointer( type ):
    """returns True, if type represents `void*`, False otherwise"""
    return is_same( type, cpptypes.pointer_t( cpptypes.void_t() ) )
Esempio n. 6
0
def is_void_pointer( type ):
    """returns True, if type represents `void*`, False otherwise"""
    return is_same( type, cpptypes.pointer_t( cpptypes.void_t() ) )