Changeset 279 in dev for trunk


Ignore:
Timestamp:
Aug 14, 2007, 3:22:02 AM (17 years ago)
Author:
dai_9181
Message:

sourceをObjectModuleに入れた

Location:
trunk/abdev
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/MakePeHdr.cpp

    r278 r279  
    174174    // 名前空間情報を取得
    175175    NamespaceSupporter::CollectNamespaces(
    176         compiler.source.GetBuffer(),
     176        compiler.GetObjectModule().source.GetBuffer(),
    177177        compiler.GetObjectModule().meta.GetNamespaces()
    178178    );
     
    181181    //   CollectProcedures関数の中で参照されるオブジェクト名を事前に取得する。
    182182    //     ※オブジェクトの内容までは取得しない
    183     compiler.GetObjectModule().meta.GetClasses().CollectClassesForNameOnly( compiler.source );
     183    compiler.GetObjectModule().meta.GetClasses().CollectClassesForNameOnly( compiler.GetObjectModule().source );
    184184
    185185    //TypeDef情報を初期化
     
    192192    compiler.pCompilingClass = NULL;
    193193    CollectProcedures(
    194         compiler.source,
     194        compiler.GetObjectModule().source,
    195195        compiler.GetObjectModule().meta.GetUserProcs(),
    196196        compiler.GetObjectModule().meta.GetDllProcs()
     
    203203    compiler.GetObjectModule().meta.GetUserProcs().Iterator_Init();
    204204    compiler.GetObjectModule().meta.GetDllProcs().Iterator_Init();
    205 
    206 /*
    207     if( !compiler.GetObjectModule().WriteXml( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.xml" ) )
    208     {
    209         MessageBox(0,"XML書き込みに失敗","test",0);
    210     }
    211     ObjectModule *pTempObjectModule = new ObjectModule();
    212     if( !pTempObjectModule->ReadXml( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.xml" ) )
    213     {
    214         MessageBox(0,"XML読み込みに失敗","test",0);
    215     }
    216 
    217     if( !compiler.GetObjectModule().meta.WriteBinary( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    218     {
    219         MessageBox(0,"バイナリ書き込みに失敗","test",0);
    220     }
    221     Meta *pTempMeta = new Meta();
    222     if( !pTempMeta->ReadBinary( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    223     {
    224         MessageBox(0,"バイナリ読み込みに失敗","test",0);
    225     }
    226     if( !compiler.GetObjectModule().meta.WriteText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    227     {
    228         MessageBox(0,"バイナリ書き込みに失敗","test",0);
    229     }
    230     Meta *pTempMeta = new Meta();
    231     if( !pTempMeta->ReadText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    232     {
    233         MessageBox(0,"バイナリ読み込みに失敗","test",0);
    234     }
    235     compiler.objectModule = (*pTempObjectModule);*/
    236205
    237206
     
    526495        // 静的リンクライブラリ
    527496
    528         if( !compiler.GetObjectModule().WriteText( OutputFileName ) )
     497        if( !compiler.GetObjectModule().Write( OutputFileName ) )
    529498        {
    530499            MessageBox(0,"XML書き込みに失敗","test",0);
     
    537506
    538507    oldSourceLines = compiler.linker.GetNativeCode().GetSourceLines();
    539 
    540 /*
    541     int t,t2;
    542     t=GetTickCount();
    543     if( !compiler.GetObjectModule().WriteText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.xml" ) )
    544     {
    545         MessageBox(0,"XML書き込みに失敗","test",0);
    546     }
    547     if( !compiler.GetObjectModule().ReadText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.xml" ) )
    548     {
    549         MessageBox(0,"XML読み込みに失敗","test",0);
    550     }
    551     t2=GetTickCount();
    552     t2-=t;
    553     char s[100];
    554     sprintf(s,"%d",t2);
    555     MessageBox(0,s,"test",0);
    556    
    557     if( !compiler.GetObjectModule().meta.WriteBinary( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    558     {
    559         MessageBox(0,"バイナリ書き込みに失敗","test",0);
    560     }
    561     Meta *pTempMeta = new Meta();
    562     if( !pTempMeta->ReadBinary( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    563     {
    564         MessageBox(0,"バイナリ読み込みに失敗","test",0);
    565     }
    566     if( !compiler.GetObjectModule().meta.WriteText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    567     {
    568         MessageBox(0,"バイナリ書き込みに失敗","test",0);
    569     }
    570     Meta *pTempMeta = new Meta();
    571     if( !pTempMeta->ReadText( Jenga::Common::Environment::GetAppDir() + "\\objectModule_test.dat" ) )
    572     {
    573         MessageBox(0,"バイナリ読み込みに失敗","test",0);
    574     }*/
    575508
    576509
  • trunk/abdev/BasicCompiler_Common/BasicCompiler.cpp

    r276 r279  
    206206}
    207207
    208 void ShowErrorLine(int LineNum,char *FileName){
     208void ShowErrorLine(int LineNum,const char *constFileName){
    209209    HANDLE hFile;
    210210    DWORD dw;
     211    char FileName[MAX_PATH];
    211212    char temporary[MAX_PATH];
     213
     214    lstrcpy( FileName, constFileName );
    212215
    213216    if(LineNum==-1) return;
     
    216219        if(FileName){
    217220
    218             while(!IsFile(FileName)){
     221            while( !IsFileExist( FileName ) ){
    219222                char temp2[MAX_PATH],temp3[MAX_PATH];
    220223                _splitpath(FileName,NULL,NULL,temp2,temp3);
  • trunk/abdev/BasicCompiler_Common/BreakPoint.cpp

    r266 r279  
    4545
    4646void CFileBreakPoint::update(char *nativeCodeBuffer){
    47     extern INCLUDEFILEINFO IncludeFileInfo;
    48 
    4947    int FileNum;
    50     for(FileNum=0;FileNum<IncludeFileInfo.FilesNum;FileNum++){
    51         if(lstrcmpi(IncludeFileInfo.ppFileNames[FileNum],lpszFileName)==0) break;
     48    for(FileNum=0;FileNum<compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileCounts();FileNum++){
     49        if(lstrcmpi(compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFilePathFromFileNumber(FileNum).c_str(),lpszFileName)==0) break;
    5250    }
    53     if(FileNum==IncludeFileInfo.FilesNum) return;
     51    if( FileNum == compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileCounts() )
     52    {
     53        return;
     54    }
    5455
    5556    int i;
    5657    for(i=0;;i++){
    57         if(IncludeFileInfo.LineOfFile[i]==FileNum||
    58             IncludeFileInfo.LineOfFile[i]==-1) break;
     58        if( compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == FileNum
     59            || compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == -1 )
     60        {
     61            break;
     62        }
    5963    }
    60     if(IncludeFileInfo.LineOfFile[i]==-1) return;
     64    if( compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == -1 )
     65    {
     66        return;
     67    }
    6168
    6269    int FileBaseLine;
     
    6572    int i2,nCount=0;
    6673    for(i2=0;;i2++){
    67         if(IncludeFileInfo.LineOfFile[FileBaseLine+i2]==-1){
     74        if( compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( FileBaseLine+i2 ) == -1 )
     75        {
    6876            //ソースコードの終端行
    6977            break;
  • trunk/abdev/BasicCompiler_Common/Debug.cpp

    r276 r279  
    5555    /////////////////////////////////////////////////////////
    5656
    57     extern INCLUDEFILEINFO IncludeFileInfo;
    58 
    5957    int FileNum;
    60     for(FileNum=0;FileNum<IncludeFileInfo.FilesNum;FileNum++){
    61         if(lstrcmpi(IncludeFileInfo.ppFileNames[FileNum],szFilePath)==0) break;
    62     }
    63     if(FileNum==IncludeFileInfo.FilesNum) return;
     58    for(FileNum=0;FileNum<compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileCounts();FileNum++){
     59        if(lstrcmpi(compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFilePathFromFileNumber(FileNum).c_str(),szFilePath)==0) break;
     60    }
     61    if( FileNum == compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileCounts() )
     62    {
     63        return;
     64    }
    6465
    6566    for(i=0;;i++){
    66         if(IncludeFileInfo.LineOfFile[i]==FileNum||
    67             IncludeFileInfo.LineOfFile[i]==-1) break;
    68     }
    69     if(IncludeFileInfo.LineOfFile[i]==-1) return;
     67        if( compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == FileNum
     68            || compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == -1 )
     69        {
     70            break;
     71        }
     72    }
     73    if( compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) == -1 )
     74    {
     75        return;
     76    }
    7077
    7178    int FileBaseLine;
     
    7380
    7481    int i2;
    75     for(i2=0;;i++,i2++){
    76         if(FileNum<IncludeFileInfo.LineOfFile[i]){
    77             while(FileNum!=IncludeFileInfo.LineOfFile[i]) i++;
     82    for(i2=0;;i++,i2++)
     83    {
     84        if( FileNum < compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) )
     85        {
     86            while( FileNum != compiler.GetObjectModule().source.GetIncludedFilesRelation().GetFileNumber( i ) )
     87            {
     88                i++;
     89            }
    7890        }
    7991
  • trunk/abdev/BasicCompiler_Common/DebugMiddleFile.cpp

    r268 r279  
    5555}
    5656void CDebugSection::make(void){
    57     int i2,i3,BufferSize;
     57    int i2,BufferSize;
    5858
    5959    if(buffer){
     
    8181        // テキストデータにシリアライズ
    8282        std::string textString;
    83         compiler.GetObjectModule().WriteTextString( textString );
     83        compiler.GetObjectModule().WriteString( textString );
    8484
    8585        // サイズ
     
    100100        memcpy( buffer+i2, textString.c_str(), textString.size() );
    101101        i2 += (int)textString.size();
    102     }
    103 
    104     // ソースコード
    105     {
    106         int length = compiler.source.GetLength();
    107         if(BufferSize<i2+(int)length+32768){
    108             while( BufferSize<i2+(int)length+32768 )
    109             {
    110                 BufferSize+=32768;
    111             }
    112 
    113             buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
    114         }
    115 
    116         // バッファ
    117         lstrcpy( buffer + i2, compiler.source.GetBuffer() );
    118         i2 += lstrlen(buffer + i2) + 1;
    119     }
    120 
    121     //インクルード情報
    122     extern INCLUDEFILEINFO IncludeFileInfo;
    123     *(long *)(buffer+i2)=IncludeFileInfo.FilesNum;
    124     i2+=sizeof(long);
    125     for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
    126         lstrcpy(buffer+i2,IncludeFileInfo.ppFileNames[i3]);
    127         i2+=lstrlen(buffer+i2)+1;
    128     }
    129     for(i3=0;;i3++){
    130         buffer[i2++]=(char)IncludeFileInfo.LineOfFile[i3];
    131         if(IncludeFileInfo.LineOfFile[i3]==-1) break;
    132 
    133         //バッファが足りない場合は再確保
    134         if(BufferSize<i2+32768){
    135             BufferSize+=32768;
    136             buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
    137         }
    138102    }
    139103
     
    226190
    227191        // テキストデータからシリアライズ
    228         this->objectModule.ReadTextString( textString );
     192        this->objectModule.ReadString( textString );
    229193
    230194        compiler.SelectObjectModule( this->objectModule );
    231195    }
    232196
    233     // ソースコード
    234     {
    235         // バッファ
    236         compiler.source.SetBuffer(buffer+i2);
    237         i2 += lstrlen( buffer+i2 ) + 1;
    238     }
    239 
    240     //インクルード情報
    241     _IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
    242     i2+=sizeof(long);
    243     _IncludeFileInfo.ppFileNames=(char **)malloc(_IncludeFileInfo.FilesNum*sizeof(char *));
    244     for(i3=0;i3<_IncludeFileInfo.FilesNum;i3++){
    245         if(buffer[i2]=='\0') break;
    246         _IncludeFileInfo.ppFileNames[i3]=(char *)malloc(lstrlen(buffer+i2)+1);
    247         lstrcpy(_IncludeFileInfo.ppFileNames[i3],buffer+i2);
    248         i2+=lstrlen(buffer+i2)+1;
    249     }
    250     for(i3=0;;i3++){
    251         _IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2++];
    252         if(_IncludeFileInfo.LineOfFile[i3]==-1) break;
    253     }
    254197
    255198    //コードと行番号の関係
     
    294237    // ブレークポイントを適用
    295238    /////////////////////////////
    296 
    297     //インクルード情報
    298     extern INCLUDEFILEINFO IncludeFileInfo;
    299     IncludeFileInfo=this->_IncludeFileInfo;
    300239
    301240    //コードと行番号の関係
     
    412351    compiler.SelectObjectModule( this->objectModule );
    413352
    414     //インクルード情報
    415     extern INCLUDEFILEINFO IncludeFileInfo;
    416     IncludeFileInfo=this->_IncludeFileInfo;
    417 
    418353    //コードと行番号の関係
    419354    extern SourceLines oldSourceLines;
     
    433368
    434369void CDebugSection::DeleteDebugInfo(void){
    435     int i2;
    436 
    437     //インクルード情報を解放
    438     for(i2=0;i2<_IncludeFileInfo.FilesNum;i2++)
    439     {
    440         free(_IncludeFileInfo.ppFileNames[i2]);
    441     }
    442     free(_IncludeFileInfo.ppFileNames);
    443 
    444370    //コードバッファを解放
    445371    free(OpBuffer);
  • trunk/abdev/BasicCompiler_Common/DebugSection.h

    r266 r279  
    2727    // オブジェクトモジュール
    2828    ObjectModule objectModule;
    29 
    30     //インクルード情報
    31     INCLUDEFILEINFO _IncludeFileInfo;
    3229
    3330    //コードと行番号の関係
  • trunk/abdev/BasicCompiler_Common/Enum.cpp

    r268 r279  
    115115    iEnumParentNum=0;
    116116
    117     const char *source = compiler.source.GetBuffer();
     117    const char *source = compiler.GetObjectModule().source.GetBuffer();
    118118
    119119    // 名前空間管理
  • trunk/abdev/BasicCompiler_Common/Intermediate_Step1.cpp

    r271 r279  
    255255
    256256                compiler.staticLibraries.push_back( new ObjectModule() );
    257                 compiler.staticLibraries.back()->ReadText( temporary );
     257                compiler.staticLibraries.back()->Read( temporary );
    258258
    259259                for(;;i2++){
  • trunk/abdev/BasicCompiler_Common/MakeExe.cpp

    r273 r279  
    2424
    2525    //最後尾に貼り付け
    26     compiler.source.Addition( temp );
     26    compiler.GetObjectModule().source.Addition( temp );
    2727
    2828    HeapDefaultFree(temp);
     
    3535    extern BOOL bStopCompile;
    3636    extern HWND hMainDlg;
    37     int i2,i3;
     37    int i3;
    3838    char temp2[MAX_PATH];
    3939
     
    5757    //プログラムをファイルから読み込む
    5858    extern char SourceFileName[MAX_PATH];
    59     if( !compiler.source.ReadFile( SourceFileName ) ){
     59    if( !compiler.GetObjectModule().source.ReadFile( SourceFileName ) ){
    6060        SetError(201,SourceFileName,-1);
    6161        goto EndCompile;
     
    188188    ShowWindow(hMainDlg,SW_SHOW);
    189189#endif
    190 
    191     //#include情報を解放
    192     extern INCLUDEFILEINFO IncludeFileInfo;
    193     for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
    194     {
    195         free(IncludeFileInfo.ppFileNames[i2]);
    196     }
    197     free(IncludeFileInfo.ppFileNames);
    198190}
    199191int MainThread(DWORD dummy){
  • trunk/abdev/BasicCompiler_Common/StrOperation.cpp

    r266 r279  
    190190    }
    191191}
    192 BOOL GetLineNum(int pos,int *pLine,char *FileName){
    193     extern INCLUDEFILEINFO IncludeFileInfo;
    194     extern char *basbuf;
    195     int i,i2,i3,i4,i5;
    196 
    197     i=pos;
    198     if(basbuf[i]=='\n') i--;
    199     for(i3=0,i2=0;i3<i;i3++){
    200         if(basbuf[i3]=='\n') i2++;
    201         if(basbuf[i3]=='\0') return 0;
    202     }
    203     i4=0;
    204     while(IncludeFileInfo.LineOfFile[i2]!=IncludeFileInfo.LineOfFile[i4]) i4++;
    205     for(i3=0,i5=0;i5<i4;i3++){
    206         if(basbuf[i3]=='\n') i5++;
    207         if(basbuf[i3]=='\0') return 0;
    208     }
    209     for(i5=0;i4<i2;i3++){
    210         if(basbuf[i3]=='\n'){
    211             i4++;
    212             i5++;
    213             if(IncludeFileInfo.LineOfFile[i2]<IncludeFileInfo.LineOfFile[i4]){
    214                 for(;IncludeFileInfo.LineOfFile[i2]!=IncludeFileInfo.LineOfFile[i4];i3++){
    215                     if(basbuf[i3]=='\n') i4++;
    216                 }
    217             }
    218         }
    219         if(basbuf[i3]=='\0') return 0;
    220     }
    221 
    222     if(IncludeFileInfo.LineOfFile[i2]==-1){
    223         //ファイル・行番号を特定できなかった場合
    224         *pLine=-1;
    225         FileName[0]=0;
    226     }
    227     else{
    228         //行番号をセット
    229         *pLine=i5;
    230 
    231         //ファイル名をセット
    232         lstrcpy(FileName,IncludeFileInfo.ppFileNames[IncludeFileInfo.LineOfFile[i2]]);
    233     }
    234 
    235     return 1;
    236 }
    237192
    238193char GetEndXXXCommand(char es){
     
    449404}
    450405
    451 BOOL IsFile(char *path){
     406bool IsFileExist(const char *path){
    452407    WIN32_FIND_DATA wfd;
    453408    HANDLE hFind;
     
    455410    hFind=FindFirstFile(path,&wfd);
    456411    if(hFind==INVALID_HANDLE_VALUE){
    457         return 0;
     412        return false;
    458413    }
    459414    FindClose(hFind);
    460415
    461     return 1;
     416    return true;
    462417}
    463418BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle){
  • trunk/abdev/BasicCompiler_Common/VarList.cpp

    r265 r279  
    591591    }
    592592
    593     if(!GetLineNum(pobj_dti->lpdwCp[pobj_dti->iProcLevel],&i2,temporary)){
     593    std::string dummyStr;
     594    if(!compiler.GetObjectModule().source.GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel], i2, dummyStr )){
    594595        extern HWND hMainDlg;
    595596        //"デバッグ情報の取得に失敗"
     
    597598        return 0;
    598599    }
    599     ShowErrorLine(i2,temporary);
     600    ShowErrorLine(i2,dummyStr.c_str());
    600601
    601602    //プロシージャ コンボボックス
     
    666667    extern WNDPROC OldProcComboProc;
    667668    int i2,i3;
    668     char temporary[MAX_PATH];
    669669
    670670    switch(message){
     
    672672            if(HIWORD(wParam)==CBN_SELCHANGE){
    673673                i2=(int)SendMessage(hwnd,CB_GETCURSEL,0,0);
    674                 GetLineNum(pobj_dti->lpdwCp[pobj_dti->iProcLevel-i2],&i3,temporary);
    675                 ShowErrorLine(i3,temporary);
     674
     675                std::string dummyStr;
     676                compiler.GetObjectModule().source.GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel-i2], i3, dummyStr );
     677                ShowErrorLine(i3,dummyStr.c_str());
    676678
    677679                RefreshLocalVar_with_WindowLock();
  • trunk/abdev/BasicCompiler_Common/common.h

    r263 r279  
    219219void GetRelationalPath(char *path,char *dir);
    220220void GetFullPath( char *path, const string &baseDirPath );
    221 void ShowErrorLine(int LineNum,char *FileName);
     221void ShowErrorLine(int LineNum,const char *FileName);
    222222BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
    223223void MakeMessageText(char *buffer,char *msg,int flag);
     
    318318void SlideBuffer(char *buffer,int length,int slide);
    319319int GetCpFromLine(int LineNum);
    320 BOOL GetLineNum(int pos,int *pLine,char *FileName);
    321320char GetEndXXXCommand(char es);
    322321void GetDefaultNameFromES(char es,char *name);
    323322const std::string &FormatEscapeSequenceStringToDefaultString( const std::string &source );
    324 BOOL IsFile(char *path);
     323bool IsFileExist(const char *path);
    325324BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath);
    326325BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
  • trunk/abdev/BasicCompiler_Common/error.cpp

    r206 r279  
    44
    55#include <Program.h>
    6 #include <Class.h>
     6#include <Compiler.h>
    77
    88#include "../BasicCompiler_Common/common.h"
     
    291291    extern ERRORINFO *pErrorInfo;
    292292    extern int ErrorNum;
    293     char temporary[1024],temp2[1024],temp3[32],FileName[MAX_PATH];
     293    char temporary[1024],temp2[1024],temp3[32];
    294294    BOOL bFirst;
    295295    int i2;
     
    329329    }
    330330    else{
    331         GetLineNum(pos,&pErrorInfo[ErrorNum].line,FileName);
    332 
    333         pErrorInfo[ErrorNum].FileName=(char *)HeapAlloc(hHeap,0,lstrlen(FileName)+1);
    334         lstrcpy(pErrorInfo[ErrorNum].FileName,FileName);
     331        std::string dummyStr;
     332        compiler.GetObjectModule().source.GetLineInfo( pos, pErrorInfo[ErrorNum].line, dummyStr );
     333
     334        pErrorInfo[ErrorNum].FileName=(char *)HeapAlloc(hHeap,0,lstrlen(dummyStr.c_str())+1);
     335        lstrcpy(pErrorInfo[ErrorNum].FileName,dummyStr.c_str());
    335336
    336337        _splitpath(pErrorInfo[ErrorNum].FileName,0,0,temp2,temp3);
  • trunk/abdev/BasicCompiler_Common/include/BoostSerializationSupport.h

    r264 r279  
    2525    bool ReadXml( const std::string &xmlFilePath, bool isShowExceptionMessage = true );
    2626    bool WriteXml( const std::string &xmlFilePath, bool isShowExceptionMessage = true ) const;
     27    bool ReadXmlString( const std::string &xmlString );
     28    bool WriteXmlString( std::string &xmlString ) const;
    2729
    2830    bool ReadBinary( const std::string &filePath, bool isShowExceptionMessage = true );
  • trunk/abdev/BasicCompiler_Common/include/Compiler.h

    r270 r279  
    4646        return namespaceSupporter;
    4747    }
    48 
    49     // ソースコード
    50     BasicSource source;
    5148
    5249    // コード生成機構
  • trunk/abdev/BasicCompiler_Common/include/DataTable.h

    r273 r279  
    2828        for( int i=0; i<size; i++ )
    2929        {
    30             if( _buffer[i*3+2] != ',' )
    31             {
    32                 //エラー
    33                 DebugBreak();
    34             }
    35             ULONG_PTR l;
    36             sscanf( _buffer.c_str() + i*3, "%02x,", &l );
    37             buffer[i] = (char)l;
     30            ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
     31            ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
     32            ULONG_PTR l = l1 + l2;
     33            buffer[i] = static_cast<char>(l);
    3834        }
    3935    }
  • trunk/abdev/BasicCompiler_Common/include/NativeCode.h

    r278 r279  
    219219        for( int i=0; i<size; i++ )
    220220        {
    221             ULONG_PTR l;
    222             sscanf( code.c_str() + i*3, "%02x,", &l );
    223             codeBuffer[i] = (char)l;
     221            ULONG_PTR l1 = ( ( code[i*3] >= 'a' ) ? ( code[i*3] - 'a' + 0x0a ) : ( code[i*3] - '0' ) ) * 0x10;
     222            ULONG_PTR l2 = ( code[i*3+1] >= 'a' ) ? ( code[i*3+1] - 'a' + 0x0a ) : ( code[i*3+1] - '0' );
     223            ULONG_PTR l = l1 + l2;
     224            codeBuffer[i] = static_cast<char>(l);
    224225        }
    225226    }
  • trunk/abdev/BasicCompiler_Common/include/ObjectModule.h

    r273 r279  
    1212    // データテーブル
    1313    DataTable dataTable;
     14
     15    // ソースコード
     16    BasicSource source;
    1417
    1518    // XMLシリアライズ用
     
    2730        ar & BOOST_SERIALIZATION_NVP( globalNativeCode );
    2831        ar & BOOST_SERIALIZATION_NVP( dataTable );
     32        ar & BOOST_SERIALIZATION_NVP( source );
    2933    }
    3034
    3135public:
    3236    void StaticLink( ObjectModule &objectModule );
     37
     38    bool Read( const std::string &filePath );
     39    bool Write( const std::string &filePath ) const;
     40    bool ReadString( const std::string &str );
     41    bool WriteString( std::string &str ) const;
    3342};
    3443typedef std::vector<ObjectModule *> ObjectModules;
  • trunk/abdev/BasicCompiler_Common/include/Source.h

    r268 r279  
    1818    int FilesNum;
    1919    int LineOfFile[MAX_LEN];
     20};
     21
     22class IncludedFilesRelation
     23{
     24    std::vector<std::string> filePaths;
     25    std::vector<int> lineFileNumbers;
     26
     27    // XMLシリアライズ用
     28private:
     29    friend class boost::serialization::access;
     30    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     31    {
     32        trace_for_serialize( "serializing - IncludedFilesRelation" );
     33
     34        ar & BOOST_SERIALIZATION_NVP( filePaths );
     35        ar & BOOST_SERIALIZATION_NVP( lineFileNumbers );
     36    }
     37
     38public:
     39    IncludedFilesRelation()
     40    {
     41    }
     42    ~IncludedFilesRelation()
     43    {
     44    }
     45
     46    const int GetFileNumber( int lineNumber ) const
     47    {
     48        return lineFileNumbers[lineNumber];
     49    }
     50    const std::string &GetFilePath( int lineNumber ) const
     51    {
     52        return filePaths[GetFileNumber( lineNumber )];
     53    }
     54    const std::string &GetFilePathFromFileNumber( int fileNumber ) const
     55    {
     56        return filePaths[fileNumber];
     57    }
     58    int GetFileCounts() const
     59    {
     60        return filePaths.size();
     61    }
     62
     63    int AddFile( const std::string &filePath )
     64    {
     65        filePaths.push_back( filePath );
     66        return filePaths.size()-1;
     67    }
     68    void AddLine( int fileNumber )
     69    {
     70        lineFileNumbers.push_back( fileNumber );
     71    }
     72
     73    int GetLineCounts() const
     74    {
     75        return lineFileNumbers.size();
     76    }
    2077};
    2178
     
    66123    static const string generateDirectiveName;
    67124
     125    IncludedFilesRelation includedFilesRelation;
     126
     127    // XMLシリアライズ用
     128private:
     129    friend class boost::serialization::access;
     130    BOOST_SERIALIZATION_SPLIT_MEMBER();
     131    template<class Archive> void load(Archive& ar, const unsigned int version)
     132    {
     133        trace_for_serialize( "serializing(load) - BasicSource" );
     134
     135        std::string _buffer;
     136        ar & BOOST_SERIALIZATION_NVP( _buffer );
     137        ar & BOOST_SERIALIZATION_NVP( length );
     138        ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
     139
     140        // 読み込み後の処理
     141        Realloc( length );
     142        for( int i=0; i<length; i++ )
     143        {
     144            ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
     145            ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
     146            ULONG_PTR l = l1 + l2;
     147            buffer[i] = static_cast<char>(l);
     148        }
     149        buffer[length] = 0;
     150    }
     151    template<class Archive> void save(Archive& ar, const unsigned int version) const
     152    {
     153        trace_for_serialize( "serializing(save) - BasicSource" );
     154
     155        // 保存準備
     156        char *tempCode = (char *)calloc( (length+1) * 3, 1 );
     157        for( int i=0; i<length; i++ )
     158        {
     159            char temp[32];
     160            sprintf( temp, "%02x,", (unsigned char)buffer[i] );
     161            tempCode[i*3] = temp[0];
     162            tempCode[i*3+1] = temp[1];
     163            tempCode[i*3+2] = temp[2];
     164        }
     165
     166        std::string _buffer = tempCode;
     167        free( tempCode );
     168
     169        ar & BOOST_SERIALIZATION_NVP( _buffer );
     170        ar & BOOST_SERIALIZATION_NVP( length );
     171        ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
     172    }
     173
     174private:
    68175    void Realloc( int newLength ){
    69176        buffer = (char *)realloc( buffer, newLength + 255 );
     
    102209    }
    103210
     211    const IncludedFilesRelation &GetIncludedFilesRelation() const
     212    {
     213        return includedFilesRelation;
     214    }
     215
    104216    void SetBuffer( const char *buffer );
    105217
     
    109221
    110222    void Addition( const char *buffer );
     223
     224    bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName );
    111225
    112226    void operator = ( const BasicSource &source ){
  • trunk/abdev/BasicCompiler_Common/src/BoostSerializationSupport.cpp

    r264 r279  
    115115    return result;
    116116}
     117template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXmlString( const std::string &xmlString )
     118{
     119    bool isSuccessful = false;
     120
     121    // 入力アーカイブの作成
     122    std::istringstream iss( xmlString );
     123
     124    try{
     125        boost::archive::xml_iarchive ia(iss);
     126
     127        // 文字列ストリームから読込
     128        ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
     129
     130        isSuccessful = true;
     131    }
     132    catch(...){
     133        // 失敗
     134    }
     135
     136    if( !isSuccessful )
     137    {
     138        return false;
     139    }
     140
     141    return true;
     142}
     143template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXmlString( std::string &xmlString ) const
     144{
     145    // 出力アーカイブの作成
     146    std::ostringstream oss;
     147
     148    bool isSuccessful = false;
     149    try{
     150        boost::archive::xml_oarchive oa(oss);
     151
     152        // 文字列ストリームに書き出し
     153        oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
     154
     155        isSuccessful = true;
     156    }
     157    catch( boost::archive::archive_exception e )
     158    {
     159        echo( e.what() );
     160    }
     161    catch(...){
     162        echo( "archive_exception以外の不明な例外" );
     163    }
     164
     165    if( !isSuccessful )
     166    {
     167        return false;
     168    }
     169
     170    xmlString = oss.str();
     171
     172    return true;
     173}
    117174
    118175template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadBinary( const string &filePath, bool isShowExceptionMessage )
  • trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp

    r276 r279  
    22
    33#include <Compiler.h>
     4
     5enum ObjectModuleDataType
     6{
     7    ObjectModuleDataTypeXml,
     8    ObjectModuleDataTypeText,
     9    ObjectModuleDataTypeBinaly,
     10};
     11const ObjectModuleDataType objectModuleDataType = ObjectModuleDataTypeText;
     12
    413
    514void ObjectModule::StaticLink( ObjectModule &objectModule )
     
    1524    dataTable.Add( objectModule.dataTable );
    1625}
     26
     27bool ObjectModule::Read( const std::string &filePath )
     28{
     29    switch( objectModuleDataType )
     30    {
     31    case ObjectModuleDataTypeXml:
     32        return ReadXml( filePath );
     33    case ObjectModuleDataTypeText:
     34        return ReadText( filePath );
     35    case ObjectModuleDataTypeBinaly:
     36        return ReadBinary( filePath );
     37    default:
     38        Jenga::Throw( "" );
     39        break;
     40    }
     41    return false;
     42}
     43bool ObjectModule::Write( const std::string &filePath ) const
     44{
     45    switch( objectModuleDataType )
     46    {
     47    case ObjectModuleDataTypeXml:
     48        return WriteXml( filePath );
     49    case ObjectModuleDataTypeText:
     50        return WriteText( filePath );
     51    case ObjectModuleDataTypeBinaly:
     52        return WriteBinary( filePath );
     53    default:
     54        Jenga::Throw( "" );
     55        break;
     56    }
     57    return false;
     58}
     59bool ObjectModule::ReadString( const std::string &str )
     60{
     61    switch( objectModuleDataType )
     62    {
     63    case ObjectModuleDataTypeXml:
     64        return ReadXmlString( str );
     65    case ObjectModuleDataTypeText:
     66        return ReadTextString( str );
     67    case ObjectModuleDataTypeBinaly:
     68        Jenga::Throw( "" );
     69        break;
     70    default:
     71        Jenga::Throw( "" );
     72        break;
     73    }
     74    return false;
     75}
     76bool ObjectModule::WriteString( std::string &str ) const
     77{
     78    switch( objectModuleDataType )
     79    {
     80    case ObjectModuleDataTypeXml:
     81        return WriteXmlString( str );
     82    case ObjectModuleDataTypeText:
     83        return WriteTextString( str );
     84    case ObjectModuleDataTypeBinaly:
     85        Jenga::Throw( "" );
     86        break;
     87    default:
     88        Jenga::Throw( "" );
     89        break;
     90    }
     91    return false;
     92}
  • trunk/abdev/BasicCompiler_Common/src/Source.cpp

    r270 r279  
    1313#include <Compiler.h>
    1414
    15 
    16 INCLUDEFILEINFO IncludeFileInfo;
    1715
    1816const string BasicSource::generateDirectiveName = "#generate";
     
    537535    char temporary[MAX_PATH],temp2[MAX_PATH+255],*LayerDir[255];
    538536
    539     IncludeFileInfo.ppFileNames=(char **)calloc(sizeof(char *),1);
    540     extern char SourceFileName[MAX_PATH];
    541     IncludeFileInfo.ppFileNames[0]=(char *)malloc(lstrlen(SourceFileName)+1);
    542     lstrcpy(IncludeFileInfo.ppFileNames[0],SourceFileName);
    543     IncludeFileInfo.FilesNum=1;
    544 
    545537    layer=0;
    546538    FileLayer[layer]=0;
     
    548540    LineNum=0;
    549541
     542    if( includedFilesRelation.GetLineCounts() != 0 )
     543    {
     544        Jenga::Throw( "インクルードファイル構造の初期値が不正" );
     545    }
     546
     547    // メインソースコード
     548    extern char SourceFileName[MAX_PATH];
     549    FileLayer[layer] = includedFilesRelation.AddFile( SourceFileName );
     550
    550551    //参照ディレクトリ
    551552    LayerDir[0]=(char *)malloc(lstrlen(BasicCurDir)+1);
     
    554555    for(i=0;;i++){
    555556        if(buffer[i]=='\0'){
    556             IncludeFileInfo.LineOfFile[LineNum]=-1;
    557557            break;
    558558        }
    559559        if(buffer[i]=='\n'){
    560             IncludeFileInfo.LineOfFile[LineNum]=FileLayer[layer];
    561             LineNum++;
     560            includedFilesRelation.AddLine( FileLayer[layer] );
    562561        }
    563562        if(i>LastFileByte[layer]){
     
    624623            }
    625624
    626             IncludeFileInfo.ppFileNames=(char **)realloc(IncludeFileInfo.ppFileNames,(IncludeFileInfo.FilesNum+1)*sizeof(char *));
    627             IncludeFileInfo.ppFileNames[IncludeFileInfo.FilesNum]=(char *)malloc(lstrlen(temporary)+1);
    628             lstrcpy(IncludeFileInfo.ppFileNames[IncludeFileInfo.FilesNum],temporary);
    629 
    630625            layer++;
    631             FileLayer[layer]=IncludeFileInfo.FilesNum;
    632             IncludeFileInfo.FilesNum++;
     626            FileLayer[layer] = includedFilesRelation.AddFile( temporary );
    633627
    634628            //#requireの場合では、既に読み込まれているファイルは読み込まないようにする
     
    926920    lstrcat( this->buffer, buffer );
    927921}
     922
     923bool BasicSource::GetLineInfo( int sourceCodePos, int &line, std::string &filePath )
     924{
     925    int i2,i3,i4,i5;
     926
     927    char *buffer = GetBuffer();
     928    int i = sourceCodePos;
     929
     930    if(buffer[i]=='\n') i--;
     931    for(i3=0,i2=0;i3<i;i3++){
     932        if(buffer[i3]=='\n') i2++;
     933        if(buffer[i3]=='\0') return 0;
     934    }
     935
     936    if( includedFilesRelation.GetLineCounts() < i2 )
     937    {
     938        Jenga::Throw( "BasicSource::GetLineInfoメソッドで不正な行の情報を取得しようとした" );
     939
     940        //ファイル・行番号を特定できなかった場合
     941        line = -1;
     942        filePath = "";
     943        return false;
     944    }
     945
     946    i4=0;
     947    while( includedFilesRelation.GetFileNumber( i2 ) != includedFilesRelation.GetFileNumber( i4 ) )
     948    {
     949        i4++;
     950    }
     951    for(i3=0,i5=0;i5<i4;i3++){
     952        if(buffer[i3]=='\n') i5++;
     953        if(buffer[i3]=='\0') return 0;
     954    }
     955    for(i5=0;i4<i2;i3++){
     956        if(buffer[i3]=='\n'){
     957            i4++;
     958            i5++;
     959            if( includedFilesRelation.GetFileNumber( i2 ) < includedFilesRelation.GetFileNumber( i4 ) )
     960            {
     961                for( ;includedFilesRelation.GetFileNumber( i2 ) != includedFilesRelation.GetFileNumber( i4 ); i3++ ){
     962                    if(buffer[i3]=='\n') i4++;
     963                }
     964            }
     965        }
     966        if(buffer[i3]=='\0') return 0;
     967    }
     968
     969    //行番号をセット
     970    line = i5;
     971
     972    //ファイル名をセット
     973    filePath = includedFilesRelation.GetFilePath( i2 );
     974
     975    return 1;
     976}
Note: See TracChangeset for help on using the changeset viewer.