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
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
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
12void MakeMiddleCode( char *buffer )
13{
14 // 改行コードをCRLFからLFにする
15 ChangeReturnCode( buffer );
16
17 // コメントを除去
18 DeleteComment( buffer );
19
20 //エスケープシーケンス設定
21 SetEscapeSequenceFormat( buffer );
22
23 //コマンド対応
24 ChangeCommandToCode( buffer );
25}
26
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
34 //最後尾に貼り付け
35 compiler.GetObjectModule().GetCurrentSource().Addition( temp );
36
37 HeapDefaultFree(temp);
38}
39
40void OutputExe(void){
41 extern HANDLE hHeap;
42 extern char *basbuf;
43 extern BOOL bStopCompile;
44 extern HWND hMainDlg;
45 int i3;
46 char temp2[MAX_PATH];
47
48 // 開始時刻を記録
49 DWORD beforeTickCount = GetTickCount();
50
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 //プログラムをファイルから読み込む
66 compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
67 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
68 if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( program.GetSourceFilePath() ) ){
69 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
70 goto EndCompile;
71 }
72
73 //イメージベースの設定
74 extern DWORD ImageBase;
75 if(compiler.IsDll()) ImageBase=0x10000000;
76 else ImageBase=0x00400000;
77
78 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
79
80
81 //////////////////////////
82 // 中間コードの生成を開始
83
84 //"最適化中..."
85 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
86
87 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
88 CheckParenthesis(basbuf);
89
90 if( compiler.errorMessenger.HasError() || bStopCompile )
91 {
92 goto EndCompile;
93 }
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
116 if( compiler.errorMessenger.HasError() || bStopCompile )
117 {
118 goto EndCompile;
119 }
120
121 //コンパイルダイアログのプログレスバーを上げる
122 StepCompileProgress();
123
124 // 重複エラー情報をクリア
125 compiler.errorMessenger.ClearSynonymKeyWords();
126
127 ChangeCommandToCode(basbuf);
128 compiler.GetObjectModule().GetSources()[0]._ResetLength();
129
130 if( compiler.errorMessenger.HasError() || bStopCompile )
131 {
132 //定数に関する情報を解放
133 goto EndCompile;
134 }
135
136 StepCompileProgress();
137
138
139 /////////////////////////////////////////////////////////////////
140 // 静的リンクライブラリをロードする
141 /////////////////////////////////////////////////////////////////
142 {
143 bool isSuccessfulLoadStaticLinkLibrary = true;
144 if( !compiler.IsCore() )
145 {
146 // コアモジュールをロードする
147 extern BOOL bDebugCompile;
148
149 const char *coreFileName = "core.lib";
150 if( compiler.IsDebug() )
151 {
152 coreFileName = "cored.lib";
153 }
154
155 char coreFilePath[MAX_PATH];
156#ifdef _AMD64_
157 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
158#else
159 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
160#endif
161 GetFullPath( coreFilePath, program.GetIncludeDir() );
162
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 {
169 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
170 }
171 else
172 {
173 compiler.errorMessenger.Output( 203, path.GetFullPath() );
174 isSuccessfulLoadStaticLinkLibrary = false;
175 }
176 }
177 else
178 {
179 compiler.errorMessenger.Output( 202, path.GetFullPath() );
180 isSuccessfulLoadStaticLinkLibrary = false;
181 }
182 }
183
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 {
192 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
193 }
194 else
195 {
196 compiler.errorMessenger.Output( 203, path.GetFullPath() );
197 isSuccessfulLoadStaticLinkLibrary = false;
198 }
199 }
200 else
201 {
202 compiler.errorMessenger.Output( 202, path.GetFullPath() );
203 isSuccessfulLoadStaticLinkLibrary = false;
204 }
205 }
206
207 if( !isSuccessfulLoadStaticLinkLibrary )
208 {
209 // 静的リンクライブラリのロードに失敗したとき
210 goto EndCompile;
211 }
212 }
213
214
215 ///////////////////////
216 // コンパイル開始
217
218 //"コンパイル中..."
219 compiler.messenger.Output(STRING_COMPILE_COMPILING);
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 //"コンパイルはユーザーにより中断されました。"
242 compiler.messenger.Output(STRING_COMPILE_STOP);
243 }
244 else{
245 extern int WarningNum;
246 if( !compiler.errorMessenger.HasError() )
247 {
248 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
249 sprintf(temp2,
250 STRING_COMPILE_SUCCESS,
251 compiler.errorMessenger.GetErrorCount(),
252 compiler.errorMessenger.GetWarningCount(),
253 ((double)(GetTickCount() - beforeTickCount))/1000
254 );
255 }
256 else
257 {
258 //"コンパイルは中断されました(エラー:%d、警告:%d)"
259 sprintf(temp2,STRING_COMPILE_ERROR,
260 compiler.errorMessenger.GetErrorCount(),
261 compiler.errorMessenger.GetWarningCount() );
262 }
263
264 compiler.messenger.Output( "" );
265 compiler.messenger.Output( "-----------------------------------------------------" );
266 compiler.messenger.Output( temp2 );
267 }
268
269 //"閉じる"
270 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
271
272 // エラーがない場合はビルド成功とする
273 if( !compiler.errorMessenger.HasError() )
274 {
275 // ビルド成功
276 compiler.BuildSuccessful();
277 }
278
279#ifdef _DEBUG
280 // デバッグモードのときはダイアログが隠れている
281 ShowWindow(hMainDlg,SW_SHOW);
282#endif
283}
284void MainThread(void *dummy)
285{
286 if( program.IsDebugRun() )
287 {
288 if( compiler.IsDebug() )
289 {
290 //デバッグコンパイル
291 OutputExe();
292 }
293
294 //デバッグ実行
295 if( !compiler.errorMessenger.HasError() )
296 {
297 DebugProgram();
298 }
299 }
300 else{
301 //リリースコンパイル
302 OutputExe();
303 }
304}
Note: See TracBrowser for help on using the repository browser.