source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/MakeExe.cpp@ 541

Last change on this file since 541 was 541, checked in by dai_9181, 16 years ago

SynonymErrorWordsを排除。
ClearSynonymErrorWordsメソッドを追加。

File size: 7.3 KB
RevLine 
[206]1#include "stdafx.h"
2
3#include <Compiler.h>
4
[4]5#include "common.h"
6
7void StepCompileProgress(void){
8 extern HWND hMainDlg;
9 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0);
10}
11
[350]12void MakeMiddleCode( char *buffer )
13{
[322]14 // 改行コードをCRLFからLFにする
[350]15 ChangeReturnCode( buffer );
[322]16
17 // コメントを除去
[350]18 DeleteComment( buffer );
[322]19
[15]20 //エスケープシーケンス設定
[350]21 SetEscapeSequenceFormat( buffer );
[15]22
23 //コマンド対応
[350]24 ChangeCommandToCode( buffer );
25}
[15]26
[350]27void AddSourceCode(const char *buffer){
28 char *temp;
29 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
30 lstrcpy(temp,buffer);
31
32 MakeMiddleCode( temp );
33
[15]34 //最後尾に貼り付け
[280]35 compiler.GetObjectModule().GetCurrentSource().Addition( temp );
[15]36
37 HeapDefaultFree(temp);
38}
39
[4]40void OutputExe(void){
41 extern HANDLE hHeap;
42 extern char *basbuf;
43 extern BOOL bStopCompile;
44 extern HWND hMainDlg;
[279]45 int i3;
[4]46 char temp2[MAX_PATH];
47
[266]48 // 開始時刻を記録
49 DWORD beforeTickCount = GetTickCount();
50
[4]51 //プログレスバーの設定
52 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6));
53 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0);
54
55 //"中断"
56 SetDlgItemText(hMainDlg,IDOK,STRING_STOP);
57
58 //中断フラグを初期化
59 bStopCompile=0;
60
61 //サブシステムのタイプ
62 extern unsigned short TypeOfSubSystem;
63 TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
64
65 //プログラムをファイルから読み込む
[308]66 compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
[280]67 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
[467]68 if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( program.GetSourceFilePath() ) ){
69 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
[15]70 goto EndCompile;
71 }
[4]72
73 //イメージベースの設定
74 extern DWORD ImageBase;
[266]75 if(compiler.IsDll()) ImageBase=0x10000000;
[4]76 else ImageBase=0x00400000;
77
[465]78 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
[4]79
80
81 //////////////////////////
82 // 中間コードの生成を開始
83
84 //"最適化中..."
[465]85 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
[4]86
87 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
88 CheckParenthesis(basbuf);
89
[465]90 if( compiler.errorMessenger.HasError() || bStopCompile )
91 {
92 goto EndCompile;
93 }
[4]94
95 //コンパイルダイアログのプログレスバーを上げる
96 StepCompileProgress();
97
98 //ディレクティブ
99 DirectiveCheck();
100
101 //Next命令語を正規表現に変換
102 //NextCommandFormat(basbuf);
103
104 //エスケープシーケンス設定
105 SetEscapeSequenceFormat(basbuf);
106
107 //Def命令語をFunction命令語に変換
108 DefCommandFormat(basbuf);
109
110 //すべてのIf命令語をブロック形式に変換
111 IfCommandFormat(basbuf);
112
113 //対になる命令語を相互チェック
114 //CheckPareCommand();
115
[465]116 if( compiler.errorMessenger.HasError() || bStopCompile )
117 {
118 goto EndCompile;
119 }
[4]120
121 //コンパイルダイアログのプログレスバーを上げる
122 StepCompileProgress();
123
[541]124 // 重複エラー情報をクリア
125 compiler.errorMessenger.ClearSynonymKeyWords();
[4]126
127 ChangeCommandToCode(basbuf);
[304]128 compiler.GetObjectModule().GetSources()[0]._ResetLength();
[4]129
[465]130 if( compiler.errorMessenger.HasError() || bStopCompile )
131 {
[4]132 //定数に関する情報を解放
133 goto EndCompile;
134 }
135
136 StepCompileProgress();
137
138
[294]139 /////////////////////////////////////////////////////////////////
140 // 静的リンクライブラリをロードする
141 /////////////////////////////////////////////////////////////////
142 {
[315]143 bool isSuccessfulLoadStaticLinkLibrary = true;
144 if( !compiler.IsCore() )
[294]145 {
[315]146 // コアモジュールをロードする
147 extern BOOL bDebugCompile;
[294]148
[315]149 const char *coreFileName = "core.lib";
[459]150 if( compiler.IsDebug() )
[315]151 {
152 coreFileName = "cored.lib";
153 }
154
155 char coreFilePath[MAX_PATH];
[308]156#ifdef _AMD64_
[315]157 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
[308]158#else
[315]159 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
[308]160#endif
[467]161 GetFullPath( coreFilePath, program.GetIncludeDir() );
[294]162
[315]163 Jenga::Common::Path path( coreFilePath );
164 if( path.IsExistFile() )
165 {
166 compiler.staticLibraries.push_back( new ObjectModule() );
167 if( compiler.staticLibraries.back()->Read( coreFilePath ) )
168 {
[523]169 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]170 }
171 else
172 {
[472]173 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]174 isSuccessfulLoadStaticLinkLibrary = false;
175 }
176 }
177 else
178 {
[472]179 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]180 isSuccessfulLoadStaticLinkLibrary = false;
181 }
182 }
[299]183
[315]184 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
185 {
186 Jenga::Common::Path path( filePath );
187 if( path.IsExistFile() )
188 {
189 compiler.staticLibraries.push_back( new ObjectModule() );
190 if( compiler.staticLibraries.back()->Read( filePath ) )
191 {
[523]192 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]193 }
194 else
195 {
[472]196 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]197 isSuccessfulLoadStaticLinkLibrary = false;
198 }
199 }
200 else
201 {
[472]202 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]203 isSuccessfulLoadStaticLinkLibrary = false;
204 }
205 }
[294]206
[315]207 if( !isSuccessfulLoadStaticLinkLibrary )
208 {
209 // 静的リンクライブラリのロードに失敗したとき
210 goto EndCompile;
211 }
[294]212 }
213
214
[4]215 ///////////////////////
216 // コンパイル開始
217
218 //"コンパイル中..."
[465]219 compiler.messenger.Output(STRING_COMPILE_COMPILING);
[4]220
221 Compile();
222
223 //リソース情報を解放
224 extern RESOURCEDATAINFO *pCursorResourceInfo;
225 extern RESOURCEDATAINFO *pIconResourceInfo;
226 extern RESOURCEDATAINFO *pBitmapResourceInfo;
227 HeapDefaultFree(pCursorResourceInfo);
228 HeapDefaultFree(pBitmapResourceInfo);
229 HeapDefaultFree(pIconResourceInfo);
230
231 //コンパイルダイアログのプログレスバーを上げる
232 StepCompileProgress();
233
234
235 //////////////////////////
236 // 終了処理
237EndCompile:
238 if(bStopCompile){
239 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
240
241 //"コンパイルはユーザーにより中断されました。"
[465]242 compiler.messenger.Output(STRING_COMPILE_STOP);
[4]243 }
244 else{
245 extern int WarningNum;
[465]246 if( !compiler.errorMessenger.HasError() )
247 {
[4]248 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
[266]249 sprintf(temp2,
250 STRING_COMPILE_SUCCESS,
[465]251 compiler.errorMessenger.GetErrorCount(),
252 compiler.errorMessenger.GetWarningCount(),
[266]253 ((double)(GetTickCount() - beforeTickCount))/1000
254 );
[4]255 }
[465]256 else
257 {
[4]258 //"コンパイルは中断されました(エラー:%d、警告:%d)"
[465]259 sprintf(temp2,STRING_COMPILE_ERROR,
260 compiler.errorMessenger.GetErrorCount(),
261 compiler.errorMessenger.GetWarningCount() );
[4]262 }
263
[465]264 compiler.messenger.Output( "" );
265 compiler.messenger.Output( "-----------------------------------------------------" );
266 compiler.messenger.Output( temp2 );
[4]267 }
268
269 //"閉じる"
270 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
271
[472]272 // エラーがない場合はビルド成功とする
273 if( !compiler.errorMessenger.HasError() )
274 {
275 // ビルド成功
276 compiler.BuildSuccessful();
277 }
278
[92]279#ifdef _DEBUG
280 // デバッグモードのときはダイアログが隠れている
281 ShowWindow(hMainDlg,SW_SHOW);
282#endif
[4]283}
[467]284void MainThread(void *dummy)
285{
286 if( program.IsDebugRun() )
287 {
[459]288 if( compiler.IsDebug() )
289 {
[4]290 //デバッグコンパイル
291 OutputExe();
292 }
293
294 //デバッグ実行
[465]295 if( !compiler.errorMessenger.HasError() )
296 {
297 DebugProgram();
298 }
[4]299 }
300 else{
301 //リリースコンパイル
302 OutputExe();
303 }
304}
Note: See TracBrowser for help on using the repository browser.