source: dev/BasicCompiler_Common/MakeExe.cpp@ 75

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

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

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