source: dev/BasicCompiler_Common/MakeExe.cpp@ 88

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

House→Smoothie
Sourceクラスを用意した。

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 TODO: 消す
102 BasicSource::ReadFile内で処理されている
103
104 //アンダーバーによる改行を正規表現に戻す
105 KillReturnCode(basbuf);
106 */
107
108 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
109 CheckParenthesis(basbuf);
110
111 if(bError||bStopCompile) goto EndCompile;
112
113 //コンパイルダイアログのプログレスバーを上げる
114 StepCompileProgress();
115
116 //ディレクティブ
117 DirectiveCheck();
118
119 //Next命令語を正規表現に変換
120 //NextCommandFormat(basbuf);
121
122 //エスケープシーケンス設定
123 SetEscapeSequenceFormat(basbuf);
124
125 //Def命令語をFunction命令語に変換
126 DefCommandFormat(basbuf);
127
128 //すべてのIf命令語をブロック形式に変換
129 IfCommandFormat(basbuf);
130
131 //対になる命令語を相互チェック
132 //CheckPareCommand();
133
134 if(bError||bStopCompile) goto EndCompile;
135
136 /*未完成
137 //定数に関する情報
138 extern CONSTINFO **ppConstHash;
139 ppConstHash=(CONSTINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(CONSTINFO *));
140 */
141
142 //コンパイルダイアログのプログレスバーを上げる
143 StepCompileProgress();
144
145 //重複エラー情報管理のメモリを確保
146 extern char **SynonymErrorWords;
147 extern int SynonymErrorNum;
148 SynonymErrorNum=0;
149 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
150
151 ChangeCommandToCode(basbuf);
152
153 //重複エラー情報管理のメモリを解放
154 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
155 HeapDefaultFree(SynonymErrorWords);
156 SynonymErrorWords=0;
157
158 if(bError||bStopCompile){
159 //定数に関する情報を解放
160 goto EndCompile;
161 }
162
163 StepCompileProgress();
164
165
166 ///////////////////////
167 // コンパイル開始
168
169 //"コンパイル中..."
170 CompileMessage(STRING_COMPILE_COMPILING);
171
172 //グローバル変数に関する情報
173 extern int AllGlobalVarSize;
174 extern int AllInitGlobalVarSize;
175 globalVars.clear();
176 AllGlobalVarSize=0;
177 AllInitGlobalVarSize=0;
178
179
180 /*
181 int t,t2;
182 t=GetTickCount();
183 Compile();
184 t2=GetTickCount();
185 t2-=t;
186 char s[100];
187 sprintf(s,"%d",t2);
188 MessageBox(0,s,"test",0);*/
189 Compile();
190
191 //リソース情報を解放
192 extern RESOURCEDATAINFO *pCursorResourceInfo;
193 extern RESOURCEDATAINFO *pIconResourceInfo;
194 extern RESOURCEDATAINFO *pBitmapResourceInfo;
195 HeapDefaultFree(pCursorResourceInfo);
196 HeapDefaultFree(pBitmapResourceInfo);
197 HeapDefaultFree(pIconResourceInfo);
198
199 //コードと行番号の関係情報を解放
200 extern LINEINFO *pLineInfo;
201 HeapDefaultFree(pLineInfo);
202
203 //サブルーチン(ユーザー定義)情報のメモリ解放
204 extern UserProc **ppSubHash;
205 extern char **ppMacroNames;
206 extern int MacroNum;
207 DeleteSubInfo(ppSubHash,ppMacroNames,MacroNum);
208
209 //Declare(DLL関数)情報のメモリ解放
210 DeleteDeclareInfo();
211
212 //関数ポインタ情報のメモリ解放
213 DeleteProcPtrInfo();
214
215 //定数に関する情報を解放
216 extern CONSTINFO **ppConstHash;
217 DeleteConstInfo(ppConstHash);
218
219 //コンパイルダイアログのプログレスバーを上げる
220 StepCompileProgress();
221
222
223 //////////////////////////
224 // 終了処理
225EndCompile:
226 if(bStopCompile){
227 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
228
229 //"コンパイルはユーザーにより中断されました。"
230 CompileMessage(STRING_COMPILE_STOP);
231 }
232 else{
233 extern int CompileMsgNum;
234 extern int WarningNum;
235 if(bError==0){
236 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
237 sprintf(temp2,STRING_COMPILE_SUCCESS,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
238 }
239 else{
240 //"コンパイルは中断されました(エラー:%d、警告:%d)"
241 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
242 }
243
244 CompileMessage("");
245 CompileMessage("-----------------------------------------------------");
246 CompileMessage(temp2);
247 }
248
249 //"閉じる"
250 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
251
252 //#include情報を解放
253 extern INCLUDEFILEINFO IncludeFileInfo;
254 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
255 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
256 HeapDefaultFree(IncludeFileInfo.ppFileNames);
257}
258int MainThread(DWORD dummy){
259 extern BOOL bDebugCompile;
260 extern BOOL bDebugRun;
261 extern int bError;
262
263 if(bDebugRun){
264 if(bDebugCompile){
265 bDebugRun=0;
266
267 //デバッグコンパイル
268 OutputExe();
269
270 bDebugRun=1;
271 }
272
273 //デバッグ実行
274 if(bError==0) DebugProgram();
275 }
276 else{
277 //リリースコンパイル
278 OutputExe();
279 }
280
281 return 0;
282}
Note: See TracBrowser for help on using the repository browser.