Changeset 387 in dev


Ignore:
Timestamp:
Feb 11, 2008, 12:06:15 PM (16 years ago)
Author:
dai_9181
Message:

メンバ情報を保持するようにした

Location:
trunk/abdev/BasicCompiler_Common
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/StrOperation.cpp

    r313 r387  
    5757    return 1;
    5858}
     59bool RemoveStringQuotes( std::string &str )
     60{
     61    if( str[0] != '\"' )
     62    {
     63        return false;
     64    }
     65
     66    str = str.substr( 1, str.length() - 2 );
     67    return true;
     68}
    5969void RemoveStringPare(char *str){
    6070    int i;
  • trunk/abdev/BasicCompiler_Common/common.h

    r381 r387  
    315315void KillStringSpaces(char *str);
    316316BOOL RemoveStringQuotes(char *str);
     317bool RemoveStringQuotes( std::string &str );
    317318void RemoveStringPare(char *str);
    318319void RemoveStringBracket(char *str);
  • trunk/abdev/BasicCompiler_Common/include/Class.h

    r382 r387  
    561561    }
    562562
     563    // 動的型データ用のメンバデータを取得
     564    std::string GetStaticDefiningStringAsMemberNames() const;
     565    std::string GetStaticDefiningStringAsMemberTypeInfoNames() const;
     566
    563567
    564568    //線形リスト用
  • trunk/abdev/BasicCompiler_Common/include/DataTable.h

    r355 r387  
    9898    int AddString( const char *str, int length );
    9999    int AddString( const char *str );
     100    int AddString( const std::string &str );
    100101    void Add( const DataTable &dataTable )
    101102    {
     
    116117        }
    117118    }
     119    int AddSpace( int size );
     120    void AddAlignment( int size );
    118121
    119122    const void *GetPtr() const
     
    142145        *(_int64 *)( buffer + pos ) = new64Value;
    143146    }
     147    void OverwriteBinary( int pos, const void *ptr, int size )
     148    {
     149        memcpy( buffer + pos, ptr, size );
     150    }
    144151
    145152    bool MakeConstObjectToProcessStaticBuffer( const CClass &objClass, const Jenga::Common::Strings &initMemberValues, int &dataTableOffset );
  • trunk/abdev/BasicCompiler_Common/src/Class.cpp

    r384 r387  
    11511151    ////////////////////////////////////////////////////////////////////
    11521152
    1153     char temporary[VN_SIZE];
     1153    char temporary[8192];
    11541154    sprintf(temporary, "%c%ctempType=Nothing%c%cTypeBaseImpl"
    11551155        , HIBYTE( COM_DIM )
     
    11751175                , "tempType=Search(\"%s\")"
    11761176                , objClass.GetFullName().c_str()
    1177                 );
     1177            );
    11781178
    11791179            // コンパイル
     
    11831183                , "tempType.SetBaseType(Search(\"%s\"))"
    11841184                , objClass.GetSuperClass().GetFullName().c_str()
    1185                 );
     1185            );
    11861186
    11871187            // コンパイル
    11881188            ChangeOpcode( temporary );
    1189         }
    1190     }
    1191 
    1192 
    1193 
    1194     ////////////////////////////////////////////////////////////////////
    1195     // 継承関係登録
    1196     ////////////////////////////////////////////////////////////////////
    1197     // TODO: 未完成
    1198     /*
    1199 
    1200     // イテレータをリセット
    1201     Iterator_Reset();
    1202 
    1203     while( Iterator_HasNext() ){
    1204         CClass *pClass = Iterator_GetNext();
    1205 
    1206         sprintf( genBuffer + length
    1207             , "obj.Search( \"%s\" ).SetBaseType( Search( \"%s\" ) ):"
    1208             , ""                // クラス名
    1209             , pClass->name      // クラス名
     1189
     1190
     1191            // メンバの型を示すTypeInfoオブジェクトへのDataOffset配列の静的データ定義文字列を取得
     1192            sprintf(
     1193                temporary,
     1194                "tempType.SetMemberTypes([%s],[%s],%d)",
     1195                objClass.GetStaticDefiningStringAsMemberNames().c_str(),
     1196                objClass.GetStaticDefiningStringAsMemberTypeInfoNames().c_str(),
     1197                objClass.GetDynamicMembers().size()
    12101198            );
    1211         length += lstrlen( genBuffer + length );
    1212 
    1213         while( length + 8192 > max ){
    1214             max += 8192;
    1215             genBuffer = (char *)realloc( genBuffer, max );
    1216         }
    1217     }*/
     1199            ChangeOpcode( temporary );
     1200        }
     1201    }
    12181202}
    12191203
     
    13471331    return pInterfaceInfo;
    13481332}
     1333
     1334std::string CClass::GetStaticDefiningStringAsMemberNames() const
     1335{
     1336    std::string result;
     1337
     1338    BOOST_FOREACH( const CMember *pMember, dynamicMembers )
     1339    {
     1340        if( result.size() )
     1341        {
     1342            result += ",";
     1343        }
     1344
     1345        result += "\"" + pMember->GetName() + "\"";
     1346    }
     1347
     1348    return result;
     1349}
     1350std::string CClass::GetStaticDefiningStringAsMemberTypeInfoNames() const
     1351{
     1352    std::string result;
     1353
     1354    BOOST_FOREACH( const CMember *pMember, dynamicMembers )
     1355    {
     1356        if( result.size() )
     1357        {
     1358            result += ",";
     1359        }
     1360
     1361        result += "\"" + compiler.TypeToString( pMember->GetType() ) + "\"";
     1362    }
     1363
     1364    return result;
     1365}
     1366
  • trunk/abdev/BasicCompiler_Common/src/DataTable.cpp

    r370 r387  
    6565    return retSize;
    6666}
    67 int DataTable::AddString( const char *str ){
    68     int retSize = size;
    69     AddString( str, lstrlen( str ) );
    70     return retSize;
     67int DataTable::AddString( const char *str )
     68{
     69    return AddString( str, lstrlen( str ) );
     70}
     71int DataTable::AddString( const std::string &str )
     72{
     73    return AddString( str.c_str(), static_cast<int>(str.length()) );
     74}
     75int DataTable::AddSpace( int size )
     76{
     77    int retSize = this->size;
     78    Realloc( this->size + size );
     79    return retSize;
     80}
     81void DataTable::AddAlignment( int size )
     82{
     83    if( this->size % size == 0 )
     84    {
     85        // 既に境界のとき
     86        return;
     87    }
     88    Realloc( this->size + ( size - (int)(this->size%size) ) );
    7189}
    7290
     
    262280    RemoveStringBracket( buffer );
    263281
    264     void *binary = malloc( 1 );
    265     int num = 0;
    266 
     282    Jenga::Common::Strings parameters;
     283    SplitParameter( buffer, parameters );
     284
     285    // アラインメント
     286    AddAlignment( tempBaseType.GetSize() );
     287
     288    // データテーブルに空間を確保
     289    dataTableOffset = AddSpace( static_cast<int>(tempBaseType.GetSize() * parameters.size()) );
     290
     291    bool isSuccessful = true;
    267292    int i = 0;
    268     bool isSuccessful = true;
    269     while( buffer[i] ){
    270         char temporary[1024];
    271 
    272         i = GetOneParameter( buffer, i, temporary );
    273         if( buffer[i] == ',' ){
    274             i++;
    275         }
    276 
    277         Type resultType;
    278         _int64 i64data;
    279         if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
    280             isSuccessful = false;
    281             break;
    282         }
    283         if( !resultType.IsWhole() ){
    284             // TODO: 実数に未対応
    285             SetError();
    286             isSuccessful = false;
    287             break;
    288         }
    289 
    290         binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
    291         memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
    292         num++;
     293    BOOST_FOREACH( const std::string &paramStr, parameters )
     294    {
     295        if( paramStr[0] == '\"' )
     296        {
     297            // 文字列
     298            std::string tempParamStr = paramStr;
     299            if( !RemoveStringQuotes( tempParamStr ) )
     300            {
     301                SetError();
     302            }
     303
     304            // 文字列を追加
     305            _int64 strOffset = this->AddString( tempParamStr );
     306
     307            // ポインタ値を上書き
     308            int tempOffset = dataTableOffset + i * tempBaseType.GetSize();
     309            this->OverwriteBinary( tempOffset, &strOffset, tempBaseType.GetSize() );
     310
     311            // DataTableスケジュール
     312            this->schedules.push_back( Schedule( Schedule::DataTable, tempOffset  ) );
     313        }
     314        else
     315        {
     316            // 数値
     317            Type resultType;
     318            _int64 i64data;
     319            if( !StaticCalculation( true, paramStr.c_str(), tempBaseType.GetBasicType(), &i64data, resultType ) ){
     320                isSuccessful = false;
     321                break;
     322            }
     323            if( !resultType.IsWhole() ){
     324                // TODO: 実数に未対応
     325                SetError();
     326                isSuccessful = false;
     327                break;
     328            }
     329
     330            // 上書き
     331            this->OverwriteBinary( dataTableOffset + i * tempBaseType.GetSize(), &i64data, tempBaseType.GetSize() );
     332        }
     333
     334        i++;
    293335    }
    294336
    295337    free( buffer );
    296 
    297     dataTableOffset = this->AddBinary( binary, num * tempBaseType.GetSize() );
    298 
    299     free( binary );
    300338
    301339    return isSuccessful;
Note: See TracChangeset for help on using the changeset viewer.