source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp

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

Typeクラスを単体テスト可能な状態へ

File size: 20.3 KB
Line 
1#include "stdafx.h"
2#include <process.h>
3#include <fcntl.h>
4#include <io.h>
5
6#include <ver.h>
7
8#include "BasicCompiler.h"
9
10#if defined HeapAlloc
11#define MEM_MAX 65536
12LPVOID pCheckMem[MEM_MAX];
13int now;
14#undef HeapAlloc
15#undef HeapReAlloc
16LPVOID CheckHeapAlloc(HANDLE hf,DWORD dwFlags,DWORD dwBytes){
17 LPVOID ret;
18 ret=HeapAlloc(hf,dwFlags,dwBytes);
19 pCheckMem[now]=ret;
20
21 //この部分にnowのチェックを挿入
22
23 now++;
24 if(now>=MEM_MAX){
25 MessageBox(0,"pCheckMemの最大値を超えました","Check - BasicCompiler.exe",0);
26 }
27 return ret;
28}
29LPVOID CheckHeapReAlloc(HANDLE hf,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes){
30 int i;
31 LPVOID ret;
32 for(i=0;;i++){
33 if(lpMem==pCheckMem[i]) break;
34 if(i>=MEM_MAX){
35 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
36 break;
37 }
38 }
39 ret=HeapReAlloc(hf,dwFlags,lpMem,dwBytes);
40 pCheckMem[i]=ret;
41 return ret;
42}
43void HeapDefaultFree(LPVOID lpMem){
44 int i;
45 for(i=0;;i++){
46 if(lpMem==pCheckMem[i]) break;
47 if(i>=MEM_MAX||lpMem==0){
48 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
49 break;
50 }
51 }
52 pCheckMem[i]=0;
53 HeapFree(hHeap,0,lpMem);
54}
55void CheckHeapCheck(){
56 int i,i2;
57 char temp[100];
58 temp[0]=0;
59 for(i=0,i2=0;i<MEM_MAX;i++){
60 if(pCheckMem[i]){
61 sprintf(temp+lstrlen(temp),"%d\r\n",i);
62 i2++;
63 if(i2==10){
64 lstrcat(temp,"これ以上の未解放が確認されています");
65 break;
66 }
67 }
68 }
69 if(temp[0]) MessageBox(0,temp,"Check - BasicCompiler.exe",0);
70}
71#define HeapAlloc CheckHeapAlloc
72#define HeapReAlloc CheckHeapReAlloc
73#else
74void HeapDefaultFree(LPVOID lpMem){
75 HeapFree(hHeap,0,lpMem);
76}
77#endif
78
79void ts(int i){
80 char temporary[255];
81 sprintf(temporary,"0x%08x",i);
82 MessageBox(0,temporary,"TestMessage",0);
83}
84void ts(int i,int i2){
85 char temporary[255];
86 sprintf(temporary,"0x%08x\r\n0x%08x",i,i2);
87 MessageBox(0,temporary,"TestMessage",0);
88}
89void ts(const char *msg){
90 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),"TestMessage",0);
91}
92void ts(const char *msg,const char *title){
93 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),title,0);
94}
95void ts(const std::string msg)
96{
97 ts(msg.c_str());
98}
99
100void epi_check(){
101 //この部分にobpのチェックを挿入
102 //※例 … epi=0x41999 → obp>=0x0999
103/*
104 extern int obp;
105 if(obp>=0x988DE){
106 int test=0;
107 }*/
108}
109
110void GetRelationalPath(char *path,char *dir){
111 //相対パスを取得
112 int i,i2,i3,i4,i5;
113 char temporary[MAX_PATH],temp2[MAX_PATH],temp3[MAX_PATH],temp4[MAX_PATH];
114
115 //ドライブ名をチェック
116 _splitpath(path,temporary,0,0,0);
117 _splitpath(dir,temp2,0,0,0);
118 if(lstrcmpi(temporary,temp2)!=0) return;
119
120 _splitpath(path,0,temporary,0,0);
121 _splitpath(dir,0,temp2,0,0);
122 i=1;i2=1;
123 while(1){
124 i4=i;
125 if(temporary[i-1]=='\\'&&temporary[i]){ //path側
126 for(i3=0;;i++,i3++){
127 if(temporary[i]=='\\'){
128 temp3[i3]=0;
129 i++;
130 break;
131 }
132 temp3[i3]=temporary[i];
133 }
134 }
135 else temp3[0]=0;
136
137 i5=i2;
138 if(temp2[i2-1]=='\\'&&temp2[i2]){ //dir側
139 for(i3=0;;i2++,i3++){
140 if(temp2[i2]=='\\'){
141 temp4[i3]=0;
142 i2++;
143 break;
144 }
145 temp4[i3]=temp2[i2];
146 }
147 }
148 else temp4[0]=0;
149
150 if(temp3[0]=='\0'&&temp4[0]=='\0'){
151 lstrcpy(temp3,".\\");
152 break;
153 }
154
155 if(lstrcmpi(temp3,temp4)!=0){
156 for(i3=0;;i5++){
157 if(temp2[i5]=='\0') break;
158 if(temp2[i5]=='\\') i3++;
159 }
160 if(i3==0) lstrcpy(temp3,".\\");
161 else{
162 temp3[0]=0;
163 for(i2=0;i2<i3;i2++) lstrcat(temp3,"..\\");
164 }
165 lstrcat(temp3,temporary+i4);
166 break;
167 }
168 }
169 _splitpath(path,0,0,temporary,temp2);
170 lstrcat(temp3,temporary);
171 lstrcat(temp3,temp2);
172 lstrcpy(path,temp3);
173}
174void GetFullPath( char *path, const std::string &baseDirPath ){
175 int i,i2,i3,i4;
176 char temporary[MAX_PATH];
177
178 // '/'→'\'
179 for( i=0;path[i];i++ ){
180 if( path[i] == '/' ){
181 path[i]='\\';
182 }
183 }
184
185 if(strstr(path,":")||strstr(path,"\\\\")) return;
186
187 i=0;i2=0;
188 while(1){
189 if(path[i]=='.'&&path[i+1]=='\\') i+=2;
190 if(path[i]=='.'&&path[i+1]=='.'&&path[i+2]=='\\'){
191 i2++;
192 i+=3;
193 }
194 else break;
195 }
196
197 std::string tempBaseDirPath = baseDirPath;
198 if( tempBaseDirPath[tempBaseDirPath.size()-1] != '\\' )
199 {
200 tempBaseDirPath += "\\";
201 }
202
203 i3=(int)tempBaseDirPath.size();i4=0;
204 while(i4<i2){
205 for(i3--;;i3--){
206 if(tempBaseDirPath[i3-1]=='\\'){
207 i4++;
208 break;
209 }
210 }
211 }
212 memcpy(temporary,tempBaseDirPath.c_str(),i3);
213 temporary[i3]=0;
214 lstrcat(temporary,path+i);
215 lstrcpy(path,temporary);
216}
217
218void ShowErrorLine(int LineNum,const char *constFileName){
219 HANDLE hFile;
220 DWORD dw;
221 char FileName[MAX_PATH];
222 char temporary[MAX_PATH];
223
224 lstrcpy( FileName, constFileName );
225
226 if(LineNum==-1) return;
227
228 if(IsWindow(hOwnerEditor)){
229 if(FileName){
230
231 while( !IsFileExist( FileName ) ){
232 char temp2[MAX_PATH],temp3[MAX_PATH];
233 _splitpath(FileName,NULL,NULL,temp2,temp3);
234 lstrcat(temp2,temp3);
235
236 sprintf(temporary,"\"%s\" が見つかりません。格納されているディレクトリを指定してください。",temp2);
237 if(!GetFolder(hOwnerEditor,temp3,temporary)) return;
238
239 if(temp3[lstrlen(temp3)-1]!='\\') lstrcat(temp3,"\\");
240
241 sprintf(FileName,"%s%s",temp3,temp2);
242 }
243
244 hFile=CreateFile(
245 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
246 GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL);
247 WriteFile(hFile,FileName,lstrlen(FileName),&dw,NULL);
248 CloseHandle(hFile);
249
250 SendMessage(hOwnerEditor,WM_SHOWERROR,LineNum,0);
251 }
252 }
253}
254
255BOOL GetFilePathDialog(HWND hwnd,char *filename,LPCSTR Filter,LPCSTR Title,BOOL bOpen){
256 OPENFILENAME ofstr;
257 filename[0]=0;
258 ofstr.lStructSize=sizeof(OPENFILENAME);
259 ofstr.hwndOwner=hwnd;
260 ofstr.hInstance=0;
261 ofstr.lpstrFilter=Filter;
262 ofstr.lpstrCustomFilter=NULL;
263 ofstr.nMaxCustFilter=0;
264 ofstr.nFilterIndex=1;
265 ofstr.lpstrFile=filename;
266 ofstr.nMaxFile=MAX_PATH;
267 ofstr.lpstrFileTitle=NULL;
268 ofstr.nMaxFileTitle=0;
269 ofstr.lpstrInitialDir=0;
270 ofstr.lpstrTitle=Title;
271 ofstr.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
272 ofstr.nFileOffset=0;
273 ofstr.nFileExtension=0;
274 ofstr.lpstrDefExt="*";
275 ofstr.lCustData=NULL;
276 ofstr.lpfnHook=NULL;
277 ofstr.lpTemplateName=NULL;
278 if(bOpen){
279 if(!GetOpenFileName(&ofstr)) return FALSE;
280 }
281 else{
282 if(!GetSaveFileName(&ofstr)) return FALSE;
283 }
284 return TRUE;
285}
286
287LRESULT CALLBACK ErrorListProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
288 int i,pos;
289 int StartPos,EndPos;
290
291 switch(message){
292 case WM_CHAR:
293 if(GetKeyState(VK_CONTROL)&0x8000){
294 //アクセラレータキーの場合を考慮
295 break;
296 }
297 return 0;
298 case WM_LBUTTONDBLCLK:
299 SendMessage(hwnd,EM_GETSEL,(WPARAM)&pos,0);
300 i=(int)SendMessage(hwnd,EM_LINEFROMCHAR,pos,0);
301 compiler.errorMessenger.ShowErrorLine( i );
302
303 StartPos=(int)SendMessage(hwnd,EM_LINEINDEX,i,0);
304 EndPos=StartPos+(int)SendMessage(hwnd,EM_LINELENGTH,pos,0);
305 SendMessage(hwnd,EM_SETSEL,StartPos,EndPos);
306 return 0;
307 }
308 return CallWindowProc(OldErrorListProc,hwnd,message,wParam,lParam);
309}
310LRESULT CALLBACK DebugListProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
311 switch(message){
312 case WM_CHAR:
313 if(GetKeyState(VK_CONTROL)&0x8000){
314 //アクセラレータキーの場合を考慮
315 break;
316 }
317 return 0;
318 }
319 return CallWindowProc(OldDebugListProc,hwnd,message,wParam,lParam);
320}
321void MakeMessageText(char *buffer,char *msg,int flag){
322 if( program.IsClipCompileView() ){
323 //ProjectView埋め込みがたインターフェイスのとき
324
325 //生成するファイルの相対パスを取得
326 char relationalPath[MAX_PATH];
327 strcpy( relationalPath, program.GetOutputFilePath().c_str() );
328 GetRelationalPath( relationalPath, BasicCurDir );
329
330 //////////
331 // 合成
332
333#if defined(JPN)
334 //日本語
335 if(flag==0){
336 if(compiler.IsDll())
337 {
338 sprintf(buffer,"DLLファイル \"%s\" [ %s ]",relationalPath,msg);
339 }
340 else sprintf(buffer,"実行ファイル \"%s\" [ %s ]",relationalPath,msg);
341 }
342 if(flag==1) sprintf(buffer,"\"%s\" を生成しています [ %s ]",relationalPath,msg);
343 if(flag==2) lstrcpy(buffer,msg);
344#else
345 //英語
346 if(flag==0){
347 if(compiler.IsDll()) sprintf(buffer,"DLL file \"%s\" [ %s ]",relationalPath,msg);
348 else sprintf(buffer,"Execution file \"%s\" [ %s ]",relationalPath,msg);
349 }
350 if(flag==1) sprintf(buffer,"Creating \"%s\" [ %s ]",relationalPath,msg);
351 if(flag==2) lstrcpy(buffer,msg);
352#endif
353 }
354 else{
355 //通常ダイアログのとき
356 lstrcpy(buffer,msg);
357 }
358}
359
360void SetPosCenter(HWND hwnd){
361 RECT OwnerRect,rect;
362 int x,y;
363
364 if(IsWindow(hOwnerEditor)) GetWindowRect(hOwnerEditor,&OwnerRect);
365 else{
366 OwnerRect.left=0;
367 OwnerRect.top=0;
368 OwnerRect.right=ScreenX;
369 OwnerRect.bottom=ScreenY;
370 }
371 GetWindowRect(hwnd,&rect);
372
373 x=((OwnerRect.right-OwnerRect.left)-(rect.right-rect.left))/2+OwnerRect.left;
374 y=((OwnerRect.bottom-OwnerRect.top)-(rect.bottom-rect.top))/2+OwnerRect.top;
375 SetWindowPos(hwnd,0,x,y,0,0,SWP_NOSIZE);
376}
377INT_PTR CALLBACK DlgCompile(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
378 extern HANDLE hDebugProcess;
379 extern DWORD processIdDebug;
380 char temporary[MAX_PATH];
381 RECT rect;
382 POINT pos;
383 SIZE size;
384 static POINT pos_List,pos_Progress;
385 static int height_Progress;
386
387 switch(message){
388 case WM_INITDIALOG:
389 pos=pobj_nv->MainDlgPos;
390 GetWindowRect(hwnd,&rect);
391 size.cx=rect.right-rect.left;
392 size.cy=rect.bottom-rect.top;
393 MoveWindow(hwnd,pos.x,pos.y,size.cx,size.cy,1);
394
395 char relationalPath[MAX_PATH];
396 lstrcpy(relationalPath,program.GetOutputFilePath().c_str());
397 GetRelationalPath(relationalPath,BasicCurDir);
398 SetDlgItemText(hwnd,IDC_EXEPATH,relationalPath);
399
400 //"エラー無し"
401 SetDlgItemText(hwnd,IDC_ERRORLIST,STRING_NOERROR);
402
403 //"デバッグ情報無し"
404 SetDlgItemText(hwnd,IDC_DEBUGLIST,STRING_NODEBUGMSG);
405
406 //リストボックスの初期位置
407 GetWindowRect(GetDlgItem(hwnd,IDC_ERRORLIST),&rect);
408 pos_List.x=rect.left;
409 pos_List.y=rect.top;
410 ScreenToClient(hwnd,&pos_List);
411
412 //プログレスバーの初期位置と高さ
413 GetWindowRect(GetDlgItem(hwnd,IDC_PROGRESS),&rect);
414 pos_Progress.x=rect.left;
415 pos_Progress.y=rect.top;
416 ScreenToClient(hwnd,&pos_Progress);
417 height_Progress=rect.bottom-rect.top;
418
419 //バージョン表記
420 sprintf(temporary,"Version %d.%02d.%02d %s",MAJOR_VER,MINOR_VER,REVISION_VER,VER_INFO);
421 SetDlgItemText(hwnd,IDC_STATIC_VERSION,temporary);
422
423 break;
424 case WM_COMMAND:
425 switch(LOWORD(wParam)){
426 case IDOK:
427 GetDlgItemText(hwnd,IDOK,temporary,MAX_PATH);
428
429 //STRING_COMPILE = "コンパイル"
430 if(lstrcmp(temporary,STRING_COMPILE)==0){
431 char tempOutputFileName[MAX_PATH];
432 GetDlgItemText(hwnd,IDC_EXEPATH,tempOutputFileName,MAX_PATH);
433 program.SetOutputFilePath(
434 Jenga::Common::Path::MakeFullPath( tempOutputFileName, BasicCurDir )
435 );
436 _beginthread( &MainThread, NULL, NULL );
437 }
438
439 //STRING_STOP = "中断"
440 else if(lstrcmp(temporary,STRING_STOP)==0){
441 if(hDebugProcess){
442 //デバッグ中のとき
443
444 //プロセスを終了
445 TerminateProcess(hDebugProcess,0);
446 hDebugProcess=0;
447 processIdDebug = 0;
448
449 //デバッグダイアログを終了
450 if(hDebugWnd){
451 DestroyWindow(hDebugWnd);
452 }
453 }
454 else{
455 //コンパイル中のとき
456 bStopCompile=1;
457
458 /* メインスレッドで「閉じる」ボタンに変更することで、
459 コンパイルを中断中の早いタイミングでも終了することが可能 */
460 //"閉じる"
461 SetDlgItemText(hwnd,IDOK,STRING_CLOSE);
462 }
463 }
464
465 else{
466 SetFocus(hOwnerEditor);
467 DestroyWindow(hwnd);
468 }
469 return 1;
470 case IDCANCEL:
471 //×ボタン用
472
473 if(hDebugProcess){
474 //デバッグ中のとき
475
476 //プロセスを終了
477 TerminateProcess(hDebugProcess,0);
478 hDebugProcess=0;
479 processIdDebug = 0;
480
481 //デバッグダイアログを終了
482 if(hDebugWnd){
483 DestroyWindow(hDebugWnd);
484 }
485 }
486
487 SetFocus(hOwnerEditor);
488 DestroyWindow(hwnd);
489 return 1;
490 case IDC_SHOWERROR:
491 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_SHOW);
492 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_HIDE);
493 return 1;
494 case IDC_SHOWDEBUG:
495 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_HIDE);
496 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_SHOW);
497 return 1;
498 }
499 break;
500 case WM_SHOWVARLIST:
501 if( program.IsClipCompileView() ){
502 //埋め込み表示
503 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DEBUGGER),hOwnerEditor,(DLGPROC)DlgDebugger,lParam);
504 ShowWindow(hDebugWnd,SW_SHOW);
505
506 SendMessage(hOwnerEditor,WM_SETDEBUGGERVIEW,0,(LPARAM)hDebugWnd);
507 }
508 else{
509 //ポップアップ表示
510 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_VARLIST),hOwnerEditor,(DLGPROC)DlgVarList,lParam);
511 SetForegroundWindow(hDebugWnd);
512 }
513 return 1;
514 case WM_SIZE:
515 if( program.IsClipCompileView() ){
516 //エラーリストの位置
517 MoveWindow(GetDlgItem(hwnd,IDC_ERRORLIST),
518 pos_List.x,
519 pos_List.y,
520 LOWORD(lParam)-pos_List.x,
521 HIWORD(lParam)-pos_List.y,
522 1);
523
524 //デバッグリストの位置
525 MoveWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),
526 pos_List.x,
527 pos_List.y,
528 LOWORD(lParam)-pos_List.x,
529 HIWORD(lParam)-pos_List.y,
530 1);
531
532 //プログレスバーの位置
533 MoveWindow(GetDlgItem(hwnd,IDC_PROGRESS),
534 pos_Progress.x,
535 pos_Progress.y,
536 LOWORD(lParam)-pos_Progress.x,
537 height_Progress,
538 1);
539 }
540 return 1;
541 case WM_DESTROY:
542 GetWindowRect(hwnd,&rect);
543
544 if( !program.IsClipCompileView() ){
545 pobj_nv->MainDlgPos.x=rect.left;
546 pobj_nv->MainDlgPos.y=rect.top;
547 }
548
549 PostQuitMessage(0);
550 return 1;
551
552
553
554 ///////////////////////
555 // デバッグコマンド
556 ///////////////////////
557
558 case WM_DEBUG_STOP:
559 Debugger_Stop();
560 return 1;
561 case WM_DEBUG_PAUSE:
562 Debugger_Pause();
563 return 1;
564
565
566 case WM_CLOSE_DEBUGGER:
567 if(hDebugWnd){
568 DestroyWindow(hDebugWnd);
569 }
570 return 1;
571 }
572 return 0;
573}
574
575void _Test()
576{
577 Jenga::Common::LoggerSetting loggerSetting;
578 bool result = loggerSetting.WriteXml( Jenga::Common::Environment::GetAppDir() + "\\logger.setting.xml" );
579}
580
581int main()
582{
583 int i;
584 char temporary[1024],temp2[MAX_PATH];
585
586 ActiveBasic::Common::EnableNX();
587 ActiveBasic::Common::SetHeapOptions();
588
589 hInst = GetModuleHandle( NULL );
590
591 // グローバルローケルを日本語にする
592 //std::locale::global(std::locale("japanese"));
593 //_setmode(_fileno(stdout), _O_BINARY);
594
595 //_Test();
596
597 //MessageBox(0,"starting compiler/debugger","ActiveBasic",MB_OK);
598 trace( "Start ActiveBasic Compiler!" );
599
600 //コモンコントロールを初期化
601 InitCommonControls();
602
603 hHeap=GetProcessHeap();
604 ScreenX=GetSystemMetrics(SM_CXSCREEN);
605 ScreenY=GetSystemMetrics(SM_CYSCREEN);
606
607 //不揮発性データを取得
608 pobj_nv=new CNonVolatile;
609 pobj_nv->load();
610
611 program.Configurate();
612
613 if( !program.AnalysisCommandLines() )
614 {
615 // コマンドラインが不正
616 return 0;
617 }
618
619 bool isSpecifiedSourceFilePathByCommandLine = false;
620 if( program.GetSourceFilePath().size() > 0 )
621 {
622 // ソースファイル名が与えられていたとき
623 isSpecifiedSourceFilePathByCommandLine = true;
624 }
625 else
626 {
627 // ソースファイル名が与えられなかったとき
628 char temp[MAX_PATH];
629 if(!GetFilePathDialog(0,temp,BasicFileFilter,"コンパイルするファイルを指定して下さい",1))
630 {
631 return 0;
632 }
633 program.SetSourceFilePath( temp );
634 }
635
636 //出力ファイル名が与えられなかったとき
637 if( program.GetOutputFilePath().size() == 0 )
638 {
639 char tempOutputFileName[MAX_PATH];
640 _splitpath( program.GetSourceFilePath().c_str(), tempOutputFileName,temporary,temp2,0);
641 lstrcat(tempOutputFileName,temporary);
642 lstrcat(tempOutputFileName,temp2);
643 if( compiler.IsSll() )
644 {
645 if( program.IsDebugRun() || compiler.IsDebug() )
646 {
647 strcat(tempOutputFileName,"_debug.abobj");
648 }
649 else
650 {
651 strcat(tempOutputFileName,".abobj");
652 }
653 }
654 else
655 {
656 if( program.IsDebugRun() || compiler.IsDebug() )
657 {
658 strcat(tempOutputFileName,"_debug.exe");
659 }
660 else
661 {
662 strcat(tempOutputFileName,".exe");
663 }
664 }
665
666 program.SetOutputFilePath( tempOutputFileName );
667 }
668
669 {
670 // カレントディレクトリを取得
671 std::string baseDirPath = Jenga::Common::Environment::GetAppDir()+"\\";
672
673 // インクルードディレクトリが指定されなかったとき
674 if( program.GetIncludeDir().size() == 0 )
675 {
676 program.SetIncludeDir( Jenga::Common::Path::MakeFullPath( ".\\Include", ActiveBasic::Common::Environment::GetAbdevRootPath() ) );
677 }
678 else
679 {
680 // インクルードディレクトリを絶対パスに変更
681 program.SetIncludeDir( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetIncludeDir() ) );
682 }
683
684 // ソースファイル名を絶対パスに変換
685 program.SetSourceFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetSourceFilePath() ) );
686
687 // 出力ファイル名を絶対パスに変換
688 program.SetOutputFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetOutputFilePath() ) );
689
690 // モジュール名をセット
691 compiler.SetModuleName( Jenga::Common::Path( program.GetOutputFilePath() ).GetFileName() );
692 }
693
694 if( compiler.IsDll() )
695 {
696 //DLLファイル名を取得
697 _splitpath( program.GetOutputFilePath().c_str(),NULL,NULL,szDllName,temporary);
698 lstrcat(szDllName,temporary);
699 }
700
701 if( program.IsDebugRun() )
702 {
703 //コマンドライン、DLLの実行可能アプリケーションを取得
704 HANDLE hFile;
705 DWORD dwAccessBytes;
706 hFile=CreateFile(
707 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
708 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
709 if(hFile!=INVALID_HANDLE_VALUE){
710 ReadFile(hFile,temporary,MAX_PATH,&dwAccessBytes,NULL);
711 CloseHandle(hFile);
712 temporary[dwAccessBytes]=0;
713 }
714 else temporary[0]=0;
715
716 for(i=0;;i++){
717 if(temporary[i]=='\r'&&temporary[i+1]=='\n'||temporary[i]=='\0'){
718 szDebugExeForDll[i]=0;
719 break;
720 }
721 szDebugExeForDll[i]=temporary[i];
722 }
723 if(temporary[i]){
724 strcpy(szDebugCmdLine,temporary+i+2);
725 }
726 }
727
728 _splitpath( program.GetSourceFilePath().c_str(), BasicCurDir,temporary,NULL,NULL);
729 strcat(BasicCurDir,temporary);
730
731 if( program.IsClipCompileView() ){
732 //ProjectEditor埋め込み型インターフェイス
733 hMainDlg=CreateDialog(hInst, MAKEINTRESOURCE(IDD_CLIPMAIN), hOwnerEditor, DlgCompile);
734 ShowWindow(hMainDlg,SW_SHOW);
735 SendMessage(hOwnerEditor,WM_SETCOMPILEVIEW,0,(LPARAM)hMainDlg);
736
737 //プログレスバーの色をセットする
738 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBARCOLOR,0,RGB(255,220,192));
739 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBKCOLOR,0,RGB(255,255,255));
740 }
741 else{
742 //通常ダイアログインターフェイス
743 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN),hOwnerEditor,(DLGPROC)DlgCompile);
744
745 if( program.IsKickedFromEditor() )
746 {
747 // エディタから起動されたとき
748 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
749 }
750 else if( program.IsShowDlg() )
751 {
752 // コマンドラインでshow_dlgパラメータが指定された場合、ダイアログを表示する
753 // すぐにビルドを開始する
754 ShowWindow(hMainDlg,SW_SHOW);
755 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
756 }
757 else if( isSpecifiedSourceFilePathByCommandLine )
758 {
759 // コマンドラインでソースコード指定があった場合はウィンドウは表示せず、そのままビルドを開始する。
760 MainThread(0);
761
762 trace("Complete ActiveBasic Compiler!");
763
764 return program.GetExitCode();
765 }
766 else
767 {
768 ShowWindow(hMainDlg,SW_SHOW);
769 }
770 }
771 SendDlgItemMessage(hMainDlg,IDC_SHOWERROR,BM_SETCHECK,BST_CHECKED,0);
772
773 //エラーリストをサブクラス化
774 OldErrorListProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(GetDlgItem(hMainDlg, IDC_ERRORLIST), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ErrorListProc)));
775
776 //デバッグリストをサブクラス化
777 OldDebugListProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(GetDlgItem(hMainDlg, IDC_DEBUGLIST), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(DebugListProc)));
778
779 if( program.IsKickedFromEditor() )
780 {
781 SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
782 }
783
784 MSG msg;
785 while(GetMessage(&msg,0,0,0)){
786 if(IsDialogMessage(hMainDlg,&msg)) continue;
787 TranslateMessage(&msg);
788 DispatchMessage(&msg);
789 }
790
791 //不揮発性データを保存
792 pobj_nv->save();
793 delete pobj_nv;
794 pobj_nv=0;
795
796#if defined HeapAlloc
797 CheckHeapCheck();
798#endif
799
800 if( program.IsClipCompileView() ){
801 SendMessage(hOwnerEditor,WM_DESTROYCOMPILEVIEW,0,0);
802 }
803
804 trace("Complete ActiveBasic Compiler!");
805
806 return program.GetExitCode();
807}
Note: See TracBrowser for help on using the repository browser.