Exemplo n.º 1
0
CNV_RETN NodeCheckCnvPtrVoid(   // CHECK CONVERSION TO 'VOID*'
    PTREE *a_expr,              // - addr( resultant tree )
    TYPE src,                   // - source type
    TYPE tgt )                  // - target type
{
    CNV_RETN retn;              // - return: CNV_ERR or CNV_OK
    type_flag src_flags;        // - source modifier flags
    type_flag tgt_flags;        // - target modifier flags
    TYPE type;                  // - type pointed at by src
    PTREE expr;                 // - expression

    type = TypePointedAt( src, &src_flags );
    if( type == NULL ) {
        retn = CNV_OK;
    } else {
        expr = *a_expr;
        if( type->id == TYP_FUNCTION ) {
            retn = NodeCheckPtrTrunc( tgt, src );
            if( retn == CNV_OK_TRUNC ) {
                retn = emitConvMsg( expr, src, tgt, ERR_FUNC_ADDR_TOO_BIG );
            }
        } else if( CNV_OK_TRUNC == NodeCheckPtrTrunc( tgt, src ) ) {
            retn = emitConvMsg( expr, src, tgt, ERR_OBJECT_ADDR_TOO_BIG );
        } else {
#if 1
            TypePointedAt( tgt, &tgt_flags );
            src_flags &= TF1_CONST | TF1_VOLATILE;
            tgt_flags &= TF1_CONST | TF1_VOLATILE;
            tgt_flags &= src_flags;
            if( src_flags == tgt_flags ) {
                retn = CNV_OK;
            } else {
                MSG_NUM msg;    // - message code
                switch( tgt_flags ) {
                case 0:
                    msg = ERR_CNV_VOID_STAR;
                    break;
                case TF1_CONST :
                    msg = ERR_CNV_VOID_STAR_CONST;
                    break;
                case TF1_VOLATILE :
                    msg = ERR_CNV_VOID_STAR_VOLATILE;
                    break;
                case TF1_CONST | TF1_VOLATILE :
                    msg = ERR_CNV_VOID_STAR_CONST_VOLATILE;
                    break;
                default:
                    msg = ERR_FRONT_END;
                    break;
                }
                retn = emitConvMsg( expr, src, tgt, msg );
            }
#else
            retn = AnalysePtrCV( expr, tgt, src, CNV_EXPR );
#endif
        }
    }
    return( retn );
}
Exemplo n.º 2
0
static TYPE type_pointed_to(    // GET BASE TYPE POINTED TO
    TYPE type )                 // - the type
{
    type_flag not_used;         // - not used

    return( TypePointedAt( type, &not_used ) );
}
Exemplo n.º 3
0
TYPE TypeSegOp(                 // GET TYPE FOR :> OPERATION
    TYPE type )                 // - type of RHS of :>
{
    type_flag flags;            // - flags for type

    type = TypePointedAt( type, &flags );
    return( TypeRebuildPcPtr( type, flags, TF1_FAR ) );
}
Exemplo n.º 4
0
unsigned ThrowCnvInit(          // THROW CONVERSIONS: INITIALIZE
    THROW_CNV_CTL *ctl,         // - control area
    TYPE type )                 // - type thrown
{
    type_flag not_used;         // - not used
    THROBJ thr_obj;             // - type of throw object

    ctl->carver = CarveCreate( sizeof( THROW_CNV ), 8 );
    ctl->hdr = NULL;
    ctl->cur = NULL;
    type = TypeCanonicalThr( type );
    ctl->error_occurred = false;
    thr_obj = ThrowCategory( type );
    if( thr_obj == THROBJ_REFERENCE ) {
        makeThrowCnvNoAcc( ctl, type, 0 );
    } else {
        makeThrowCnv( ctl, type, 0 );
    }
    switch( thr_obj ) {
      case THROBJ_VOID_STAR :
      case THROBJ_ANYTHING :
      case THROBJ_SCALAR :
        break;
      case THROBJ_PTR_SCALAR :
        makeCnvVoidStar( ctl );
        break;
      case THROBJ_REFERENCE :
        type = TypeReference( type );
        if( NULL != StructType( type ) ) {
            throwClassCnvs( type, ctl );
        } else {
            type = TypePointedAt( type, &not_used );
            if( type != NULL ) {
                type = StructType( type );
                if( type != NULL ) {
                    throwClassPtrCnvs( type, ctl );
                }
                makeCnvVoidStar( ctl );
            }
        }
        break;
      case THROBJ_CLASS :
      case THROBJ_CLASS_VIRT :
        throwClassCnvs( type, ctl );
        break;
      case THROBJ_PTR_CLASS :
        throwClassPtrCnvs( type, ctl );
        makeCnvVoidStar( ctl );
        break;
      case THROBJ_PTR_FUN :
        if( CgCodePtrSize() <= CgDataPtrSize() ) {
            makeCnvVoidStar( ctl );
        }
        break;
      DbgDefault( "EXCEPT -- illegal throw object" );
    }
    return RingCount( ctl->hdr );
}
Exemplo n.º 5
0
bool TypeIsBasedPtr(            // SEE IF A PTR TO BASED ITEM
    TYPE type )                 // - the type
{
    bool ok;                    // - false ==> not based
    type_flag flags;            // - flags for item pointed at

    if( NULL == TypePointedAt( type, &flags ) ) {
        ok = false;
    } else {
        ok = ( (flags & TF1_BASED) != 0 );
    }
    return( ok );
}
Exemplo n.º 6
0
CNV_RETN CgTypeTruncation(      // GET CNV_... FOR TRUNCATION
    TYPE tgt,                   // - target type
    TYPE src )                  // - source type
{
    CNV_RETN retn;              // - CNV_OK or CNV_OK_TRUNC
    type_flag src_flags;        // - flags for pointed source type
    type_flag tgt_flags;        // - flags for pointed target type
    TYPE umod;                  // - unmodified type for item
    TYPE ptr_type;              // - pointer type

    umod = TypePointedAt( tgt, &tgt_flags );
    if( ( umod != NULL ) && ( tgt_flags & ( TF1_BASED | TF1_FAR16 ) ) ) {
        retn = CNV_OK;
    } else {
        umod = TypePointedAt( src, &src_flags );
        if( ( umod != NULL ) && ( src_flags & ( TF1_BASED | TF1_FAR16 ) ) ) {
            src = TypeConvertFromPcPtr( src );
        }
        if( cgTypeTruncSize( tgt ) < cgTypeTruncSize( src ) ) {
            retn = CNV_OK_TRUNC;
            if( tgt_flags & TF1_NEAR ) {
                if( src_flags & (TF1_FAR|TF1_HUGE) ) {
                    ptr_type = PointerTypeEquivalent( src );
                    if( ptr_type->id == TYP_POINTER ) {
                        /* far to near cnv of a ptr/ref */
                        if( ( ptr_type->flag & TF1_FAR_BUT_NEAR ) != 0 ) {
                            /* but the far is really near */
                            retn = CNV_OK;
                        }
                    }
                }
            }
        } else {
            retn = CNV_OK;
        }
    }
    return( retn );
}
Exemplo n.º 7
0
bool PointerToFuncEquivalent(   // TEST IF EQUIVALENT TO PTR(FUNCTION)
    TYPE type )
{
    bool ok;                    // - return: true ==> equiv. to ptr to funct.
    type_flag not_used;

    ok = false;
    type = TypedefModifierRemove( type );
    if( type->id == TYP_FUNCTION ) {
        ok = true;
    } else if( PointerTypeEquivalent( type ) ) {
        type = TypePointedAt( type, &not_used );
        if( type->id == TYP_FUNCTION ) {
            ok = true;
        }
    }
    return( ok );
}
Exemplo n.º 8
0
static void infMsgType(         // DISPLAY INFORMATION FOR A CONVERSION TYPE
    MSG_NUM msg_num,            // - message number
    TYPE type )                 // - TYPE in error
{
    TYPE cl_type;               // - type, when class or ref to class

    InfMsgPtr( msg_num, type );
    cl_type = ClassTypeForType( type );
    if( cl_type != NULL && !TypeDefined( cl_type ) ) {
        InfMsgPtr( INF_CLASS_NOT_DEFINED, cl_type );
    } else {
        TYPE ptr_type = PointerTypeEquivalent( type );
        if( NULL != ptr_type ) {
            type_flag not_used;
            cl_type = StructType( TypePointedAt( type, &not_used ) );
            if( NULL != cl_type && !TypeDefined( cl_type ) ) {
                InfMsgPtr( INF_CLASS_NOT_DEFINED, cl_type );
            }
        }
    }
}
Exemplo n.º 9
0
static target_size_t cgTypeTruncSize( // GET SIZE FOR TRUNCATION
    TYPE type )                 // - type to be sized
{
    target_size_t size;         // - size of element
    type_flag flags;            // - flags for a type

    switch( TypedefModifierRemove( type )->id ) {
      case TYP_ARRAY :
      case TYP_FUNCTION :
      case TYP_POINTER :
        TypePointedAt( type, &flags );
        if( flags & ( TF1_BASED | TF1_FAR16 ) ) {
            type = TypeConvertFromPcPtr( type );
        }
        size = cgPtrSize( type );
        break;
      default :
        size = CgTypeSize( type );
        break;
    }
    return( size );
}
Exemplo n.º 10
0
TYPE TypeConvertFromPcPtr(      // TRANSFORM TYPE AFTER CONVERSION FROM PC PTR
    TYPE ptype )                // - pointer type
{
    type_flag flags;            // - flags for item pointed at
    TYPE pted;                  // - type pointed at (modified)
    TYPE type;                  // - type pointed at (unmodified)
    SYMBOL baser;               // - basing infomation

    pted = TypePointedAtModified( ptype );
    type = TypeModExtract( pted, &flags, &baser, TC1_NOT_ENUM_CHAR );
    switch( flags & TF1_BASED ) {
    case 0 :
        if( flags & TF1_FAR16 ) {
            ptype = TypeRebuildPcPtr( type, flags, DefaultMemoryFlag( type ) );
        }
        break;
    case TF1_BASED_VOID :
        ptype = TypeRebuildPcPtr( type, flags, TF1_NEAR );
        break;
    case TF1_BASED_ADD :
      { type_flag bflags;       // - flags for baser
        TypePointedAt( baser->sym_type, &bflags );
        ptype = TypeRebuildPcPtr( type, flags, bflags & TF1_MEM_MODEL );
      } break;
    case TF1_BASED_SELF :
        ptype = TypeRebuildPcPtr( type, flags, TF1_FAR );
        break;
    case TF1_BASED_FETCH :
        ptype = TypeRebuildPcPtr( type, flags, TF1_FAR );
        break;
    case TF1_BASED_STRING :
        ptype = TypeRebuildPcPtr( type, flags, TF1_FAR );
        break;
    }
    return( ptype );
}