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

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

BasicSysDirをGetAppDirに置き換えた

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