Beispiel #1
0
static bool same_ptr_types(     // TEST FOR EQUIVALENT POINTER TYPES
    TYPE t1,                    // - type [1]
    TYPE t2 )                   // - type [2]
{
    return( TypeCompareExclude( type_pointed_to( t1 )
                             , type_pointed_to( t2 )
                             , TC1_FUN_LINKAGE ) );
}
Beispiel #2
0
bool PtrCnvInfo(                // FILL IN PTR-CONVERSION INFORMATION
    TYPE ptr_src,               // - source type
    TYPE ptr_tgt,               // - target pointer type
    PTRCNV* info )              // - pointer-conversion information
{
    bool ok;                    // - return: true ==> can convert trivially
    bool first_level;           // - true ==> at first level
    bool const_always;          // - true ==> const on all preceding levels
    TYPE orig_src;              // - original src type

    info->converts = false;
    info->to_base = false;
    info->to_derived = false;
    info->to_void = false;
    info->ptr_integral_ext = false;
    info->cv_err_0 = false;
    info->reint_cast_ok = false;
    orig_src = ptr_src;
    ptr_src = TypePointedAtModified( ptr_src );
    ptr_tgt = TypePointedAtModified( ptr_tgt );
    if( ptr_src == NULL ) {
        info->pted_src = NULL;
        info->flags_src = 0;
        ptr_tgt = TypeGetActualFlags( ptr_tgt, &info->flags_tgt );
        info->pted_tgt = ptr_tgt;
        if( ptr_tgt->id == TYP_VOID ) {
            info->to_void = true;
        }
        if( NULL != orig_src && IntegralType( orig_src ) ) {
            info->reint_cast_ok = true;
        }
        ok = false;
    } else {
        first_level = true;
        const_always = true;
        info->reint_cast_ok = true;
        for( ; ; ) {
            type_flag flags_src;    // source flags
            type_flag flags_tgt;    // target flags
            type_flag cv_src;       // source CV flags
            type_flag cv_tgt;       // target CV flags
            ptr_src = TypeGetActualFlags( ptr_src, &flags_src );
            ptr_tgt = TypeGetActualFlags( ptr_tgt, &flags_tgt );
            cv_src = flags_src & TF1_CV_MASK;
            cv_tgt = flags_tgt & TF1_CV_MASK;
            if( cv_src != ( cv_tgt & cv_src ) ) {   // test cv-containment
                if( first_level ) {
                    info->cv_err_0 = true;          // - diagnose elsewhere
                } else {
                    ok = false;
                    break;
                }
            }
            if( first_level ) {
                TYPE cl_src;        // class for source
                TYPE cl_tgt;        // class for target
                ok = true;
                info->pted_src = ptr_src;
                info->pted_tgt = ptr_tgt;
                info->flags_src = flags_src;
                info->flags_tgt = flags_tgt;
                cl_src = StructType( ptr_src );
                if( ptr_tgt->id == TYP_VOID ) {
                    info->to_void = true;
//                  ok = (ptr_src == TYP_VOID);
//                  break;
                } else if( NULL != cl_src ) {
                    cl_tgt = StructType( ptr_tgt );
                    if( NULL != cl_tgt
                     && cl_tgt != cl_src ) {
                        if( TypeDerived( ptr_src, ptr_tgt ) ) {
                            info->to_base = true;
                            ok = false;
//                          break;
                        } else if( TypeDerived( ptr_tgt, ptr_src ) ) {
                            info->to_derived = true;
                            ok = false;
//                          break;
                        }
                    }
                } else if( ( ptr_src->id != ptr_tgt->id )
                        && IntegralType( ptr_src )
                        && IntegralType( ptr_tgt )
                        && ( CgMemorySize( ptr_src ) == CgMemorySize( ptr_tgt ) ) ) {
                    info->ptr_integral_ext = true;
                }
                if( !ok ) {
                    if( info->cv_err_0 ) {
                        info->reint_cast_ok = false;
                    }
                    break;
                }
                first_level = false;
            }
            if( cv_tgt != cv_src ) {                // test const'ed to here
                if( ! const_always ) {
                    info->reint_cast_ok = false;
                    ok = false;
                    break;
                }
            }
            if( (cv_tgt & TF1_CONST) == 0 ) {
                const_always = false;
            }
            if( ptr_src == ptr_tgt ) {
                ok = true;
                break;
            }
            if( TYP_FUNCTION == ptr_src->id
             || TYP_FUNCTION == ptr_tgt->id ) {
                ok = TypeCompareExclude( ptr_src
                                         , ptr_tgt
                                         , TC1_FUN_LINKAGE |
                                           TC1_NOT_ENUM_CHAR );
                break;
            }
            ptr_src = TypePointedAtModified( ptr_src );
            ptr_tgt = TypePointedAtModified( ptr_tgt );
            if( NULL == ptr_src ) {
                if( NULL != ptr_tgt
                 && NULL != FunctionDeclarationType( ptr_tgt ) ) {
                    info->reint_cast_ok = false;
                }
                ok = false;
                break;
            }
            if( NULL == ptr_tgt ) {
                ok = false;
                break;
            }
        }
    }
    return( ok );
}
Beispiel #3
0
bool TypesIdentical( TYPE type1, TYPE type2 )
/*******************************************/
{
    return TypeCompareExclude( type1, type2, TC1_PTR_FUN | TC1_NOT_ENUM_CHAR );
}
Beispiel #4
0
bool TypesSameExclude( TYPE type1, TYPE type2, type_exclude mask )
/****************************************************************/
{
    return( TypeCompareExclude( type1, type2, mask | TC1_PTR_FUN ) );
}