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

Last change on this file since 734 was 734, checked in by dai, 16 years ago

MainThread関数の定義を元に戻す。

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