Esempio n. 1
0
// The following can be extended for more types, if required
//
TYPE TypeFromCgType(            // GET C++ TYPE FOR cg_type
    cg_type cgtype )            // - code-gen type
{
    TYPE type;                  // - C++ type

    switch( cgtype ) {
      case TY_UINT_1 :
        type = GetBasicType( TYP_UCHAR );
        break;
      case TY_INT_1 :
        type = GetBasicType( TYP_SCHAR );
        break;
      case TY_UINT_2 :
        type = GetBasicType( TYP_USHORT );
        break;
      case TY_INT_2 :
        type = GetBasicType( TYP_SSHORT );
        break;
      case TY_UINT_4 :
      #if( TARGET_INT == 4 )
        type = GetBasicType( TYP_UINT );
      #else
        type = GetBasicType( TYP_ULONG );
      #endif
        break;
      case TY_INT_4 :
      #if( TARGET_INT == 4 )
        type = GetBasicType( TYP_SINT );
      #else
        type = GetBasicType( TYP_SLONG );
      #endif
        break;
      case TY_INT_8 :
        type = GetBasicType( TYP_SLONG64 );
        break;
      case TY_UINT_8 :
        type = GetBasicType( TYP_ULONG64 );
        break;
      case TY_BOOLEAN :
      case TY_INTEGER :
        type = GetBasicType( TYP_SINT );
        break;
      case TY_UNSIGNED :
        type = GetBasicType( TYP_UINT );
        break;
      default :
        type = MakeInternalType( BETypeLength( cgtype ) );
        break;
    }
    return type;
}
Esempio n. 2
0
TYPE_SIG *TypeSigFind(          // FIND TYPE SIGNATURE
    TYPE_SIG_ACCESS acc,        // - access type
    TYPE type,                  // - type for signature
    TOKEN_LOCN* err_locn,       // - error location for access errors
    bool *error_occurred )      // - to set error indication
{
    TYPE_SIG *srch;             // - signature for searching
    TYPE_SIG *sig;              // - signature
    SYMBOL sym;                 // - symbol
    unsigned size;              // - size of R/O data
    NAME typesig_name;          // - name of type signature
    TYPE typesig_type;          // - type of type signature
    bool err_this_time;         // - true ==> we have error
    TYPE_SIG_ACCESS acc_ind;    // - indirect access

    err_this_time = false;
    type = TypeCanonicalThr( type );
    sig = NULL;
    RingIterBeg( type_sigs, srch ) {
        if( TypesSameExclude( srch->type, type, TC1_NOT_ENUM_CHAR ) ) {
            sig = srch;
            break;
        }
    } RingIterEnd( srch );
    if( sig == NULL ) {
        THROBJ thr;             // - category of object
        DbgVerify( 0 == ( acc & TSA_GEN )
                 , "TypeSigFind -- no type signature & TSA_GEN" );
        sig = RingCarveAlloc( carveTYPE_SIG, &type_sigs );
        sig->type = type;
        sig->default_ctor = NULL;
        sig->copy_ctor = NULL;
        sig->dtor = NULL;
        sig->sym = NULL;
        sig->base = NULL;
        sig->cgref = false;
        sig->cggen = false;
        sig->free = false;
        thr = ThrowCategory( type );
        if( acc & TSA_INDIRECT ) {
            acc_ind = acc | TSA_INDIRECT_ACCESS;
        } else if( acc & TSA_INDIRECT_ACCESS ) {
            acc_ind = ( acc & ~ TSA_INDIRECT ) | TSA_INDIRECT_GEN;
        } else {
            acc_ind = acc;
        }
        size = 0;
        switch( thr ) {
        case THROBJ_PTR_SCALAR :
        case THROBJ_PTR_CLASS :
            sig->base = TypeSigFind( acc_ind & TSA_INDIRECT
                                   , TypePointedAtModified( type )
                                   , err_locn
                                   , &err_this_time );
            size = typeSigHdrSize();
            break;
        case THROBJ_SCALAR :
        case THROBJ_PTR_FUN :
        case THROBJ_VOID_STAR :
            size = typeSigHdrSize() + SizeTargetSizeT();
            break;
        case THROBJ_REFERENCE :
            sig->base = TypeSigFind( acc_ind
                                   , TypeReference( type )
                                   , err_locn
                                   , &err_this_time );
            break;
        case THROBJ_CLASS :
        case THROBJ_CLASS_VIRT :
            size = 3 * CgCodePtrSize() + CgDataPtrSize() + typeSigHdrSize();
            break;
        case THROBJ_ANYTHING :
            break;
        default :
            DbgStmt( CFatal( "cgTypeSignature -- invalid throw category" ) );
        }
        size += typeSigNameSize( thr );
        if( size == 0 ) {
            sym = NULL;
        } else {                // - type for TYPE SIGNATURE variable
            typesig_name = CppNameTypeSig( type );
            sym = ScopeAlreadyExists( GetFileScope(), typesig_name );
            if( sym == NULL ) {
                typesig_type = MakeInternalType( size );
                typesig_type = MakeCompilerConstCommonData( typesig_type );
                sym = SymCreateFileScope( typesig_type
                                        , SC_PUBLIC
                                        , SF_REFERENCED | SF_ADDR_TAKEN
                                        , typesig_name );
                LinkageSet( sym, "C++" );
                CgSegId( sym );
            }
        }
        sig->sym = sym;
    }
    if( err_this_time ) {
        *error_occurred = true;
    } else {
        if( NULL != sig->sym ) {
            SegmentMarkUsed( sig->sym->segid );
        }
        *error_occurred = false;
        typeSigAccess( acc, sig, err_locn, error_occurred );
    }
    return( sig );
}