#include "stdafx.h" #include #include "common.h" void StepCompileProgress(void){ extern HWND hMainDlg; PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0); } void MakeMiddleCode( char *buffer ) { // 改行コードをCRLFからLFにする ChangeReturnCode( buffer ); // コメントを除去 DeleteComment( buffer ); //エスケープシーケンス設定 SetEscapeSequenceFormat( buffer ); //コマンド対応 ChangeCommandToCode( buffer ); } void AddSourceCode(const char *buffer){ char *temp; temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192); lstrcpy(temp,buffer); MakeMiddleCode( temp ); //最後尾に貼り付け compiler.GetObjectModule().GetCurrentSource().Addition( temp ); HeapDefaultFree(temp); } void OutputExe(void){ extern HANDLE hHeap; extern char *basbuf; extern BOOL bStopCompile; extern HWND hMainDlg; int i3; char temp2[MAX_PATH]; // 開始時刻を記録 DWORD beforeTickCount = GetTickCount(); //プログレスバーの設定 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6)); PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0); //"中断" SetDlgItemText(hMainDlg,IDOK,STRING_STOP); //中断フラグを初期化 bStopCompile=0; //サブシステムのタイプ extern unsigned short TypeOfSubSystem; TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI; //プログラムをファイルから読み込む compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() ); compiler.GetObjectModule().GetSources().push_back( BasicSource() ); if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( program.GetSourceFilePath() ) ){ compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1); goto EndCompile; } //イメージベースの設定 extern DWORD ImageBase; if(compiler.IsDll()) ImageBase=0x10000000; else ImageBase=0x00400000; if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile; ////////////////////////// // 中間コードの生成を開始 //"最適化中..." compiler.messenger.Output( STRING_COMPILE_OPTIMIZING ); //カッコを相互チェック(ダブルクォートチェックチェックを含む) CheckParenthesis(basbuf); if( compiler.errorMessenger.HasError() || bStopCompile ) { goto EndCompile; } //コンパイルダイアログのプログレスバーを上げる StepCompileProgress(); //ディレクティブ DirectiveCheck(); //Next命令語を正規表現に変換 //NextCommandFormat(basbuf); //エスケープシーケンス設定 SetEscapeSequenceFormat(basbuf); //Def命令語をFunction命令語に変換 DefCommandFormat(basbuf); //すべてのIf命令語をブロック形式に変換 IfCommandFormat(basbuf); //対になる命令語を相互チェック //CheckPareCommand(); if( compiler.errorMessenger.HasError() || bStopCompile ) { goto EndCompile; } //コンパイルダイアログのプログレスバーを上げる StepCompileProgress(); // 重複エラー情報をクリア compiler.errorMessenger.ClearSynonymKeyWords(); ChangeCommandToCode(basbuf); compiler.GetObjectModule().GetSources()[0]._ResetLength(); if( compiler.errorMessenger.HasError() || bStopCompile ) { //定数に関する情報を解放 goto EndCompile; } StepCompileProgress(); ///////////////////////////////////////////////////////////////// // 静的リンクライブラリをロードする ///////////////////////////////////////////////////////////////// { bool isSuccessfulLoadStaticLinkLibrary = true; if( !compiler.IsCore() ) { // コアモジュールをロードする extern BOOL bDebugCompile; const char *coreFileName = "core.lib"; if( compiler.IsDebug() ) { coreFileName = "cored.lib"; } char coreFilePath[MAX_PATH]; #ifdef _AMD64_ sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName ); #else sprintf( coreFilePath, "..\\lib\\%s", coreFileName ); #endif GetFullPath( coreFilePath, program.GetIncludeDir() ); Jenga::Common::Path path( coreFilePath ); if( path.IsExistFile() ) { compiler.staticLibraries.push_back( new ObjectModule() ); if( compiler.staticLibraries.back()->Read( coreFilePath ) ) { compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() ); } else { compiler.errorMessenger.Output( 203, path.GetFullPath() ); isSuccessfulLoadStaticLinkLibrary = false; } } else { compiler.errorMessenger.Output( 202, path.GetFullPath() ); isSuccessfulLoadStaticLinkLibrary = false; } } BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths ) { Jenga::Common::Path path( filePath ); if( path.IsExistFile() ) { compiler.staticLibraries.push_back( new ObjectModule() ); if( compiler.staticLibraries.back()->Read( filePath ) ) { compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() ); } else { compiler.errorMessenger.Output( 203, path.GetFullPath() ); isSuccessfulLoadStaticLinkLibrary = false; } } else { compiler.errorMessenger.Output( 202, path.GetFullPath() ); isSuccessfulLoadStaticLinkLibrary = false; } } if( !isSuccessfulLoadStaticLinkLibrary ) { // 静的リンクライブラリのロードに失敗したとき goto EndCompile; } } /////////////////////// // コンパイル開始 //"コンパイル中..." compiler.messenger.Output(STRING_COMPILE_COMPILING); Compile(); //リソース情報を解放 extern RESOURCEDATAINFO *pCursorResourceInfo; extern RESOURCEDATAINFO *pIconResourceInfo; extern RESOURCEDATAINFO *pBitmapResourceInfo; HeapDefaultFree(pCursorResourceInfo); HeapDefaultFree(pBitmapResourceInfo); HeapDefaultFree(pIconResourceInfo); //コンパイルダイアログのプログレスバーを上げる StepCompileProgress(); ////////////////////////// // 終了処理 EndCompile: if(bStopCompile){ PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0); //"コンパイルはユーザーにより中断されました。" compiler.messenger.Output(STRING_COMPILE_STOP); } else{ extern int WarningNum; if( !compiler.errorMessenger.HasError() ) { //"コンパイルは正常に完了しました(エラー:%d、警告:%d)" sprintf(temp2, STRING_COMPILE_SUCCESS, compiler.errorMessenger.GetErrorCount(), compiler.errorMessenger.GetWarningCount(), ((double)(GetTickCount() - beforeTickCount))/1000 ); } else { //"コンパイルは中断されました(エラー:%d、警告:%d)" sprintf(temp2,STRING_COMPILE_ERROR, compiler.errorMessenger.GetErrorCount(), compiler.errorMessenger.GetWarningCount() ); } compiler.messenger.Output( "" ); compiler.messenger.Output( "-----------------------------------------------------" ); compiler.messenger.Output( temp2 ); } //"閉じる" SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE); // エラーがない場合はビルド成功とする if( !compiler.errorMessenger.HasError() ) { // ビルド成功 compiler.BuildSuccessful(); } #ifdef _DEBUG // デバッグモードのときはダイアログが隠れている ShowWindow(hMainDlg,SW_SHOW); #endif } void MainThread(void *dummy) { if( program.IsDebugRun() ) { if( compiler.IsDebug() ) { //デバッグコンパイル OutputExe(); } //デバッグ実行 if( !compiler.errorMessenger.HasError() ) { DebugProgram(); } } else{ //リリースコンパイル OutputExe(); } }