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

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

ResourceManagerクラスを追加。既存のリソース管理モジュールの置き換えを行った。

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