Exemplo n.º 1
0
def create_cv_types(base):
    """implementation details"""
    return [
        base,
        cpptypes.const_t(base),
        cpptypes.volatile_t(base),
        cpptypes.volatile_t(cpptypes.const_t(base))
    ]
Exemplo n.º 2
0
def remove_pointer(type):
    """removes pointer from the type definition

    If type is not pointer type, it will be returned as is.
    """
    nake_type = remove_alias( type )
    if not is_pointer( nake_type ):
        return type
    elif isinstance( nake_type, cpptypes.volatile_t ) and isinstance( nake_type.base, cpptypes.pointer_t ):
        return cpptypes.volatile_t( nake_type.base.base )
    elif isinstance( nake_type, cpptypes.const_t ) and isinstance( nake_type.base, cpptypes.pointer_t ):
        return cpptypes.const_t( nake_type.base.base )
    elif isinstance( nake_type, cpptypes.volatile_t ) \
         and isinstance( nake_type.base, cpptypes.const_t ) \
         and isinstance( nake_type.base.base, cpptypes.pointer_t ):
        return cpptypes.volatile_t( cpptypes.const_t( nake_type.base.base.base ) )
    elif isinstance( nake_type.base, cpptypes.calldef_type_t ):
        return type
    else:
        return nake_type.base
Exemplo n.º 3
0
def remove_pointer(type):
    """removes pointer from the type definition

    If type is not pointer type, it will be returned as is.
    """
    nake_type = remove_alias( type )
    if not is_pointer( nake_type ):
        return type
    elif isinstance( nake_type, cpptypes.volatile_t ) and isinstance( nake_type.base, cpptypes.pointer_t ):
        return cpptypes.volatile_t( nake_type.base.base )
    elif isinstance( nake_type, cpptypes.const_t ) and isinstance( nake_type.base, cpptypes.pointer_t ):
        return cpptypes.const_t( nake_type.base.base )
    elif isinstance( nake_type, cpptypes.volatile_t ) \
         and isinstance( nake_type.base, cpptypes.const_t ) \
         and isinstance( nake_type.base.base, cpptypes.pointer_t ):
        return cpptypes.volatile_t( cpptypes.const_t( nake_type.base.base.base ) )
    elif isinstance( nake_type.base, cpptypes.calldef_type_t ):
        return type
    else:
        return nake_type.base
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
def has_public_binary_operator( type_, operator_symbol ):
    """returns True, if `type_` has public binary operator, otherwise False"""
    not_artificial = lambda decl: not decl.is_artificial
    type_ = remove_alias( type_ )
    type_ = remove_cv( type_ )
    type_ = remove_declarated( type_ )
    assert isinstance( type_, class_declaration.class_t )

    if is_std_string( type_ ) or is_std_wstring( type_ ):
        #In some case compare operators of std::basic_string are not instantiated
        return True

    operators = type_.member_operators( function=matchers.custom_matcher_t( not_artificial ) \
                                                 & matchers.access_type_matcher_t( 'public' )
                                       , symbol=operator_symbol
                                       , allow_empty=True
                                       , recursive=False )
    if operators:
        return True

    t = cpptypes.declarated_t( type_ )
    t = cpptypes.const_t( t )
    t = cpptypes.reference_t( t )
    operators = type_.top_parent.operators( function=not_artificial
                                           , arg_types=[t, None]
                                           , symbol=operator_symbol
                                           , allow_empty=True
                                           , recursive=True )
    if operators:
        return True
    for bi in type_.recursive_bases:
        assert isinstance( bi, class_declaration.hierarchy_info_t )
        if bi.access_type != class_declaration.ACCESS_TYPES.PUBLIC:
            continue
        operators = bi.related_class.member_operators( function=matchers.custom_matcher_t( not_artificial ) \
                                                                & matchers.access_type_matcher_t( 'public' )
                                                       , symbol=operator_symbol
                                                       , allow_empty=True
                                                       , recursive=False )
        if operators:
            return True
    return False
Exemplo n.º 7
0
def has_public_binary_operator( type_, operator_symbol ):
    """returns True, if `type_` has public binary operator, otherwise False"""
    not_artificial = lambda decl: not decl.is_artificial
    type_ = remove_alias( type_ )
    type_ = remove_cv( type_ )
    type_ = remove_declarated( type_ )
    assert isinstance( type_, class_declaration.class_t )

    if is_std_string( type_ ) or is_std_wstring( type_ ):
        #In some case compare operators of std::basic_string are not instantiated
        return True

    operators = type_.member_operators( function=matchers.custom_matcher_t( not_artificial ) \
                                                 & matchers.access_type_matcher_t( 'public' )
                                       , symbol=operator_symbol
                                       , allow_empty=True
                                       , recursive=False )
    if operators:
        return True

    t = cpptypes.declarated_t( type_ )
    t = cpptypes.const_t( t )
    t = cpptypes.reference_t( t )
    operators = type_.top_parent.operators( function=not_artificial
                                           , arg_types=[t, None]
                                           , symbol=operator_symbol
                                           , allow_empty=True
                                           , recursive=True )
    if operators:
        return True
    for bi in type_.recursive_bases:
        assert isinstance( bi, class_declaration.hierarchy_info_t )
        if bi.access_type != class_declaration.ACCESS_TYPES.PUBLIC:
            continue
        operators = bi.related_class.member_operators( function=matchers.custom_matcher_t( not_artificial ) \
                                                                & matchers.access_type_matcher_t( 'public' )
                                                       , symbol=operator_symbol
                                                       , allow_empty=True
                                                       , recursive=False )
        if operators:
            return True
    return False
Exemplo n.º 8
0
def create_cv_types( base ):
    """implementation details"""
    return [ base
             , cpptypes.const_t( base )
             , cpptypes.volatile_t( base )
             , cpptypes.volatile_t( cpptypes.const_t( base ) ) ]