Changeset 15 in dev for BasicCompiler_Common
- Timestamp:
- Dec 11, 2006, 3:07:59 AM (18 years ago)
- Location:
- BasicCompiler_Common
- Files:
-
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/BasicCompiler.cpp
r14 r15 1 1 #include "BasicCompiler.h" 2 3 2 4 3 #if defined HeapAlloc -
BasicCompiler_Common/BasicCompiler.h
r14 r15 1 #include " common.h"1 #include "../BasicCompiler_Common/common.h" 2 2 3 3 LPSTR BasicFileFilter="プログラム ファイル(*.ab;*.bas;*.abp;*.sbp)\0*.ab;*.bas;*.abp;*sbp\0テキスト ファイル(*.txt)\0*.txt\0すべてのファイル(*.*)\0*\0\0"; … … 83 83 BOOL bDll; 84 84 85 char *basbuf; 86 char *pBaseBuffer; 87 85 88 char BasicSystemDir[MAX_PATH]; //BasicCompiler.exeが存在するディレクトリ 86 89 char BasicCurDir[MAX_PATH]; //コンパイルするファイルが存在するディレクトリ -
BasicCompiler_Common/Compile.cpp
r7 r15 392 392 BufferSize=128; 393 393 Command=(char *)HeapAlloc(hHeap,0,BufferSize); 394 /* 395 i = CSource::obj.GetTokenIndex(cp); 396 CToken *ptoken; 397 do{ 398 //次のトークン 399 ptoken = CSource::obj.GetToken(i++); 400 401 //ステップ区切り(改行またはコロン)の場合 402 while(ptoken->GetType() == TOKEN_DELIMITATION){ 403 ptoken = CSource::obj.GetToken(i++); 404 continue; 405 } 406 407 if(ptoken->GetType() == TOKEN_ESCAPESEQUENCE){ 408 //////////////////////////// 409 // 特殊記号 410 //////////////////////////// 411 412 if(ptoken->GetExtended() == ESC_LINENUM){ 413 414 //行番号 415 ptoken = CSource::obj.GetToken(i++); 416 417 i3=atoi(ptoken->ToString()); 418 i4=i+1; 419 420 //Goto先ラベル 421 pLabelNames=(LABEL *)HeapReAlloc(hHeap,0,pLabelNames,(MaxLabelNum+1)*sizeof(LABEL)); 422 pLabelNames[MaxLabelNum].pName=0; 423 pLabelNames[MaxLabelNum].line=i3; 424 pLabelNames[MaxLabelNum].address=obp; 425 MaxLabelNum++; 426 427 //書き込みスケジュール 428 for(i=0;i<GotoLabelScheduleNum;i++){ 429 if(pGotoLabelSchedule[i].pName==0&& 430 pGotoLabelSchedule[i].line==i3){ 431 *((long *)(OpBuffer+pGotoLabelSchedule[i].pos))=obp-(pGotoLabelSchedule[i].pos+sizeof(long)); 432 433 //詰める 434 GotoLabelScheduleNum--; 435 for(i2=i;i2<GotoLabelScheduleNum;i2++){ 436 pGotoLabelSchedule[i2].pName=pGotoLabelSchedule[i2+1].pName; 437 pGotoLabelSchedule[i2].line=pGotoLabelSchedule[i2+1].line; 438 pGotoLabelSchedule[i2].pos=pGotoLabelSchedule[i2+1].pos; 439 } 440 i--; 441 } 442 } 443 444 //カンマ 445 i++; 446 447 //次のトークン 448 ptoken = CSource::obj.GetToken(i++); 449 } 450 } 451 }while(ptoken->GetType() == TOKEN_EOF); 452 */ 394 453 for(cp++,i2=0;;cp++,i2++){ 395 454 if(i2>=BufferSize){ -
BasicCompiler_Common/DebugMiddleFile.cpp
r14 r15 474 474 //ソースコード 475 475 i2++; 476 CSource::obj.SetSourceCode(buffer + i2); 477 this->basbuf=CSource::obj.SourceCode; 476 pBaseBuffer=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+3); 477 basbuf=pBaseBuffer+2; 478 lstrcpy(basbuf,buffer+i2); 479 i2+=lstrlen(buffer+i2)+1; 478 480 extern char *basbuf; 479 481 basbuf=this->basbuf; 480 i2+=lstrlen(buffer+i2)+1;481 482 482 483 //コードと行番号の関係 … … 933 934 934 935 //ソースコード 936 extern char *pBaseBuffer; 935 937 extern char *basbuf; 938 pBaseBuffer=this->pBaseBuffer; 936 939 basbuf=this->basbuf; 937 940 … … 1013 1016 DeleteConstInfo(ppConstHash); 1014 1017 1018 //ソースコードを解放 1019 HeapDefaultFree(pBaseBuffer); 1020 1015 1021 //コードと行番号の関係を解放 1016 1022 HeapDefaultFree(pLineInfo); -
BasicCompiler_Common/DebugSection.h
r14 r15 25 25 26 26 //ソースコード 27 char *pBaseBuffer; 27 28 char *basbuf; 28 29 -
BasicCompiler_Common/MakeExe.cpp
r14 r15 34 34 } 35 35 36 void 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 36 63 void OutputExe(void){ 37 64 extern HANDLE hHeap; 38 65 extern char *basbuf; 66 extern char *pBaseBuffer; 39 67 extern int ErrorNum; 40 68 extern BOOL bStopCompile; … … 59 87 //プログラムをファイルから読み込む 60 88 extern char SourceFileName[MAX_PATH]; 61 CSource::obj.OpenFile(SourceFileName); 62 63 //未完成 64 basbuf = CSource::obj.SourceCode; 89 pBaseBuffer=OpenBasicFile(SourceFileName); 90 if(!pBaseBuffer){ 91 SetError(201,SourceFileName,-1); 92 goto EndCompile; 93 } 94 basbuf=pBaseBuffer+2; 65 95 66 96 //イメージベースの設定 … … 142 172 143 173 StepCompileProgress(); 144 145 146 //字句解析147 CSource::obj.LexicalAnalysis(0);148 174 149 175 … … 265 291 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]); 266 292 HeapDefaultFree(IncludeFileInfo.ppFileNames); 293 294 if(pBaseBuffer) HeapDefaultFree(pBaseBuffer); 267 295 } 268 296 int MainThread(DWORD dummy){ -
BasicCompiler_Common/StrOperation.cpp
r4 r15 249 249 return i; 250 250 } 251 int GetStringInPare(char *buffer,c har *ReadBuffer){251 int GetStringInPare(char *buffer,const char *ReadBuffer){ 252 252 int i,IsStr,PareNum; 253 253 for(i=0,IsStr=0,PareNum=0;;i++){ … … 294 294 return i; 295 295 } 296 int GetStringInBracket(char *buffer,c har *ReadBuffer){296 int GetStringInBracket(char *buffer,const char *ReadBuffer){ 297 297 int i,IsStr,PareNum; 298 298 for(i=0,IsStr=0,PareNum=0;;i++){ -
BasicCompiler_Common/calculation.cpp
r14 r15 10 10 _int64 i64stack[255]; 11 11 12 bool IsNumberTopChar(c har *buffer){12 bool IsNumberTopChar(const char *buffer){ 13 13 int c = buffer[0]; 14 14 if('0' <= c && c <= '9') return true; 15 if( buffer[0]== '&' && (buffer[1] == 'h' || buffer[1] == 'H' || buffer[1] == 'o' || buffer[1] == 'O')) return true;15 if(c == '&' && (buffer[1] == 'h' || buffer[1] == 'H' || buffer[1] == 'o' || buffer[1] == 'O')) return true; 16 16 17 17 return false; 18 18 } 19 bool IsNumberChar(c har c){19 bool IsNumberChar(const char c){ 20 20 if('0' <= c && c <= '9') return true; 21 21 if('a' <= c && c <= 'f') return true; 22 22 if('A' <= c && c <= 'F') return true; 23 if(c=='.' || c=='e'||c=='E') return true; 23 24 24 25 return false; 25 26 } 26 BOOL IsJudgMark(c har *Command,int p){27 BOOL IsJudgMark(const char *Command,int p){ 27 28 if(Command[p]==1){ 28 29 if(Command[p+1]==ESC_AND) return 1; … … 33 34 return 0; 34 35 } 35 BOOL IsNumCalcMark(c har *Command,int p){36 BOOL IsNumCalcMark(const char *Command,int p){ 36 37 if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'|| 37 38 (Command[p]==1&&Command[p+1]==ESC_MOD)||Command[p]=='+'||Command[p]=='-'|| … … 41 42 return 0; 42 43 } 43 BOOL IsNumCalcMark_Back(c har *Command,int p){44 BOOL IsNumCalcMark_Back(const char *Command,int p){ 44 45 if(p==0){ 45 46 if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'|| … … 56 57 return 0; 57 58 } 58 BOOL IsStrCalcMark(c har c){59 BOOL IsStrCalcMark(const char c){ 59 60 if(c=='+'||c=='&') return 1; 60 61 return 0; 61 62 } 62 BOOL IsExponent(c har *Command,int p){63 BOOL IsExponent(const char *Command,int p){ 63 64 int i,sw; 64 65 for(i=p-2,sw=FALSE;i>=0;i--){ … … 388 389 } 389 390 390 int StaticCalculation(bool enableerror, c har *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList){391 int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList){ 391 392 extern HANDLE hHeap; 392 393 extern int cp; … … 1346 1347 } 1347 1348 1348 BYTE GetCalcId(c har *Command,int *pi){1349 BYTE GetCalcId(const char *Command,int *pi){ 1349 1350 *pi=0; 1350 1351 … … 1400 1401 return 0; 1401 1402 } 1402 BOOL GetNumOpeElements(c har *Command,int *pnum,1403 BOOL GetNumOpeElements(const char *Command,int *pnum, 1403 1404 char *values[255],long calc[255],long stack[255]){ 1404 1405 extern int cp; -
BasicCompiler_Common/common.h
r14 r15 29 29 #include "../BasicCompiler_Common/psapi.h" 30 30 #include "../BasicCompiler_Common/BreakPoint.h" 31 #include "../BasicCompiler_Common/LexicalAnalysis.h"32 31 33 32 … … 154 153 }; 155 154 156 //#define情報157 class CDefine{158 int num;159 char **ppNames;160 public:161 CDefine();162 ~CDefine();163 164 BOOL add(char *name);165 BOOL undef(char *name);166 BOOL check(char *name);167 };168 155 169 156 //変数 … … 405 392 406 393 407 int StaticCalculation(bool enableerror, c har *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList=0);394 int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList=0); 408 395 409 396 … … 466 453 void DeleteConstInfo(CONSTINFO **ppConstHash); 467 454 void DeleteDeclareInfo(void); 455 void AddSourceCode(char *buffer); 468 456 void OutputExe(void); 469 457 int MainThread(DWORD dummy); … … 487 475 488 476 //preprocessor.cpp 489 void DirectiveIfdef(char *buffer); 490 char *IncludeFiles(char *base); 477 char *OpenBasicFile(char *FileName); 491 478 492 479 //Resource.cpp … … 517 504 int JumpOneParameter(char *Parameter,int i); 518 505 int GetStringInQuotation(char *buffer,char *ReadBuffer); 519 int GetStringInPare(char *buffer,c har *ReadBuffer);506 int GetStringInPare(char *buffer,const char *ReadBuffer); 520 507 int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer); 521 int GetStringInBracket(char *buffer,c har *ReadBuffer);508 int GetStringInBracket(char *buffer,const char *ReadBuffer); 522 509 int JumpStringInPare(char *buffer,int pos); 523 510 int JumpStringInBracket(char *buffer,int pos); … … 531 518 532 519 //calculation.cpp 533 bool IsNumberTopChar(c har *buffer);534 bool IsNumberChar(c har c);535 BOOL IsNumCalcMark(c har *Command,int p);536 BOOL IsNumCalcMark_Back(c har *Command,int p);537 BOOL IsStrCalcMark(c har c);538 BOOL IsExponent(c har *Command,int p);520 bool IsNumberTopChar(const char *buffer); 521 bool IsNumberChar(const char c); 522 BOOL IsNumCalcMark(const char *Command,int p); 523 BOOL IsNumCalcMark_Back(const char *Command,int p); 524 BOOL IsStrCalcMark(const char c); 525 BOOL IsExponent(const char *Command,int p); 539 526 int GetLiteralIndex(_int64 i64data); 540 527 int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2); … … 545 532 BOOL IsStringSubsituation(CClass *pobj_c); 546 533 int IsStrCalculation(char *Command); 547 BYTE GetCalcId(c har *Command,int *pi);548 BOOL GetNumOpeElements(c har *Command,int *pnum,534 BYTE GetCalcId(const char *Command,int *pi); 535 BOOL GetNumOpeElements(const char *Command,int *pnum, 549 536 char *values[255],long calc[255],long stack[255]); 550 537 -
BasicCompiler_Common/preprocessor.cpp
r14 r15 8 8 9 9 10 class CDefine{ 11 int num; 12 char **ppNames; 13 public: 14 CDefine(); 15 ~CDefine(); 16 17 BOOL add(char *name); 18 BOOL undef(char *name); 19 BOOL check(char *name); 20 }; 10 21 CDefine::CDefine(){ 11 22 extern HANDLE hHeap; … … 300 311 301 312 char *IncludeFiles(char *base){ 313 extern HANDLE hHeap; 302 314 extern char szIncludeDir[MAX_PATH]; 303 315 extern char BasicCurDir[MAX_PATH]; … … 423 435 424 436 i3=lstrlen(buffer)+FileSize; 425 base=(char *) realloc(base,i3*2);437 base=(char *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,base,i3*2); 426 438 buffer=base+2; 427 439 SlideString(buffer+i2,FileSize+(i-i2)); … … 451 463 return base; 452 464 } 465 char *OpenBasicFile(char *FileName){ 466 extern HANDLE hHeap; 467 char *base,*buffer; 468 DWORD dwFileSize,dwAccBytes; 469 HANDLE hFile; 470 471 //ファイルオープン 472 hFile=CreateFile(FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); 473 if(hFile==INVALID_HANDLE_VALUE) return 0; 474 475 //#define情報を初期化 476 pobj_define=new CDefine; 477 478 //バッファ領域確保 479 dwFileSize=GetFileSize(hFile,0); 480 base=(char *)HeapAlloc(hHeap,0,dwFileSize*2+255); 481 base[0]='\n'; 482 base[1]='\n'; 483 buffer=base+2; 484 lstrcpy(buffer,"#include <basic.sbp>\n"); 485 buffer+=lstrlen(buffer); 486 487 //読み込み 488 ReadFile(hFile,buffer,dwFileSize,&dwAccBytes,0); 489 buffer[dwAccBytes]=0; 490 491 //CRLFをLFに変換 492 ChangeReturnCode(buffer); 493 494 //コメント削除 495 DeleteComment(buffer); 496 497 //#ifdefディレクティブ 498 DirectiveIfdef(buffer); 499 500 //最終行には文字を含ませないようにする 501 lstrcat(buffer,"\n"); 502 503 //ファイルクローズ 504 CloseHandle(hFile); 505 506 //インクルードファイルを読み込む 507 base=IncludeFiles(base); 508 509 //#define情報を破棄 510 delete pobj_define; 511 pobj_define=0; 512 513 return base; 514 }
Note:
See TracChangeset
for help on using the changeset viewer.