source: dev/trunk/abdev/BasicCompiler_Common/MakeExe.cpp@ 315

Last change on this file since 315 was 315, checked in by dai_9181, 17 years ago

静的リンクライブラリの読み込みに失敗したときにコンパイルエラーメッセージを表示するようにした

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