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

Last change on this file since 721 was 721, checked in by イグトランス (egtra), 16 years ago

#192への対処

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