Changeset 192 in dev for trunk/jenga/src/smoothie/Type.cpp


Ignore:
Timestamp:
Jun 26, 2007, 5:04:29 AM (17 years ago)
Author:
dai_9181
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jenga/src/smoothie/Type.cpp

    r186 r192  
    6161    return false;
    6262}
    63 
    64 
    65 bool Type::StringToType( const string &typeName, Type &type ){
    66     type.index = -1;
    67 
    68     if( typeName[0] == '*' ){
    69         if( typeName.size() >= 3
    70             && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){
    71                 //関数ポインタ(*Function)
    72                 type.basicType = DEF_PTR_PROC;
    73                 type.index = Smoothie::GetMeta().GetProcPointers().Add( typeName );
    74                 return true;
    75         }
    76 
    77         const string &nextTypeName = typeName.substr( 1 );
    78 
    79         if( !StringToType( nextTypeName, type ) ){
    80             return false;
    81         }
    82 
    83         type.PtrLevelUp();
    84 
    85         return true;
    86     }
    87 
    88     if( StringToBasicType( typeName, type.basicType ) ){
    89         // 基本型だったとき
    90         return true;
    91     }
    92 
    93 
    94     // Object型だったとき
    95     if( typeName == "Object" ){
    96         type.SetType( DEF_OBJECT, Smoothie::GetMeta().GetClasses().GetObjectClassPtr() );
    97         return true;
    98     }
    99 
    100     // String型だったとき
    101     if( typeName == "String" ){
    102         type.SetType( DEF_OBJECT, Smoothie::GetMeta().GetClasses().GetStringClassPtr() );
    103         return true;
    104     }
    105 
    106 
    107     ////////////////////
    108     // TypeDefされた型
    109     ////////////////////
    110     int i=Smoothie::GetMeta().typeDefs.GetIndex( typeName );
    111     if(i!=-1){
    112         type = Smoothie::GetMeta().typeDefs[i].GetBaseType();
    113         return true;
    114     }
    115 
    116     //クラス
    117     const CClass *pobj_c = Smoothie::GetMeta().GetClasses().Find( typeName );
    118     if(pobj_c){
    119         type.pClass = pobj_c;
    120 
    121         if( pobj_c->IsStructure() ){
    122             type.basicType = DEF_STRUCT;
    123         }
    124         else{
    125             type.basicType = DEF_OBJECT;
    126         }
    127         return true;
    128     }
    129 
    130     return false;
     63const char *Type::BasicTypeToCharPtr( const Type &type )
     64{
     65    for( int i=0; ; i++ ){
     66        if( basicTypeList[i] == DEF_NON ){
     67            break;
     68        }
     69        if( basicTypeList[i] == type.GetBasicType() ){
     70            return basicTypeNameList[i].c_str();
     71        }
     72    }
     73    return NULL;
    13174}
    13275
     
    488431}
    489432
    490 
    491 const string Type::ToString() const
    492 {
    493     if( PTR_LEVEL( basicType ) ){
    494         //ポインタレベルが1以上の場合
    495         Type type( *this );
    496         type.PtrLevelDown();
    497 
    498         return (string)"*" + type.ToString();
    499     }
    500     else if( IsObject() || IsStruct() ){
    501         //オブジェクトまたは構造体
    502 
    503         if( !( index == 0 || index == -1 ) ){
    504             if( pClass->GetNamespaceScopes().size() >= 1 )
    505             {
    506                 return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName();
    507             }
    508             return pClass->GetName();
    509         }
    510     }
    511     else if( IsProcPtr() ){
    512         if( index == 0 || index == -1 ){
    513             return "VoidPtr";
    514         }
    515         else{
    516             if( Smoothie::GetMeta().GetProcPointers()[index]->ReturnType().IsNull() ){
    517                 return "*Sub";
    518             }
    519             return "*Function";
    520         }
    521     }
    522     else{
    523         // 基本型
    524 
    525         for( int i=0; ; i++ ){
    526             if( basicTypeList[i] == DEF_NON ){
    527                 break;
    528             }
    529             if( basicTypeList[i] == basicType ){
    530                 return basicTypeNameList[i];
    531             }
    532         }
    533     }
    534 
    535     SmoothieException::Throw( 1 );
    536 
    537     return (string)"(null)";
    538 }
    539 
    540 Type Type::String(){
    541     return Type( DEF_OBJECT, *Smoothie::GetMeta().GetClasses().GetStringClassPtr() );
    542 }
    543 
    544433int Type::GetBasicTypeFromSimpleName( const char *variable ){
    545434    extern char DefIntVari[26],DefSngVari[26],DefStrVari[26],divNum,dsvNum,dStrvNum;
Note: See TracChangeset for help on using the changeset viewer.