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

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

Unicodeライブラリに対応

File size: 7.6 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){
[733]29 char *temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
[350]30 lstrcpy(temp,buffer);
31
32 MakeMiddleCode( temp );
33
[15]34 //最後尾に貼り付け
[636]35 compiler.GetObjectModule().GetSource().Addition( temp );
[15]36
37 HeapDefaultFree(temp);
38}
39
[733]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
[605]62void Build()
63{
[4]64 extern HANDLE hHeap;
65 extern char *basbuf;
66 extern BOOL bStopCompile;
67 extern HWND hMainDlg;
68 char temp2[MAX_PATH];
69
[266]70 // 開始時刻を記録
71 DWORD beforeTickCount = GetTickCount();
72
[4]73 //プログレスバーの設定
[733]74 HWND hwndProgress=GetDlgItem(hMainDlg,IDC_PROGRESS);
75 PostMessage(hwndProgress,PBM_SETRANGE,0,MAKELPARAM(0,6));
76 PostMessage(hwndProgress,PBM_SETSTEP,1,0);
[4]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
[636]88 // オブジェクトモジュール名をセットする
89 compiler.GetObjectModule().SetName( program.GetOutputFileName() );
90
[4]91 //プログラムをファイルから読み込む
[636]92 bool result = compiler.GetObjectModule().GetSource().ReadFile(
[554]93 program.GetSourceFilePath(),
94 compiler.IsDebug(),
95 compiler.IsDll(),
96 compiler.IsUnicode(),
[602]97 MAJOR_VER,
98 program.GetSourceFilePath(),
99 program.GetIncludeDir()
[554]100 );
101 if( !result ){
[467]102 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
[15]103 goto EndCompile;
104 }
[636]105 if( !compiler.GetCurrentSource().cannotIncludePath.empty() )
[555]106 {
107 compiler.errorMessenger.Output(
108 35,
[636]109 compiler.GetCurrentSource().cannotIncludePath,
110 compiler.GetCurrentSource().cannotIncludeSourcePos
[555]111 );
112 goto EndCompile;
113 }
[4]114
115 //イメージベースの設定
116 extern DWORD ImageBase;
[266]117 if(compiler.IsDll()) ImageBase=0x10000000;
[4]118 else ImageBase=0x00400000;
119
[465]120 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
[4]121
122
123 //////////////////////////
124 // 中間コードの生成を開始
125
126 //"最適化中..."
[465]127 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
[4]128
129 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
130 CheckParenthesis(basbuf);
131
[465]132 if( compiler.errorMessenger.HasError() || bStopCompile )
133 {
134 goto EndCompile;
135 }
[4]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
[465]158 if( compiler.errorMessenger.HasError() || bStopCompile )
159 {
160 goto EndCompile;
161 }
[4]162
163 //コンパイルダイアログのプログレスバーを上げる
164 StepCompileProgress();
165
[541]166 // 重複エラー情報をクリア
167 compiler.errorMessenger.ClearSynonymKeyWords();
[4]168
169 ChangeCommandToCode(basbuf);
[636]170 compiler.GetObjectModule().GetSource()._ResetLength();
[4]171
[465]172 if( compiler.errorMessenger.HasError() || bStopCompile )
173 {
[4]174 //定数に関する情報を解放
175 goto EndCompile;
176 }
177
178 StepCompileProgress();
179
180
[294]181 /////////////////////////////////////////////////////////////////
182 // 静的リンクライブラリをロードする
183 /////////////////////////////////////////////////////////////////
184 {
[315]185 bool isSuccessfulLoadStaticLinkLibrary = true;
186 if( !compiler.IsCore() )
[294]187 {
[315]188 // コアモジュールをロードする
189 extern BOOL bDebugCompile;
[294]190
[733]191 const char *coreFileName = GetCoreLibName();
[315]192
193 char coreFilePath[MAX_PATH];
[733]194#if defined _AMD64_
[315]195 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
[308]196#else
[315]197 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
[308]198#endif
[467]199 GetFullPath( coreFilePath, program.GetIncludeDir() );
[294]200
[315]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 {
[733]207 compiler.messenger.Output( ('\"' + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]208 }
209 else
210 {
[472]211 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]212 isSuccessfulLoadStaticLinkLibrary = false;
213 }
214 }
215 else
216 {
[472]217 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]218 isSuccessfulLoadStaticLinkLibrary = false;
219 }
220 }
[299]221
[639]222 ActiveBasic::Common::Environment::SetRemoveExternalMark( true );
223
[315]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 {
[733]232 compiler.messenger.Output( ('\"' + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]233 }
234 else
235 {
[472]236 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]237 isSuccessfulLoadStaticLinkLibrary = false;
238 }
239 }
240 else
241 {
[472]242 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]243 isSuccessfulLoadStaticLinkLibrary = false;
244 }
245 }
[294]246
[639]247 ActiveBasic::Common::Environment::SetRemoveExternalMark( false );
248
[315]249 if( !isSuccessfulLoadStaticLinkLibrary )
250 {
251 // 静的リンクライブラリのロードに失敗したとき
252 goto EndCompile;
253 }
[294]254 }
255
256
[4]257 ///////////////////////
258 // コンパイル開始
259
[605]260 MakeExe();
[4]261
262 //コンパイルダイアログのプログレスバーを上げる
263 StepCompileProgress();
264
265
266 //////////////////////////
267 // 終了処理
268EndCompile:
269 if(bStopCompile){
[733]270 PostMessage(hwndProgress,PBM_SETPOS,0,0);
[4]271
272 //"コンパイルはユーザーにより中断されました。"
[465]273 compiler.messenger.Output(STRING_COMPILE_STOP);
[4]274 }
275 else{
276 extern int WarningNum;
[465]277 if( !compiler.errorMessenger.HasError() )
278 {
[4]279 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
[266]280 sprintf(temp2,
281 STRING_COMPILE_SUCCESS,
[465]282 compiler.errorMessenger.GetErrorCount(),
283 compiler.errorMessenger.GetWarningCount(),
[266]284 ((double)(GetTickCount() - beforeTickCount))/1000
285 );
[4]286 }
[465]287 else
288 {
[4]289 //"コンパイルは中断されました(エラー:%d、警告:%d)"
[465]290 sprintf(temp2,STRING_COMPILE_ERROR,
291 compiler.errorMessenger.GetErrorCount(),
292 compiler.errorMessenger.GetWarningCount() );
[4]293 }
294
[465]295 compiler.messenger.Output( "" );
296 compiler.messenger.Output( "-----------------------------------------------------" );
297 compiler.messenger.Output( temp2 );
[4]298 }
299
300 //"閉じる"
301 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
302
[472]303 // エラーがない場合はビルド成功とする
304 if( !compiler.errorMessenger.HasError() )
305 {
306 // ビルド成功
307 compiler.BuildSuccessful();
308 }
309
[92]310#ifdef _DEBUG
311 // デバッグモードのときはダイアログが隠れている
312 ShowWindow(hMainDlg,SW_SHOW);
313#endif
[4]314}
[733]315unsigned __stdcall MainThread(void *)
[467]316{
317 if( program.IsDebugRun() )
318 {
[459]319 if( compiler.IsDebug() )
320 {
[4]321 //デバッグコンパイル
[605]322 Build();
[4]323 }
324
325 //デバッグ実行
[465]326 if( !compiler.errorMessenger.HasError() )
327 {
328 DebugProgram();
329 }
[4]330 }
331 else{
332 //リリースコンパイル
[605]333 Build();
[4]334 }
[733]335 return 0;
[4]336}
Note: See TracBrowser for help on using the repository browser.