Changeset 75 in dev for BasicCompiler_Common
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- Location:
- BasicCompiler_Common
- Files:
-
- 2 added
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/BasicCompiler.h
r73 r75 20 20 21 21 //プログラム情報 22 BOOL bCompilingGlobal;23 22 BOOL bStrict; 24 23 DWORD ImageBase; 25 24 INCLUDEFILEINFO IncludeFileInfo; 26 SubInfo**ppSubHash;25 UserProc **ppSubHash; 27 26 int SubNum; 28 27 char **ppMacroNames; 29 28 int MacroNum; 30 D ECLAREINFO**ppDeclareHash;29 DllProc **ppDeclareHash; 31 30 CONSTINFO **ppConstHash; 32 P ROCPTRINFO *pProcPtrInfo;31 ProcPointer **ppProcPointer; 33 32 int ProcPtrInfoNum; 34 33 -
BasicCompiler_Common/Class.cpp
r73 r75 16 16 17 17 18 CMember::CMember( CClass *pobj_c, DWORD access, bool isConst, bool isRef, char *buffer, int NowLine ){18 CMember::CMember( CClass *pobj_c, DWORD access, bool isConst, bool isRef, char *buffer, int nowLine ){ 19 19 extern int cp; 20 20 … … 23 23 char init_buf[VN_SIZE]; 24 24 char constract_parameter[VN_SIZE]; 25 GetDimentionFormat(buffer, isRef,VarName,SubScripts,&TypeInfo,init_buf,constract_parameter);25 GetDimentionFormat(buffer,VarName,SubScripts,*this,init_buf,constract_parameter); 26 26 27 27 //重複チェック … … 30 30 } 31 31 32 if( TypeInfo.type==DEF_OBJECT){33 if( TypeInfo.u.pobj_Class->IsAbstract()){32 if( IsObject() ){ 33 if( GetClass().IsAbstract() ){ 34 34 //抽象クラスだったとき 35 SetError(125, TypeInfo.u.pobj_Class->name,cp);35 SetError(125,GetClass().name,cp); 36 36 } 37 37 } … … 47 47 this->isConst = isConst; 48 48 49 //参照型かどうか50 this->isRef = isRef;51 52 49 //初期データ 53 50 InitBuf=(char *)HeapAlloc(hHeap,0,lstrlen(init_buf)+1); … … 59 56 60 57 //ソースコードの位置 61 source_code_address= NowLine;62 } 63 CMember::CMember(CMember *pobj){64 //コピーコンストラクタ65 memset(this,0,sizeof(CMember)); 58 source_code_address=nowLine; 59 } 60 CMember::CMember(CMember &member): 61 Type( member ) 62 { 66 63 67 64 //name 68 name=(char *)HeapAlloc(hHeap,0,lstrlen( pobj->name)+1);69 lstrcpy(name, pobj->name);65 name=(char *)HeapAlloc(hHeap,0,lstrlen(member.name)+1); 66 lstrcpy(name,member.name); 70 67 71 68 //定数扱いかどうか 72 isConst = pobj->isConst; 73 74 //参照型かどうか 75 isRef = pobj->isRef; 69 isConst = member.isConst; 76 70 77 71 //SubScripts 78 memcpy(SubScripts,pobj->SubScripts,MAX_ARRAYDIM*sizeof(int)); 79 80 //TypeInfo 81 TypeInfo=pobj->TypeInfo; 72 memcpy(SubScripts,member.SubScripts,MAX_ARRAYDIM*sizeof(int)); 82 73 83 74 //ソースコードの位置 84 source_code_address= pobj->source_code_address;75 source_code_address=member.source_code_address; 85 76 } 86 77 CMember::CMember(){ … … 95 86 bool CMember::IsConst(){ 96 87 return isConst; 97 }98 bool CMember::IsRef(){99 return isRef;100 }101 102 int CMember::GetSize(){103 //メンバサイズを取得104 return GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex);105 88 } 106 89 … … 126 109 temporary, 127 110 member->SubScripts, 128 member->TypeInfo, 129 GetTypeSize(member->TypeInfo.type,member->TypeInfo.u.lpIndex), 111 *member, 130 112 member->InitBuf, 131 113 member->ConstractParameter, … … 151 133 memset(this,0,sizeof(CMethod)); 152 134 153 p si=pobj->psi;135 pUserProc=pobj->pUserProc; 154 136 155 137 bAbstract=pobj->bAbstract; … … 224 206 iMemberNum=pInheritsClass->iMemberNum; 225 207 for(i3=0;i3<pInheritsClass->iMemberNum;i3++){ 226 ppobj_Member[i3]=new CMember( pInheritsClass->ppobj_Member[i3]);208 ppobj_Member[i3]=new CMember( *pInheritsClass->ppobj_Member[i3] ); 227 209 228 210 //dwAccess … … 263 245 iMemberNum++; 264 246 } 265 void CClass::AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int NowLine ){266 CMember *member = new CMember( this, dwAccess, isConst, isRef, buffer, NowLine );247 void CClass::AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int nowLine ){ 248 CMember *member = new CMember( this, dwAccess, isConst, isRef, buffer, nowLine ); 267 249 staticMembers.push_back( member ); 268 250 } 269 void CClass::AddMethod( SubInfo *psi,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ){251 void CClass::AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ){ 270 252 CMethod *method = new CMethod(); 271 method->p si = psi;253 method->pUserProc = pUserProc; 272 254 method->dwAccess = dwAccess; 273 255 method->isConst = isConst; … … 277 259 278 260 methods.push_back( method ); 279 } 280 void CClass::AddStaticMethod(SubInfo *psi,DWORD dwAccess){ 261 262 // プロシージャオブジェクトと関連付け 263 pUserProc->SetMethod( method ); 264 } 265 void CClass::AddStaticMethod(UserProc *pUserProc,DWORD dwAccess){ 281 266 CMethod *method = new CMethod(); 282 method->p si=psi;267 method->pUserProc=pUserProc; 283 268 method->dwAccess=dwAccess; 284 269 method->bAbstract=0; … … 287 272 288 273 staticMethods.push_back( method ); 274 275 // プロシージャオブジェクトと関連付け 276 pUserProc->SetMethod( method ); 289 277 } 290 278 BOOL CClass::DupliCheckAll(const char *name){ … … 296 284 //メソッド 297 285 foreach( CMethod *method, methods ){ 298 if( lstrcmp( name, method->p si->name) == 0 ){286 if( lstrcmp( name, method->pUserProc->GetName().c_str() ) == 0 ){ 299 287 return 1; 300 288 } … … 322 310 return 0; 323 311 } 324 CMethod *CClass::GetMethodInfo( SubInfo *psi ){ 312 CMethod *CClass::GetMethodInfo( UserProc *pUserProc ) const 313 { 325 314 for( int i=(int)methods.size()-1; i>=0; i-- ){ 326 if( p si == methods[i]->psi) return methods[i];315 if( pUserProc == methods[i]->pUserProc ) return methods[i]; 327 316 } 328 317 return NULL; 329 318 } 330 CMethod *CClass::GetStaticMethodInfo( SubInfo *psi ){ 319 CMethod *CClass::GetStaticMethodInfo( UserProc *pUserProc ) const 320 { 331 321 for( int i=(int)staticMethods.size()-1; i>=0; i-- ){ 332 if( p si == staticMethods[i]->psi) return staticMethods[i];322 if( pUserProc == staticMethods[i]->pUserProc ) return staticMethods[i]; 333 323 } 334 324 return NULL; 335 325 } 336 bool CClass::IsExistMethod( const char *name ){ 326 bool CClass::IsExistMethod( const char *name ) const 327 { 337 328 foreach( CMethod *method, methods ){ 338 if( lstrcmp( method->psi->name, name ) == 0) return true;329 if( method->pUserProc->GetName() == name ) return true; 339 330 } 340 331 return false; 341 332 } 342 bool CClass::IsExistStaticMethod( const char *name ){ 333 bool CClass::IsExistStaticMethod( const char *name ) const 334 { 343 335 foreach( CMethod *method, staticMethods ){ 344 if( lstrcmp( method->psi->name, name ) == 0) return true;336 if( method->pUserProc->GetName() == name ) return true; 345 337 } 346 338 return false; 347 339 } 348 340 349 void CClass::EnumStaticMethod( const char *methodName, std::vector< SubInfo*> &subs ) const341 void CClass::EnumStaticMethod( const char *methodName, std::vector<UserProc *> &subs ) const 350 342 { 351 343 foreach( CMethod *method, staticMethods ){ 352 if( lstrcmp(methodName,method->psi->name)==0){353 subs.push_back( method->p si);354 } 355 } 356 } 357 358 void CClass::EnumMethod( const char *methodName, std::vector< SubInfo*> &subs ) const344 if( method->pUserProc->GetName() == methodName ){ 345 subs.push_back( method->pUserProc ); 346 } 347 } 348 } 349 350 void CClass::EnumMethod( const char *methodName, std::vector<UserProc *> &subs ) const 359 351 { 360 352 //オブジェクトのメンバ関数の場合 361 353 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う 362 354 for( int i=(int)methods.size()-1; i>=0; i-- ){ 363 if( lstrcmp(methodName,methods[i]->psi->name)==0){364 subs.push_back( methods[i]->p si);365 } 366 } 367 } 368 369 void CClass::EnumMethod( const BYTE idOperatorCalc, std::vector< SubInfo*> &subs ) const355 if( methods[i]->pUserProc->GetName() == methodName ){ 356 subs.push_back( methods[i]->pUserProc ); 357 } 358 } 359 } 360 361 void CClass::EnumMethod( const BYTE idOperatorCalc, std::vector<UserProc *> &subs ) const 370 362 { 371 363 //オブジェクトのメンバ関数の場合 372 364 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う 373 365 for( int i=(int)methods.size()-1; i>=0; i-- ){ 374 SubInfo *psi = methods[i]->psi;375 c har *temp = psi->name;366 UserProc *pUserProc = methods[i]->pUserProc; 367 const char *temp = pUserProc->GetName().c_str(); 376 368 if(temp[0]==1&&temp[1]==ESC_OPERATOR){ 377 369 if((BYTE)temp[2]==idOperatorCalc){ 378 subs.push_back( p si);370 subs.push_back( pUserProc ); 379 371 } 380 372 } … … 423 415 //アラインメントを算出 424 416 int member_size; 425 if( pMember->TypeInfo.type==DEF_STRUCT){417 if( pMember->IsStruct() ){ 426 418 //メンバクラスのアラインメントを取得 427 member_size=pMember-> TypeInfo.u.pobj_Class->GetAlignment();419 member_size=pMember->GetClass().GetAlignment(); 428 420 } 429 421 else{ … … 486 478 CMember *pMember = ppobj_Member[i]; 487 479 488 if(pMember-> TypeInfo.type==DEF_STRUCT){480 if(pMember->IsStruct()){ 489 481 //メンバクラスのアラインメントを取得 490 member_size=pMember-> TypeInfo.u.pobj_Class->GetAlignment();482 member_size=pMember->GetClass().GetAlignment(); 491 483 } 492 484 else{ … … 508 500 509 501 510 int CClass::GetFuncNumInVtbl( const SubInfo *psi) const502 int CClass::GetFuncNumInVtbl( const UserProc *pUserProc ) const 511 503 { 512 504 int n = 0; 513 505 foreach( CMethod *method, methods ){ 514 if( method->p si == psi) break;515 if( method-> psi->bVirtual ) n++;506 if( method->pUserProc == pUserProc ) break; 507 if( method->bVirtual ) n++; 516 508 } 517 509 return n; … … 527 519 ////////////////////////////////////// 528 520 529 SubInfo**ppsi;530 ppsi=( SubInfo **)HeapAlloc(hHeap,0,vtbl_num*sizeof(SubInfo*));521 UserProc **ppsi; 522 ppsi=(UserProc **)HeapAlloc(hHeap,0,vtbl_num*sizeof(UserProc *)); 531 523 532 524 //関数テーブルに値をセット … … 534 526 foreach( CMethod *method, methods ){ 535 527 if(method->bVirtual){ 536 method->p si->bUse=1;528 method->pUserProc->Using(); 537 529 538 530 if(method->bAbstract){ … … 542 534 ppsi[i2]=0; 543 535 } 544 else ppsi[i2]=method->p si;536 else ppsi[i2]=method->pUserProc; 545 537 i2++; 546 538 } … … 565 557 int i; 566 558 for(i=0;i<vtbl_num;i++){ 567 SubInfo *psi; 568 psi=(SubInfo *)pVtbl[i]; 569 if(!psi) continue; 570 pVtbl[i]=psi->CompileAddress+ImageBase+MemPos_CodeSection; 571 } 572 } 573 bool CClass::IsAbstract(){ 559 UserProc *pUserProc; 560 pUserProc=(UserProc *)pVtbl[i]; 561 if(!pUserProc) continue; 562 pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection; 563 } 564 } 565 bool CClass::IsAbstract() const 566 { 574 567 //未実装の仮想関数を持つ場合はtrueを返す 575 568 … … 584 577 //コンポジションの関係にあるメンバも検査する 585 578 for(int i=0;i < iMemberNum;i++){ 586 if(ppobj_Member[i]-> TypeInfo.type==DEF_OBJECT){587 if(ppobj_Member[i]-> TypeInfo.u.pobj_Class->IsAbstract())579 if(ppobj_Member[i]->IsObject()){ 580 if(ppobj_Member[i]->GetClass().IsAbstract()) 588 581 return true; 589 582 } … … 604 597 605 598 //コンストラクタをコンパイル中かどうかを判別 606 bool CClass::IsCompilingConstructor(){ 599 bool CClass::IsCompilingConstructor() const 600 { 607 601 return isCompilingConstructor; 608 602 } … … 619 613 620 614 //デストラクタをコンパイル中かどうかを判別 621 bool CClass::IsCompilingDestructor(){ 615 bool CClass::IsCompilingDestructor() const 616 { 622 617 return isCompilingDestructor; 623 618 } … … 625 620 626 621 //自身と等しいクラスかどうかを確認 627 bool CClass::IsEquals( CClass *pClass ){ 622 bool CClass::IsEquals( const CClass *pClass ) const 623 { 628 624 if( this == pClass ) return true; 629 625 return false; … … 631 627 632 628 //自身の派生クラスかどうかを確認 633 bool CClass::IsSubClass( CClass *pClass ){ 629 bool CClass::IsSubClass( const CClass *pClass ) const 630 { 634 631 pClass = pClass->pobj_InheritsClass; 635 632 while( pClass ){ … … 641 638 642 639 //自身と等しいまたは派生クラスかどうかを確認 643 bool CClass::IsEqualsOrSubClass( CClass *pClass ){ 640 bool CClass::IsEqualsOrSubClass( const CClass *pClass ) const 641 { 644 642 if( IsEquals( pClass ) ) return true; 645 643 return IsSubClass( pClass ); … … 722 720 } 723 721 724 CClass *CDBClass::AddClass(const char *name,int NowLine){722 CClass *CDBClass::AddClass(const char *name,int nowLine){ 725 723 ////////////////////////////////////////////////////////////////////////// 726 724 // クラスを追加 … … 753 751 if(lstrcmp(name,pobj_c2->name)==0){ 754 752 //重複した場合 755 SetError(15,name, NowLine);753 SetError(15,name,nowLine); 756 754 return 0; 757 755 } … … 781 779 basbuf[i+1]==ESC_INTERFACE 782 780 )){ 783 int NowLine;784 NowLine=i;781 int nowLine; 782 nowLine=i; 785 783 786 784 i+=2; … … 802 800 803 801 //クラスを追加 804 CClass *pClass = pobj_DBClass->AddClass(temporary, NowLine);802 CClass *pClass = pobj_DBClass->AddClass(temporary,nowLine); 805 803 if( pClass ){ 806 if( basbuf[ NowLine+1] == ESC_CLASS ){804 if( basbuf[nowLine+1] == ESC_CLASS ){ 807 805 pClass->classType = CClass::Class; 808 806 } 809 else if( basbuf[ NowLine+1] == ESC_INTERFACE ){807 else if( basbuf[nowLine+1] == ESC_INTERFACE ){ 810 808 pClass->classType = CClass::Interface; 811 809 } … … 820 818 821 819 void CDBClass::AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract, 822 BOOL bVirtual, BOOL bOverride, char *buffer, int NowLine){820 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine){ 823 821 int i,i2; 824 822 char temporary[VN_SIZE]; … … 835 833 836 834 //関数ハッシュへ登録 837 SubInfo *psi;838 p si=AddSubData(buffer,NowLine,bVirtual,pobj_c,bStatic);839 if(!p si) return;835 UserProc *pUserProc; 836 pUserProc=AddSubData(buffer,nowLine,bVirtual,pobj_c, (bStatic!=0) ); 837 if(!pUserProc) return; 840 838 841 839 … … 849 847 850 848 //標準コンストラクタ(引数なし) 851 if(p si->params.size()==0) fConstructor=1;849 if(pUserProc->Params().size()==0) fConstructor=1; 852 850 853 851 //強制的にConst修飾子をつける … … 857 855 //デストラクタの場合はその名前が正しいかチェックを行う 858 856 if(lstrcmp(temporary+1,pobj_c->name)!=0) 859 SetError(117,NULL, NowLine);857 SetError(117,NULL,nowLine); 860 858 else 861 859 bDestructor=1; … … 864 862 // コンストラクタ、デストラクタのアクセシビリティをチェック 865 863 if(dwAccess!=ACCESS_PUBLIC){ 866 SetError(116,NULL, NowLine);864 SetError(116,NULL,nowLine); 867 865 dwAccess=ACCESS_PUBLIC; 868 866 } … … 884 882 885 883 if(pobj_c->DupliCheckMember(temporary)){ 886 SetError(15,temporary, NowLine);884 SetError(15,temporary,nowLine); 887 885 return; 888 886 } … … 893 891 if(method->pobj_InheritsClass) continue; 894 892 895 if( lstrcmp(temporary,method->psi->name)==0){896 if( Parameter::Equals( method->p si->params, psi->params) ){893 if( method->pUserProc->GetName() == temporary ){ 894 if( Parameter::Equals( method->pUserProc->Params(), pUserProc->Params() ) ){ 897 895 //関数名、パラメータ属性が合致したとき 898 SetError(15,p si->name,NowLine);896 SetError(15,pUserProc->GetName().c_str(),nowLine); 899 897 return; 900 898 } … … 903 901 904 902 //仮想関数の場合 905 if(bAbstract) p si->bCompile=1;903 if(bAbstract) pUserProc->CompleteCompile(); 906 904 907 905 //メソッドのオーバーライド 908 906 foreach( CMethod *method, pobj_c->methods ){ 909 if( lstrcmp(temporary,method->psi->name)==0){910 if( Parameter::Equals( method->p si->params, psi->params) ){911 912 if(method-> psi->bVirtual){907 if( method->pUserProc->GetName() == temporary ){ 908 if( Parameter::Equals( method->pUserProc->Params(), pUserProc->Params() ) ){ 909 910 if(method->bVirtual){ 913 911 //メンバ関数を上書き 914 method->p si=psi;912 method->pUserProc=pUserProc; 915 913 method->bAbstract=0; 916 914 917 915 if(!bOverride){ 918 SetError(127,NULL, NowLine);916 SetError(127,NULL,nowLine); 919 917 } 920 918 if(method->dwAccess!=dwAccess){ 921 SetError(128,NULL, NowLine);919 SetError(128,NULL,nowLine); 922 920 } 921 922 pUserProc->SetMethod( method ); 923 923 return; 924 924 } … … 927 927 } 928 928 929 if( psi->bVirtual){929 if(bVirtual){ 930 930 pobj_c->vtbl_num++; 931 931 } 932 932 933 933 if(bOverride){ 934 SetError(12,"Override", NowLine);934 SetError(12,"Override",nowLine); 935 935 } 936 936 937 937 if(bStatic){ 938 pobj_c->AddStaticMethod(p si,dwAccess);938 pobj_c->AddStaticMethod(pUserProc,dwAccess); 939 939 } 940 940 else{ 941 pobj_c->AddMethod(p si, dwAccess, isConst, bAbstract, bVirtual);942 } 943 } 944 945 BOOL CDBClass::MemberVar_LoopRefCheck( CClass *pobj_c){941 pobj_c->AddMethod(pUserProc, dwAccess, isConst, bAbstract, bVirtual); 942 } 943 } 944 945 BOOL CDBClass::MemberVar_LoopRefCheck(const CClass &objClass){ 946 946 int i,i2,bRet=1; 947 for(i=0;i< pobj_c->iMemberNum;i++){948 CMember *pMember = pobj_c->ppobj_Member[i];949 if(pMember-> TypeInfo.type==DEF_OBJECT){947 for(i=0;i<objClass.iMemberNum;i++){ 948 const CMember *pMember = objClass.ppobj_Member[i]; 949 if(pMember->IsObject()){ 950 950 //循環参照でないかをチェック 951 if(pobj_LoopRefCheck->check(pMember-> TypeInfo.u.pobj_Class->name)){951 if(pobj_LoopRefCheck->check(pMember->GetClass().name)){ 952 952 extern int cp; 953 SetError(124,pMember-> TypeInfo.u.pobj_Class->name,cp);953 SetError(124,pMember->GetClass().name,cp); 954 954 return 0; 955 955 } 956 956 957 pobj_LoopRefCheck->add( pobj_c->name);958 959 i2=MemberVar_LoopRefCheck(pMember-> TypeInfo.u.pobj_Class);957 pobj_LoopRefCheck->add(objClass.name); 958 959 i2=MemberVar_LoopRefCheck(pMember->GetClass()); 960 960 if(bRet==1) bRet=i2; 961 961 962 pobj_LoopRefCheck->del( pobj_c->name);962 pobj_LoopRefCheck->del(objClass.name); 963 963 } 964 964 } … … 1347 1347 1348 1348 1349 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.type==DEF_OBJECT||1350 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.type==DEF_STRUCT){1351 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.u.pobj_Class->ppobj_Member==0){1349 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsObject()|| 1350 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsStruct()){ 1351 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetClass().ppobj_Member==0){ 1352 1352 //参照先が読み取られていないとき 1353 GetClass_recur(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.u.pobj_Class->name);1353 GetClass_recur(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetClass().name); 1354 1354 } 1355 1355 } 1356 1356 1357 1357 1358 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.type==DEF_OBJECT){1358 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsObject()){ 1359 1359 //循環参照のチェック 1360 1360 pobj_LoopRefCheck->add(pobj_c->name); 1361 if(!MemberVar_LoopRefCheck(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.u.pobj_Class)){1361 if(!MemberVar_LoopRefCheck(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetClass())){ 1362 1362 //エラー回避 1363 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]-> TypeInfo.type=DEF_PTR_VOID;1363 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->SetBasicType( DEF_PTR_VOID ); 1364 1364 } 1365 1365 pobj_LoopRefCheck->del(pobj_c->name); … … 1438 1438 } 1439 1439 1440 void CDBClass::StartCompile( SubInfo *psi){1441 pCompilingClass = p si->pobj_ParentClass;1440 void CDBClass::StartCompile( UserProc *pUserProc ){ 1441 pCompilingClass = pUserProc->GetParentClassPtr(); 1442 1442 if( pCompilingClass ){ 1443 pCompilingMethod = pCompilingClass->GetMethodInfo( p si);1443 pCompilingMethod = pCompilingClass->GetMethodInfo( pUserProc ); 1444 1444 if( !pCompilingMethod ){ 1445 pCompilingMethod = pCompilingClass->GetStaticMethodInfo( p si);1445 pCompilingMethod = pCompilingClass->GetStaticMethodInfo( pUserProc ); 1446 1446 if( !pCompilingMethod ){ 1447 1447 SetError(300,NULL,cp); -
BasicCompiler_Common/Class.h
r73 r75 1 1 #include <vector> 2 #include "Type.h" 2 3 3 4 class CClass; 4 class SubInfo; 5 6 //データ型 7 struct TYPEINFO{ 8 int type; 9 union{ 10 LONG_PTR lpIndex; 11 CClass *pobj_Class; 12 }u; 13 }; 5 class UserProc; 14 6 15 7 #define ACCESS_NON 0 … … 18 10 #define ACCESS_PROTECTED 3 19 11 20 class CMember{ 12 class CMember : public Type 13 { 21 14 bool isConst; 22 bool isRef;23 15 public: 24 16 char *name; 25 17 int SubScripts[MAX_ARRAYDIM]; 26 TYPEINFO TypeInfo;27 18 28 19 DWORD dwAccess; … … 34 25 35 26 36 CMember( CClass *pobj_c, DWORD access, bool idConst, bool isRef, char *buffer, int NowLine=-1 );37 CMember( CMember *pobj);27 CMember( CClass *pobj_c, DWORD access, bool idConst, bool isRef, char *buffer, int nowLine=-1 ); 28 CMember( CMember &member ); 38 29 CMember(); 39 30 ~CMember(); 40 31 41 32 bool IsConst(); 42 bool IsRef();43 int GetSize();44 33 45 34 … … 48 37 class CMethod{ 49 38 public: 50 SubInfo *psi;39 UserProc *pUserProc; 51 40 DWORD dwAccess; 52 41 BOOL bAbstract; … … 115 104 //メンバ、メソッドの追加 116 105 void AddMember( DWORD dwAccess, bool idConst, bool isRef, char *buffer ); 117 void AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int NowLine );118 void AddMethod( SubInfo *psi,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual );119 void AddStaticMethod( SubInfo *psi,DWORD dwAccess);106 void AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int nowLine ); 107 void AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ); 108 void AddStaticMethod(UserProc *pUserProc,DWORD dwAccess); 120 109 121 110 //重複チェック … … 124 113 125 114 //メソッド取得 126 CMethod *GetMethodInfo( SubInfo *psi );127 CMethod *GetStaticMethodInfo( SubInfo *psi );115 CMethod *GetMethodInfo( UserProc *pUserProc ) const; 116 CMethod *GetStaticMethodInfo( UserProc *pUserProc ) const; 128 117 129 118 //メソッドの存在を確認 130 bool IsExistMethod( const char *name ) ;131 bool IsExistStaticMethod( const char *name ) ;119 bool IsExistMethod( const char *name ) const; 120 bool IsExistStaticMethod( const char *name ) const; 132 121 133 122 //メソッドを列挙 134 void EnumStaticMethod( const char *methodName, std::vector< SubInfo*> &subs ) const;135 void EnumMethod( const char *methodName, std::vector< SubInfo*> &subs ) const;136 void EnumMethod( const BYTE idOperatorCalc, std::vector< SubInfo*> &subs ) const;123 void EnumStaticMethod( const char *methodName, std::vector<UserProc *> &subs ) const; 124 void EnumMethod( const char *methodName, std::vector<UserProc *> &subs ) const; 125 void EnumMethod( const BYTE idOperatorCalc, std::vector<UserProc *> &subs ) const; 137 126 138 127 //デフォルト コンストラクタ メソッドを取得 … … 157 146 long vtbl_offset; 158 147 public: 159 int GetFuncNumInVtbl( const SubInfo *psi) const;148 int GetFuncNumInVtbl( const UserProc *pUserProc ) const; 160 149 LONG_PTR GetVtblGlobalOffset(void); 161 150 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); 162 bool IsAbstract() ;151 bool IsAbstract() const; 163 152 164 153 … … 169 158 void NotifyStartConstructorCompile(); 170 159 void NotifyFinishConstructorCompile(); 171 bool IsCompilingConstructor() ;160 bool IsCompilingConstructor() const; 172 161 173 162 //デストラクタをコンパイルしているかどうかのチェックフラグ … … 177 166 void NotifyStartDestructorCompile(); 178 167 void NotifyFinishDestructorCompile(); 179 bool IsCompilingDestructor() ;168 bool IsCompilingDestructor() const; 180 169 181 170 182 171 //自身と等しいクラスかどうかを確認 183 bool IsEquals( CClass *pClass );172 bool IsEquals( const CClass *pClass ) const; 184 173 185 174 //自身の派生クラスかどうかを確認 186 bool IsSubClass( CClass *pClass );175 bool IsSubClass( const CClass *pClass ) const; 187 176 188 177 //自身と等しいまたは派生クラスかどうかを確認 189 bool IsEqualsOrSubClass( CClass *pClass );178 bool IsEqualsOrSubClass( const CClass *pClass ) const; 190 179 191 180 … … 214 203 CClass *check(const char *name); 215 204 216 CClass *AddClass(const char *name,int NowLine);205 CClass *AddClass(const char *name,int nowLine); 217 206 218 207 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); … … 220 209 private: 221 210 void AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract, 222 BOOL bVirtual, BOOL bOverride, char *buffer, int NowLine);223 BOOL MemberVar_LoopRefCheck( CClass *pobj_c);211 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine); 212 BOOL MemberVar_LoopRefCheck(const CClass &objClass); 224 213 public: 225 214 void InitNames(void); … … 245 234 public: 246 235 //コンパイル開始の通知を受け取るメソッド 247 void StartCompile( SubInfo *psi);236 void StartCompile( UserProc *pUserProc ); 248 237 249 238 //現在コンパイル中のメソッド情報を取得 -
BasicCompiler_Common/CommandFormat.cpp
r4 r75 1 1 #include "common.h" 2 2 3 void ComOpen(char *Parameter,char *buffer,int NowLine){3 void ComOpen(char *Parameter,char *buffer,int nowLine){ 4 4 int i,i2,IsStr; 5 5 char temporary[255]; … … 26 26 for(i2=0;;i++,i2++){ 27 27 if(Parameter[i]=='\0'){ 28 SetError(1,NULL, NowLine);28 SetError(1,NULL,nowLine); 29 29 return; 30 30 } … … 39 39 else if(lstrcmpi(temporary,"append")==0) lstrcat(buffer,",3"); 40 40 else{ 41 SetError(1,NULL, NowLine);41 SetError(1,NULL,nowLine); 42 42 return; 43 43 } … … 63 63 } 64 64 65 void ComLine(char *Parameter,char *buffer,int NowLine){65 void ComLine(char *Parameter,char *buffer,int nowLine){ 66 66 int i,i2,PareNum; 67 67 char temporary[VN_SIZE],temp2[VN_SIZE]; … … 75 75 else{ 76 76 if(Parameter[0]!='('){ 77 SetError(10,"Line", NowLine);77 SetError(10,"Line",nowLine); 78 78 return; 79 79 } … … 93 93 94 94 if(Parameter[i+1]!='-'){ 95 SetError(10,"Line", NowLine);95 SetError(10,"Line",nowLine); 96 96 return; 97 97 } … … 107 107 108 108 if(Parameter[i]!='('){ 109 SetError(10,"Line", NowLine);109 SetError(10,"Line",nowLine); 110 110 return; 111 111 } … … 129 129 } 130 130 else if(Parameter[i+1]!=','){ 131 SetError(10,"Line", NowLine);131 SetError(10,"Line",nowLine); 132 132 return; 133 133 } … … 147 147 else if(lstrcmpi(temporary,"bf")==0) lstrcat(buffer,",2"); 148 148 else{ 149 SetError(10,"Line", NowLine);149 SetError(10,"Line",nowLine); 150 150 return; 151 151 } … … 158 158 i=GetOneParameter(Parameter,i,temporary); //第7パラメータ取得 159 159 if(Parameter[i-1]==','){ 160 SetError(10,"Line", NowLine);160 SetError(10,"Line",nowLine); 161 161 return; 162 162 } … … 165 165 lstrcat(buffer,temporary); 166 166 } 167 void ComCircle(char *Parameter,char *buffer,int NowLine){167 void ComCircle(char *Parameter,char *buffer,int nowLine){ 168 168 int i,i2,PareNum; 169 169 char temporary[VN_SIZE],temp2[VN_SIZE]; … … 172 172 173 173 if(Parameter[0]!='('){ 174 SetError(10,"Circle", NowLine);174 SetError(10,"Circle",nowLine); 175 175 return; 176 176 } … … 189 189 i++; 190 190 if(Parameter[i]!=','){ 191 SetError(10,"Circle", NowLine);191 SetError(10,"Circle",nowLine); 192 192 return; 193 193 } … … 241 241 } 242 242 else{ 243 SetError(10,"Circle", NowLine);243 SetError(10,"Circle",nowLine); 244 244 return; 245 245 } … … 251 251 lstrcat(buffer,temporary); 252 252 if(Parameter[i-1]==','){ 253 SetError(10,"Circle", NowLine);253 SetError(10,"Circle",nowLine); 254 254 return; 255 255 } … … 260 260 } 261 261 } 262 void ComPSet(char *Parameter,char *buffer,int NowLine){262 void ComPSet(char *Parameter,char *buffer,int nowLine){ 263 263 int i,i2,PareNum; 264 264 … … 266 266 267 267 if(Parameter[0]!='('){ 268 SetError(10,"PSet", NowLine);268 SetError(10,"PSet",nowLine); 269 269 return; 270 270 } … … 284 284 else if(Parameter[i+1]=='\0') lstrcat(buffer,",7"); 285 285 else{ 286 SetError(10,"PSet", NowLine);287 return; 288 } 289 } 290 void ComPaint(char *Parameter,char *buffer,int NowLine){286 SetError(10,"PSet",nowLine); 287 return; 288 } 289 } 290 void ComPaint(char *Parameter,char *buffer,int nowLine){ 291 291 int i,i2,PareNum; 292 292 … … 294 294 295 295 if(Parameter[0]!='('){ 296 SetError(10,"Paint", NowLine);296 SetError(10,"Paint",nowLine); 297 297 return; 298 298 } … … 309 309 } 310 310 if(Parameter[i+1]!=','){ 311 SetError(10,"Paint", NowLine);311 SetError(10,"Paint",nowLine); 312 312 return; 313 313 } -
BasicCompiler_Common/Const.cpp
r7 r75 153 153 } 154 154 void CDBConst::AddConst(char *Name, char *Expression){ 155 LONG_PTR lpIndex;156 155 _int64 i64data; 157 int Type = StaticCalculation(false, Expression, 0, &i64data, &lpIndex); 158 159 if(Type){ 160 //リテラル値の場合 161 //登録を行う 162 163 CConst *newconst = new CConst(Name, Type, i64data); 164 165 AddConst(Name, newconst); 166 } 167 else{ 156 Type resultType; 157 if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){ 168 158 //変数の場合 169 159 //何もしない(実行領域コンパイル時にdim宣言として扱う) 170 } 160 return; 161 } 162 163 //リテラル値の場合 164 //登録を行う 165 166 CConst *newconst = new CConst(Name, resultType.GetBasicType(), i64data); 167 168 AddConst(Name, newconst); 171 169 } 172 170 void CDBConst::AddConst(char *Name, int value){ -
BasicCompiler_Common/Debug.cpp
r73 r75 224 224 SendDlgItemMessage(hMainDlg,IDC_DEBUGLIST,EM_REPLACESEL,0,(LPARAM)buffer); 225 225 } 226 SubInfo*GetSubFromObp(ULONG_PTR pos){227 extern SubInfo**ppSubHash;228 SubInfo *psi;226 UserProc *GetSubFromObp(ULONG_PTR pos){ 227 extern UserProc **ppSubHash; 228 UserProc *pUserProc; 229 229 int i2; 230 230 231 231 for(i2=0;i2<MAX_HASH;i2++){ 232 p si=ppSubHash[i2];233 while(p si){234 if(rva_to_real(p si->CompileAddress) <= pos &&235 pos < rva_to_real(p si->EndOpAddr))236 return p si;237 238 p si=psi->pNextData;232 pUserProc=ppSubHash[i2]; 233 while(pUserProc){ 234 if(rva_to_real(pUserProc->beginOpAddress) <= pos && 235 pos < rva_to_real(pUserProc->endOpAddress)) 236 return pUserProc; 237 238 pUserProc=pUserProc->pNextData; 239 239 } 240 240 } … … 447 447 pobj_dti=new CDebugThreadInfo(); 448 448 449 SubInfo *psi;449 UserProc *pUserProc; 450 450 451 451 extern DWORD dwStepRun; … … 681 681 if(!bRet) MessageBox(hMainDlg,"プロセスメモリーの読み込みに失敗","error",MB_OK); 682 682 683 extern SubInfo*pSub_DebugSys_EndProc;683 extern UserProc *pSub_DebugSys_EndProc; 684 684 if((BYTE)temporary[0]==0xE8&& 685 *((long *)(temporary+1))+5==(long)rva_to_real(pSub_DebugSys_EndProc-> CompileAddress)-(long)EIP_RIP(Context)){685 *((long *)(temporary+1))+5==(long)rva_to_real(pSub_DebugSys_EndProc->beginOpAddress)-(long)EIP_RIP(Context)){ 686 686 //プロシージャの終端位置の場合はステップインを行う 687 687 goto StepIn; … … 700 700 else{ 701 701 //プロシージャを識別 702 p si=GetSubFromObp(pobj_dti->lplpObp[pobj_dti->iProcLevel]);702 pUserProc=GetSubFromObp(pobj_dti->lplpObp[pobj_dti->iProcLevel]); 703 703 704 704 //シングルステップON 705 705 WriteProcessMemory(hDebugProcess, 706 (void *)rva_to_real(p si->CompileAddress),707 pobj_DBDebugSection->pobj_now->SingleStepCodeBuffer+p si->CompileAddress,708 p si->EndOpAddr-psi->CompileAddress,706 (void *)rva_to_real(pUserProc->beginOpAddress), 707 pobj_DBDebugSection->pobj_now->SingleStepCodeBuffer+pUserProc->beginOpAddress, 708 pUserProc->endOpAddress-pUserProc->beginOpAddress, 709 709 &lpAccBytes); 710 710 } -
BasicCompiler_Common/DebugMiddleFile.cpp
r73 r75 10 10 11 11 12 void SetLpIndex_DebugFile(char *buffer,int *p, int type,LONG_PTR lpIndex){13 if(NATURAL_TYPE(type )==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){14 lstrcpy(buffer+(*p), ((CClass *)lpIndex)->name);12 void SetLpIndex_DebugFile(char *buffer,int *p,const Type &type){ 13 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){ 14 lstrcpy(buffer+(*p),type.GetClass().name); 15 15 (*p)+=lstrlen(buffer+(*p))+1; 16 16 } 17 17 else{ 18 *(LONG_PTR *)(buffer+(*p))= lpIndex;18 *(LONG_PTR *)(buffer+(*p))=type.GetIndex(); 19 19 (*p)+=sizeof(LONG_PTR); 20 20 } … … 22 22 23 23 24 void GetLpIndex_DebugFile(char *buffer,int *p, int type,LONG_PTR *plpIndex){25 if(NATURAL_TYPE(type )==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){24 void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){ 25 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){ 26 26 char szClassName[VN_SIZE]; 27 27 lstrcpy(szClassName,buffer+(*p)); 28 28 (*p)+=lstrlen(buffer+(*p))+1; 29 29 30 *plpIndex=(LONG_PTR)pobj_DBClass->check(szClassName);30 type.SetIndex( (LONG_PTR)pobj_DBClass->check(szClassName) ); 31 31 } 32 32 else{ 33 *plpIndex=*(LONG_PTR *)(buffer+(*p));33 type.SetIndex( *(LONG_PTR *)(buffer+(*p)) ); 34 34 (*p)+=sizeof(LONG_PTR); 35 35 } … … 49 49 } 50 50 void CDebugSection::make(void){ 51 extern VARIABLE *GlobalVar;52 extern int MaxGlobalVarNum;53 51 extern INCLUDEFILEINFO IncludeFileInfo; 54 52 int i2,i3,i4,i5,BufferSize; … … 160 158 161 159 //グローバル変数情報 162 *(long *)(buffer+i2)=MaxGlobalVarNum; 163 i2+=sizeof(long); 164 for(i3=0;i3<MaxGlobalVarNum;i3++){ 165 VARIABLE *pVar=&GlobalVar[i3]; 166 160 *(long *)(buffer+i2)=(int)::globalVars.size(); 161 i2+=sizeof(long); 162 foreach( Variable *pVar, ::globalVars ){ 167 163 //変数名 168 lstrcpy(buffer+i2,pVar-> name);164 lstrcpy(buffer+i2,pVar->GetName().c_str()); 169 165 i2+=lstrlen(buffer+i2)+1; 170 166 171 167 //型 172 *(long *)(buffer+i2)=pVar-> type;168 *(long *)(buffer+i2)=pVar->GetBasicType(); 173 169 i2+=sizeof(long); 174 170 175 171 //型の拡張情報 176 SetLpIndex_DebugFile(buffer,&i2, pVar->type,pVar->u.index);177 178 buffer[i2++] =(char)pVar->fRef;179 180 buffer[i2++] =(char)pVar->bArray;181 182 if(pVar-> bArray){183 for(i 4=0;;i4++){184 *(long *)(buffer+i2)=pVar-> SubScripts[i4];172 SetLpIndex_DebugFile(buffer,&i2,*pVar); 173 174 buffer[i2++] = pVar->IsRef() ? 1 : 0; 175 176 buffer[i2++] = pVar->IsArray() ? 1 : 0; 177 178 if(pVar->IsArray()){ 179 for(i5=0;;i5++){ 180 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5]; 185 181 i2+=sizeof(long); 186 if(pVar-> SubScripts[i4]==-1) break;182 if(pVar->GetSubScriptsPtr()[i5]==-1) break; 187 183 } 188 184 } … … 213 209 214 210 //プロシージャ情報 215 extern SubInfo**ppSubHash;211 extern UserProc **ppSubHash; 216 212 extern int SubNum; 217 SubInfo *psi;213 UserProc *pUserProc; 218 214 *(long *)(buffer+i2)=SubNum; 219 215 i2+=sizeof(long); 220 216 for(i3=0;i3<MAX_HASH;i3++){ 221 p si=ppSubHash[i3];222 while(p si){223 if(p si->pobj_ParentClass){224 lstrcpy(buffer+i2,p si->pobj_ParentClass->name);217 pUserProc=ppSubHash[i3]; 218 while(pUserProc){ 219 if(pUserProc->GetParentClassPtr()){ 220 lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->name); 225 221 i2+=lstrlen(buffer+i2)+1; 226 222 } … … 231 227 232 228 //ID 233 *(long *)(buffer+i2)=p si->id;229 *(long *)(buffer+i2)=pUserProc->id; 234 230 i2+=sizeof(long); 235 231 236 232 //関数名 237 lstrcpy(buffer+i2,p si->name);233 lstrcpy(buffer+i2,pUserProc->GetName().c_str()); 238 234 i2+=lstrlen(buffer+i2)+1; 239 235 240 *(long *)(buffer+i2)=psi->CompileAddress; 241 i2+=sizeof(long); 242 *(long *)(buffer+i2)=psi->EndOpAddr; 243 i2+=sizeof(long); 244 245 *(long *)(buffer+i2)=psi->bVirtual; 236 *(long *)(buffer+i2)=pUserProc->beginOpAddress; 237 i2+=sizeof(long); 238 *(long *)(buffer+i2)=pUserProc->endOpAddress; 246 239 i2+=sizeof(long); 247 240 248 241 //ローカル変数情報 249 *(long *)(buffer+i2)= psi->VarNum;242 *(long *)(buffer+i2)=(int)pUserProc->localVars.size(); 250 243 i2+=sizeof(long); 251 244 … … 256 249 } 257 250 258 for(i4=0;i4<psi->VarNum;i4++){ 259 VARIABLE *pVar=&psi->pVar[i4]; 260 lstrcpy(buffer+i2,pVar->name); 251 foreach( Variable *pVar, pUserProc->localVars ){ 252 lstrcpy(buffer+i2,pVar->GetName().c_str()); 261 253 i2+=lstrlen(buffer+i2)+1; 262 254 263 255 //型 264 *(long *)(buffer+i2)=pVar-> type;256 *(long *)(buffer+i2)=pVar->GetBasicType(); 265 257 i2+=sizeof(long); 266 258 267 259 //型の拡張情報 268 SetLpIndex_DebugFile(buffer,&i2, pVar->type,pVar->u.index);260 SetLpIndex_DebugFile(buffer,&i2,*pVar); 269 261 270 262 //参照型パラメータかどうか 271 buffer[i2++] =(char)pVar->fRef;263 buffer[i2++] = pVar->IsRef() ? 1 : 0; 272 264 273 265 //配列かどうか 274 buffer[i2++] =(char)pVar->bArray;266 buffer[i2++] = pVar->IsArray() ? 1 : 0; 275 267 276 268 //配列要素 277 if(pVar-> bArray){269 if(pVar->IsArray()){ 278 270 for(i5=0;;i5++){ 279 *(long *)(buffer+i2)=pVar-> SubScripts[i5];271 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5]; 280 272 i2+=sizeof(long); 281 if(pVar-> SubScripts[i5]==-1) break;273 if(pVar->GetSubScriptsPtr()[i5]==-1) break; 282 274 } 283 275 } 284 else pVar->SubScripts[0]=-1;285 276 286 277 //レキシカルスコープ情報 … … 306 297 } 307 298 308 p si=psi->pNextData;299 pUserProc=pUserProc->pNextData; 309 300 } 310 301 } … … 347 338 348 339 //型 349 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]-> TypeInfo.type;340 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetBasicType(); 350 341 i2+=sizeof(long); 351 342 352 343 //型の拡張情報 353 SetLpIndex_DebugFile(buffer,&i2, pobj_c->ppobj_Member[i4]->TypeInfo.type,pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);344 SetLpIndex_DebugFile(buffer,&i2,*pobj_c->ppobj_Member[i4]); 354 345 355 346 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->dwAccess; … … 377 368 i2+=lstrlen(buffer+i2)+1; 378 369 } 379 lstrcpy(buffer+i2,method->p si->name);370 lstrcpy(buffer+i2,method->pUserProc->GetName().c_str()); 380 371 i2+=lstrlen(buffer+i2)+1; 381 372 } … … 392 383 393 384 //型 394 *(long *)(buffer+i2)=member-> TypeInfo.type;385 *(long *)(buffer+i2)=member->GetBasicType(); 395 386 i2+=sizeof(long); 396 387 397 388 //型の拡張情報 398 SetLpIndex_DebugFile(buffer,&i2, member->TypeInfo.type,member->TypeInfo.u.lpIndex);389 SetLpIndex_DebugFile(buffer,&i2,*member); 399 390 400 391 *(long *)(buffer+i2)=member->dwAccess; … … 540 531 541 532 //グローバル変数情報 542 MaxGlobalVarNum=*(long *)(buffer+i2); 543 i2+=sizeof(long); 544 GlobalVar=(VARIABLE *)HeapAlloc(hHeap,0,MaxGlobalVarNum*sizeof(VARIABLE)+1); 545 for(i3=0;i3<MaxGlobalVarNum;i3++){ 546 VARIABLE *pVar=&GlobalVar[i3]; 533 globalVars.clear(); 534 int maxGlobalVars=*(long *)(buffer+i2); 535 i2+=sizeof(long); 536 for(i3=0;i3<maxGlobalVars;i3++){ 547 537 548 538 //変数名 549 lstrcpy(pVar->name,buffer+i2); 550 i2+=lstrlen(buffer+i2)+1; 551 552 pVar->type=*(long *)(buffer+i2); 553 i2+=sizeof(long); 554 555 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index); 556 557 pVar->fRef=(long)buffer[i2++]; 558 559 pVar->bArray=(long)buffer[i2++]; 560 if(pVar->bArray){ 539 char *name = buffer+i2; 540 i2+=lstrlen(buffer+i2)+1; 541 542 int basicType = *(long *)(buffer+i2); 543 i2+=sizeof(long); 544 545 Type type( basicType ); 546 GetLpIndex_DebugFile(buffer,&i2,type); 547 548 bool isRef = (buffer[i2++]) ? true:false; 549 550 bool isArray = (buffer[i2++]) ? true:false; 551 552 Variable *pVar = new Variable( name, type, false, isRef ); 553 554 if(isArray){ 555 int SubScripts[MAX_ARRAYDIM]; 561 556 for(i4=0;;i4++){ 562 pVar->SubScripts[i4]=*(long *)(buffer+i2);557 SubScripts[i4]=*(long *)(buffer+i2); 563 558 i2+=sizeof(long); 564 559 565 if(pVar->SubScripts[i4]==-1) break; 566 } 560 if(SubScripts[i4]==-1) break; 561 } 562 563 pVar->SetArray( SubScripts ); 567 564 } 568 565 … … 578 575 pVar->offset=*(long *)(buffer+i2); 579 576 i2+=sizeof(long); 577 578 //変数を追加 579 globalVars.push_back( pVar ); 580 580 } 581 581 … … 585 585 586 586 //プロシージャ情報 587 SubInfo *psi;587 UserProc *pUserProc; 588 588 SubNum=*(long *)(buffer+i2); 589 589 i2+=sizeof(long); 590 ppSubHash=(SubInfo **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SubInfo *)); 591 for(i3=0;i3<SubNum;i3++){ 592 psi = new SubInfo(); 593 psi->pNextData=0; 594 590 ppSubHash=(UserProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(UserProc *)); 591 for(int i6=0;i6<SubNum;i6++){ 595 592 char szParentClassName[VN_SIZE]; 596 593 lstrcpy(szParentClassName,buffer+i2); 597 594 i2+=lstrlen(buffer+i2)+1; 598 595 596 CClass *pClass = NULL; 599 597 if(szParentClassName[0]) 600 psi->pobj_ParentClass=pobj_DBClass->check(szParentClassName); 601 else psi->pobj_ParentClass=0; 598 pClass=pobj_DBClass->check(szParentClassName); 602 599 603 600 //ID 604 psi->id=*(long *)(buffer+i2);601 int id=*(long *)(buffer+i2); 605 602 i2+=sizeof(long); 606 603 607 604 //名前 608 psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1); 609 lstrcpy(psi->name,buffer+i2); 610 i2+=lstrlen(buffer+i2)+1; 611 612 psi->CompileAddress=*(long *)(buffer+i2); 613 i2+=sizeof(long); 614 psi->EndOpAddr=*(long *)(buffer+i2); 615 i2+=sizeof(long); 616 617 psi->bVirtual=*(long *)(buffer+i2); 618 i2+=sizeof(long); 619 620 psi->bCompile=1; 605 char *name = buffer+i2; 606 i2+=lstrlen(buffer+i2)+1; 607 608 // オブジェクトを生成 609 pUserProc = new UserProc( name, UserProc::Function, false, false, false ); 610 pUserProc->pNextData=0; 611 pUserProc->id=id; 612 pUserProc->SetParentClass( pClass ); 613 614 pUserProc->beginOpAddress=*(long *)(buffer+i2); 615 i2+=sizeof(long); 616 pUserProc->endOpAddress=*(long *)(buffer+i2); 617 i2+=sizeof(long); 618 619 pUserProc->CompleteCompile(); 621 620 622 621 //ローカル変数情報 623 psi->VarNum=*(long *)(buffer+i2); 624 i2+=sizeof(long); 625 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,psi->VarNum*sizeof(VARIABLE)+1); 626 for(i4=0;i4<psi->VarNum;i4++){ 627 VARIABLE *pVar=&psi->pVar[i4]; 628 629 //ローカル変数名 630 lstrcpy(pVar->name,buffer+i2); 622 pUserProc->localVars.clear(); 623 int maxLocalVar=*(long *)(buffer+i2); 624 i2+=sizeof(long); 625 for(i3=0;i3<maxLocalVar;i3++){ 626 //変数名 627 char *name = buffer+i2; 631 628 i2+=lstrlen(buffer+i2)+1; 632 629 633 //型634 pVar->type=*(long *)(buffer+i2);635 i2+=sizeof(long); 636 637 //型の拡張情報638 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index); 639 640 //参照型パラメータかどうか 641 pVar->fRef=(long)buffer[i2++];642 643 //配列かどうか644 pVar->bArray=(long)buffer[i2++]; 645 if( pVar->bArray){646 for(i5=0;;i5++){647 //配列要素648 pVar->SubScripts[i5]=*(long *)(buffer+i2);630 int basicType = *(long *)(buffer+i2); 631 i2+=sizeof(long); 632 633 Type type( basicType ); 634 GetLpIndex_DebugFile(buffer,&i2,type); 635 636 bool isRef = (buffer[i2++]) ? true:false; 637 638 bool isArray = (buffer[i2++]) ? true:false; 639 640 Variable *pVar = new Variable( name, type, false, isRef ); 641 642 if(isArray){ 643 int SubScripts[MAX_ARRAYDIM]; 644 for(i4=0;;i4++){ 645 SubScripts[i4]=*(long *)(buffer+i2); 649 646 i2+=sizeof(long); 650 647 651 if( pVar->SubScripts[i5]==-1) break;648 if(SubScripts[i4]==-1) break; 652 649 } 650 651 pVar->SetArray( SubScripts ); 653 652 } 654 653 … … 661 660 i2+=sizeof(long); 662 661 663 //メモリ 上の位置662 //メモリ位置 664 663 pVar->offset=*(long *)(buffer+i2); 665 664 i2+=sizeof(long); 665 666 //変数を追加 667 pUserProc->localVars.push_back( pVar ); 666 668 } 667 669 668 670 669 671 ///////////////////////////////// 670 // 格納位置を計算してp siをセット672 // 格納位置を計算してpUserProcをセット 671 673 ///////////////////////////////// 672 674 673 i4=hash_default(p si->name);674 675 SubInfo*psi2;675 i4=hash_default(pUserProc->GetName().c_str()); 676 677 UserProc *psi2; 676 678 if(ppSubHash[i4]){ 677 679 psi2=ppSubHash[i4]; 678 680 while(1){ 679 681 if(psi2->pNextData==0){ 680 psi2->pNextData=p si;682 psi2->pNextData=pUserProc; 681 683 break; 682 684 } … … 685 687 } 686 688 else{ 687 ppSubHash[i4]=p si;689 ppSubHash[i4]=pUserProc; 688 690 } 689 691 } … … 723 725 724 726 //型 725 pobj_c->ppobj_Member[i4]->TypeInfo.type=*(long *)(buffer+i2);727 Type type( *(long *)(buffer+i2) ); 726 728 i2+=sizeof(long); 727 729 728 730 //型の拡張情報 729 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,&pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex); 731 GetLpIndex_DebugFile(buffer,&i2,type); 732 733 pobj_c->ppobj_Member[i4]->SetType( type.GetBasicType(), type.GetIndex() ); 730 734 731 735 pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2); … … 757 761 if(pobj_temp_c==0) pobj_temp_c=pobj_c; 758 762 i5=hash_default(temp2); 759 p si=ppSubHash[i5];763 pUserProc=ppSubHash[i5]; 760 764 while(1){ 761 if( lstrcmp(psi->name,temp2)==0&&psi->pobj_ParentClass==pobj_temp_c) break;762 p si=psi->pNextData;763 } 764 method->p si=psi;765 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break; 766 pUserProc=pUserProc->pNextData; 767 } 768 method->pUserProc=pUserProc; 765 769 766 770 pobj_c->methods.push_back( method ); … … 781 785 782 786 //型 783 member->TypeInfo.type=*(long *)(buffer+i2);787 Type type( *(long *)(buffer+i2) ); 784 788 i2+=sizeof(long); 785 789 786 790 //型の拡張情報 787 GetLpIndex_DebugFile(buffer,&i2,member->TypeInfo.type,&member->TypeInfo.u.lpIndex); 791 GetLpIndex_DebugFile(buffer,&i2,type); 792 793 member->SetType( type.GetBasicType(), type.GetIndex() ); 788 794 789 795 member->dwAccess=*(long *)(buffer+i2); … … 800 806 801 807 802 extern SubInfo**ppSubHash;808 extern UserProc **ppSubHash; 803 809 ppSubHash=this->ppSubHash; 804 810 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc"); … … 956 962 ppConstHash=this->ppConstHash; 957 963 958 //グローバル変数に関する情報959 extern VARIABLE *GlobalVar;960 extern int MaxGlobalVarNum;961 GlobalVar=this->GlobalVar;962 MaxGlobalVarNum=this->MaxGlobalVarNum;963 964 964 //グローバル実行領域のサイズ 965 965 extern int GlobalOpBufferSize; … … 969 969 extern char **ppMacroNames; 970 970 ppMacroNames=0; 971 extern SubInfo**ppSubHash;971 extern UserProc **ppSubHash; 972 972 extern int SubNum; 973 973 ppSubHash=this->ppSubHash; 974 974 SubNum=this->SubNum; 975 975 976 extern SubInfo*pSub_DebugSys_EndProc;976 extern UserProc *pSub_DebugSys_EndProc; 977 977 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc; 978 978 … … 989 989 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]); 990 990 HeapDefaultFree(IncludeFileInfo.ppFileNames); 991 992 //グローバル変数に関する情報を解放993 HeapDefaultFree(GlobalVar);994 995 //ローカル変数に関する情報を解放996 SubInfo *psi;997 for(i2=0;i2<MAX_HASH;i2++){998 psi=ppSubHash[i2];999 while(psi){1000 if(psi->bCompile)1001 HeapDefaultFree(psi->pVar);1002 1003 psi=psi->pNextData;1004 }1005 }1006 991 1007 992 //クラスに関するメモリを解放 -
BasicCompiler_Common/DebugSection.h
r73 r75 41 41 CONSTINFO **ppConstHash; 42 42 43 //グローバル変数に関する情報44 VARIABLE *GlobalVar;45 int MaxGlobalVarNum;46 47 43 //グローバル実行領域のサイズ 48 44 int GlobalOpBufferSize; 49 45 50 46 //プロシージャ 51 SubInfo**ppSubHash;47 UserProc **ppSubHash; 52 48 int SubNum; 53 49 54 SubInfo*pSub_DebugSys_EndProc;50 UserProc *pSub_DebugSys_EndProc; 55 51 56 52 //ネイティブコードバッファ -
BasicCompiler_Common/Enum.cpp
r47 r75 15 15 16 16 17 CEnumParent::CEnumParent(char *buffer,int NowLine){17 CEnumParent::CEnumParent(char *buffer,int nowLine){ 18 18 ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1); 19 19 iEnumMemberNum=0; … … 42 42 43 43 if(buffer[i]=='\0'){ 44 SetError(22,"Enum", NowLine);44 SetError(22,"Enum",nowLine); 45 45 return; 46 46 } … … 65 65 if(temporary[0]=='\0'){ 66 66 if(buffer[i]=='\0'){ 67 SetError(22,"Enum", NowLine);67 SetError(22,"Enum",nowLine); 68 68 break; 69 69 } -
BasicCompiler_Common/Enum.h
r4 r75 17 17 public: 18 18 19 CEnumParent(char *buffer,int NowLine);19 CEnumParent(char *buffer,int nowLine); 20 20 ~CEnumParent(); 21 21 -
BasicCompiler_Common/Intermediate_Step2.cpp
r64 r75 146 146 //数値定数 147 147 _int64 i64data; 148 pci->type=StaticCalculation(true, temporary,0,&i64data,&pci->lpIndex); 148 Type resultType; 149 StaticCalculation(true, temporary,0,&i64data,resultType); 150 pci->type=resultType.GetBasicType(); 149 151 if(IsRealNumberType(pci->type)){ 150 152 //実数型 … … 231 233 232 234 _int64 i64data; 233 LONG_PTR lpIndex; 234 StaticCalculation(true, temp2,DEF_LONG,&i64data,&lpIndex); 235 StaticCalculation(true, temp2,DEF_LONG,&i64data,Type()); 235 236 NextValue=(int)i64data; 236 237 } … … 303 304 304 305 char ConstructorDestructorSchedule[MAX_PATH]; 305 void MakeConstructorAndDestructor(char *buffer,int NowLine,char *ClassName){306 void MakeConstructorAndDestructor(char *buffer,int nowLine,char *ClassName){ 306 307 int i,i2; 307 308 char temporary[MAX_PATH],*pTemp; … … 312 313 bDestructor=0; 313 314 314 for(i= NowLine;;i++){315 for(i=nowLine;;i++){ 315 316 if(buffer[i]=='\0') break; 316 317 if(buffer[i]==1&&buffer[i+1]==ESC_ENDCLASS){ … … 360 361 } 361 362 } 362 void ChangeCommand(char *buffer,int NowLine,char *Command){363 void ChangeCommand(char *buffer,int nowLine,char *Command){ 363 364 int i,i2,IsStr; 364 365 unsigned _int16 ComNum; … … 391 392 392 393 //コンストラクタ、デストラクタを暗黙的に生成 393 MakeConstructorAndDestructor(buffer, NowLine,Command+2);394 MakeConstructorAndDestructor(buffer,nowLine,Command+2); 394 395 break; 395 396 case ESC_INTERFACE: … … 457 458 if( nCountOfNonGlobalScope == 0 ){ 458 459 //グローバル 459 if(lstrcmpi(com,"Open")==0) ComOpen(Command+i,pam, NowLine);460 if(lstrcmpi(com,"Open")==0) ComOpen(Command+i,pam,nowLine); 460 461 else if(lstrcmpi(com,"Close")==0) ComClose(Command+i,pam); 461 462 else if(lstrcmpi(com,"Field")==0|| 462 463 lstrcmpi(com,"Get")==0|| 463 464 lstrcmpi(com,"Put")==0) ComField(Command+i,pam); 464 else if(lstrcmpi(com,"Line")==0) ComLine(Command+i,pam, NowLine);465 else if(lstrcmpi(com,"Circle")==0) ComCircle(Command+i,pam, NowLine);466 else if(lstrcmpi(com,"PSet")==0) ComPSet(Command+i,pam, NowLine);467 else if(lstrcmpi(com,"Paint")==0) ComPaint(Command+i,pam, NowLine);465 else if(lstrcmpi(com,"Line")==0) ComLine(Command+i,pam,nowLine); 466 else if(lstrcmpi(com,"Circle")==0) ComCircle(Command+i,pam,nowLine); 467 else if(lstrcmpi(com,"PSet")==0) ComPSet(Command+i,pam,nowLine); 468 else if(lstrcmpi(com,"Paint")==0) ComPaint(Command+i,pam,nowLine); 468 469 469 470 else if( -
BasicCompiler_Common/LexicalScoping.cpp
r73 r75 85 85 CallDestructorsOfScopeEnd(); 86 86 87 extern BOOL bCompilingGlobal; 88 VARIABLE *pVar; 89 int num; 90 if(bCompilingGlobal){ 91 //グローバル領域をコンパイルしているとき 92 extern VARIABLE *GlobalVar; 93 extern int MaxGlobalVarNum; 94 pVar=GlobalVar; 95 num=MaxGlobalVarNum; 96 } 97 else{ 98 //ローカル領域をコンパイルしているとき 99 extern VARIABLE *LocalVar; 100 extern int MaxLocalVarNum; 101 pVar=LocalVar; 102 num=MaxLocalVarNum; 103 } 87 Variables &vars = UserProc::IsGlobalAreaCompiling()? 88 globalVars : 89 UserProc::CompilingUserProc().localVars; 104 90 105 91 //使用済みローカル変数の生存チェックを外す 106 for (int i=0;i<num;i++){107 if(pVar [i].bLiving&&pVar[i].ScopeLevel==level){108 pVar [i].bLiving=0;92 foreach( Variable *pVar, vars ){ 93 if(pVar->bLiving&&pVar->ScopeLevel==level){ 94 pVar->bLiving=0; 109 95 extern int obp; 110 pVar [i].ScopeEndAddress=obp;96 pVar->ScopeEndAddress=obp; 111 97 } 112 98 } … … 163 149 // スコープ終了時のデストラクタ呼び出し 164 150 void CLexicalScopes::CallDestructorsOfScopeEnd(){ 165 extern BOOL bCompilingGlobal; 166 VARIABLE *pVar; 167 int num; 168 if(bCompilingGlobal){ 169 //グローバルオブジェクトの解放処理 170 extern VARIABLE *GlobalVar; 171 extern int MaxGlobalVarNum; 172 pVar=GlobalVar; 173 num=MaxGlobalVarNum; 174 } 175 else{ 176 //ローカルオブジェクトの解放処理 177 extern VARIABLE *LocalVar; 178 extern int MaxLocalVarNum; 179 pVar=LocalVar; 180 num=MaxLocalVarNum; 181 } 151 152 Variables &vars = UserProc::IsGlobalAreaCompiling()? 153 globalVars : 154 UserProc::CompilingUserProc().localVars; 182 155 183 156 184 157 int i3; 185 158 int indexSystemGC=-1; 186 for( i3 = num - 1; i3 >= 0; i3-- ){ //確保したのと逆順序で解放するため、バックサーチにする 187 188 if( bCompilingGlobal && GetNowLevel() == 0 ){ 189 if(lstrcmp(pVar[i3].name,"_System_GC")==0){ 159 for( i3 = (int)vars.size() - 1; i3 >= 0; i3-- ){ //確保したのと逆順序で解放するため、バックサーチにする 160 161 Variable *pVar = vars[i3]; 162 163 if( UserProc::IsGlobalAreaCompiling() && GetNowLevel() == 0 ){ 164 if( pVar->GetName() == "_System_GC" ){ 190 165 indexSystemGC=i3; 191 166 continue; … … 194 169 195 170 //同一レベルのレキシカルスコープのみを検知 196 if(!pVar [i3].bLiving) continue;197 if( pVar [i3].ScopeLevel != GetNowLevel() ) continue;198 199 if( pVar[i3].type==DEF_STRUCT&&pVar[i3].fRef&OBJECT_PARAMETER){171 if(!pVar->bLiving) continue; 172 if( pVar->ScopeLevel != GetNowLevel() ) continue; 173 174 if( pVar->IsStruct() && pVar->IsParameter() ){ 200 175 //構造体パラメータを持つとき 201 176 … … 207 182 //mov rcx,qword ptr[rsp+offset] 208 183 op_mov_RM(sizeof(_int64),REG_RCX,REG_RSP, 209 -pVar [i3].offset,184 -pVar->offset, 210 185 MOD_BASE_DISP32); 211 186 obp-=sizeof(long); … … 216 191 217 192 //mov ecx,dword ptr[ebp+offset] 218 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar [i3].offset,MOD_BASE_DISP32);193 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->offset,MOD_BASE_DISP32); 219 194 obp-=sizeof(long); 220 195 AddLocalVarAddrSchedule(); … … 226 201 227 202 //call free 228 extern SubInfo*pSub_free;203 extern UserProc *pSub_free; 229 204 op_call(pSub_free); 230 205 231 206 232 if( bCompilingGlobal){207 if( UserProc::IsGlobalAreaCompiling() ){ 233 208 //ここには来ないハズ 234 209 SetError(300,NULL,cp); 235 210 } 236 211 } 237 238 /*239 TODO: 消す240 else if(pVar[i3].type==DEF_OBJECT&&pVar[i3].fRef==0){241 //デストラクタの呼び出し242 CMethod *method = pVar[i3].u.pobj_c->GetDestructorMethod();243 if( method ){244 int ss[MAX_ARRAYDIM];245 memset(ss,0,MAX_ARRAYDIM*sizeof(int));246 if(pVar[i3].SubScripts[0]!=-1){247 while(1){248 for(i4=0;;i4++){249 if(pVar[i3].SubScripts[i4]==-1) break;250 251 if(ss[i4]>pVar[i3].SubScripts[i4]){252 ss[i4]=0;253 ss[i4+1]++;254 }255 else break;256 }257 if(pVar[i3].SubScripts[i4]==-1) break;258 char temporary[VN_SIZE];259 sprintf(temporary,"%s[%d",pVar[i3].name,ss[0]);260 for(i4=1;;i4++){261 if(pVar[i3].SubScripts[i4]==-1) break;262 263 sprintf(temporary+lstrlen(temporary),",%d",ss[i4]);264 }265 lstrcat(temporary,"]");266 Opcode_CallProc("",method->psi,0,temporary,DEF_OBJECT);267 268 ss[0]++;269 270 271 //ネイティブコードバッファの再確保272 extern int obp_AllocSize;273 if(obp_AllocSize<obp+8192){274 obp_AllocSize+=8192;275 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea276 }277 }278 }279 else{280 Opcode_CallProc("",method->psi,0,pVar[i3].name,DEF_OBJECT);281 }282 }283 }284 */285 212 } 286 213 287 214 if(indexSystemGC!=-1){ 288 215 //_System_GCオブジェクトのデストラクタの呼び出し処理 289 CMethod *method = pVar[indexSystemGC].u.pobj_c->GetDestructorMethod();216 CMethod *method = vars[indexSystemGC]->GetClass().GetDestructorMethod(); 290 217 if( method ){ 291 Opcode_CallProc("",method->p si,0,pVar[indexSystemGC].name,DEF_OBJECT);218 Opcode_CallProc("",method->pUserProc,0,vars[indexSystemGC]->GetName().c_str(),DEF_OBJECT); 292 219 } 293 220 } -
BasicCompiler_Common/LexicalScoping.h
r34 r75 70 70 //Returnステートメント用のデストラクタ呼び出し 71 71 void CallDestructorsOfReturn( int BaseLevel = 0 ); 72 73 private:74 VARIABLE *add(void);75 72 }; 76 73 -
BasicCompiler_Common/MakeExe.cpp
r73 r75 165 165 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]); 166 166 HeapDefaultFree(SynonymErrorWords); 167 SynonymErrorWords=0; 167 168 168 169 if(bError||bStopCompile){ … … 181 182 182 183 //グローバル変数に関する情報 183 extern VARIABLE *GlobalVar;184 184 extern int MaxGlobalVarNum; 185 185 extern int AllGlobalVarSize; 186 186 extern int AllInitGlobalVarSize; 187 GlobalVar=(VARIABLE *)HeapAlloc(hHeap,0,1);187 globalVars.clear(); 188 188 MaxGlobalVarNum=0; 189 189 AllGlobalVarSize=0; … … 214 214 HeapDefaultFree(pLineInfo); 215 215 216 //グローバル変数に関する情報を解放217 int i;218 for(i=0;i<MaxGlobalVarNum;i++){219 if(GlobalVar[i].ConstractParameter)220 HeapDefaultFree(GlobalVar[i].ConstractParameter);221 }222 HeapDefaultFree(GlobalVar);223 224 //ローカル変数に関する情報を解放225 extern SubInfo **ppSubHash;226 SubInfo *psi;227 for(i2=0;i2<MAX_HASH;i2++){228 psi=ppSubHash[i2];229 while(psi){230 if(psi->bCompile) HeapDefaultFree(psi->pVar);231 psi=psi->pNextData;232 }233 }234 235 216 //TypeDef情報を初期化 236 217 delete pobj_DBTypeDef; … … 238 219 239 220 //サブルーチン(ユーザー定義)情報のメモリ解放 240 extern SubInfo**ppSubHash;221 extern UserProc **ppSubHash; 241 222 extern char **ppMacroNames; 242 223 extern int MacroNum; -
BasicCompiler_Common/NumOpe_GetType.cpp
r73 r75 28 28 type=CalcType; 29 29 30 if( !BaseType){30 if(BaseType==0||BaseType==-1){ 31 31 //ベースタイプが未定のとき 32 32 return type; … … 38 38 } 39 39 40 if(BaseType==DEF_OBJECT ){40 if(BaseType==DEF_OBJECT||BaseType==DEF_STRUCT){ 41 41 //ベースタイプがオブジェクトのときは暗黙の変換は必要なし 42 42 return type; … … 188 188 } 189 189 190 int GetReturnType_OperatorProc(int idCalc, TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,int &sp){190 int GetReturnType_OperatorProc(int idCalc,const Type &baseType,int *type,LONG_PTR *index_stack,int &sp){ 191 191 //オーバーロードされたオペレータ関数の戻り値を取得 192 192 CClass *pobj_c; 193 193 pobj_c=(CClass *)index_stack[sp-2]; 194 194 195 std::vector< SubInfo*> subs;195 std::vector<UserProc *> subs; 196 196 pobj_c->EnumMethod( idCalc, subs ); 197 197 if( subs.size() == 0 ){ … … 212 212 213 213 //_System_LocalThis 214 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 215 int iParmNum=0; 214 Parameters params; 216 215 217 216 if(bTwoTerm){ 218 ppi[iParmNum].bArray=0; 219 ppi[iParmNum].bByVal=0; 220 ppi[iParmNum].name=0; 221 ppi[iParmNum].type=type[sp-1]; 222 ppi[iParmNum].u.index=index_stack[sp-1]; 223 ppi[iParmNum].SubScripts[0]=-1; 224 iParmNum++; 217 params.push_back( new Parameter( "", Type( type[sp-1], index_stack[sp-1] ) ) ); 225 218 } 226 219 … … 230 223 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"=="); 231 224 else GetCalcName(idCalc,temporary); 232 SubInfo *psi; 233 psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo); 234 235 236 if(!psi){ 237 HeapDefaultFree(ppi); 225 UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType ); 226 227 if(bTwoTerm){ 228 delete params[0]; 229 } 230 231 if(!pUserProc){ 238 232 return 0; 239 233 } 240 234 else{ 241 235 //オーバーロードされていないが、パラメータ個数が一致しないとき 242 if(iParmNum!=psi->params.size()){ 243 HeapDefaultFree(ppi); 236 if(params.size()!=pUserProc->Params().size()){ 244 237 return 0; 245 238 } 246 239 } 247 240 248 HeapDefaultFree(ppi);249 250 241 sp--; 251 type[sp-1]=p si->ReturnType;252 index_stack[sp-1]=p si->u.ReturnIndex;242 type[sp-1]=pUserProc->ReturnType().GetBasicType(); 243 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 253 244 254 245 return 1; 255 246 } 256 247 257 int Operator_New_GetType(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo){248 bool Operator_New_GetType(const char *Parameter,const Type &baseType, Type &resultType ){ 258 249 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE]; 259 250 int i,i2; … … 279 270 if(Parameter[i]!='\0'){ 280 271 SetError(42,NULL,cp); 281 return 0;272 return false; 282 273 } 283 274 break; … … 290 281 } 291 282 292 int type; 293 type=GetTypeFixed(TypeName,plpIndex); 294 295 if( baseTypeInfo.type == DEF_OBJECT ){ 296 return DEF_OBJECT; 297 } 298 return DEF_PTR_OBJECT; 283 if( !Type::StringToType( TypeName, resultType ) ){ 284 return false; 285 } 286 287 if( baseType.IsObject() ){ 288 resultType.SetBasicType( DEF_OBJECT ); 289 } 290 else{ 291 resultType.SetBasicType( DEF_PTR_OBJECT ); 292 } 293 return true; 299 294 } 300 295 301 int NumOpe_GetType_Old( const char *Command,TYPEINFO *pBaseType,LONG_PTR *plpIndex){296 bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ){ 302 297 extern int cp; 303 298 int i,i2,i3,i4; 304 299 char temporary[1024],temp2[1024],temp3[1024]; 305 300 306 if( Command[0]=='\0'){301 if(expression[0]=='\0'){ 307 302 SetError(1,NULL,cp); 308 return 0;309 } 310 311 if( Command[0]==1&& Command[1]==ESC_NEW ){303 return false; 304 } 305 306 if(expression[0]==1&& expression[1]==ESC_NEW ){ 312 307 //New演算子(オブジェクト生成) 313 return Operator_New_GetType( Command+2,plpIndex, *pBaseType );308 return Operator_New_GetType(expression+2,baseType, resultType ); 314 309 } 315 310 … … 323 318 long stack[255]; 324 319 int pnum; 325 if(!GetNumOpeElements( Command,&pnum,values,calc,stack)){320 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){ 326 321 for(i=0;i<pnum;i++){ 327 322 if(values[i]) HeapDefaultFree(values[i]); 328 323 } 329 return 0;324 return false; 330 325 } 331 326 … … 343 338 344 339 int sp; 345 int type [255];340 int type_stack[255]; 346 341 LONG_PTR index_stack[255]; 347 342 _int64 i64data; … … 351 346 352 347 if(idCalc){ 353 if(type [sp-2]==DEF_OBJECT){348 if(type_stack[sp-2]==DEF_OBJECT){ 354 349 //オーバーロードされたオペレータを呼び出す 355 if(!GetReturnType_OperatorProc(idCalc, pBaseType,type,index_stack,sp)){350 if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){ 356 351 goto error; 357 352 } … … 360 355 } 361 356 362 if(!CheckCalcType(idCalc,type ,sp)) goto error;357 if(!CheckCalcType(idCalc,type_stack,sp)) goto error; 363 358 } 364 359 … … 374 369 StrLiteral: 375 370 376 if(pBaseType){ 377 if(pBaseType->type==DEF_OBJECT){ 378 if(IsStringObjectType(*pBaseType)){ 379 //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合 380 extern CClass *pobj_StringClass; 381 type[sp]=DEF_OBJECT; 382 index_stack[sp]=(LONG_PTR)pobj_StringClass; 383 bLiteralCalculation=0; 384 385 sp++; 386 break; 387 } 388 } 371 if( baseType.IsStringObject() ){ 372 //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合 373 extern CClass *pobj_StringClass; 374 type_stack[sp]=DEF_OBJECT; 375 index_stack[sp]=(LONG_PTR)pobj_StringClass; 376 bLiteralCalculation=0; 377 378 sp++; 379 break; 389 380 } 390 381 391 type [sp]=typeOfPtrChar;382 type_stack[sp]=typeOfPtrChar; 392 383 bLiteralCalculation=0; 393 384 } … … 413 404 414 405 int idProc; 415 void *p Info;416 idProc=GetProc(temporary, &pInfo);406 void *pProc; 407 idProc=GetProc(temporary,(void **)&pProc); 417 408 418 409 if(idProc){ … … 433 424 //////////////// 434 425 435 i2=GetReturnTypeOfProc(idProc,pInfo,temporary,temp2,&index_stack[sp]); 436 if(i2==-1){ 426 Type resultType; 427 if( !CallProc(idProc,pProc,temporary,temp2, resultType, false ) ){ 428 goto error; 429 } 430 if( resultType.IsNull() ){ 437 431 //戻り値が存在しないとき 438 432 goto error; 439 433 } 440 434 441 type[sp]=i2; 435 type_stack[sp] = resultType.GetBasicType(); 436 index_stack[sp] = resultType.GetIndex(); 437 442 438 bLiteralCalculation=0; 443 439 … … 454 450 455 451 //マクロ関数の場合 456 i2=NumOpe_GetType_Old(temp3,NULL,&index_stack[sp]); 457 458 if(!IS_LITERAL(index_stack[sp])){ 452 Type tempType; 453 NumOpe_GetType(temp3,Type(),tempType); 454 455 if(!IS_LITERAL(tempType.GetIndex())){ 459 456 //リテラル値ではなかったとき 460 457 bLiteralCalculation=0; 461 458 } 462 459 463 type[sp]=i2; 460 type_stack[sp] = tempType.GetBasicType(); 461 index_stack[sp] = tempType.GetIndex(); 464 462 465 463 sp++; … … 473 471 GetArrayElement(term,VarName,ArrayElements); 474 472 if(ArrayElements[0]){ 475 CClass *pobj_c; 476 i2=GetVarType(VarName,(LONG_PTR *)&pobj_c,0); 477 if(i2==DEF_OBJECT){ 478 TYPEINFO RetTypeInfo; 479 if( !GetReturnTypeOfIndexerGetterProc(pobj_c,RetTypeInfo) ){ 473 Type type; 474 GetVarType(VarName,type,false); 475 if( type.IsObject() ){ 476 if( !GetReturnTypeOfIndexerGetterProc( type.GetClass(),type) ){ 480 477 SetError(1,NULL,cp); 481 478 goto error; 482 479 } 483 type [sp]=RetTypeInfo.type;484 index_stack[sp]= RetTypeInfo.u.lpIndex;480 type_stack[sp]=type.GetBasicType(); 481 index_stack[sp]=type.GetIndex(); 485 482 bLiteralCalculation=0; 486 483 … … 493 490 // Nothing 494 491 if( lstrcmp( term, "Nothing" ) == 0 ){ 495 type [sp] = DEF_OBJECT;496 if( pBaseType && pBaseType->type == DEF_OBJECT){497 index_stack[sp] = pBaseType->u.lpIndex;492 type_stack[sp] = DEF_OBJECT; 493 if( baseType.IsObject() ){ 494 index_stack[sp] = baseType.GetIndex(); 498 495 } 499 496 else{ … … 506 503 507 504 508 i2=GetVarType(term,&index_stack[sp],0);509 if( i2!=-1){505 Type varType; 506 if( GetVarType(term,varType,0) ){ 510 507 ////////// 511 508 // 変数 512 509 ////////// 513 510 514 if( i2&FLAG_PTR){511 if( varType.GetBasicType() & FLAG_PTR ){ 515 512 //配列ポインタ 516 type [sp]=GetPtrType(i2^FLAG_PTR,index_stack[sp]);513 type_stack[sp]=GetPtrType( varType.GetBasicType()^FLAG_PTR ); 517 514 } 518 515 else{ 519 type[sp]=i2; 520 } 516 type_stack[sp]=varType.GetBasicType(); 517 } 518 index_stack[sp] = varType.GetIndex(); 521 519 522 520 bLiteralCalculation=0; … … 532 530 i3 = CDBConst::obj.GetType(term); 533 531 if(i3){ 534 type [sp]=i3;532 type_stack[sp]=i3; 535 533 if(IsRealNumberType(i3)){ 536 534 //実数 … … 563 561 i3=GetTypeFixed(term,&lp); 564 562 if(i3!=-1){ 565 type [sp]=i3|FLAG_CAST;563 type_stack[sp]=i3|FLAG_CAST; 566 564 index_stack[sp]=lp; 567 565 sp++; … … 579 577 580 578 if(GetSubHash(VarName,0)){ 581 T YPEINFO RetTypeInfo;582 GetReturnTypeOfPropertyMethod(term,NULL, &RetTypeInfo);579 Type tempType; 580 GetReturnTypeOfPropertyMethod(term,NULL,tempType); 583 581 584 582 //大きな型への暗黙の変換 585 type [sp]=RetTypeInfo.type;586 587 index_stack[sp]= RetTypeInfo.u.lpIndex;583 type_stack[sp]=tempType.GetBasicType(); 584 585 index_stack[sp]=tempType.GetIndex(); 588 586 bLiteralCalculation=0; 589 587 … … 597 595 bError=1; 598 596 SetError(3,term,cp); 599 type [sp]=DEF_DOUBLE;597 type_stack[sp]=DEF_DOUBLE; 600 598 } 601 599 else{ 602 600 //リテラル値 603 int base_type; 604 base_type=0; 605 if(pBaseType) base_type=pBaseType->type; 606 type[sp]=GetLiteralValue(term,&i64data,base_type); 601 int base_type = 0; 602 if( !baseType.IsNull() ) base_type = baseType.GetBasicType(); 603 type_stack[sp]=GetLiteralValue(term,&i64data,base_type); 607 604 Literal: 608 605 if((long)i64data==0&&index_stack[sp]==-1) index_stack[sp]=LITERAL_NULL; … … 617 614 case CALC_AND: 618 615 sp--; 619 type [sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);616 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]); 620 617 break; 621 618 case CALC_NOT: … … 632 629 case CALC_EQUAL: //values[sp-2] = values[sp-1] 633 630 sp--; 634 type [sp-1]=DEF_LONG;631 type_stack[sp-1]=DEF_LONG; 635 632 break; 636 633 … … 646 643 case CALC_PRODUCT: 647 644 sp--; 648 type [sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);645 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]); 649 646 break; 650 647 case CALC_MOD: … … 652 649 //剰余演算 653 650 sp--; 654 type [sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);651 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]); 655 652 break; 656 653 case CALC_QUOTIENT: … … 658 655 //除算 659 656 sp--; 660 type [sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);657 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]); 661 658 break; 662 659 case CALC_INTQUOTIENT: … … 664 661 //整数除算 665 662 sp--; 666 type [sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);663 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]); 667 664 break; 668 665 case CALC_MINUSMARK: … … 677 674 case CALC_AS: 678 675 //キャスト 679 type [sp-2]=type[sp-1]&(~FLAG_CAST);676 type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST); 680 677 index_stack[sp-2]=index_stack[sp-1]; 681 678 … … 685 682 case CALC_BYVAL: 686 683 //ポインタ型→参照型 687 if( PTR_LEVEL( type [sp-1] ) <= 0 ){684 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){ 688 685 //ポインタ型ではないとき 689 686 SetError( 3, NULL, cp ); … … 691 688 } 692 689 693 type [sp-1] = PTR_LEVEL_DOWN( type[sp-1] );690 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] ); 694 691 break; 695 692 } … … 705 702 if(bLiteralCalculation){ 706 703 //右辺値が数値の定数式の場合 707 LONG_PTR lpCalcIndex;708 i nt base_type=0;709 if(pBaseType) base_type=pBaseType->type;710 i2=StaticCalculation(true, Command,base_type,&i64data,&lpCalcIndex);711 712 type [0]=i2;713 index_stack[0]= lpCalcIndex;704 int base_type = 0; 705 if( !baseType.IsNull() ) base_type = baseType.GetBasicType(); 706 Type tempType; 707 StaticCalculation(true, expression,base_type,&i64data,tempType); 708 709 type_stack[0]=tempType.GetBasicType(); 710 index_stack[0]=tempType.GetIndex(); 714 711 } 715 712 else{ … … 718 715 } 719 716 720 if(plpIndex) *plpIndex=index_stack[0]; 721 722 int RetType; 723 RetType=type[0]; 717 resultType.SetType( type_stack[0], index_stack[0] ); 718 719 bool isSuccessful = true; 724 720 goto finish; 725 721 … … 730 726 731 727 error: 732 RetType=-1;728 isSuccessful = false; 733 729 goto finish; 734 730 … … 738 734 if(values[i]) HeapDefaultFree(values[i]); 739 735 } 740 return RetType;736 return isSuccessful; 741 737 } 742 743 bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ){744 TYPEINFO baseTypeInfo = {745 baseType.GetBasicType(),746 baseType.GetIndex()747 };748 LONG_PTR lpIndex;749 int basicType = NumOpe_GetType_Old( expression,750 baseType.IsNull() ? NULL:&baseTypeInfo,751 &lpIndex );752 753 resultType.SetBasicType( basicType );754 resultType.SetIndex( lpIndex );755 756 return ( basicType != -1 );757 } -
BasicCompiler_Common/Object.cpp
r73 r75 9 9 extern HANDLE hHeap; 10 10 11 void CallConstructor(char *ObjectName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter){ 12 if(TypeInfo.type!=DEF_OBJECT) return; 11 void CallConstructor( const char *ObjectName,const int *SubScripts,const Type &type,const char *Parameter){ 12 if( !type.IsObject() ){ 13 return; 14 } 13 15 14 16 ///////////////////////////////////// … … 16 18 // ※コンストラクタの呼び出し 17 19 ///////////////////////////////////// 18 CClass *pobj_c;19 pobj_c=(CClass *)TypeInfo.u.lpIndex;20 20 21 SubInfo *psi;22 p si=GetMethodHash(ObjectName,pobj_c->name,Parameter);23 if(!p si){24 if(Parameter[0]) SetError(113, pobj_c->name,cp);21 UserProc *pUserProc; 22 pUserProc=GetMethodHash(ObjectName,type.GetClass().name,Parameter); 23 if(!pUserProc){ 24 if(Parameter[0]) SetError(113,type.GetClass().name,cp); 25 25 return; 26 26 } … … 52 52 lstrcat(temporary,"]"); 53 53 54 LONG_PTR lp;55 sprintf(temporary+lstrlen(temporary),".%s", pobj_c->name);56 CallProc( PROC_DEFAULT,57 p si,54 Type dummyType; 55 sprintf(temporary+lstrlen(temporary),".%s",type.GetClass().name); 56 CallProc( PROC_DEFAULT, 57 pUserProc, 58 58 temporary, 59 59 Parameter, 60 &lp);60 dummyType ); 61 61 62 62 ss[0]++; … … 72 72 } 73 73 else{ 74 LONG_PTR lp;75 sprintf(temporary,"%s.%s",ObjectName, pobj_c->name);76 CallProc( PROC_DEFAULT,77 p si,74 Type dummyType; 75 sprintf(temporary,"%s.%s",ObjectName,type.GetClass().name); 76 CallProc( PROC_DEFAULT, 77 pUserProc, 78 78 temporary, 79 79 Parameter, 80 &lp);80 dummyType ); 81 81 } 82 82 } 83 84 bool Operator_New( const char *expression, const Type &baseType, Type &resultType ){ 85 char CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE]; 86 int i,i2; 87 88 i=0; 89 90 if(expression[0]=='['){ 91 i=GetStringInBracket(objectSizeStr,expression); 92 93 SlideString(objectSizeStr+1,-1); 94 objectSizeStr[i-2]=0; 95 } 96 else objectSizeStr[0]=0; 97 98 char typeName[VN_SIZE]; 99 for(i2=0;;i++,i2++){ 100 if(expression[i]=='('){ 101 typeName[i2]=0; 102 103 //コンストラクタに渡すパラメータを取得 104 i2=GetStringInPare(CreateParameter,expression+i); 105 RemoveStringPare(CreateParameter); 106 i+=i2; 107 if(expression[i]!='\0'){ 108 SetError(42,NULL,cp); 109 return false; 110 } 111 break; 112 } 113 typeName[i2]=expression[i]; 114 if(expression[i]=='\0'){ 115 CreateParameter[0]=0; 116 break; 117 } 118 } 119 120 if( !Type::StringToType( typeName, resultType ) ){ 121 SetError(3,typeName,cp); 122 return false; 123 } 124 125 if( !resultType.IsObject() ){ 126 //////////////////////// 127 // 通常のデータ型の場合 128 //////////////////////// 129 130 SetError(121,NULL,cp); 131 return false; 132 } 133 134 Operator_New( resultType.GetClass(), objectSizeStr, CreateParameter, baseType ); 135 136 if( !baseType.IsObject() ){ 137 // オブジェクトポインタ向け 138 resultType.SetBasicType( DEF_PTR_OBJECT ); 139 } 140 141 return true; 142 } -
BasicCompiler_Common/Overload.cpp
r73 r75 7 7 #endif 8 8 9 SubInfo*OverloadSolutionWithStrParam(9 UserProc *OverloadSolutionWithStrParam( 10 10 const char *name, 11 std::vector< SubInfo*> &subs,11 std::vector<UserProc *> &subs, 12 12 const char *Parameter, 13 const char *ObjectName, 14 TYPEINFO *pReturnTypeInfo){ 13 const char *ObjectName){ 15 14 16 15 // オーバーロードの解決 … … 31 30 //メソッドの場合は静的かどうかを調べる 32 31 bool isStatic = false; 33 CClass *pClass = subs[0]-> pobj_ParentClass;32 CClass *pClass = subs[0]->GetParentClassPtr(); 34 33 if( pClass ){ 35 34 isStatic = pClass->IsExistStaticMethod( MethodName ); … … 37 36 */ 38 37 //パラメータオブジェクトを生成 39 if(lstrcmp(Parameter,"\"test\"")==0){40 int i=0;41 }42 38 pobj_parameter=new ParamImpl(Parameter); 43 if(pReturnTypeInfo) pobj_parameter->SetReturnType(pReturnTypeInfo);44 39 45 40 46 SubInfo *psi;47 p si=pobj_parameter->OverloadSolution(name,subs);41 UserProc *pUserProc; 42 pUserProc=pobj_parameter->OverloadSolution(name,subs); 48 43 49 44 … … 52 47 pobj_parameter=0; 53 48 54 return p si;49 return pUserProc; 55 50 } 56 57 SubInfo *OverloadSolution( 51 UserProc *OverloadSolution( 58 52 const char *name, 59 std::vector<SubInfo *> &subs, 60 const PARAMETER_INFO *ppi, 61 const int ParmNum, 62 TYPEINFO *pReturnTypeInfo){ 53 std::vector<UserProc *> &subs, 54 const Parameters ¶ms, 55 const Type &returnType ){ 63 56 64 57 // オーバーロードの解決 … … 68 61 69 62 70 ParamImpl *pobj_Parameter=new ParamImpl(ppi,ParmNum); 71 if(pReturnTypeInfo) pobj_Parameter->SetReturnType(pReturnTypeInfo); 63 ParamImpl *pobj_Parameter=new ParamImpl( params ); 64 if( !returnType.IsNull() ){ 65 pobj_Parameter->SetReturnType( returnType ); 66 } 72 67 73 SubInfo *psi;74 p si=pobj_Parameter->OverloadSolution(name,subs);68 UserProc *pUserProc; 69 pUserProc=pobj_Parameter->OverloadSolution(name,subs); 75 70 76 71 delete pobj_Parameter; 77 72 78 return p si;73 return pUserProc; 79 74 } -
BasicCompiler_Common/PESchedule.cpp
r73 r75 197 197 198 198 CImportAddrSchedule::CImportAddrSchedule(){ 199 ppdi=(D ECLAREINFO**)HeapAlloc(hHeap,0,1);199 ppdi=(DllProc **)HeapAlloc(hHeap,0,1); 200 200 } 201 201 CImportAddrSchedule::~CImportAddrSchedule(){ … … 203 203 } 204 204 205 void CImportAddrSchedule::add(D ECLAREINFO *pdi){206 ppdi=(D ECLAREINFO **)HeapReAlloc(hHeap,0,ppdi,(num+1)*sizeof(DECLAREINFO*));207 ppdi[num]=p di;205 void CImportAddrSchedule::add(DllProc *pDllProc){ 206 ppdi=(DllProc **)HeapReAlloc(hHeap,0,ppdi,(num+1)*sizeof(DllProc *)); 207 ppdi[num]=pDllProc; 208 208 209 209 CSchedule::add(); … … 220 220 221 221 CSubAddrSchedule::CSubAddrSchedule(){ 222 ppsi=( SubInfo**)HeapAlloc(hHeap,0,1);222 ppsi=(UserProc **)HeapAlloc(hHeap,0,1); 223 223 pbCall=(BOOL *)HeapAlloc(hHeap,0,1); 224 224 } … … 228 228 } 229 229 230 void CSubAddrSchedule::add( SubInfo *psi,BOOL bCall){231 if(!p si) return;232 233 ppsi=( SubInfo **)HeapReAlloc(hHeap,0,ppsi,(num+1)*sizeof(SubInfo*));234 ppsi[num]=p si;230 void CSubAddrSchedule::add(UserProc *pUserProc,BOOL bCall){ 231 if(!pUserProc) return; 232 233 ppsi=(UserProc **)HeapReAlloc(hHeap,0,ppsi,(num+1)*sizeof(UserProc *)); 234 ppsi[num]=pUserProc; 235 235 pbCall=(BOOL *)HeapReAlloc(hHeap,0,pbCall,(num+1)*sizeof(BOOL)); 236 236 pbCall[num]=bCall; … … 283 283 284 284 285 286 -
BasicCompiler_Common/PESchedule.h
r73 r75 63 63 class CImportAddrSchedule:public CSchedule{ 64 64 public: 65 D ECLAREINFO**ppdi;65 DllProc **ppdi; 66 66 67 67 CImportAddrSchedule(); 68 68 ~CImportAddrSchedule(); 69 69 70 void add(D ECLAREINFO *pdi);70 void add(DllProc *pDllProc); 71 71 }; 72 72 extern CImportAddrSchedule *pobj_ImportAddrSchedule; … … 79 79 class CSubAddrSchedule:public CSchedule{ 80 80 public: 81 SubInfo**ppsi;81 UserProc **ppsi; 82 82 BOOL *pbCall; 83 83 … … 85 85 ~CSubAddrSchedule(); 86 86 87 void add( SubInfo *psi,BOOL bCall);87 void add(UserProc *pUserProc,BOOL bCall); 88 88 }; 89 89 extern CSubAddrSchedule *pobj_SubAddrSchedule; -
BasicCompiler_Common/ParamImpl.cpp
r73 r75 7 7 #endif 8 8 9 ParamImpl::ParamImpl(const char *buffer){ 9 ParamImpl::ParamImpl(const char *buffer): 10 returnType() 11 { 10 12 /////////////////////////// 11 13 // パラメータ文字列を整理 … … 55 57 ParmsNum++; 56 58 59 types.push_back( Type() ); 60 57 61 if(buffer[i]==',') i++; 58 62 } 59 60 ReturnTypeInfo.type=DEF_NON; 61 ReturnTypeInfo.u.lpIndex=-1; 62 } 63 ParamImpl::ParamImpl(const PARAMETER_INFO *pParamInfo,const int ParmNum){ 64 int i; 65 for(i=0;i<ParmNum;i++){ 66 Parms[i]=0; 67 types[i].type=pParamInfo[i].type; 68 types[i].u.lpIndex=pParamInfo[i].u.index; 69 } 70 this->ParmsNum=ParmNum; 71 72 ReturnTypeInfo.type=DEF_NON; 73 ReturnTypeInfo.u.lpIndex=-1; 74 } 75 ParamImpl::ParamImpl(const Parameters ¶ms){ 76 int count = 0; 63 } 64 ParamImpl::ParamImpl(const Parameters ¶ms): 65 returnType() 66 { 67 ParmsNum = 0; 77 68 foreach( Parameter *pParam, params ){ 78 types[count].type = pParam->GetBasicType(); 79 types[count].u.lpIndex = pParam->GetIndex(); 80 count++; 81 } 82 this->ParmsNum=params.size(); 83 84 ReturnTypeInfo.type=DEF_NON; 85 ReturnTypeInfo.u.lpIndex=-1; 69 Parms[ParmsNum]=0; 70 ParmsNum++; 71 72 types.push_back( *pParam ); 73 } 86 74 } 87 75 ParamImpl::~ParamImpl(){ … … 96 84 } 97 85 98 void ParamImpl::SetReturnType( TYPEINFO *pTypeInfo){99 ReturnTypeInfo=*pTypeInfo;100 } 101 102 BOOL ParamImpl::_overload_check( Parameters ¶ms,TYPEINFO *pReturnTypeInfo,int overload_level){86 void ParamImpl::SetReturnType( const Type &returnType ){ 87 this->returnType = returnType; 88 } 89 90 bool ParamImpl::_overload_check( int level, const Parameters &targetParms, const Type &targetResultType ){ 103 91 //パラメータを識別してオーバーロードを解決 104 92 105 93 //パラメータの個数が不一致の場合 106 int max = (int)params.size(); 107 if(max!=ParmsNum) return 0; 94 int max = (int)targetParms.size(); 95 if(max!=ParmsNum){ 96 return false; 97 } 108 98 109 99 Type argType; 110 100 for(int i=0;i<max;i++){ 111 Parameter ¶m = * params[i];101 Parameter ¶m = *targetParms[i]; 112 102 113 103 if(Parms[i]){ … … 115 105 116 106 NumOpe_GetType(Parms[i], 117 ( overload_level==OVERLOAD_LEVEL0)? nullParam : param,107 (level==OVERLOAD_LEVEL0)? nullParam : param, 118 108 argType); 119 109 } 120 110 else{ 121 argType .SetType( types[i].type, types[i].u.lpIndex );111 argType = types[i]; 122 112 } 123 113 124 114 if(argType.GetBasicType()!=param.GetBasicType()){ 125 if( overload_level==OVERLOAD_LEVEL1 || overload_level == OVERLOAD_LEVEL0){126 return 0;127 } 128 else if( overload_level==OVERLOAD_LEVEL2){115 if(level==OVERLOAD_LEVEL1 || level == OVERLOAD_LEVEL0){ 116 return false; 117 } 118 else if(level==OVERLOAD_LEVEL2){ 129 119 if(!( 130 120 IsWholeNumberType(argType.GetBasicType())&&IsWholeNumberType(param.GetBasicType())|| 131 121 IsRealNumberType(argType.GetBasicType())&&IsRealNumberType(param.GetBasicType()) 132 )) return 0; 133 } 134 else if(overload_level==OVERLOAD_LEVEL3){ 122 )){ 123 return false; 124 } 125 } 126 else if(level==OVERLOAD_LEVEL3){ 135 127 if(argType.GetBasicType()==DEF_OBJECT||param.GetBasicType()==DEF_OBJECT) return 0; 136 128 } … … 138 130 else{ 139 131 if(NATURAL_TYPE(argType.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(argType.GetBasicType())==DEF_STRUCT){ 140 if(argType.GetIndex()!=param.GetIndex()) return 0; 141 } 142 } 143 } 144 145 if(pReturnTypeInfo){ 132 if(argType.GetIndex()!=param.GetIndex()){ 133 return false; 134 } 135 } 136 } 137 } 138 139 if( !targetResultType.IsNull() ){ 146 140 //戻り値も比較対象にする 147 if(ReturnTypeInfo.type==pReturnTypeInfo->type){ 148 if(NATURAL_TYPE(ReturnTypeInfo.type)==DEF_OBJECT 149 || NATURAL_TYPE(ReturnTypeInfo.type)==DEF_STRUCT ){ 150 if(ReturnTypeInfo.u.lpIndex != pReturnTypeInfo->u.lpIndex) return 0; 151 } 152 } 153 else return 0; 154 } 155 156 return 1; 157 } 158 159 SubInfo *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo *> &subs ){ 141 if( !returnType.Equals( targetResultType ) ){ 142 return false; 143 } 144 } 145 146 return true; 147 } 148 149 UserProc *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs ){ 160 150 int sw=0; 161 SubInfo *psi; 162 psi=0; 151 UserProc *pUserProc = NULL; 163 152 164 153 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 165 foreach( SubInfo *temp_psi, subs ){ 166 167 TYPEINFO ReturnTypeInfo; 168 ReturnTypeInfo.type=temp_psi->ReturnType; 169 ReturnTypeInfo.u.lpIndex=temp_psi->u.ReturnIndex; 154 foreach( UserProc *pTempUserProc, subs ){ 170 155 171 156 //エラーチェック 172 if(_overload_check( temp_psi->params,&ReturnTypeInfo,level)){157 if(_overload_check( level, pTempUserProc->Params(), pTempUserProc->ReturnType() )){ 173 158 if(sw){ 174 159 SetError(52,name,cp); … … 177 162 sw=1; 178 163 179 p si = temp_psi;164 pUserProc = pTempUserProc; 180 165 break; 181 166 } … … 190 175 } 191 176 192 return p si;193 } 194 SubInfo *ParamImpl::OverloadSolution( const char *name, std::vector<SubInfo*> &subs ){177 return pUserProc; 178 } 179 UserProc *ParamImpl::OverloadSolution( const char *name, std::vector<UserProc *> &subs ){ 195 180 int sw=0; 196 SubInfo *psi;197 p si=0;181 UserProc *pUserProc; 182 pUserProc=0; 198 183 199 184 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 200 185 201 foreach( SubInfo *temp_psi, subs ){186 foreach( UserProc *pTempUserProc, subs ){ 202 187 203 188 //エラーチェック 204 if(_overload_check( temp_psi->params,NULL,level)){189 if(_overload_check( level, pTempUserProc->Params(), Type() )){ 205 190 if(sw){ 206 191 return OverloadSolutionWithReturnType(name,subs); … … 208 193 sw=1; 209 194 210 p si = temp_psi;195 pUserProc = pTempUserProc; 211 196 } 212 197 } … … 216 201 217 202 if(!sw){ 218 SubInfo *temp_psi; 219 foreach( temp_psi, subs ){ 203 foreach( UserProc *pTempUserProc, subs ){ 220 204 221 205 //エラーチェック 222 if( temp_psi->params.size()==this->ParmsNum){206 if(pTempUserProc->Params().size()==this->ParmsNum){ 223 207 if(sw){ 224 208 sw=0; … … 227 211 sw=1; 228 212 229 p si=temp_psi;213 pUserProc=pTempUserProc; 230 214 } 231 215 } … … 237 221 } 238 222 239 return psi; 240 } 241 242 BOOL ParamImpl::ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){ 243 if(ParmsNum>pi_num){ 244 if(ppi[pi_num-1].type!=DEF_ELLIPSE){ 245 //パラメータが多すぎるとき 246 SetError(10,FuncName,cp); 247 return 0; 248 } 249 } 250 else if(ParmsNum<pi_num){ 251 if(ParmsNum<SecondParmNum){ 252 if(ppi[ParmsNum].type==DEF_ELLIPSE){ 253 return 1; 254 } 255 256 //パラメータが少なすぎるとき 257 SetError(10,FuncName,cp); 258 return 0; 259 } 260 261 //省略パラメータに "0" を指定する 262 for(;ParmsNum < pi_num;ParmsNum++){ 263 extern HANDLE hHeap; 264 char temporary[64]; 265 if(ppi[ParmsNum].bByVal) lstrcpy(temporary,"0"); 266 else sprintf(temporary,"%c%c0",1,ESC_BYVAL); 267 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 268 lstrcpy(Parms[ParmsNum],temporary); 269 } 270 } 271 272 return 1; 273 } 274 bool ParamImpl::ErrorCheck( const char *procName, const Parameters ¶ms, int SecondParmNum ){ 223 return pUserProc; 224 } 225 226 bool ParamImpl::ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 227 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 228 275 229 if(ParmsNum>(int)params.size()){ 276 230 if(params[params.size()-1]->GetBasicType()!=DEF_ELLIPSE){ … … 305 259 } 306 260 307 void ParamImpl::MacroParameterSupport(PARAMETER_INFO *ppi){308 for(int i=0;i<ParmsNum;i++){309 if(Parms[i][0]=='\0'){310 extern HANDLE hHeap;311 char temporary[64];312 if(ppi[i].bByVal) lstrcpy(temporary,"0");313 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);314 HeapDefaultFree(Parms[i]);315 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);316 lstrcpy(Parms[i],temporary);317 }318 }319 }320 261 void ParamImpl::MacroParameterSupport( const Parameters ¶ms ){ 321 262 for(int i=0;i<ParmsNum;i++){ -
BasicCompiler_Common/Parameter.h
r73 r75 46 46 } 47 47 48 bool IsRef(){ 48 bool IsRef() const 49 { 49 50 return isRef; 50 51 } -
BasicCompiler_Common/Procedure.cpp
r74 r75 1 1 #include "common.h" 2 2 3 SubInfo::SubInfo(): 4 pNextData( NULL ) 5 { 3 bool UserProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ){ 4 int i = 0; 5 int i2,i3,sw; 6 char temporary[8192],temp2[VN_SIZE]; 7 8 //ソースコードの位置 9 this->codePos = nowLine; 10 11 //パラメータ 12 if(sourceOfParams[i]!='('){ 13 SetError(1,NULL,nowLine); 14 return 0; 15 } 16 i++; 17 if(sourceOfParams[i]!=')'&& this->pParentClass ){ 18 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす 19 if(this->GetName()[0]=='~'){ 20 SetError(114,NULL,nowLine); 21 i=JumpStringInPare(sourceOfParams,i); 22 } 23 } 24 while(1){ 25 if(sourceOfParams[i]==')') break; 26 27 //ByRef 28 bool isRef; 29 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 30 isRef = false; 31 i+=2; 32 } 33 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 34 isRef = true; 35 i+=2; 36 } 37 else isRef = false; 38 39 //パラメータ名 40 bool isArray = false; 41 int subScripts[MAX_ARRAYDIM]; 42 char name[VN_SIZE]; 43 sw=0; 44 for(i2=0;;i++,i2++){ 45 if(sourceOfParams[i]=='('){ 46 if(!sw) sw=1; 47 48 i3=GetStringInPare(name+i2,sourceOfParams+i); 49 i2+=i3-1; 50 i+=i3-1; 51 continue; 52 } 53 if(sourceOfParams[i]=='['){ 54 if(!sw) sw=1; 55 56 i3=GetStringInBracket(name+i2,sourceOfParams+i); 57 i2+=i3-1; 58 i+=i3-1; 59 continue; 60 } 61 if(!IsVariableChar(sourceOfParams[i])){ 62 name[i2]=0; 63 break; 64 } 65 name[i2]=sourceOfParams[i]; 66 } 67 if(sw){ 68 //配列パラメータ 69 if( isRef == false ) SetError(29,NULL,nowLine); 70 isArray = true; 71 72 if((name[i2-2]=='('&&name[i2-1]==')')|| 73 (name[i2-2]=='['&&name[i2-1]==']')){ 74 subScripts[0]=LONG_MAX; 75 subScripts[1]=-1; 76 77 name[i2-2]=0; 78 } 79 else{ 80 GetArrange(name,temp2,subScripts); 81 lstrcpy(name,temp2); 82 } 83 84 i2=lstrlen(name); 85 } 86 87 //型 88 Type type( DEF_NON ); 89 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 90 i+=2; 91 92 i2=0; 93 while(sourceOfParams[i]=='*'){ 94 temporary[i2]=sourceOfParams[i]; 95 i++; 96 i2++; 97 } 98 for(;;i++,i2++){ 99 if(!IsVariableChar(sourceOfParams[i])){ 100 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){ 101 temporary[i2++]=sourceOfParams[i++]; 102 temporary[i2]=sourceOfParams[i]; 103 continue; 104 } 105 temporary[i2]=0; 106 break; 107 } 108 temporary[i2]=sourceOfParams[i]; 109 } 110 111 Type::StringToType( temporary, type ); 112 113 if(temporary[0]=='*'&& 114 temporary[1]==1&& 115 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 116 if(sourceOfParams[i]!='('){ 117 SetError(10,temporary,nowLine); 118 break; 119 } 120 i3=GetStringInPare(temporary+i2,sourceOfParams+i); 121 i+=i3; 122 i2+=i3; 123 124 if(temporary[2]==ESC_FUNCTION&&sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 125 temporary[i2++]=sourceOfParams[i++]; 126 temporary[i2++]=sourceOfParams[i++]; 127 for(;;i++,i2++){ 128 if(!IsVariableChar(sourceOfParams[i])){ 129 temporary[i2]=0; 130 break; 131 } 132 temporary[i2]=sourceOfParams[i]; 133 } 134 } 135 } 136 else{ 137 //TypeDefをする前のベース型を取得 138 GetOriginalTypeName(temporary); 139 } 140 141 if( type.IsNull() ){ 142 SetError(3,temporary,nowLine); 143 type.SetBasicType( DEF_PTR_VOID ); 144 } 145 } 146 else{ 147 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 148 SetError(-103,temporary,nowLine); 149 } 150 151 if( type.IsProcPtr() ){ 152 //関数ポインタの場合 153 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2], nowLine) ); 154 } 155 156 Parameter *pParam = new Parameter( name, type, isRef ); 157 if( isArray ){ 158 pParam->SetArray( subScripts ); 159 } 160 161 //パラメータを追加 162 this->params.push_back( pParam ); 163 164 if(sourceOfParams[i]==','){ 165 i++; 166 continue; 167 } 168 else if(sourceOfParams[i]==')') continue; 169 else{ 170 SetError(1,NULL,nowLine); 171 break; 172 } 173 } 174 this->secondParmNum = (int)this->params.size(); 175 i++; 176 if(sourceOfParams[i]=='('){ 177 i++; 178 while(1){ 179 if(sourceOfParams[i]==')') break; 180 181 //ByRef 182 bool isRef; 183 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 184 isRef = false; 185 i+=2; 186 } 187 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 188 isRef = true; 189 i+=2; 190 } 191 else isRef = false; 192 193 //パラメータ名 194 bool isArray = false; 195 int subScripts[MAX_ARRAYDIM]; 196 char name[VN_SIZE]; 197 sw=0; 198 for(i2=0;;i++,i2++){ 199 if(sourceOfParams[i]=='('){ 200 if(!sw) sw=1; 201 202 i3=GetStringInPare(name+i2,sourceOfParams+i); 203 i2+=i3-1; 204 i+=i3-1; 205 continue; 206 } 207 if(sourceOfParams[i]=='['){ 208 if(!sw) sw=1; 209 210 i3=GetStringInBracket(name+i2,sourceOfParams+i); 211 i2+=i3-1; 212 i+=i3-1; 213 continue; 214 } 215 if(!IsVariableChar(sourceOfParams[i])){ 216 name[i2]=0; 217 break; 218 } 219 name[i2]=sourceOfParams[i]; 220 } 221 if(sw){ 222 //配列パラメータ 223 if( isRef == false ) SetError(29,NULL,nowLine); 224 isArray = true; 225 226 if((name[i2-2]=='('&&name[i2-1]==')')|| 227 (name[i2-2]=='['&&name[i2-1]==']')){ 228 subScripts[0]=LONG_MAX; 229 subScripts[1]=-1; 230 231 name[i2-2]=0; 232 } 233 else{ 234 GetArrange(name,temp2,subScripts); 235 lstrcpy(name,temp2); 236 } 237 238 i2=lstrlen(name); 239 } 240 241 //型 242 Type type( DEF_NON ); 243 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 244 i+=2; 245 246 i2=0; 247 while(sourceOfParams[i]=='*'){ 248 temporary[i2]=sourceOfParams[i]; 249 i++; 250 i2++; 251 } 252 for(;;i++,i2++){ 253 if(!IsVariableChar(sourceOfParams[i])){ 254 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){ 255 temporary[i2++]=sourceOfParams[i++]; 256 temporary[i2]=sourceOfParams[i]; 257 continue; 258 } 259 temporary[i2]=0; 260 break; 261 } 262 temporary[i2]=sourceOfParams[i]; 263 } 264 265 Type::StringToType( temporary, type ); 266 267 if(temporary[0]=='*'&& 268 temporary[1]==1&& 269 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 270 if(sourceOfParams[i]!='('){ 271 SetError(10,temporary,nowLine); 272 break; 273 } 274 i3=GetStringInPare(temporary+i2,sourceOfParams+i); 275 i+=i3; 276 i2+=i3; 277 278 if(temporary[2]==ESC_FUNCTION&&sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 279 temporary[i2++]=sourceOfParams[i++]; 280 temporary[i2++]=sourceOfParams[i++]; 281 for(;;i++,i2++){ 282 if(!IsVariableChar(sourceOfParams[i])){ 283 temporary[i2]=0; 284 break; 285 } 286 temporary[i2]=sourceOfParams[i]; 287 } 288 } 289 } 290 else{ 291 //TypeDefをする前のベース型を取得 292 GetOriginalTypeName(temporary); 293 } 294 295 if( type.IsNull() ){ 296 SetError(3,temporary,nowLine); 297 type.SetBasicType( DEF_PTR_VOID ); 298 } 299 } 300 else{ 301 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 302 SetError(-103,temporary,nowLine); 303 } 304 305 if( type.IsProcPtr() ){ 306 //関数ポインタの場合 307 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2], nowLine) ); 308 } 309 310 Parameter *pParam = new Parameter( name, type, isRef ); 311 if( isArray ){ 312 pParam->SetArray( subScripts ); 313 } 314 315 //パラメータを追加 316 this->params.push_back( pParam ); 317 318 if(sourceOfParams[i]==','){ 319 i++; 320 continue; 321 } 322 else if(sourceOfParams[i]==')') continue; 323 else{ 324 SetError(1,NULL,nowLine); 325 break; 326 } 327 } 328 i++; 329 } 330 331 if(sourceOfParams[i]){ 332 /////////////////// 333 // 戻り値を取得 334 /////////////////// 335 336 if( !this->IsFunction() ){ 337 // Sub/Macroの場合 338 SetError(38,this->GetName(),nowLine); 339 } 340 341 if( this->pParentClass ){ 342 if( this->GetName() == this->pParentClass->name || 343 this->GetName()[0]=='~'){ 344 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす 345 SetError(115,NULL,nowLine); 346 } 347 } 348 349 350 i2=lstrlen(sourceOfParams)-2; 351 352 int sw_as=0; 353 for(;i2>0;i2--){ 354 if(sourceOfParams[i2]==')') break; 355 356 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){ 357 i2+=2; 358 i3=0; 359 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++]; 360 for(;;i2++,i3++){ 361 if(!IsVariableChar(sourceOfParams[i2])){ 362 temporary[i3]=0; 363 break; 364 } 365 temporary[i3]=sourceOfParams[i2]; 366 } 367 Type::StringToType( temporary, this->returnType ); 368 if( this->returnType.IsNull() ) SetError(3,temporary,nowLine); 369 370 sw_as=1; 371 break; 372 } 373 } 374 375 if(!sw_as){ 376 SetError(-104,this->GetName().c_str(),nowLine); 377 378 this->returnType.SetBasicType( DEF_DOUBLE ); 379 } 380 } 381 else{ 382 //戻り値なしのSub定義 383 this->returnType.SetNull(); 384 } 385 386 //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する場合がある) 387 388 if( this->pParentClass && isStatic == false ){ 389 //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用 390 string name = "_System_LocalThis"; 391 Type type( DEF_PTR_VOID ); 392 this->realParams.push_back( new Parameter( name, type ) ); 393 } 394 395 if( this->returnType.IsStruct() ){ 396 //構造体を戻り値として持つ場合 397 //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする 398 399 string name = this->GetName(); 400 if(name[0]==1&&name[1]==ESC_OPERATOR){ 401 name="_System_ReturnValue"; 402 } 403 Type type( DEF_STRUCT, this->returnType.GetIndex() ); 404 this->realParams.push_back( new Parameter( name, type, true ) ); 405 } 406 407 //パラメータをコピー 408 foreach( Parameter *pParam, params ){ 409 this->realParams.push_back( new Parameter( *pParam ) ); 410 } 411 412 return true; 6 413 } 414 415 bool DllProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){ 416 int i = 0; 417 int i2,i3,sw; 418 char temporary[8192],temp2[VN_SIZE]; 419 420 //ソースコードの位置 421 this->codePos = nowLine; 422 423 //パラメータ 424 if(sourceOfParams[i]!='('){ 425 SetError(1,NULL,nowLine); 426 return 0; 427 } 428 i++; 429 430 while(1){ 431 if(sourceOfParams[i]==')') break; 432 433 //ByRef 434 bool isRef; 435 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 436 isRef = false; 437 i+=2; 438 } 439 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 440 isRef = true; 441 i+=2; 442 } 443 else isRef = false; 444 445 //パラメータ名 446 bool isArray = false; 447 int subScripts[MAX_ARRAYDIM]; 448 char name[VN_SIZE]; 449 sw=0; 450 for(i2=0;;i++,i2++){ 451 if(sourceOfParams[i]=='('){ 452 if(!sw) sw=1; 453 454 i3=GetStringInPare(name+i2,sourceOfParams+i); 455 i2+=i3-1; 456 i+=i3-1; 457 continue; 458 } 459 if(sourceOfParams[i]=='['){ 460 if(!sw) sw=1; 461 462 i3=GetStringInBracket(name+i2,sourceOfParams+i); 463 i2+=i3-1; 464 i+=i3-1; 465 continue; 466 } 467 if(!IsVariableChar(sourceOfParams[i])){ 468 name[i2]=0; 469 break; 470 } 471 name[i2]=sourceOfParams[i]; 472 } 473 if(sw){ 474 //配列パラメータ 475 if( isRef == false ) SetError(29,NULL,nowLine); 476 isArray = true; 477 478 if((name[i2-2]=='('&&name[i2-1]==')')|| 479 (name[i2-2]=='['&&name[i2-1]==']')){ 480 subScripts[0]=LONG_MAX; 481 subScripts[1]=-1; 482 483 name[i2-2]=0; 484 } 485 else{ 486 GetArrange(name,temp2,subScripts); 487 lstrcpy(name,temp2); 488 } 489 490 i2=lstrlen(name); 491 } 492 493 //型 494 Type type( DEF_NON ); 495 if(lstrcmp(name,"...")==0) type.SetBasicType( DEF_ELLIPSE ); 496 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 497 i+=2; 498 499 i2=0; 500 while(sourceOfParams[i]=='*'){ 501 temporary[i2]=sourceOfParams[i]; 502 i++; 503 i2++; 504 } 505 for(;;i++,i2++){ 506 if(!IsVariableChar(sourceOfParams[i])){ 507 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){ 508 temporary[i2++]=sourceOfParams[i++]; 509 temporary[i2]=sourceOfParams[i]; 510 continue; 511 } 512 temporary[i2]=0; 513 break; 514 } 515 temporary[i2]=sourceOfParams[i]; 516 } 517 518 Type::StringToType( temporary, type ); 519 520 if(temporary[0]=='*'&& 521 temporary[1]==1&& 522 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 523 if(sourceOfParams[i]!='('){ 524 SetError(10,temporary,nowLine); 525 break; 526 } 527 i3=GetStringInPare(temporary+i2,sourceOfParams+i); 528 i+=i3; 529 i2+=i3; 530 531 if(temporary[2]==ESC_FUNCTION&&sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 532 temporary[i2++]=sourceOfParams[i++]; 533 temporary[i2++]=sourceOfParams[i++]; 534 for(;;i++,i2++){ 535 if(!IsVariableChar(sourceOfParams[i])){ 536 temporary[i2]=0; 537 break; 538 } 539 temporary[i2]=sourceOfParams[i]; 540 } 541 } 542 } 543 else{ 544 //TypeDefをする前のベース型を取得 545 GetOriginalTypeName(temporary); 546 } 547 548 if( type.IsNull() ){ 549 SetError(3,temporary,nowLine); 550 type.SetBasicType( DEF_PTR_VOID ); 551 } 552 } 553 else{ 554 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 555 SetError(-103,temporary,nowLine); 556 } 557 558 if( type.IsProcPtr() ){ 559 //関数ポインタの場合 560 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2], nowLine ) ); 561 } 562 563 Parameter *pParam = new Parameter( name, type, isRef ); 564 if( isArray ){ 565 pParam->SetArray( subScripts ); 566 } 567 568 //パラメータを追加 569 this->params.push_back( pParam ); 570 571 if(sourceOfParams[i]==','){ 572 i++; 573 continue; 574 } 575 else if(sourceOfParams[i]==')') continue; 576 else{ 577 SetError(1,NULL,nowLine); 578 break; 579 } 580 } 581 i++; 582 583 if(sourceOfParams[i]){ 584 /////////////////// 585 // 戻り値を取得 586 /////////////////// 587 588 i2=lstrlen(sourceOfParams)-2; 589 590 int sw_as=0; 591 for(;i2>0;i2--){ 592 if(sourceOfParams[i2]==')') break; 593 594 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){ 595 i2+=2; 596 i3=0; 597 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++]; 598 for(;;i2++,i3++){ 599 if(!IsVariableChar(sourceOfParams[i2])){ 600 temporary[i3]=0; 601 break; 602 } 603 temporary[i3]=sourceOfParams[i2]; 604 } 605 Type::StringToType( temporary, this->returnType ); 606 if( this->returnType.IsNull() ) SetError(3,temporary,nowLine); 607 608 sw_as=1; 609 break; 610 } 611 } 612 } 613 else{ 614 //戻り値なしのSub定義 615 this->returnType.SetNull(); 616 } 617 618 return true; 619 } 620 621 bool ProcPointer::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){ 622 int i = 0; 623 int i2,i3,sw; 624 char temporary[8192],temp2[VN_SIZE]; 625 626 //ソースコードの位置 627 this->codePos = nowLine; 628 629 //パラメータ 630 if(sourceOfParams[i]!='('){ 631 SetError(1,NULL,nowLine); 632 return 0; 633 } 634 i++; 635 while(1){ 636 if(sourceOfParams[i]==')') break; 637 638 //ByRef 639 bool isRef; 640 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 641 isRef = false; 642 i+=2; 643 } 644 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 645 isRef = true; 646 i+=2; 647 } 648 else isRef = false; 649 650 //パラメータ名 651 bool isArray = false; 652 int subScripts[MAX_ARRAYDIM]; 653 char name[VN_SIZE]; 654 sw=0; 655 for(i2=0;;i++,i2++){ 656 if(sourceOfParams[i]=='('){ 657 if(!sw) sw=1; 658 659 i3=GetStringInPare(name+i2,sourceOfParams+i); 660 i2+=i3-1; 661 i+=i3-1; 662 continue; 663 } 664 if(sourceOfParams[i]=='['){ 665 if(!sw) sw=1; 666 667 i3=GetStringInBracket(name+i2,sourceOfParams+i); 668 i2+=i3-1; 669 i+=i3-1; 670 continue; 671 } 672 if(!IsVariableChar(sourceOfParams[i])){ 673 name[i2]=0; 674 break; 675 } 676 name[i2]=sourceOfParams[i]; 677 } 678 if(sw){ 679 //配列パラメータ 680 if( isRef == false ) SetError(29,NULL,nowLine); 681 isArray = true; 682 683 if((name[i2-2]=='('&&name[i2-1]==')')|| 684 (name[i2-2]=='['&&name[i2-1]==']')){ 685 subScripts[0]=LONG_MAX; 686 subScripts[1]=-1; 687 688 name[i2-2]=0; 689 } 690 else{ 691 GetArrange(name,temp2,subScripts); 692 lstrcpy(name,temp2); 693 } 694 695 i2=lstrlen(name); 696 } 697 698 //型 699 Type type( DEF_NON ); 700 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 701 i+=2; 702 703 i2=0; 704 while(sourceOfParams[i]=='*'){ 705 temporary[i2]=sourceOfParams[i]; 706 i++; 707 i2++; 708 } 709 for(;;i++,i2++){ 710 if(!IsVariableChar(sourceOfParams[i])){ 711 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){ 712 temporary[i2++]=sourceOfParams[i++]; 713 temporary[i2]=sourceOfParams[i]; 714 continue; 715 } 716 temporary[i2]=0; 717 break; 718 } 719 temporary[i2]=sourceOfParams[i]; 720 } 721 722 Type::StringToType( temporary, type ); 723 724 if(temporary[0]=='*'&& 725 temporary[1]==1&& 726 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 727 if(sourceOfParams[i]!='('){ 728 SetError(10,temporary,nowLine); 729 break; 730 } 731 i3=GetStringInPare(temporary+i2,sourceOfParams+i); 732 i+=i3; 733 i2+=i3; 734 735 if(temporary[2]==ESC_FUNCTION&&sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 736 temporary[i2++]=sourceOfParams[i++]; 737 temporary[i2++]=sourceOfParams[i++]; 738 for(;;i++,i2++){ 739 if(!IsVariableChar(sourceOfParams[i])){ 740 temporary[i2]=0; 741 break; 742 } 743 temporary[i2]=sourceOfParams[i]; 744 } 745 } 746 } 747 else{ 748 //TypeDefをする前のベース型を取得 749 GetOriginalTypeName(temporary); 750 } 751 752 if( type.IsNull() ){ 753 SetError(3,temporary,nowLine); 754 type.SetBasicType( DEF_PTR_VOID ); 755 } 756 } 757 else{ 758 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 759 SetError(-103,temporary,nowLine); 760 } 761 762 if( type.IsProcPtr() ){ 763 //関数ポインタの場合 764 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2], nowLine ) ); 765 } 766 767 Parameter *pParam = new Parameter( name, type, isRef ); 768 if( isArray ){ 769 pParam->SetArray( subScripts ); 770 } 771 772 //パラメータを追加 773 this->params.push_back( pParam ); 774 775 if(sourceOfParams[i]==','){ 776 i++; 777 continue; 778 } 779 else if(sourceOfParams[i]==')') continue; 780 else{ 781 SetError(1,NULL,nowLine); 782 break; 783 } 784 } 785 i++; 786 787 if(sourceOfParams[i]){ 788 /////////////////// 789 // 戻り値を取得 790 /////////////////// 791 792 i2=lstrlen(sourceOfParams)-2; 793 794 int sw_as=0; 795 for(;i2>0;i2--){ 796 if(sourceOfParams[i2]==')') break; 797 798 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){ 799 i2+=2; 800 i3=0; 801 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++]; 802 for(;;i2++,i3++){ 803 if(!IsVariableChar(sourceOfParams[i2])){ 804 temporary[i3]=0; 805 break; 806 } 807 temporary[i3]=sourceOfParams[i2]; 808 } 809 Type::StringToType( temporary, this->returnType ); 810 if( this->returnType.IsNull() ) SetError(3,temporary,nowLine); 811 812 sw_as=1; 813 break; 814 } 815 } 816 } 817 else{ 818 //戻り値なしのSub定義 819 this->returnType.SetNull(); 820 } 821 822 //戻り値のエラーチェック 823 if( IsFunction() ){ 824 // Function定義 825 826 if( this->ReturnType().IsNull() ){ 827 // 戻り値がない 828 SetError(26,this->GetName(),nowLine); 829 } 830 } 831 else{ 832 if( !this->ReturnType().IsNull() ){ 833 // Sub定義なのに、戻り値がある 834 SetError(38,this->GetName(),nowLine); 835 } 836 } 837 838 return true; 839 } 840 841 UserProc *UserProc::pCompilingUserProc = NULL; -
BasicCompiler_Common/Procedure.h
r74 r75 2 2 struct VARIABLE; 3 3 4 #define SUBTYPE_SUB 1 5 #define SUBTYPE_FUNCTION 2 6 #define SUBTYPE_MACRO 3 7 class SubInfo{ 8 public: 9 SubInfo(); 10 11 DWORD dwType; 12 13 //クラス情報 14 CClass *pobj_ParentClass; 15 4 class Procedure{ 5 public: 6 // 種類 7 enum Kind{ 8 Sub, 9 Function, 10 }; 11 12 private: 13 const string name; 14 15 Kind kind; 16 17 bool isCdecl; 18 bool isUsing; 19 20 protected: 21 22 // パラメータ 23 Parameters params; 24 25 // 戻り値の型 26 Type returnType; 27 28 // ソースコードの位置 29 int codePos; 30 31 public: 32 Procedure( const string &name, Kind kind, bool isCdecl ): 33 name( name ), 34 kind( kind ), 35 isCdecl( isCdecl ), 36 isUsing( false ), 37 codePos( -1 ) 38 {} 39 ~Procedure(){ 40 foreach( Parameter *pParam, params ){ 41 delete pParam; 42 } 43 } 44 45 const string &GetName() const 46 { 47 return name; 48 } 49 50 bool IsSub() const 51 { 52 return ( kind == Sub ); 53 } 54 bool IsFunction() const 55 { 56 return ( kind == Function ); 57 } 58 59 bool IsCdecl() const 60 { 61 return isCdecl; 62 } 63 void Using(){ 64 isUsing = true; 65 } 66 bool IsUsing() const 67 { 68 return isUsing; 69 } 70 71 int GetCodePos() const 72 { 73 return codePos; 74 } 75 76 const Parameters &Params() const 77 { 78 return params; 79 } 80 const Type &ReturnType() const 81 { 82 return returnType; 83 } 84 }; 85 86 class UserProc : public Procedure 87 { 88 89 private: 90 bool isMacro; 91 92 // パラメータの追加情報 93 int secondParmNum; 94 Parameters realParams; 95 int realSecondParmNum; 96 97 // 親クラスと対応するメソッド 98 CClass *pParentClass; 99 CMethod *pMethod; 100 101 // 各種フラグ 102 bool isExport; 103 bool isSystem; 104 bool isCompiled; 105 106 public: 107 // ハッシュリスト用 108 UserProc *pNextData; 109 110 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ): 111 Procedure( name, kind, isCdecl ), 112 isMacro( isMacro ), 113 pParentClass( NULL ), 114 pMethod( NULL ), 115 isExport( isExport ), 116 isSystem( false ), 117 isCompiled( false ), 118 pNextData( NULL ) 119 { 120 } 121 ~UserProc(){ 122 foreach( Parameter *pParam, realParams ){ 123 delete pParam; 124 } 125 } 126 127 bool IsMacro() const 128 { 129 return isMacro; 130 } 131 132 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ); 133 134 int GetSecondParmNum() const 135 { 136 return secondParmNum; 137 } 138 const Parameters &RealParams() const 139 { 140 return realParams; 141 } 142 int GetRealSecondParmNum() const 143 { 144 return realSecondParmNum; 145 } 146 147 void SetParentClass( CClass *pParentClass ){ 148 this->pParentClass = pParentClass; 149 } 150 CClass *GetParentClassPtr() 151 { 152 return pParentClass; 153 } 154 const CClass &GetParentClass() const 155 { 156 return *pParentClass; 157 } 158 void SetMethod( CMethod *pMethod ){ 159 this->pMethod = pMethod; 160 } 161 162 void ExportOff(){ 163 isExport = false; 164 } 165 bool IsExport() const 166 { 167 return isExport; 168 } 169 void ThisIsSystemProc(){ 170 isSystem = true; 171 } 172 bool IsSystem() const 173 { 174 return isSystem; 175 } 176 void CompleteCompile(){ 177 isCompiled = true; 178 } 179 void KillCompileStatus(){ 180 isCompiled = false; 181 } 182 bool IsCompiled() const 183 { 184 return isCompiled; 185 } 186 bool IsDestructor() const 187 { 188 return ( GetName()[0] == '~' ); 189 } 190 bool IsVirtual() const 191 { 192 if( pMethod == NULL ){ 193 return false; 194 } 195 return ( pMethod->bVirtual != 0 ); 196 } 197 198 199 // バイナリコードの位置 200 DWORD beginOpAddress; 201 DWORD endOpAddress; 202 203 // ローカル変数 204 Variables localVars; 205 206 // TODO: 適切なコードへ直す 16 207 long id; 17 208 18 char *name; 19 long address; 20 21 //パラメータ 22 Parameters params; 23 int SecondParmNum; 24 Parameters realParams; 25 int RealSecondParmNum; 26 27 //戻り値 28 int ReturnType; 29 union{ 30 LONG_PTR ReturnIndex; 31 CClass *Return_pobj_c; 32 }u; 33 bool isReturnRef; 34 35 DWORD CompileAddress; 36 DWORD EndOpAddr; 37 VARIABLE *pVar; 38 int VarNum; 39 40 BOOL bExport; 41 BOOL bCdecl; 42 BOOL bVirtual; 43 BOOL bUse; 44 BOOL bCompile; 45 BOOL bSystem; 46 47 SubInfo *pNextData; 48 }; 209 210 ///////////////////////////////////////////////////////////////// 211 // コンパイル中の関数を管理 212 ///////////////////////////////////////////////////////////////// 213 private: 214 static UserProc *pCompilingUserProc; 215 public: 216 static void CompileStartForGlobalArea(){ 217 pCompilingUserProc = NULL; 218 } 219 static void CompileStartForUserProc( UserProc *pUserProc ){ 220 pCompilingUserProc = pUserProc; 221 } 222 static bool IsGlobalAreaCompiling(){ 223 return ( pCompilingUserProc == NULL ); 224 } 225 static bool IsLocalAreaCompiling(){ 226 return ( pCompilingUserProc != NULL ); 227 } 228 static UserProc &CompilingUserProc(){ 229 return *pCompilingUserProc; 230 } 231 }; 232 233 class DllProc : public Procedure 234 { 235 const string dllFileName; 236 const string alias; 237 int lookupAddress; 238 239 public: 240 // ハッシュリスト用 241 DllProc *pNextData; 242 243 DllProc( const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ): 244 Procedure( name, kind, isCdecl ), 245 dllFileName( dllFileName ), 246 alias( alias ), 247 lookupAddress( 0 ), 248 pNextData( NULL ) 249 { 250 } 251 ~DllProc(){} 252 253 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ); 254 255 const string &GetDllFileName() const 256 { 257 return dllFileName; 258 } 259 const string &GetAlias() const 260 { 261 return alias; 262 } 263 264 void SetLookupAddress( int lookupAddress ){ 265 this->lookupAddress = lookupAddress; 266 } 267 int GetLookupAddress() const 268 { 269 return lookupAddress; 270 } 271 272 }; 273 274 class ProcPointer : public Procedure 275 { 276 public: 277 ProcPointer( Kind kind ): 278 Procedure( "", kind, false ) 279 { 280 } 281 ~ProcPointer(){} 282 283 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ); 284 }; -
BasicCompiler_Common/Resource.cpp
r4 r75 50 50 51 51 _int64 i64data; 52 int type; 53 type=StaticCalculation(true, temporary,0,&i64data,0); 54 if(IsRealNumberType(type)){ 52 Type resultType; 53 if( !StaticCalculation(true, temporary,0,&i64data,resultType) ){ 54 return; 55 } 56 if(resultType.IsReal()){ 55 57 SetError(9,temporary,0); 56 58 return; -
BasicCompiler_Common/Subroutine.cpp
r73 r75 6 6 #include "../BasicCompiler32/opcode.h" 7 7 #endif 8 9 //コンパイル中の関数情報10 SubInfo *pCompilingSubInfo;11 8 12 9 int GetCallProcName(char *buffer,char *name){ … … 56 53 57 54 //関数ポインタ 58 int type; 59 LONG_PTR lpIndex; 60 type=GetVarType(name,&lpIndex,0); 61 if(type==DEF_PTR_PROC) return PROC_PTR; 55 Type type; 56 if( !GetVarType( name, type, false ) ){ 57 return 0; 58 } 59 if( type.IsProcPtr() ){ 60 return PROC_PTR; 61 } 62 62 63 63 return 0; … … 105 105 } 106 106 107 108 int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){ 109 int ret_type; 110 111 if(idProc==PROC_DEFAULT){ 107 bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn ){ 108 109 //GetSubHash内でエラー提示が行われた場合 110 if(pProc==(Procedure *)-1){ 111 return false; 112 } 113 114 if(kind==PROC_DEFAULT){ 112 115 ///////////////////// 113 116 // ユーザー定義関数 114 117 ///////////////////// 115 118 116 SubInfo *pSub; 117 pSub=(SubInfo *)pInfo; 118 119 //GetSubHash内でエラー提示が行われた場合 120 if(pSub==(SubInfo *)-1) return -1; 121 119 UserProc *pUserProc = (UserProc *)pProc; 122 120 123 121 //オブジェクト名を取得 124 122 char ObjectName[VN_SIZE]; 125 123 int RefType; 126 SplitObjectName( name,ObjectName,&RefType);124 SplitObjectName(fullCallName,ObjectName,&RefType); 127 125 128 126 … … 131 129 //////////////////////// 132 130 133 std::vector< SubInfo*> subs;134 GetOverloadSubHash( name,subs);131 std::vector<UserProc *> subs; 132 GetOverloadSubHash(fullCallName,subs); 135 133 if(subs.size()){ 136 134 //オーバーロードを解決 137 pSub=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL); 138 139 if(!pSub) return 0; 140 } 141 142 143 Opcode_CallProc(Parameter,pSub,0,ObjectName,RefType); 144 if( plpRetIndex ){ 145 *plpRetIndex = pSub->u.ReturnIndex; 146 } 147 return pSub->ReturnType; 148 } 149 else if(idProc==PROC_DLL){ 135 pUserProc=OverloadSolutionWithStrParam(fullCallName,subs,lpszParms,ObjectName); 136 137 if(!pUserProc){ 138 return false; 139 } 140 } 141 142 resultType = pUserProc->ReturnType(); 143 144 if( isCallOn ){ 145 if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName,RefType) ){ 146 return false; 147 } 148 } 149 } 150 else if(kind==PROC_DLL){ 150 151 ///////////////////////// 151 152 // DLL関数 152 153 ///////////////////////// 153 DECLAREINFO *pdi; 154 pdi=(DECLAREINFO *)pInfo; 155 156 ret_type=Opcode_CallDllProc(Parameter,pdi,plpRetIndex); 157 } 158 else if(idProc==PROC_BUILTIN){ 154 DllProc *pDllProc = (DllProc *)pProc; 155 156 resultType = pDllProc->ReturnType(); 157 158 if( isCallOn ){ 159 if( !Opcode_CallDllProc(lpszParms,pDllProc) ){ 160 return false; 161 } 162 } 163 } 164 else if(kind==PROC_BUILTIN){ 159 165 ///////////////////////// 160 166 // 組み込み関数 161 167 ///////////////////////// 162 int FuncId; 163 FuncId=(int)(_int64)pInfo; 164 165 TYPEINFO ReturnTypeInfo = { DEF_LONG, NULL }; 166 Opcode_CallFunc( Parameter, FuncId, ReturnTypeInfo ); 167 if( plpRetIndex ){ 168 *plpRetIndex = ReturnTypeInfo.u.lpIndex; 169 } 170 return ReturnTypeInfo.type; 171 } 172 else if(idProc==PROC_PTR){ 168 int FuncId = (int)(_int64)pProc; 169 170 if( !Opcode_CallFunc( lpszParms, FuncId, resultType, isCallOn ) ){ 171 return false; 172 } 173 } 174 else if(kind==PROC_PTR){ 173 175 ///////////////// 174 176 // 関数ポインタ 175 177 ///////////////// 176 178 177 LONG_PTR lpIndex; 178 GetVarType(name,&lpIndex,0); 179 180 extern PROCPTRINFO *pProcPtrInfo; 181 ret_type=Opcode_CallProcPtr(name,Parameter,&pProcPtrInfo[lpIndex],plpRetIndex); 182 } 183 184 return ret_type; 185 } 186 BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){ 179 Type type; 180 GetVarType(fullCallName,type,false); 181 182 extern ProcPointer **ppProcPointer; 183 ProcPointer *pProcPtr = ppProcPointer[type.GetIndex()]; 184 resultType = pProcPtr->ReturnType(); 185 186 if( isCallOn ){ 187 if( !Opcode_CallProcPtr(fullCallName,lpszParms,pProcPtr) ){ 188 return false; 189 } 190 } 191 } 192 else{ 193 return false; 194 } 195 196 return true; 197 } 198 bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType){ 187 199 //プロパティ用のメソッドを呼び出す 188 200 … … 197 209 198 210 //オーバーロード用の関数リストを作成 199 std::vector< SubInfo*> subs;211 std::vector<UserProc *> subs; 200 212 GetOverloadSubHash(VarName,subs); 201 213 if(subs.size()==0){ 202 return 0;214 return false; 203 215 } 204 216 205 217 //パラメータを整備 206 218 char *Parameter; 207 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen( RightSide)+32);219 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32); 208 220 lstrcpy(Parameter,ArrayElements); 209 if( RightSide){210 if(Parameter[0]&& RightSide[0]) lstrcat(Parameter,",");211 lstrcat(Parameter, RightSide);221 if(rightSide){ 222 if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,","); 223 lstrcat(Parameter,rightSide); 212 224 } 213 225 214 226 //オーバーロードを解決 215 SubInfo *pSub;216 p Sub=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);217 218 if(p Sub){227 UserProc *pUserProc; 228 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 229 230 if(pUserProc){ 219 231 //呼び出し 220 Opcode_CallProc(Parameter,pSub,0,ObjectName,RefType); 221 222 if( pRetTypeInfo ){ 223 pRetTypeInfo->type = pSub->ReturnType; 224 pRetTypeInfo->u.lpIndex = pSub->u.ReturnIndex; 225 } 232 Opcode_CallProc(Parameter,pUserProc,0,ObjectName,RefType); 233 234 resultType = pUserProc->ReturnType(); 226 235 } 227 236 228 237 HeapDefaultFree(Parameter); 229 238 230 return 1; 231 } 232 233 234 int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){ 235 int ret_type; 236 237 if(idProc==PROC_DEFAULT){ 238 ///////////////////// 239 // ユーザー定義関数 240 ///////////////////// 241 242 SubInfo *pSub; 243 pSub=(SubInfo *)pInfo; 244 245 //GetSubHash内でエラー提示が行われた場合 246 if(pSub==(SubInfo *)-1) return -1; 247 248 249 //オブジェクト名を取得 250 char ObjectName[VN_SIZE]; 251 int RefType; 252 SplitObjectName(name,ObjectName,&RefType); 253 254 255 //////////////////////// 256 // オーバーロードを解決 257 //////////////////////// 258 259 std::vector<SubInfo *> subs; 260 GetOverloadSubHash(name,subs); 261 if( subs.size() > 0 ){ 262 //オーバーロードを解決 263 pSub=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL); 264 265 if(!pSub) return 0; 266 } 267 268 269 ret_type=pSub->ReturnType; 270 *plpRetIndex=pSub->u.ReturnIndex; 271 } 272 else if(idProc==PROC_DLL){ 273 ///////////////////////// 274 // DLL関数 275 ///////////////////////// 276 DECLAREINFO *pdi; 277 pdi=(DECLAREINFO *)pInfo; 278 279 ret_type=pdi->ReturnType; 280 *plpRetIndex=pdi->u.ReturnIndex; 281 } 282 else if(idProc==PROC_BUILTIN){ 283 ///////////////////////// 284 // 組み込み関数 285 ///////////////////////// 286 int FuncId; 287 FuncId=(int)(_int64)pInfo; 288 289 ret_type=GetFunctionType(FuncId); 290 *plpRetIndex=-1; 291 } 292 else if(idProc==PROC_PTR){ 293 ///////////////// 294 // 関数ポインタ 295 ///////////////// 296 297 LONG_PTR lpIndex; 298 GetVarType(name,&lpIndex,0); 299 300 extern PROCPTRINFO *pProcPtrInfo; 301 ret_type=pProcPtrInfo[lpIndex].ReturnType; 302 *plpRetIndex=pProcPtrInfo[lpIndex].u.ReturnIndex; 303 } 304 305 return ret_type; 306 } 307 BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){ 239 return true; 240 } 241 242 bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ){ 308 243 //プロパティ用のメソッドを呼び出す 309 244 … … 318 253 319 254 //オーバーロード用の関数リストを作成 320 std::vector< SubInfo*> subs;255 std::vector<UserProc *> subs; 321 256 GetOverloadSubHash(VarName,subs); 322 257 if(subs.size()==0){ … … 326 261 //パラメータを整備 327 262 char *Parameter; 328 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen( RightSide)+32);263 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32); 329 264 lstrcpy(Parameter,ArrayElements); 330 if( RightSide){331 if(Parameter[0]&& RightSide[0]) lstrcat(Parameter,",");332 lstrcat(Parameter, RightSide);265 if(rightSide){ 266 if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,","); 267 lstrcat(Parameter,rightSide); 333 268 } 334 269 335 270 //オーバーロードを解決 336 SubInfo *pSub; 337 pSub=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL); 338 339 if(pSub){ 340 if(pRetTypeInfo){ 341 pRetTypeInfo->type=pSub->ReturnType; 342 pRetTypeInfo->u.lpIndex=pSub->u.ReturnIndex; 343 } 271 UserProc *pUserProc; 272 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 273 274 if(pUserProc){ 275 resultType = pUserProc->ReturnType(); 344 276 } 345 277 … … 348 280 349 281 //インデクサ(getter)の戻り値を取得 350 bool GetReturnTypeOfIndexerGetterProc( CClass *pobj_Class,TYPEINFO &RetTypeInfo){351 std::vector< SubInfo*> subs;352 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs );282 bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ){ 283 std::vector<UserProc *> subs; 284 objClass.EnumMethod( CALC_ARRAY_GET, subs ); 353 285 if( subs.size() == 0 ){ 354 286 return false; 355 287 } 356 288 357 RetTypeInfo.type = subs[0]->ReturnType; 358 RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex; 289 resultType = subs[0]->ReturnType(); 359 290 360 291 return true; … … 362 293 363 294 364 void AddDeclareData(char *buffer,int NowLine){295 void AddDeclareData(char *buffer,int nowLine){ 365 296 extern HANDLE hHeap; 366 int i,i2,i3,i4,sw,IsFunction; 367 char temporary[VN_SIZE]; 368 369 i=0; 370 371 DWORD dwType; 372 BOOL bCdecl=0; 373 374 //Static/Dynamic 375 if(buffer[i]==ESC_STATIC){ 376 dwType=DECLARE_STATIC; 377 i++; 378 } 379 else dwType=DECLARE_DYNAMIC; 297 int i2; 298 299 int i=0; 380 300 381 301 //Sub/Function 382 if(buffer[i]==ESC_SUB) IsFunction=0; 383 else if(buffer[i]==ESC_FUNCTION) IsFunction=1; 302 Procedure::Kind kind = Procedure::Sub; 303 if(buffer[i]==ESC_SUB){ 304 } 305 else if(buffer[i]==ESC_FUNCTION){ 306 kind = Procedure::Function; 307 } 384 308 else{ 385 SetError(1,NULL, NowLine);309 SetError(1,NULL,nowLine); 386 310 return; 387 311 } … … 389 313 390 314 //プロシージャ名 315 char procName[VN_SIZE]; 316 bool isCdecl = false; 391 317 for(i2=0;;i++,i2++){ 392 318 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL){ 393 bCdecl=1;319 isCdecl = true; 394 320 395 321 i+=2; 396 temporary[i2]=0;322 procName[i2]=0; 397 323 break; 398 324 } 399 325 if(buffer[i]==','){ 400 temporary[i2]=0;326 procName[i2]=0; 401 327 break; 402 328 } 403 329 if(buffer[i]=='\0'){ 404 SetError(1,NULL, NowLine);330 SetError(1,NULL,nowLine); 405 331 return; 406 332 } 407 temporary[i2]=buffer[i]; 408 } 333 procName[i2]=buffer[i]; 334 } 335 i++; 409 336 410 337 //ユーザー定義関数との重複チェック 411 if(GetSubHash( temporary)){412 SetError(15, temporary,NowLine);338 if(GetSubHash(procName)){ 339 SetError(15,procName,nowLine); 413 340 return; 414 341 } 415 342 416 343 344 //ライブラリ 345 char dllFileName[MAX_PATH]; 346 i = GetOneParameter( buffer, i, dllFileName ); 347 Type resultType; 348 _int64 i64data; 349 if( !StaticCalculation( true, dllFileName, 0, &i64data, resultType ) ){ 350 return; 351 } 352 if( resultType.GetBasicType() != typeOfPtrChar ){ 353 SetError(1,NULL,nowLine); 354 return; 355 } 356 lstrcpy( dllFileName, (char *)i64data ); 357 CharUpper(dllFileName); 358 if(!strstr(dllFileName,".")){ 359 lstrcat(dllFileName,".DLL"); 360 if(lstrlen(dllFileName)>=16){ 361 SetError(7,NULL,nowLine); 362 return; 363 } 364 } 365 366 //エイリアス 367 char alias[VN_SIZE]; 368 i = GetOneParameter( buffer, i, alias ); 369 if( alias[0] ){ 370 if( !StaticCalculation( true, alias, 0, &i64data, resultType ) ){ 371 return; 372 } 373 if( resultType.GetBasicType() != typeOfPtrChar ){ 374 SetError(1,NULL,nowLine); 375 return; 376 } 377 lstrcpy( alias, (char *)i64data ); 378 } 379 else{ 380 //省略されたときは関数名 381 lstrcpy( alias, procName ); 382 } 383 384 385 // オブジェクトを生成 386 DllProc *pDllProc = new DllProc( procName, kind, isCdecl, dllFileName, alias ); 387 388 // パラメータを解析 389 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 390 pDllProc->SetParamsAndReturnType( buffer + i, nowLine ); 391 392 // パラメータのエラーチェック 393 foreach( const Parameter *pParam, pDllProc->Params() ){ 394 if( pParam->IsObject() ){ 395 SetError(25,pParam->GetVarName(),nowLine); 396 } 397 if( !pParam->IsRef() ){ 398 if( pParam->IsStruct() ){ 399 SetError(28,pParam->GetVarName(),nowLine); 400 } 401 } 402 } 403 404 //戻り値のエラーチェック 405 if( pDllProc->IsFunction() ){ 406 // Function定義 407 408 if( pDllProc->ReturnType().IsObject() ){ 409 // DLL関数ではオブジェクトを戻り値にできない 410 SetError(40,pDllProc->GetName(),nowLine); 411 } 412 } 413 414 417 415 ///////////////////////////////// 418 // 格納位置を計算してp ciにセット416 // 格納位置を計算してppDeclareHashにセット 419 417 ///////////////////////////////// 420 418 421 419 //ハッシュ値を取得 422 420 int key; 423 key=hash_default(temporary); 424 425 extern DECLAREINFO **ppDeclareHash; 426 DECLAREINFO *pdi; 421 key=hash_default(procName); 422 423 extern DllProc **ppDeclareHash; 427 424 if(ppDeclareHash[key]){ 428 pdi=ppDeclareHash[key]; 425 DllProc *pTempProc; 426 pTempProc=ppDeclareHash[key]; 429 427 while(1){ 430 if( lstrcmpi(pdi->name,temporary)==0){428 if( pDllProc->GetName() == pTempProc->GetName() ){ 431 429 //重複エラー 432 SetError(15, temporary,NowLine);430 SetError(15,procName,nowLine); 433 431 return; 434 432 } 435 433 436 if(p di->pNextData==0){437 p di->pNextData=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO));434 if(pTempProc->pNextData==0){ 435 pTempProc->pNextData=pDllProc; 438 436 break; 439 437 } 440 p di=pdi->pNextData;441 } 442 p di=pdi->pNextData;438 pTempProc=pTempProc->pNextData; 439 } 440 pTempProc=pTempProc->pNextData; 443 441 } 444 442 else{ 445 ppDeclareHash[key]=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO)); 446 pdi=ppDeclareHash[key]; 447 } 448 449 pdi->dwType=dwType; 450 pdi->bCdecl=bCdecl; 451 452 pdi->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 453 lstrcpy(pdi->name,temporary); 443 ppDeclareHash[key]=pDllProc; 444 } 445 } 446 447 UserProc *AddSubData(char *buffer,int nowLine,BOOL bVirtual,CClass *pobj_c, bool isStatic){ 448 int i2,i3; 449 char temporary[8192]; 450 451 int i=1; 452 453 UserProc::Kind kind = Procedure::Sub; 454 bool isMacro = false; 455 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function; 456 if(buffer[i]==ESC_MACRO){ 457 isMacro = true; 458 } 459 454 460 i++; 455 461 456 //ライブラリ 457 i = GetOneParameter( buffer, i, temporary ); 458 int type; 459 LONG_PTR lpIndex; 460 _int64 i64data; 461 type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex ); 462 if( type != typeOfPtrChar ){ 463 SetError(1,NULL,NowLine); 464 return; 465 } 466 lstrcpy( temporary, (char *)i64data ); 467 CharUpper(temporary); 468 if(!strstr(temporary,".")){ 469 if(pdi->dwType==DECLARE_STATIC) lstrcat(temporary,".LIB"); 470 else{ 471 lstrcat(temporary,".DLL"); 472 if(lstrlen(temporary)>=16){ 473 SetError(7,NULL,NowLine); 474 return; 475 } 476 } 477 } 478 pdi->file=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 479 lstrcpy(pdi->file,temporary); 480 481 //エイリアス 482 i = GetOneParameter( buffer, i, temporary ); 483 if( temporary[0] ){ 484 type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex ); 485 if( type != typeOfPtrChar ){ 486 SetError(1,NULL,NowLine); 487 return; 488 } 489 lstrcpy( temporary, (char *)i64data ); 490 491 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 492 lstrcpy(pdi->alias,temporary); 493 } 494 else{ 495 //省略されたときは関数名 496 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(pdi->name)+1); 497 lstrcpy(pdi->alias,pdi->name); 498 } 499 500 //パラメータの始めのカッコ 501 if(buffer[i]!='('){ 502 SetError(1,NULL,NowLine); 503 return; 504 } 505 i++; 506 507 pdi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1); 508 509 //各パラメータ 510 for(i3=0;;i3++){ 511 if(buffer[i]==')') break; 512 513 pdi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pdi->pParmInfo,(i3+1)*sizeof(PARAMETER_INFO)); 514 515 //ByVal 516 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){ 517 pdi->pParmInfo[i3].bByVal=1; 462 bool isCdecl = false; 463 bool isExport = false; 464 while(1){ 465 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){ 466 isCdecl = true; 467 518 468 i+=2; 519 469 } 520 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){ 521 pdi->pParmInfo[i3].bByVal=0; 522 i+=2; 523 } 524 else pdi->pParmInfo[i3].bByVal=1; 525 526 //変数名は無視(temporaryの変数名は型宣言文字判断のため) 527 sw=0; 528 for(i2=0;;i++,i2++){ 529 if(buffer[i]=='('){ 530 if(!sw) sw=1; 531 532 i4=GetStringInPare(temporary+i2,buffer+i); 533 i2+=i4-1; 534 i+=i4-1; 535 continue; 536 } 537 if(buffer[i]=='['){ 538 if(!sw) sw=1; 539 540 i4=GetStringInBracket(temporary+i2,buffer+i); 541 i2+=i4-1; 542 i+=i4-1; 543 continue; 544 } 545 if(!IsVariableChar(buffer[i])){ 546 temporary[i2]=0; 547 break; 548 } 549 temporary[i2]=buffer[i]; 550 } 551 if(lstrcmp(temporary,"...")==0) pdi->pParmInfo[i3].type=DEF_ELLIPSE; 552 else{ 553 //型 554 if(buffer[i]==1&&buffer[i+1]==ESC_AS){ 555 i+=2; 556 for(i2=0;;i++,i2++){ 557 if(!(IsVariableChar(buffer[i])||buffer[i]=='*')){ 558 temporary[i2]=0; 559 break; 560 } 561 temporary[i2]=buffer[i]; 562 } 563 pdi->pParmInfo[i3].type=GetTypeFixed(temporary,&pdi->pParmInfo[i3].u.index); 564 } 565 else{ 566 pdi->pParmInfo[i3].type=GetTypeFromSimpleName(temporary); 567 SetError(-103,temporary,NowLine); 568 } 569 570 if(sw){ 571 //配列ポインタを引き渡すとき 572 pdi->pParmInfo[i3].type=GetPtrType(pdi->pParmInfo[i3].type,pdi->pParmInfo[i3].u.index); 573 } 574 } 575 576 //名前はダミー(使用しないため) 577 pdi->pParmInfo[i3].name=""; 578 579 //構造体の場合はエラーチェック 580 if(pdi->pParmInfo[i3].type==-1) SetError(3,temporary,NowLine); 581 if(pdi->pParmInfo[i3].type==DEF_OBJECT){ 582 if(pdi->pParmInfo[i3].bByVal) pdi->pParmInfo[i3].type=DEF_LONG;//SetError(28,temporary,NowLine); 583 } 584 585 //構造体アドレスの空白部 586 while(buffer[i]==' ') i++; 587 588 if(buffer[i]==','){ 589 i++; 590 continue; 591 } 592 else if(buffer[i]==')') continue; 593 else{ 594 SetError(1,NULL,NowLine); 595 break; 596 } 597 } 598 pdi->ParmNum=i3; 599 600 //戻り値 601 i++; 602 if(buffer[i]==1&&buffer[i+1]==ESC_AS){ 603 if(IsFunction==0) SetError(1,NULL,NowLine); 604 i+=2; 605 pdi->ReturnType=GetTypeFixed(buffer+i,&pdi->u.ReturnIndex); 606 if(pdi->ReturnType==DEF_NON) SetError(3,buffer+i,NowLine); 607 if(pdi->ReturnType==DEF_OBJECT) SetError(40,NULL,NowLine); 608 } 609 else if(buffer[i]) SetError(1,NULL,NowLine); 610 else pdi->ReturnType=DEF_NON; 611 612 pdi->pos=NowLine; 613 } 614 615 BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2){ 616 if(pi_num1!=pi_num2) return 1; 617 618 int i; 619 for(i=0;i<pi_num1;i++){ 620 if(ppi1[i].type!=ppi2[i].type){ 621 622 if(ppi1[i].bByVal==0&&ppi1[i].type==DEF_ANY&& 623 ppi2[i].bByVal==1&&IsPtrType(ppi2[i].type)|| 624 ppi1[i].bByVal==1&&IsPtrType(ppi1[i].type)&& 625 ppi2[i].bByVal==0&&ppi2[i].type==DEF_ANY){ 626 /* ByRef var As Any 627 と 628 var As VoidPtr 629 は同等 630 */ 631 continue; 632 } 633 634 return 1; 635 } 636 else{ 637 if(NATURAL_TYPE(ppi1[i].type)==DEF_OBJECT 638 || NATURAL_TYPE(ppi1[i].type)==DEF_STRUCT ){ 639 if(ppi1[i].u.index!=ppi2[i].u.index) return 1; 640 } 641 } 642 } 643 644 return 0; 645 } 646 SubInfo *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic){ 647 int i,i2,i3,sw; 648 DWORD dwType; 649 char temporary[8192],temp2[VN_SIZE]; 650 651 i=1; 652 if(buffer[i]==ESC_SUB) dwType=SUBTYPE_SUB; 653 else if(buffer[i]==ESC_FUNCTION) dwType=SUBTYPE_FUNCTION; 654 else if(buffer[i]==ESC_MACRO) dwType=SUBTYPE_MACRO; 655 656 i++; 657 658 BOOL bExport=0,bCdecl=0; 659 while(1){ 660 if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&&bExport==0){ 661 bExport=1; 662 663 i+=2; 664 } 665 else if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&&bCdecl==0){ 666 bCdecl=1; 470 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){ 471 isExport = true; 667 472 668 473 i+=2; … … 674 479 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){ 675 480 if(!pobj_c){ 676 SetError(126,NULL, NowLine);481 SetError(126,NULL,nowLine); 677 482 return 0; 678 483 } … … 708 513 } 709 514 if(!iCalcId){ 710 SetError(1,NULL, NowLine);515 SetError(1,NULL,nowLine); 711 516 return 0; 712 517 } … … 735 540 } 736 541 737 if( dwType==SUBTYPE_MACRO){542 if( isMacro ){ 738 543 //大文字に変換 739 544 CharUpper(temporary); … … 753 558 754 559 if(GetDeclareHash(temporary)){ 755 SetError(15,temporary, NowLine);560 SetError(15,temporary,nowLine); 756 561 return 0; 757 562 } … … 761 566 SubNum++; 762 567 763 SubInfo *pSub = new SubInfo(); 764 765 //クラス名 766 pSub->pobj_ParentClass=pobj_c; 568 569 UserProc *pUserProc = new UserProc( temporary, kind, isMacro, isCdecl, isExport ); 570 pUserProc->SetParentClass( pobj_c ); 767 571 768 572 //ID 769 573 static int id_base=0; 770 pSub->id=(id_base++); 771 772 //関数名 773 pSub->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 774 lstrcpy(pSub->name,temporary); 775 776 //ソースコードの位置 777 pSub->address=NowLine; 778 779 pSub->bExport=bExport; 780 pSub->bCdecl=bCdecl; 781 pSub->bVirtual=bVirtual; 782 if(bExport) pSub->bUse=1; 783 else pSub->bUse=0; 784 pSub->bCompile=0; 785 pSub->bSystem=0; 786 787 pSub->dwType=dwType; 788 789 790 if(pSub->dwType==SUBTYPE_FUNCTION){ 791 /////////////////// 792 // 戻り値を取得 793 /////////////////// 794 795 pSub->isReturnRef = false; 796 797 if(pobj_c){ 798 if(lstrcmp(pSub->name,pobj_c->name)==0|| 799 pSub->name[0]=='~'){ 800 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす 801 SetError(115,NULL,NowLine); 802 } 803 } 804 805 806 i2=lstrlen(buffer)-2; 807 808 int sw_as=0; 809 for(;i2>0;i2--){ 810 if(buffer[i2]==')') break; 811 812 if(buffer[i2]==1&&buffer[i2+1]==ESC_AS){ 813 if( buffer[i2-2] == 1 && buffer[i2-1] == ESC_BYREF ){ 814 //参照型 815 pSub->isReturnRef = true; 816 } 817 818 i2+=2; 819 i3=0; 820 while(buffer[i2]=='*') temporary[i3++]=buffer[i2++]; 821 for(;;i2++,i3++){ 822 if(!IsVariableChar(buffer[i2])){ 823 temporary[i3]=0; 824 break; 825 } 826 temporary[i3]=buffer[i2]; 827 } 828 pSub->ReturnType=GetTypeFixed(temporary,&pSub->u.ReturnIndex); 829 if(pSub->ReturnType==DEF_NON) SetError(3,temporary,NowLine); 830 831 sw_as=1; 832 break; 833 } 834 } 835 836 if(!sw_as){ 837 SetError(-104,pSub->name,NowLine); 838 839 pSub->ReturnType=DEF_DOUBLE; 840 } 841 } 842 else{ 843 //戻り値なしのSub定義 844 pSub->ReturnType=DEF_NON; 845 pSub->u.ReturnIndex=-1; 846 } 847 848 //パラメータ 849 if(buffer[i]!='('){ 850 SetError(1,NULL,NowLine); 851 return 0; 852 } 853 i++; 854 if(buffer[i]!=')'&&pobj_c){ 855 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす 856 if(pSub->name[0]=='~'){ 857 SetError(114,NULL,NowLine); 858 i=JumpStringInPare(buffer,i); 859 } 860 } 861 while(1){ 862 if(buffer[i]==')') break; 863 864 //ByRef 865 bool isRef; 866 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){ 867 isRef = false; 868 i+=2; 869 } 870 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){ 871 isRef = true; 872 i+=2; 873 } 874 else isRef = false; 875 876 //パラメータ名 877 bool isArray = false; 878 int subScripts[MAX_ARRAYDIM]; 879 char name[VN_SIZE]; 880 sw=0; 881 for(i2=0;;i++,i2++){ 882 if(buffer[i]=='('){ 883 if(!sw) sw=1; 884 885 i3=GetStringInPare(name+i2,buffer+i); 886 i2+=i3-1; 887 i+=i3-1; 888 continue; 889 } 890 if(buffer[i]=='['){ 891 if(!sw) sw=1; 892 893 i3=GetStringInBracket(name+i2,buffer+i); 894 i2+=i3-1; 895 i+=i3-1; 896 continue; 897 } 898 if(!IsVariableChar(buffer[i])){ 899 name[i2]=0; 900 break; 901 } 902 name[i2]=buffer[i]; 903 } 904 if(sw){ 905 //配列パラメータ 906 if( isRef == false ) SetError(29,NULL,NowLine); 907 isArray = true; 908 909 if((name[i2-2]=='('&&name[i2-1]==')')|| 910 (name[i2-2]=='['&&name[i2-1]==']')){ 911 subScripts[0]=LONG_MAX; 912 subScripts[1]=-1; 913 914 name[i2-2]=0; 915 } 916 else{ 917 GetArrange(name,temp2,subScripts); 918 lstrcpy(name,temp2); 919 } 920 921 i2=lstrlen(name); 922 } 923 924 //型 925 Type type( DEF_NON ); 926 if(buffer[i]==1&&buffer[i+1]==ESC_AS){ 927 i+=2; 928 929 i2=0; 930 while(buffer[i]=='*'){ 931 temporary[i2]=buffer[i]; 932 i++; 933 i2++; 934 } 935 for(;;i++,i2++){ 936 if(!IsVariableChar(buffer[i])){ 937 if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){ 938 temporary[i2++]=buffer[i++]; 939 temporary[i2]=buffer[i]; 940 continue; 941 } 942 temporary[i2]=0; 943 break; 944 } 945 temporary[i2]=buffer[i]; 946 } 947 948 Type::StringToType( temporary, type ); 949 950 if(temporary[0]=='*'&& 951 temporary[1]==1&& 952 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 953 if(buffer[i]!='('){ 954 SetError(10,temporary,NowLine); 955 break; 956 } 957 i3=GetStringInPare(temporary+i2,buffer+i); 958 i+=i3; 959 i2+=i3; 960 961 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){ 962 temporary[i2++]=buffer[i++]; 963 temporary[i2++]=buffer[i++]; 964 for(;;i++,i2++){ 965 if(!IsVariableChar(buffer[i])){ 966 temporary[i2]=0; 967 break; 968 } 969 temporary[i2]=buffer[i]; 970 } 971 } 972 } 973 else{ 974 //TypeDefをする前のベース型を取得 975 GetOriginalTypeName(temporary); 976 } 977 978 if( type.IsNull() ){ 979 SetError(3,temporary,NowLine); 980 type.SetBasicType( DEF_PTR_VOID ); 981 } 982 } 983 else{ 984 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 985 SetError(-103,temporary,NowLine); 986 } 987 988 if( type.IsProcPtr() ){ 989 //関数ポインタの場合 990 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2]) ); 991 } 992 993 Parameter *pParam = new Parameter( name, type, isRef ); 994 if( isArray ){ 995 pParam->SetArray( subScripts ); 996 } 997 998 //パラメータを追加 999 pSub->params.push_back( pParam ); 1000 1001 if(buffer[i]==','){ 1002 i++; 1003 continue; 1004 } 1005 else if(buffer[i]==')') continue; 1006 else{ 1007 SetError(1,NULL,NowLine); 1008 break; 1009 } 1010 } 1011 pSub->SecondParmNum = (int)pSub->params.size(); 1012 i++; 1013 if(buffer[i]=='('){ 1014 i++; 1015 while(1){ 1016 if(buffer[i]==')') break; 1017 1018 //ByRef 1019 bool isRef; 1020 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){ 1021 isRef = false; 1022 i+=2; 1023 } 1024 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){ 1025 isRef = true; 1026 i+=2; 1027 } 1028 else isRef = false; 1029 1030 //パラメータ名 1031 bool isArray = false; 1032 int subScripts[MAX_ARRAYDIM]; 1033 char name[VN_SIZE]; 1034 sw=0; 1035 for(i2=0;;i++,i2++){ 1036 if(buffer[i]=='('){ 1037 if(!sw) sw=1; 1038 1039 i3=GetStringInPare(name+i2,buffer+i); 1040 i2+=i3-1; 1041 i+=i3-1; 1042 continue; 1043 } 1044 if(buffer[i]=='['){ 1045 if(!sw) sw=1; 1046 1047 i3=GetStringInBracket(name+i2,buffer+i); 1048 i2+=i3-1; 1049 i+=i3-1; 1050 continue; 1051 } 1052 if(!IsVariableChar(buffer[i])){ 1053 name[i2]=0; 1054 break; 1055 } 1056 name[i2]=buffer[i]; 1057 } 1058 if(sw){ 1059 //配列パラメータ 1060 if( isRef == false ) SetError(29,NULL,NowLine); 1061 isArray = true; 1062 1063 if((name[i2-2]=='('&&name[i2-1]==')')|| 1064 (name[i2-2]=='['&&name[i2-1]==']')){ 1065 subScripts[0]=LONG_MAX; 1066 subScripts[1]=-1; 1067 1068 name[i2-2]=0; 1069 } 1070 else{ 1071 GetArrange(name,temp2,subScripts); 1072 lstrcpy(name,temp2); 1073 } 1074 1075 i2=lstrlen(name); 1076 } 1077 1078 //型 1079 Type type( DEF_NON ); 1080 if(buffer[i]==1&&buffer[i+1]==ESC_AS){ 1081 i+=2; 1082 1083 i2=0; 1084 while(buffer[i]=='*'){ 1085 temporary[i2]=buffer[i]; 1086 i++; 1087 i2++; 1088 } 1089 for(;;i++,i2++){ 1090 if(!IsVariableChar(buffer[i])){ 1091 if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){ 1092 temporary[i2++]=buffer[i++]; 1093 temporary[i2]=buffer[i]; 1094 continue; 1095 } 1096 temporary[i2]=0; 1097 break; 1098 } 1099 temporary[i2]=buffer[i]; 1100 } 1101 1102 Type::StringToType( temporary, type ); 1103 1104 if(temporary[0]=='*'&& 1105 temporary[1]==1&& 1106 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){ 1107 if(buffer[i]!='('){ 1108 SetError(10,temporary,NowLine); 1109 break; 1110 } 1111 i3=GetStringInPare(temporary+i2,buffer+i); 1112 i+=i3; 1113 i2+=i3; 1114 1115 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){ 1116 temporary[i2++]=buffer[i++]; 1117 temporary[i2++]=buffer[i++]; 1118 for(;;i++,i2++){ 1119 if(!IsVariableChar(buffer[i])){ 1120 temporary[i2]=0; 1121 break; 1122 } 1123 temporary[i2]=buffer[i]; 1124 } 1125 } 1126 } 1127 else{ 1128 //TypeDefをする前のベース型を取得 1129 GetOriginalTypeName(temporary); 1130 } 1131 1132 if( type.IsNull() ){ 1133 SetError(3,temporary,NowLine); 1134 type.SetBasicType( DEF_PTR_VOID ); 1135 } 1136 } 1137 else{ 1138 type.SetBasicType( GetTypeFromSimpleName(temporary) ); 1139 SetError(-103,temporary,NowLine); 1140 } 1141 1142 if( type.IsProcPtr() ){ 1143 //関数ポインタの場合 1144 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2]) ); 1145 } 1146 1147 Parameter *pParam = new Parameter( name, type, isRef ); 1148 if( isArray ){ 1149 pParam->SetArray( subScripts ); 1150 } 1151 1152 //パラメータを追加 1153 pSub->params.push_back( pParam ); 1154 1155 if(buffer[i]==','){ 1156 i++; 1157 continue; 1158 } 1159 else if(buffer[i]==')') continue; 1160 else{ 1161 SetError(1,NULL,NowLine); 1162 break; 1163 } 1164 } 1165 i++; 1166 } 1167 1168 //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する場合がある) 1169 1170 if(pobj_c&&bStatic==0){ 1171 //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用 1172 string name = "_System_LocalThis"; 1173 Type type( DEF_PTR_VOID ); 1174 pSub->realParams.push_back( new Parameter( name, type ) ); 1175 } 1176 1177 if(pSub->ReturnType==DEF_STRUCT){ 1178 //構造体を戻り値として持つ場合 1179 //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする 1180 1181 string name = pSub->name; 1182 if(pSub->name[0]==1&&pSub->name[1]==ESC_OPERATOR){ 1183 name="_System_ReturnValue"; 1184 } 1185 Type type( DEF_STRUCT, pSub->u.ReturnIndex ); 1186 pSub->realParams.push_back( new Parameter( name, type, true ) ); 1187 } 1188 1189 //パラメータをコピー 1190 foreach( Parameter *pParam, pSub->params ){ 1191 pSub->realParams.push_back( new Parameter( *pParam ) ); 1192 } 574 pUserProc->id = (id_base++); 575 576 if(isExport){ 577 pUserProc->Using(); 578 } 579 580 // パラメータを解析 581 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 582 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic ); 1193 583 1194 584 … … 1198 588 1199 589 int key; 1200 key=hash_default(p Sub->name);1201 1202 extern SubInfo**ppSubHash;590 key=hash_default(pUserProc->GetName().c_str()); 591 592 extern UserProc **ppSubHash; 1203 593 if(ppSubHash[key]){ 1204 SubInfo*psi2;594 UserProc *psi2; 1205 595 psi2=ppSubHash[key]; 1206 596 while(1){ 1207 if(pobj_c==psi2-> pobj_ParentClass){597 if(pobj_c==psi2->GetParentClassPtr()){ 1208 598 //重複エラーチェックを行う 1209 if( lstrcmp(psi2->name,pSub->name)==0){1210 if( Parameter::Equals( psi2-> params, pSub->params) ){1211 SetError(15,p Sub->name,NowLine);599 if( pUserProc->GetName() == psi2->GetName() ){ 600 if( Parameter::Equals( psi2->Params(), pUserProc->Params() ) ){ 601 SetError(15,pUserProc->GetName().c_str(),nowLine); 1212 602 return 0; 1213 603 } … … 1218 608 psi2=psi2->pNextData; 1219 609 } 1220 psi2->pNextData=p Sub;610 psi2->pNextData=pUserProc; 1221 611 } 1222 612 else{ 1223 ppSubHash[key]=p Sub;1224 } 1225 1226 return p Sub;613 ppSubHash[key]=pUserProc; 614 } 615 616 return pUserProc; 1227 617 } 1228 618 … … 1234 624 1235 625 //Declare(DLL関数)情報を初期化 1236 extern D ECLAREINFO**ppDeclareHash;1237 ppDeclareHash=(D ECLAREINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DECLAREINFO*));626 extern DllProc **ppDeclareHash; 627 ppDeclareHash=(DllProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DllProc *)); 1238 628 1239 629 //サブルーチン(ユーザー定義)情報を初期化 1240 extern SubInfo**ppSubHash;630 extern UserProc **ppSubHash; 1241 631 extern int SubNum; 1242 ppSubHash=( SubInfo **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SubInfo*));632 ppSubHash=(UserProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(UserProc *)); 1243 633 SubNum=0; 1244 634 … … 1334 724 AddSubData(temporary,0,0,0); 1335 725 } 1336 void Delete_si(SubInfo *pSub){ 1337 foreach( Parameter *pParam, pSub->params ){ 1338 delete pParam; 1339 } 1340 1341 foreach( Parameter *pParam, pSub->realParams ){ 1342 delete pParam; 1343 } 1344 1345 if(pSub->pNextData) Delete_si(pSub->pNextData); 1346 1347 HeapDefaultFree(pSub->name); 1348 delete pSub; 1349 } 1350 void DeleteSubInfo(SubInfo **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放 726 void Delete_si(UserProc *pUserProc){ 727 if(pUserProc->pNextData) Delete_si(pUserProc->pNextData); 728 delete pUserProc; 729 } 730 void DeleteSubInfo(UserProc **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放 1351 731 int i; 1352 732 for(i=0;i<MAX_HASH;i++){ … … 1365 745 } 1366 746 } 1367 void Delete_di(DECLAREINFO *pdi){ 1368 if(pdi->pParmInfo) HeapDefaultFree(pdi->pParmInfo); 1369 1370 HeapDefaultFree(pdi->name); 1371 if(pdi->file) HeapDefaultFree(pdi->file); 1372 if(pdi->alias) HeapDefaultFree(pdi->alias); 1373 1374 if(pdi->pNextData) Delete_di(pdi->pNextData); 1375 1376 HeapDefaultFree(pdi); 747 void Delete_di(DllProc *pDllProc){ 748 if(pDllProc->pNextData) Delete_di(pDllProc->pNextData); 749 750 delete pDllProc; 1377 751 } 1378 752 void DeleteDeclareInfo(void){ 1379 753 //DLL情報を解放 1380 extern D ECLAREINFO**ppDeclareHash;754 extern DllProc **ppDeclareHash; 1381 755 int i; 1382 756 for(i=0;i<MAX_HASH;i++){ … … 1394 768 /////////////////////// 1395 769 1396 int AddProcPtrInfo(char *buffer,DWORD dwProcType){ 1397 extern HANDLE hHeap; 1398 extern int cp; 1399 extern PROCPTRINFO *pProcPtrInfo; 770 int AddProcPtrInfo( char *buffer, DWORD dwProcType, int nowLine ){ 771 772 Procedure::Kind kind = Procedure::Sub; 773 if( dwProcType == ESC_FUNCTION ){ 774 kind = Procedure::Function; 775 } 776 777 ProcPointer *pProcPointer = new ProcPointer( kind ); 778 779 //buffer[0]は'('となっている 780 pProcPointer->SetParamsAndReturnType( buffer, nowLine ); 781 782 extern ProcPointer **ppProcPointer; 1400 783 extern int ProcPtrInfoNum; 1401 int i,i2,i3,sw; 1402 PROCPTRINFO *pi; 1403 char temporary[VN_SIZE],temp2[VN_SIZE]; 1404 1405 pProcPtrInfo=(PROCPTRINFO *)HeapReAlloc(hHeap,0,pProcPtrInfo,(ProcPtrInfoNum+1)*sizeof(PROCPTRINFO)); 1406 pi=&pProcPtrInfo[ProcPtrInfoNum]; 784 ppProcPointer=(ProcPointer **)HeapReAlloc(hHeap,0,ppProcPointer,(ProcPtrInfoNum+1)*sizeof(ProcPointer *)); 785 ppProcPointer[ProcPtrInfoNum] = pProcPointer; 1407 786 ProcPtrInfoNum++; 1408 787 1409 pi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);1410 pi->ParmNum=0;1411 1412 //buffer[0]は'('となっている1413 i=1;1414 1415 while(1){1416 if(buffer[i]==')') break;1417 1418 pi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pi->pParmInfo,(pi->ParmNum+1)*sizeof(PARAMETER_INFO));1419 1420 //ByVal1421 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){1422 pi->pParmInfo[pi->ParmNum].bByVal=1;1423 i+=2;1424 }1425 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){1426 pi->pParmInfo[pi->ParmNum].bByVal=0;1427 i+=2;1428 }1429 else pi->pParmInfo[pi->ParmNum].bByVal=1;1430 1431 //パラメータ名1432 sw=0;1433 for(i2=0;;i++,i2++){1434 if(buffer[i]=='('){1435 if(!sw) sw=1;1436 1437 i3=GetStringInPare(temporary+i2,buffer+i);1438 i2+=i3-1;1439 i+=i3-1;1440 continue;1441 }1442 if(buffer[i]=='['){1443 if(!sw) sw=1;1444 1445 i3=GetStringInBracket(temporary+i2,buffer+i);1446 i2+=i3-1;1447 i+=i3-1;1448 continue;1449 }1450 if(!IsVariableChar(buffer[i])){1451 temporary[i2]=0;1452 break;1453 }1454 temporary[i2]=buffer[i];1455 }1456 pi->pParmInfo[pi->ParmNum].name=0;1457 1458 if(sw){1459 //配列パラメータ1460 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(29,NULL,cp);1461 pi->pParmInfo[pi->ParmNum].bArray=1;1462 1463 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||1464 (temporary[i2-2]=='['&&temporary[i2-1]==']')){1465 pi->pParmInfo[pi->ParmNum].SubScripts[0]=LONG_MAX;1466 pi->pParmInfo[pi->ParmNum].SubScripts[1]=-1;1467 1468 temporary[i2-2]=0;1469 }1470 else{1471 GetArrange(temporary,temp2,pi->pParmInfo[pi->ParmNum].SubScripts);1472 lstrcpy(temporary,temp2);1473 }1474 1475 i2=lstrlen(temporary);1476 }1477 else{1478 pi->pParmInfo[pi->ParmNum].bArray=0;1479 pi->pParmInfo[pi->ParmNum].SubScripts[0]=-1;1480 }1481 1482 //型1483 if(buffer[i]==1&&buffer[i+1]==ESC_AS){1484 i+=2;1485 1486 i2=0;1487 while(buffer[i]=='*'){1488 temporary[i2]=buffer[i];1489 i++;1490 i2++;1491 }1492 for(;;i++,i2++){1493 if(!IsVariableChar(buffer[i])){1494 temporary[i2]=0;1495 break;1496 }1497 temporary[i2]=buffer[i];1498 }1499 1500 pi->pParmInfo[pi->ParmNum].type=1501 GetTypeFixed(temporary,&pi->pParmInfo[pi->ParmNum].u.index);1502 if(pi->pParmInfo[pi->ParmNum].type==-1){1503 SetError(3,temporary,cp);1504 pi->pParmInfo[pi->ParmNum].type=DEF_PTR_VOID;1505 }1506 if(pi->pParmInfo[pi->ParmNum].type==DEF_OBJECT){1507 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(28,temporary,cp);1508 }1509 }1510 else{1511 pi->pParmInfo[pi->ParmNum].type=GetTypeFromSimpleName(temporary);1512 SetError(-103,temporary,cp);1513 }1514 1515 pi->ParmNum++;1516 1517 if(buffer[i]==','){1518 i++;1519 continue;1520 }1521 else if(buffer[i]==')') continue;1522 else{1523 SetError(1,NULL,cp);1524 return 0;1525 }1526 }1527 i++;1528 1529 //戻り値1530 if(dwProcType==ESC_FUNCTION){1531 if(buffer[i]==1&&buffer[i+1]==ESC_AS){1532 i+=2;1533 i2=0;1534 if(buffer[i]=='*') temporary[i2++]=buffer[i++];1535 for(;;i++,i2++){1536 if(!IsVariableChar(buffer[i])){1537 temporary[i2]=0;1538 break;1539 }1540 temporary[i2]=buffer[i];1541 }1542 pi->ReturnType=GetTypeFixed(temporary,&pi->u.ReturnIndex);1543 if(pi->ReturnType==DEF_NON) SetError(3,temporary,cp);1544 }1545 else pi->ReturnType=DEF_DOUBLE;1546 }1547 else pi->ReturnType=DEF_NON;1548 1549 788 return ProcPtrInfoNum-1; 1550 789 } 1551 790 void DeleteProcPtrInfo(void){ 1552 extern P ROCPTRINFO *pProcPtrInfo;791 extern ProcPointer **ppProcPointer; 1553 792 extern int ProcPtrInfoNum; 1554 int i; 1555 1556 for(i=0;i<ProcPtrInfoNum;i++){ 1557 HeapDefaultFree(pProcPtrInfo[i].pParmInfo); 1558 } 1559 1560 HeapDefaultFree(pProcPtrInfo); 1561 } 793 794 for(int i=0;i<ProcPtrInfoNum;i++){ 795 delete ppProcPointer[i]; 796 } 797 798 HeapDefaultFree(ppProcPointer); 799 } -
BasicCompiler_Common/Type.cpp
r73 r75 65 65 //関数ポインタ(*Function) 66 66 type.basicType = DEF_PTR_PROC; 67 return true; 67 68 } 68 69 … … 109 110 } 110 111 112 int Type::GetBasicSize( int basicType ) 113 { 114 115 // 基本型 116 switch( basicType ){ 117 case DEF_SBYTE: 118 case DEF_BYTE: 119 case DEF_BOOLEAN: 120 return sizeof(BYTE); 121 122 case DEF_INTEGER: 123 case DEF_WORD: 124 return sizeof(WORD); 125 126 case DEF_LONG: 127 case DEF_DWORD: 128 return sizeof(DWORD); 129 130 case DEF_INT64: 131 case DEF_QWORD: 132 return sizeof(_int64); 133 134 case DEF_DOUBLE: 135 return sizeof(double); 136 case DEF_SINGLE: 137 return sizeof(float); 138 } 139 140 // ポインタ 141 if(IsPtrType(basicType)){ 142 return PTR_SIZE; 143 } 144 145 // オブジェクト 146 if(basicType==DEF_OBJECT){ 147 return PTR_SIZE; 148 } 149 150 SetError(); 151 return 0; 152 } 153 111 154 112 155 bool Type::Equals( const Type &type ) const … … 128 171 } 129 172 173 int Type::GetBasicSize() const 174 { 175 GetBasicSize( basicType ); 176 return 0; 177 } 178 int Type::GetSize() const 179 { 180 181 // 基本型 182 switch( basicType ){ 183 case DEF_LONG: 184 if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){ 185 return sizeof(BYTE); 186 } 187 else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){ 188 return sizeof(WORD); 189 } 190 return sizeof(DWORD); 191 192 case DEF_SBYTE: 193 case DEF_BYTE: 194 case DEF_BOOLEAN: 195 return sizeof(BYTE); 196 197 case DEF_INTEGER: 198 case DEF_WORD: 199 return sizeof(WORD); 200 201 case DEF_DWORD: 202 return sizeof(DWORD); 203 204 case DEF_INT64: 205 case DEF_QWORD: 206 return sizeof(_int64); 207 208 case DEF_DOUBLE: 209 return sizeof(double); 210 case DEF_SINGLE: 211 return sizeof(float); 212 } 213 214 // ポインタ 215 if(IsPtrType(basicType)){ 216 return PTR_SIZE; 217 } 218 219 // 構造体 220 if( basicType == DEF_STRUCT ){ 221 if( !pClass ){ 222 SetError(); 223 return 0; 224 } 225 226 return pClass->GetSize(); 227 } 228 229 // オブジェクト 230 if(basicType==DEF_OBJECT){ 231 return PTR_SIZE; 232 } 233 234 SetError(); 235 return 0; 236 } 237 130 238 bool Type::IsNull() const{ 131 239 if( basicType == DEF_NON ){ … … 134 242 return false; 135 243 } 244 245 bool Type::IsByte() const{ 246 if( basicType == DEF_BYTE ){ 247 return true; 248 } 249 return false; 250 } 251 bool Type::IsSByte() const{ 252 if( basicType == DEF_SBYTE ){ 253 return true; 254 } 255 return false; 256 } 257 bool Type::IsWord() const{ 258 if( basicType == DEF_WORD ){ 259 return true; 260 } 261 return false; 262 } 263 bool Type::IsInteger() const{ 264 if( basicType == DEF_INTEGER ){ 265 return true; 266 } 267 return false; 268 } 269 bool Type::IsDWord() const{ 270 if( basicType == DEF_DWORD ){ 271 return true; 272 } 273 return false; 274 } 275 bool Type::IsLong() const{ 276 if( basicType == DEF_LONG ){ 277 return true; 278 } 279 return false; 280 } 281 bool Type::IsQWord() const{ 282 if( basicType == DEF_QWORD ){ 283 return true; 284 } 285 return false; 286 } 287 bool Type::IsInt64() const{ 288 if( basicType == DEF_INT64 ){ 289 return true; 290 } 291 return false; 292 } 293 bool Type::IsSingle() const{ 294 if( basicType == DEF_SINGLE ){ 295 return true; 296 } 297 return false; 298 } 299 bool Type::IsDouble() const{ 300 if( basicType == DEF_DOUBLE ){ 301 return true; 302 } 303 return false; 304 } 305 bool Type::IsBoolean() const{ 306 if( basicType == DEF_BOOLEAN ){ 307 return true; 308 } 309 return false; 310 } 311 136 312 bool Type::IsPointer() const 137 313 { … … 219 395 return false; 220 396 } 397 bool Type::IsStructPtr() const 398 { 399 if( basicType == DEF_PTR_STRUCT ){ 400 return true; 401 } 402 return false; 403 } 404 bool Type::IsObject() const 405 { 406 if( basicType == DEF_OBJECT ){ 407 return true; 408 } 409 return false; 410 } 411 bool Type::IsObjectPtr() const 412 { 413 if( basicType == DEF_PTR_OBJECT ){ 414 return true; 415 } 416 return false; 417 } 418 bool Type::IsStringObject() const 419 { 420 if( basicType == DEF_OBJECT ){ 421 if( lstrcmp( pClass->name,"String")==0){ 422 return true; 423 } 424 } 425 return false; 426 } 427 bool Type::IsVoidPtr() const 428 { 429 if( basicType == DEF_PTR_VOID ){ 430 return true; 431 } 432 return false; 433 } 434 435 bool Type::IsAny() const 436 { 437 if( basicType == DEF_ANY ){ 438 return true; 439 } 440 return false; 441 } 442 443 const string Type::ToString() const 444 { 445 if( PTR_LEVEL( basicType ) ){ 446 //ポインタレベルが1以上の場合 447 Type type( *this ); 448 type.PtrLevelDown(); 449 450 return (string)"*" + type.ToString(); 451 } 452 else if( IsObject() || IsStruct() ){ 453 //オブジェクトまたは構造体 454 455 if( !( index == 0 || index == -1 ) ){ 456 return pClass->name; 457 } 458 } 459 else if( IsProcPtr() ){ 460 if( index == 0 || index == -1 ){ 461 return "VoidPtr"; 462 } 463 else{ 464 extern ProcPointer **ppProcPointer; 465 if( ppProcPointer[index]->ReturnType().IsNull() ){ 466 return "*Sub"; 467 } 468 return "*Function"; 469 } 470 } 471 else{ 472 // 基本型 473 474 for( int i=0; ; i++ ){ 475 if( basicTypeList[i] == DEF_NON ){ 476 break; 477 } 478 if( basicTypeList[i] == basicType ){ 479 return basicTypeNameList[i]; 480 } 481 } 482 } 483 484 extern int cp; 485 SetError(1,NULL,cp); 486 487 return (string)"(null)"; 488 } -
BasicCompiler_Common/Type.h
r73 r75 1 #pragma once 1 2 2 #ifndef _ACTIVEBASIC_COMPILER_TYPE_H 3 #define _ACTIVEBASIC_COMPILER_TYPE_H 3 class CClass; 4 4 5 5 class Type{ … … 18 18 static bool StringToBasicType( const string &typeName, int &basicType ); 19 19 static bool StringToType( const string &typeName, Type &type ); 20 static int GetBasicSize( int basicType ); 20 21 21 22 Type(): … … 30 31 index( index ){} 31 32 32 Type( int basicType, CClass &objClass ):33 Type( int basicType, const CClass &objClass ): 33 34 basicType( basicType ), 34 35 index( (LONG_PTR)&objClass ){} … … 38 39 index( type.index ){} 39 40 40 int GetBasicType() const41 __inline int GetBasicType() const 41 42 { 42 #ifdef _DEBUG43 if( basicType<-10000 ){44 DebugBreak();45 }46 #endif47 43 return basicType; 48 44 } … … 64 60 void SetNull(){ 65 61 SetBasicType( DEF_NON ); 62 SetIndex( -1 ); 66 63 } 67 64 void SetType( int basicType, LONG_PTR index ){ … … 74 71 } 75 72 73 int PtrLevel() const 74 { 75 return PTR_LEVEL( basicType ); 76 } 76 77 void PtrLevelUp(){ 77 78 PTR_LEVEL_UP( basicType ); 79 } 80 void PtrLevelDown(){ 81 PTR_LEVEL_DOWN( basicType ); 78 82 } 79 83 80 84 bool Equals( const Type &type ) const; 81 85 86 int GetBasicSize() const; 87 int GetSize() const; 88 82 89 bool IsNull() const; 90 91 bool IsByte() const; 92 bool IsSByte() const; 93 bool IsWord() const; 94 bool IsInteger() const; 95 bool IsDWord() const; 96 bool IsLong() const; 97 bool IsQWord() const; 98 bool IsInt64() const; 99 bool IsSingle() const; 100 bool IsDouble() const; 101 bool IsBoolean() const; 102 83 103 bool IsPointer() const; 84 104 bool IsSigned() const; … … 89 109 bool IsProcPtr() const; 90 110 bool IsStruct() const; 111 bool IsStructPtr() const; 112 bool IsObject() const; 113 bool IsObjectPtr() const; 114 bool IsStringObject() const; 115 bool IsVoidPtr() const; 116 bool IsAny() const; 91 117 118 const string ToString() const; 119 120 void operator= ( const Type &type ){ 121 basicType = type.basicType; 122 index = type.index; 123 } 92 124 }; 93 94 #endif //_ACTIVEBASIC_COMPILER_TYPE_H -
BasicCompiler_Common/Variable.cpp
r73 r75 1 #include "../BasicCompiler_Common/common.h"2 3 #ifdef _AMD64_4 #include "../BasicCompiler64/opcode.h"5 #else6 #include "../BasicCompiler32/opcode.h"7 #endif8 9 BOOL IsVariableTopChar(char c){10 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_') return 1;11 return 0;12 }13 BOOL IsVariableChar(char c){14 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||15 c=='%'||c=='!'||c=='#'||c=='$'||16 c=='_'||c=='.') return 1;17 return 0;18 }19 BOOL IsPtrType(int type){20 if(type==-1) return 0;21 22 if(PTR_LEVEL(type)||type==DEF_PTR_VOID||type==DEF_PTR_PROC||23 (type&FLAG_PTR) ) return 1;24 25 return 0;26 }27 BOOL IsSignedType(int type){28 switch(type){29 case DEF_SBYTE:30 case DEF_INTEGER:31 case DEF_LONG:32 case DEF_INT64:33 case DEF_SINGLE:34 case DEF_DOUBLE:35 case DEF_CHAR:36 return 1;37 default:38 break;39 }40 return 0;41 }42 BOOL IsNaturalWholeNumberType(int type){43 switch(type){44 case DEF_SBYTE:45 case DEF_BYTE:46 case DEF_INTEGER:47 case DEF_WORD:48 case DEF_LONG:49 case DEF_DWORD:50 case DEF_INT64:51 case DEF_QWORD:52 case DEF_CHAR:53 return 1;54 default:55 break;56 }57 return 0;58 }59 BOOL IsWholeNumberType(int type){60 return (61 IsNaturalWholeNumberType(type)62 || IsPtrType(type)63 || type == DEF_BOOLEAN64 );65 }66 BOOL IsRealNumberType(int type){67 switch(type){68 case DEF_DOUBLE:69 case DEF_SINGLE:70 return 1;71 default:72 break;73 }74 return 0;75 }76 BOOL Is64Type(int type){77 switch(type){78 case DEF_INT64:79 case DEF_QWORD:80 return 1;81 default:82 break;83 }84 #ifdef _AMD64_85 return IsPtrType(type);86 #else87 return 0;88 #endif89 }90 int GetSignedType(int type){91 switch(type){92 case DEF_BYTE:93 return DEF_SBYTE;94 case DEF_WORD:95 return DEF_INTEGER;96 case DEF_DWORD:97 return DEF_LONG;98 case DEF_QWORD:99 return DEF_INT64;100 default:101 break;102 }103 #ifdef _AMD64_104 if(IsPtrType(type)) return DEF_INT64;105 #else106 if(IsPtrType(type)) return DEF_LONG;107 #endif108 return type;109 }110 int GetUnsignedType(int type){111 switch(type){112 case DEF_SBYTE:113 return DEF_BYTE;114 case DEF_INTEGER:115 return DEF_WORD;116 case DEF_LONG:117 return DEF_DWORD;118 case DEF_INT64:119 return DEF_QWORD;120 case DEF_CHAR:121 if( isUnicode ) return DEF_WORD;122 return DEF_BYTE;123 }124 return type;125 }126 int GetTypeSize(int type,LONG_PTR lpIndex){127 if(type==DEF_LONG){128 if(lpIndex==LITERAL_NULL||lpIndex==LITERAL_M128_0||lpIndex==LITERAL_0_255)129 return sizeof(BYTE);130 else if(lpIndex==LITERAL_M32768_0||lpIndex==LITERAL_0_65535)131 return sizeof(WORD);132 133 return sizeof(DWORD);134 }135 136 //整数型137 if(type==DEF_INT64||type==DEF_QWORD)138 return sizeof(_int64);139 else if(type==DEF_LONG||type==DEF_DWORD)140 return sizeof(DWORD);141 else if(type==DEF_INTEGER||type==DEF_WORD)142 return sizeof(WORD);143 else if(type==DEF_SBYTE||type==DEF_BYTE || type == DEF_BOOLEAN)144 return sizeof(BYTE);145 146 //実数型147 else if(type==DEF_DOUBLE) return sizeof(double);148 else if(type==DEF_SINGLE) return sizeof(float);149 150 //文字型151 else if( type == DEF_CHAR ){152 if( isUnicode ) return sizeof( WORD );153 return sizeof( BYTE );154 }155 156 //ポインタ型157 else if(IsPtrType(type)) return PTR_SIZE;158 159 else if( type == DEF_STRUCT ){160 CClass *pobj_c;161 pobj_c=(CClass *)lpIndex;162 if(!pobj_c){163 SetError(300,NULL,cp);164 return 0;165 }166 167 return pobj_c->GetSize();168 }169 170 else if(type==DEF_OBJECT){171 return PTR_SIZE;172 }173 else{174 SetError(300,NULL,cp);175 }176 return 0;177 }178 int GetPtrType(int type,LONG_PTR lpIndex){179 return MAKE_PTR_TYPE(NATURAL_TYPE(type),PTR_LEVEL(type)+1);180 }181 int GetTypeFixed(const char *TypeName,LONG_PTR *lpNum){182 int type;183 184 if(lpNum) *lpNum=-1;185 186 if(TypeName[0]=='*'){187 if(TypeName[1]==1&&(TypeName[2]==ESC_FUNCTION||TypeName[2]==ESC_SUB)){188 //関数ポインタ(*Function)189 return DEF_PTR_PROC;190 }191 192 type=GetTypeFixed(TypeName+1,lpNum);193 if(type==-1) return -1;194 195 return GetPtrType(type,*lpNum);196 }197 198 //整数型199 if(lstrcmpi(TypeName,"SByte")==0) return DEF_SBYTE;200 else if(lstrcmpi(TypeName,"Byte")==0) return DEF_BYTE;201 else if(lstrcmpi(TypeName,"Integer")==0) return DEF_INTEGER;202 else if(lstrcmpi(TypeName,"WORD")==0) return DEF_WORD;203 else if(lstrcmpi(TypeName,"Long")==0) return DEF_LONG;204 else if(lstrcmpi(TypeName,"DWORD")==0) return DEF_DWORD;205 else if(lstrcmpi(TypeName,"Int64")==0) return DEF_INT64;206 else if(lstrcmpi(TypeName,"QWORD")==0) return DEF_QWORD;207 208 //実数型209 else if(lstrcmpi(TypeName,"Single")==0) return DEF_SINGLE;210 else if(lstrcmpi(TypeName,"Double")==0) return DEF_DOUBLE;211 212 //文字型213 //else if( lstrcmpi( TypeName, "Char" ) == 0 ) return DEF_CHAR;214 215 //bool型216 else if( lstrcmpi( TypeName, "Boolean" ) == 0 ) return DEF_BOOLEAN;217 218 //ポインタ型219 //※VoidPtr型以外のポインタ型はTypeDef宣言により定義される220 else if(lstrcmpi(TypeName,"VoidPtr")==0) return DEF_PTR_VOID;221 222 //その他223 else if(lstrcmpi(TypeName,"Any")==0) return DEF_ANY;224 225 226 ////////////////////227 // TypeDefされた型228 ////////////////////229 int i;230 i=pobj_DBTypeDef->check(TypeName);231 if(i!=-1){232 return GetTypeFixed(pobj_DBTypeDef->ppobj_TypeDef[i]->lpszBaseName,lpNum);233 }234 235 if(!lpNum) return -1;236 237 //クラス238 CClass *pobj_c;239 pobj_c=pobj_DBClass->check(TypeName);240 if(pobj_c){241 *lpNum=(LONG_PTR)pobj_c;242 243 if( pobj_c->IsStructure() ){244 return DEF_STRUCT;245 }246 else{247 return DEF_OBJECT;248 }249 }250 251 return -1;252 }253 void GetOriginalTypeName(char *buffer){254 // TypeDefされた型に対して、オリジナルの型の名前に変更する255 256 if(buffer[0]=='*'){257 if(buffer[1]==1&&(buffer[2]==ESC_FUNCTION||buffer[2]==ESC_SUB)) return;258 259 GetOriginalTypeName(buffer+1);260 return;261 }262 263 int i;264 i=pobj_DBTypeDef->check(buffer);265 if(i!=-1){266 lstrcpy(buffer,pobj_DBTypeDef->ppobj_TypeDef[i]->lpszBaseName);267 GetOriginalTypeName(buffer);268 }269 }270 BOOL GetTypeName(int type,LONG_PTR lpIndex,char *name){271 if(PTR_LEVEL(type)){272 //ポインタ型273 name[0]='*';274 return GetTypeName(MAKE_PTR_TYPE(NATURAL_TYPE(type),PTR_LEVEL(type)-1),lpIndex,name+1);275 }276 277 //整数型278 if(type==DEF_SBYTE) lstrcpy(name,"SByte");279 else if(type==DEF_BYTE) lstrcpy(name,"Byte");280 else if(type==DEF_INTEGER) lstrcpy(name,"Integer");281 else if(type==DEF_WORD) lstrcpy(name,"Word");282 else if(type==DEF_LONG) lstrcpy(name,"Long");283 else if(type==DEF_DWORD) lstrcpy(name,"DWord");284 else if(type==DEF_INT64) lstrcpy(name,"Int64");285 else if(type==DEF_QWORD) lstrcpy(name,"QWord");286 287 //実数型288 else if(type==DEF_SINGLE) lstrcpy(name,"Single");289 else if(type==DEF_DOUBLE) lstrcpy(name,"Double");290 291 //文字型292 //else if(type==DEF_CHAR) lstrcpy(name,"Char");293 294 //bool型295 else if(type==DEF_BOOLEAN) lstrcpy(name,"Boolean");296 297 //オブジェクト298 else if(type==DEF_OBJECT || type==DEF_STRUCT){299 if(lpIndex==0) lstrcpy(name,"non");300 else{301 lstrcpy(name,((CClass *)lpIndex)->name);302 }303 }304 305 //ポインタ型306 else if(type==DEF_PTR_VOID) lstrcpy(name,"VoidPtr");307 308 else if(type==DEF_PTR_PROC){309 if(lpIndex==-1) lstrcpy(name,"VoidPtr");310 else{311 extern PROCPTRINFO *pProcPtrInfo;312 if(pProcPtrInfo[lpIndex].ReturnType==DEF_NON)313 lstrcpy(name,"*Sub");314 else lstrcpy(name,"*Function");315 }316 }317 318 else{319 extern int cp;320 SetError(1,NULL,cp);321 return 0;322 }323 return 1;324 }325 326 TYPEINFO GetStringTypeInfo(){327 extern CClass *pobj_StringClass;328 TYPEINFO TypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass };329 return TypeInfo;330 }331 332 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member ){333 int p1 = 0, p2 = 0;334 335 for( int i=0; term[i]!='\0' ; i++ ){336 337 if( term[i] == '[' ){338 i = JumpStringInBracket( term, i + 1 );339 if( term[i] == '\0' ) break;340 continue;341 }342 if( term[i] == '(' ){343 int temp_p = i;344 i = JumpStringInPare( term, i + 1 ) + 1;345 if( term[i] == '\0' ) break;346 if( term[i] == '.'347 || term[i] == 1 && term[i] == ESC_PSMEM ){348 p1 = temp_p;349 p2 = i;350 }351 continue;352 }353 }354 if( !p1 ) return false;355 356 //メソッド名357 memcpy( procName, term, p1 );358 procName[p1] = 0;359 360 //パラメータ361 memcpy( parameter, term + p1 + 1, p2 - p1 - 2 );362 parameter[ p2 - p1 - 2 ] = 0;363 364 //参照タイプ365 if( term[p2] == '.' ){366 refType = CClass::Dot;367 }368 else{369 refType = CClass::Pointer;370 p2++;371 }372 373 //メンバ374 lstrcpy( member, term + p2 + 1 );375 376 return true;377 }378 379 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,CClass::RefType &refType){380 extern int cp;381 int i,i2,i3;382 char cPare_Open,cPare_Close;383 384 array[0]=0;385 array2[0]=0;386 NestMember[0]=0;387 for(i=0;;i++){388 if(buffer[i]=='\"'){389 for(i++;;i++){390 if(IsDBCSLeadByte(buffer[i])){391 i++;392 continue;393 }394 if(buffer[i]=='\"') break;395 }396 }397 if(buffer[i]=='['||buffer[i]=='('){398 if(buffer[i]=='['){399 cPare_Open='[';400 cPare_Close=']';401 }402 else{403 cPare_Open='(';404 cPare_Close=')';405 }406 buffer[i]=0;407 for(i++,i2=0;;i++,i2++){408 if(buffer[i]==cPare_Open){409 if(cPare_Open=='[') i3=GetStringInBracket(array+i2,buffer+i);410 else i3=GetStringInPare(array+i2,buffer+i);411 i+=i3-1;412 i2+=i3-1;413 continue;414 }415 if(buffer[i]==cPare_Close){416 array[i2]=0;417 break;418 }419 array[i2]=buffer[i];420 }421 if(buffer[i+1]==cPare_Open){422 for(i+=2,i2=0;;i++,i2++){423 if(buffer[i]==cPare_Open){424 if(cPare_Open=='[') i3=GetStringInBracket(array2+i2,buffer+i);425 else i3=GetStringInPare(array2+i2,buffer+i);426 i+=i3-1;427 i2+=i3-1;428 continue;429 }430 if(buffer[i]==cPare_Close){431 array2[i2]=0;432 break;433 }434 array2[i2]=buffer[i];435 }436 if(buffer[i+1]==cPare_Open){437 SetError(14,buffer,cp);438 return 0;439 }440 }441 continue;442 }443 if(buffer[i]=='.'){444 lstrcpy(NestMember,buffer+i+1);445 refType = CClass::Dot;446 buffer[i]=0;447 break;448 }449 if(buffer[i]==1&&buffer[i+1]==ESC_PSMEM){450 lstrcpy(NestMember,buffer+i+2);451 refType = CClass::Pointer;452 buffer[i]=0;453 break;454 }455 if(buffer[i]=='\0') break;456 }457 return 1;458 }459 460 void GetArrayElement(char *buffer,char *variable,char *array_element){461 array_element[0]=0;462 463 if(buffer[lstrlen(buffer)-1]!=']'){464 lstrcpy(variable,buffer);465 return;466 }467 468 int i,i2;469 for(i=0;;i++){470 if(buffer[i]=='\0') break;471 if(buffer[i]=='['){472 i2=GetStringInBracket(array_element,buffer+i);473 i+=i2-1;474 continue;475 }476 }477 478 lstrcpy(variable,buffer);479 variable[lstrlen(variable)-lstrlen(array_element)]=0;480 481 RemoveStringBracket(array_element);482 }483 484 BOOL CheckVarNameError(char *name,int NowLine){485 int i2;486 487 if(!IsVariableTopChar(name[0])){488 SetError(1,NULL,NowLine);489 return 0;490 }491 for(i2=1;;i2++){492 if(name[i2]=='\0') break;493 if(!IsVariableChar(name[i2])){494 SetError(1,NULL,NowLine);495 return 0;496 }497 }498 return 1;499 }500 501 int JumpSubScripts(int *ss){502 //DIMで定義された並んだ配列の数だけアドレスを進める503 int i,i2;504 for(i=0,i2=1;i<255;i++){505 if(ss[i]==-1) break;506 i2*=ss[i]+1;507 }508 return i2;509 }510 void GetArrange(char *variable,char *variAnswer,int *SubScripts){511 extern int cp;512 int i,i2,i3,i4;513 double dbl;514 _int64 i64data;515 BOOL bBracket;516 char temporary[VN_SIZE];517 518 for(i=0;;i++){519 if(variable[i]=='('||variable[i]=='['){520 if(variable[i]=='[') bBracket=1;521 else bBracket=0;522 523 variAnswer[i]=0;524 for(i++,i2=0,i3=0;;i++,i2++){525 if(variable[i]==','){526 temporary[i2]=0;527 528 i2=StaticCalculation(true, temporary,0,&i64data,0);529 if(IsRealNumberType(i2)){530 memcpy(&dbl,&i64data,sizeof(double));531 i64data=(_int64)dbl;532 }533 534 if(i64data<0){535 //error536 SubScripts[i3]=0;537 }538 else SubScripts[i3]=(int)i64data;539 i3++;540 i2=-1;541 continue;542 }543 if(variable[i]=='('){544 i4=GetStringInPare(temporary+i2,variable+i);545 i2+=i4-1;546 i+=i4-1;547 continue;548 }549 if(variable[i]=='['){550 i4=GetStringInBracket(temporary+i2,variable+i);551 i2+=i4-1;552 i+=i4-1;553 continue;554 }555 if(variable[i]==')'&&bBracket==0||556 variable[i]==']'&&bBracket){557 temporary[i2]=0;558 if(i2==0){559 SubScripts[i3]=-2;560 break;561 }562 563 i2=StaticCalculation(true, temporary,0,&i64data,0);564 if(IsRealNumberType(i2)){565 memcpy(&dbl,&i64data,sizeof(double));566 i64data=(_int64)dbl;567 }568 569 if(i64data<0){570 //error571 SubScripts[i3]=0;572 }573 else SubScripts[i3]=(int)i64data;574 SubScripts[i3+1]=-1;575 break;576 }577 if(variable[i]=='\"'){578 SetError(1,NULL,cp);579 return;580 }581 temporary[i2]=variable[i];582 }583 break;584 }585 variAnswer[i]=variable[i];586 if(variable[i]=='\0'){587 SubScripts[0]=-1;588 break;589 }590 }591 }592 593 int GetTypeFromSimpleName(char *variable){594 extern char DefIntVari[26],DefSngVari[26],DefStrVari[26],divNum,dsvNum,dStrvNum;595 int i;596 char name[VN_SIZE];597 598 //構造体メンバの場合を考慮599 for(i=lstrlen(variable);i>0;i--){600 if(variable[i]=='.'){601 i++;602 break;603 }604 }605 606 for(;;i++){607 if(variable[i]=='('||variable[i]=='\0'){608 name[i]=0;609 break;610 }611 name[i]=variable[i];612 }613 //変数名から選択614 i--;615 if(name[i]=='#') return DEF_DOUBLE;616 if(name[i]=='!') return DEF_SINGLE;617 if(name[i]=='%') return DEF_INTEGER;618 return DEF_DOUBLE;619 }620 621 622 int GetMemberType(CClass *pobj_c,char *member,LONG_PTR *plpNestIndex,BOOL bPrivateAccess,BOOL bError){623 extern int cp;624 int i;625 626 //クラス、配列の構成要素を解析する627 char VarName[VN_SIZE]; //変数名628 char array[VN_SIZE]; //第1次配列629 char lpPtrOffset[VN_SIZE]; //第2次配列630 char NestMember[VN_SIZE]; //入れ子メンバ631 CClass::RefType refType = CClass::Non;632 lstrcpy(VarName,member);633 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0;634 635 for(i=0;i<pobj_c->iMemberNum;i++){636 if(lstrcmp(pobj_c->ppobj_Member[i]->name,VarName)==0) break;637 }638 if(i==pobj_c->iMemberNum){639 if(bError) SetError(103,VarName,cp);640 return -1;641 }642 643 //アクセシビリティをチェック644 if(pobj_c==pobj_CompilingClass){645 //同一クラスオブジェクトの場合はプライベートアクセスを容認する646 if(pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){647 if(bError) SetError(107,VarName,cp);648 return -1;649 }650 }651 else{652 if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||653 pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){654 if(bError) SetError(107,VarName,cp);655 return -1;656 }657 else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){658 if(bError) SetError(108,VarName,cp);659 return -1;660 }661 }662 663 int type;664 type=pobj_c->ppobj_Member[i]->TypeInfo.type;665 *plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex;666 667 //ポインタ変数の場合668 if(IsPtrType(type)){669 if(pobj_c->ppobj_Member[i]->SubScripts[0]==-1){670 lstrcpy(lpPtrOffset,array);671 array[0]=0;672 }673 }674 else{675 if(lpPtrOffset[0]){676 if(bError) SetError(16,member,cp);677 return 0;678 }679 }680 681 if( refType != CClass::Non ){682 //入れ子構造の場合683 684 return GetMemberType(pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,685 NestMember,686 plpNestIndex,687 0,688 bError);689 }690 691 if(array[0]==0&&pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){692 return type|FLAG_PTR;693 }694 695 if(lpPtrOffset[0]){696 if(PTR_LEVEL(type)){697 type=MAKE_PTR_TYPE(NATURAL_TYPE(type),PTR_LEVEL(type)-1);698 }699 else{700 //エラー701 if(bError) SetError(1,NULL,cp);702 return -1;703 }704 }705 706 return type;707 }708 int GetVarType(const char *NameBuffer,LONG_PTR *plpIndex,BOOL bError){709 extern BOOL bCompilingGlobal;710 int i;711 LONG_PTR lpIndex;712 char variable[VN_SIZE],member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];713 714 if(NameBuffer[0]=='.'){715 GetWithName(variable);716 lstrcat(variable,NameBuffer);717 }718 else lstrcpy(variable,NameBuffer);719 720 721 CClass::RefType refType;722 if( FormatUseProcReturnObject( variable, VarName, array, refType, member ) ){723 // 戻り値オブジェクトのメンバを直接参照しているとき724 //例: func().member725 726 void *pInfo;727 int idProc=GetProc(VarName,&pInfo);728 729 if(idProc){730 731 int type=GetReturnTypeOfProc(idProc,pInfo,VarName,array,&lpIndex);732 733 return GetMemberType((CClass *)lpIndex,member,plpIndex,1,bError);734 }735 }736 737 738 739 lstrcpy(VarName,variable);740 GetVarFormatString(VarName,array,lpPtrOffset,member,refType);741 742 int *pSubScripts;743 int type;744 745 extern int MaxGlobalVarNum;746 extern VARIABLE *GlobalVar;747 extern int MaxLocalVarNum;748 extern VARIABLE *LocalVar;749 750 if(bCompilingGlobal==0){751 /////////////////752 // ローカル変数753 /////////////////754 755 for(i=MaxLocalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ756 if( LocalVar[i].bLiving //現在のスコープで有効なもの757 && LocalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)758 ){759 if(lstrcmp(VarName,LocalVar[i].name)==0) break;760 }761 }762 if(i>=0){763 //ポインタ変数の場合764 if(IsPtrType(LocalVar[i].type)){765 if(LocalVar[i].SubScripts[0]==-1){766 lstrcpy(lpPtrOffset,array);767 array[0]=0;768 }769 }770 else{771 if(lpPtrOffset[0]){772 if(bError) SetError(16,variable,cp);773 return -1;774 }775 }776 777 type=LocalVar[i].type;778 lpIndex=LocalVar[i].u.index;779 pSubScripts=LocalVar[i].SubScripts;780 781 goto ok;782 }783 }784 785 if(pobj_CompilingClass){786 ///////////////////////787 // クラスメンバの参照788 ///////////////////////789 790 if(lstrcmpi(variable,"This")==0){791 //Thisオブジェクト792 *plpIndex=(LONG_PTR)pobj_CompilingClass;793 return DEF_OBJECT;794 }795 796 if(_memicmp(variable,"This.",5)==0){797 //Thisオブジェクトのメンバを参照するとき798 SlideString(variable+5,-5);799 lstrcpy(VarName,variable);800 }801 else{802 //クラス内メンバを参照するとき(通常)803 804 for(i=0;i<pobj_CompilingClass->iMemberNum;i++){805 if(lstrcmp(VarName,pobj_CompilingClass->ppobj_Member[i]->name)==0) break;806 }807 if(i==pobj_CompilingClass->iMemberNum) goto NonClassMember;808 }809 810 return GetMemberType(pobj_CompilingClass,variable,plpIndex,1,bError);811 }812 813 NonClassMember:814 815 //////////////////////////816 // 静的ローカル変数817 // ※"Static.Object.Method.Variable"818 //////////////////////////819 820 char temporary[VN_SIZE];821 extern SubInfo *pCompilingSubInfo;822 if(pCompilingSubInfo){823 GetNowStaticVarFullName(VarName,temporary);824 825 for(i=0;i<MaxGlobalVarNum;i++){826 if(lstrcmp(temporary,GlobalVar[i].name)==0) break;827 }828 if(i!=MaxGlobalVarNum){829 goto GlobalOk;830 }831 }832 833 834 //////////////////////////835 // クラスの静的メンバ836 //////////////////////////837 838 if(member[0]){839 lstrcpy(temporary,member);840 char tempMember[VN_SIZE];841 char tempArray[VN_SIZE];842 {843 CClass::RefType refType;844 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember,refType);845 }846 847 char temp2[VN_SIZE];848 sprintf(temp2,"%s.%s",VarName,temporary);849 for(i=0;i<MaxGlobalVarNum;i++){850 if(lstrcmp(temp2,GlobalVar[i].name)==0) break;851 }852 853 if(i!=MaxGlobalVarNum){854 lstrcpy(member,tempMember);855 lstrcpy(array,tempArray);856 goto GlobalOk;857 }858 }859 860 if(pobj_CompilingClass){861 //自身のクラスから静的メンバを参照する場合862 char temp2[VN_SIZE];863 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName);864 for(i=0;i<MaxGlobalVarNum;i++){865 if(lstrcmp(temp2,GlobalVar[i].name)==0) break;866 }867 868 if(i!=MaxGlobalVarNum){869 goto GlobalOk;870 }871 }872 873 874 ////////////////////875 // グローバル変数876 ////////////////////877 878 for(i=MaxGlobalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ879 if( GlobalVar[i].bLiving //現在のスコープで有効なもの880 && GlobalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)881 ){882 if(lstrcmp(VarName,GlobalVar[i].name)==0) break;883 }884 }885 886 if(i>=0){887 goto GlobalOk;888 }889 890 //変数として見つからなかったとき891 if(bError) SetError(3,variable,cp);892 return -1;893 894 GlobalOk:895 896 //ポインタ変数の場合897 if(IsPtrType(GlobalVar[i].type)){898 if(GlobalVar[i].SubScripts[0]==-1){899 lstrcpy(lpPtrOffset,array);900 array[0]=0;901 }902 }903 else{904 if(lpPtrOffset[0]){905 if(bError) SetError(16,variable,cp);906 return -1;907 }908 }909 910 type=GlobalVar[i].type;911 lpIndex=GlobalVar[i].u.index;912 pSubScripts=GlobalVar[i].SubScripts;913 914 ok:915 916 if(member[0]){917 if( NATURAL_TYPE(type)==DEF_OBJECT918 || NATURAL_TYPE(type)==DEF_STRUCT){919 return GetMemberType((CClass *)lpIndex,member,plpIndex,0,bError);920 }921 }922 923 if(array[0]==0&&pSubScripts[0]!=-1){924 //配列の先頭ポインタを示す場合925 type|=FLAG_PTR;926 }927 928 if(lpPtrOffset[0]){929 if(PTR_LEVEL(type)){930 type=MAKE_PTR_TYPE(NATURAL_TYPE(type),PTR_LEVEL(type)-1);931 }932 else{933 //エラー934 if(bError) SetError(1,NULL,cp);935 return -1;936 }937 }938 939 *plpIndex=lpIndex;940 return type;941 }942 943 BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){944 //読み取り専用で変数へアクセス945 return GetVarOffset(946 true, //エラー表示有効947 false, //書き込みアクセスは無し948 NameBuffer,949 pType,950 pRelativeVar,951 plpIndex,952 pss);953 }954 BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){955 //読み書き両用で変数へアクセス956 return GetVarOffset(957 true, //エラー表示有効958 true, //書き込みアクセス959 NameBuffer,960 pType,961 pRelativeVar,962 plpIndex,963 pss);964 }965 966 967 968 BOOL GetDimentionFormat(const char *buffer, const bool isRef, char *VarName,int *SubScripts,TYPEINFO *pTypeInfo,char *InitBuf,char *ConstractParameter){969 int i,i2,i3,IsStr;970 char variable[VN_SIZE],temporary[8192];971 972 for(i=0;;i++){973 if((buffer[i]==1&&buffer[i+1]==ESC_AS)||974 buffer[i]=='='||975 buffer[i]=='\0'){976 variable[i]=0;977 break;978 }979 variable[i]=buffer[i];980 }981 982 if(buffer[i]=='='){983 ////////////////////////////////////984 // 初期化データが指定されいるとき985 ////////////////////////////////////986 987 for(i++,i2=0,IsStr=0;;i++,i2++){988 if(buffer[i]=='\"') IsStr^=1;989 if(buffer[i]=='('&&IsStr==0){990 i3=GetStringInPare(InitBuf+i2,buffer+i);991 i+=i3-1;992 i2+=i3-1;993 continue;994 }995 if(buffer[i]=='['&&IsStr==0){996 i3=GetStringInBracket(InitBuf+i2,buffer+i);997 i+=i3-1;998 i2+=i3-1;999 continue;1000 }1001 if((buffer[i]==1&&buffer[i+1]==ESC_AS)||1002 (buffer[i]==','&&IsStr==0)||1003 buffer[i]=='\0'){1004 InitBuf[i2]=0;1005 break;1006 }1007 InitBuf[i2]=buffer[i];1008 }1009 }1010 else{1011 //初期化データなし1012 InitBuf[0]=0;1013 }1014 1015 ConstractParameter[0]=0;1016 if(buffer[i]==1&&buffer[i+1]==ESC_AS){1017 /////////////////////////////1018 // "As ~" による型指定あり1019 /////////////////////////////1020 1021 for(i+=2,i2=0;;i++,i2++){1022 if(buffer[i]==','||buffer[i]=='('||buffer[i]=='\0'){1023 temporary[i2]=0;1024 break;1025 }1026 temporary[i2]=buffer[i];1027 }1028 pTypeInfo->type=GetTypeFixed(temporary,&pTypeInfo->u.lpIndex);1029 if(pTypeInfo->type==-1){1030 SetError(3,temporary,cp);1031 pTypeInfo->type=DEF_LONG;1032 }1033 1034 if(pTypeInfo->type==DEF_PTR_PROC){1035 if(temporary[0]=='*'&&1036 temporary[1]==1&&1037 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){1038 if(buffer[i]!='('){1039 SetError(10,temporary,cp);1040 return 0;1041 }1042 i3=GetStringInPare(temporary+3,buffer+i);1043 i+=i3;1044 i2+=i3;1045 1046 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){1047 temporary[i2++]=buffer[i++];1048 temporary[i2++]=buffer[i++];1049 for(;;i++,i2++){1050 if(!IsVariableChar(buffer[i])){1051 temporary[i2]=0;1052 break;1053 }1054 temporary[i2]=buffer[i];1055 }1056 }1057 }1058 else{1059 //TypeDefをする前のベース型を取得1060 GetOriginalTypeName(temporary);1061 }1062 1063 if(temporary[3]!='('){1064 SetError(10,temporary,cp);1065 return 0;1066 }1067 1068 //関数ポインタ1069 pTypeInfo->u.lpIndex=AddProcPtrInfo(temporary+3,temporary[2]);1070 }1071 1072 if(buffer[i]=='('){1073 //コンストラクタに渡すパラメータを取得1074 i2=GetStringInPare(ConstractParameter,buffer+i);1075 i+=i2;1076 RemoveStringPare(ConstractParameter);1077 1078 if(pTypeInfo->type!=DEF_OBJECT){1079 SetError(112,variable,cp);1080 return 0;1081 }1082 }1083 }1084 else{1085 /////////////////1086 // As指定なし1087 /////////////////1088 1089 if( InitBuf[0] == '\0' ){1090 //As指定も、初期値指定もない場合1091 pTypeInfo->type=GetTypeFromSimpleName(variable);1092 1093 i2=lstrlen(variable)-1;1094 if(i2>=0){1095 if(!(variable[i2]=='#'||variable[i2]=='!'||variable[i2]=='%'||variable[i2]=='$'))1096 SetError(-103,variable,cp);1097 }1098 }1099 else{1100 //初期値の型を判別して自動的に型情報を付加する1101 TYPEINFO BaseType = GetStringTypeInfo();1102 int result = NumOpe_GetType_Old( InitBuf, &BaseType, &pTypeInfo->u.lpIndex );1103 1104 //エラーの場合1105 if( result == -1 ) return 0;1106 1107 pTypeInfo->type = result;1108 }1109 1110 }1111 1112 if( InitBuf[0] != '\0' && ConstractParameter[0] != '\0' ){1113 //初期値とコンストラクタパラメータが同時に呼び出されているとき1114 SetError(132, NULL, cp);1115 }1116 1117 /*1118 TODO: 消す1119 if( pTypeInfo->type == DEF_OBJECT && InitBuf[0] != '\0' && InitBuf[0] != '[' && isRef == false ){1120 if( pTypeInfo->u.pobj_Class->GetCopyConstructorMethod() ){1121 //オブジェクトでコピーコンストラクタが存在するとき1122 lstrcpy( ConstractParameter, InitBuf );1123 InitBuf[0] = 0;1124 }1125 }*/1126 1127 GetArrange(variable,VarName,SubScripts);1128 return 1;1129 }1130 1131 BOOL GetNowStaticVarFullName(char *VarName,char *FullName){1132 extern SubInfo *pCompilingSubInfo;1133 if(!pCompilingSubInfo) return 0;1134 1135 //Static識別1136 lstrcpy(FullName,"Static%");1137 1138 //クラス名1139 if(pobj_CompilingClass){1140 lstrcat(FullName,pobj_CompilingClass->name);1141 lstrcat(FullName,"%");1142 }1143 1144 //関数(またはメソッド)名1145 lstrcat(FullName,pCompilingSubInfo->name);1146 lstrcat(FullName,"%");1147 1148 //ID1149 char temp[255];1150 sprintf(temp,"%x",pCompilingSubInfo->id);1151 lstrcat(FullName,temp);1152 lstrcat(FullName,"%");1153 1154 //変数名1155 lstrcat(FullName,VarName);1156 1157 return 1;1158 }1159 1160 1161 void AddGlobalVariable(bool isRef, char *name,int *SubScripts,TYPEINFO *pTypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlag){1162 /////////////////////////1163 // グローバル変数を追加1164 /////////////////////////1165 extern VARIABLE *GlobalVar;1166 extern int MaxGlobalVarNum;1167 extern int AllInitGlobalVarSize;1168 extern int AllGlobalVarSize;1169 1170 int i2,i3,VarSize;1171 1172 for(i2=0;i2<MaxGlobalVarNum;i2++){1173 if(GlobalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==GlobalVar[i2].ScopeLevel){1174 if(lstrcmp(GlobalVar[i2].name,name)==0){1175 //2重定義のエラー1176 SetError(15,name,cp);1177 return;1178 }1179 }1180 }1181 1182 GlobalVar=(VARIABLE *)HeapReAlloc(hHeap,0,GlobalVar,(MaxGlobalVarNum+1)*sizeof(VARIABLE));1183 VARIABLE *pVar = &GlobalVar[MaxGlobalVarNum];1184 MaxGlobalVarNum++;1185 1186 if( isRef ){1187 //参照型1188 pVar->fRef = REF_VARIABLE;1189 TypeSize = PTR_SIZE;1190 }1191 else pVar->fRef=0;1192 1193 for(i2=1,i3=0;i3<255;i3++){1194 //配列要素数1195 pVar->SubScripts[i3]=SubScripts[i3];1196 1197 if(SubScripts[i3]==-1) break;1198 i2*=SubScripts[i3]+1;1199 }1200 VarSize=TypeSize*i2;1201 if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE);1202 1203 lstrcpy(pVar->name,name);1204 if(dwFlag & DIMFLAG_CONST) pVar->bConst = true;1205 else pVar->bConst = false;1206 if(SubScripts[0]==-1) pVar->bArray=0;1207 else pVar->bArray=1;1208 pVar->type=pTypeInfo->type;1209 pVar->u.index=pTypeInfo->u.lpIndex;1210 1211 //コンストラクタ用パラメータ1212 pVar->ConstractParameter=(char *)HeapAlloc(hHeap,0,lstrlen(ConstractParameter)+1);1213 lstrcpy(pVar->ConstractParameter,ConstractParameter);1214 1215 //レキシカルスコープ1216 pVar->ScopeLevel=obj_LexScopes.GetNowLevel();1217 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();1218 pVar->bLiving=TRUE;1219 1220 //エラー用1221 pVar->source_code_address=cp;1222 1223 //アラインメントを考慮1224 int alignment = 0;1225 if( pVar->type==DEF_STRUCT ){1226 alignment = pVar->u.pobj_c->iAlign;1227 }1228 1229 if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){1230 //初期バッファがあるとき1231 1232 if( alignment ){1233 if( AllInitGlobalVarSize % alignment ){1234 AllInitGlobalVarSize += alignment - (AllInitGlobalVarSize % alignment);1235 }1236 }1237 1238 pVar->offset=AllInitGlobalVarSize;1239 AllInitGlobalVarSize+=VarSize;1240 }1241 else{1242 //初期バッファがないとき1243 1244 if( alignment ){1245 if( AllGlobalVarSize % alignment ){1246 AllGlobalVarSize += alignment - (AllGlobalVarSize % alignment);1247 }1248 }1249 1250 pVar->offset=AllGlobalVarSize | 0x80000000;1251 AllGlobalVarSize+=VarSize;1252 }1253 1254 if(InitBuf[0]){1255 int result = 0;1256 if( pVar->type != DEF_OBJECT ){1257 //初期バッファにデータをセット1258 extern BYTE *initGlobalBuf;1259 initGlobalBuf=(BYTE *)HeapReAlloc(hHeap,1260 HEAP_ZERO_MEMORY,1261 initGlobalBuf,1262 AllInitGlobalVarSize);1263 1264 result = SetInitGlobalData(pVar->offset,1265 pVar->type,1266 pVar->u.index,1267 pVar->SubScripts,1268 InitBuf);1269 }1270 1271 if(!result){1272 //動的な式だった場合は代入演算を行う1273 1274 //初期代入時のみ、書き込みアクセスを許可する1275 bool bConstBack = pVar->bConst;1276 pVar->bConst = false;1277 1278 //代入1279 char temporary[8192];1280 sprintf(temporary,"%s=%s",name,InitBuf);1281 OpcodeCalc(temporary);1282 1283 //アクセス制限を元に戻す1284 pVar->bConst = bConstBack;1285 }1286 }1287 1288 1289 if( pTypeInfo->type==DEF_OBJECT ){1290 //デストラクタの利用フラグをオンにする1291 CMethod *method = pTypeInfo->u.pobj_Class->GetDestructorMethod();1292 if( method ){1293 method->psi->bUse = 1;1294 }1295 }1296 1297 /*1298 TODO: 消す1299 if(pTypeInfo->type==DEF_OBJECT){1300 //利用対象のクラスコンストラクタ、デストラクタに使用チェックをつける1301 for(i2=0;i2<pTypeInfo->u.pobj_Class->iMethodNum;i2++){1302 if(lstrcmp(pTypeInfo->u.pobj_Class->ppobj_Method[i2]->psi->name,pTypeInfo->u.pobj_Class->name)==0){1303 //コンストラクタ1304 pTypeInfo->u.pobj_Class->ppobj_Method[i2]->psi->bUse=1;1305 }1306 if(pTypeInfo->u.pobj_Class->ppobj_Method[i2]->psi->name[0]=='~'){1307 //デストラクタ1308 pTypeInfo->u.pobj_Class->ppobj_Method[i2]->psi->bUse=1;1309 }1310 }1311 }*/1312 } -
BasicCompiler_Common/Variable.h
r64 r75 1 2 class Variable : public Type 3 { 4 string name; 5 bool isConst; 6 bool isRef; 7 bool isArray; 8 int subScripts[MAX_ARRAYDIM]; 9 10 bool isParameter; 11 12 public: 13 Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false ): 14 Type( type ), 15 name( name ), 16 isConst( isConst ), 17 isRef( isRef ), 18 isArray( false ), 19 isParameter( false) 20 { 21 subScripts[0] = -1; 22 } 23 Variable( const Variable &var ): 24 Type( var ), 25 name( var.name ), 26 isConst( var.isConst ), 27 isRef( var.isRef ), 28 isArray( false ), 29 isParameter( false ) 30 { 31 subScripts[0] = -1; 32 if( var.isArray ){ 33 SetArray( var.subScripts ); 34 } 35 } 36 ~Variable(){} 37 38 void SetArray( const int *pSubScripts ){ 39 isArray = true; 40 memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM ); 41 } 42 43 const string &GetName() const 44 { 45 return name; 46 } 47 48 void ConstOff(){ 49 isConst = false; 50 } 51 void ConstOn(){ 52 isConst = true; 53 } 54 bool IsConst() const 55 { 56 return isConst; 57 } 58 bool IsRef() const 59 { 60 return isRef; 61 } 62 bool IsArray()const 63 { 64 return isArray; 65 } 66 const int *GetSubScriptsPtr() const 67 { 68 return subScripts; 69 } 70 71 void ThisIsParameter(){ 72 isParameter = true; 73 } 74 bool IsParameter() const 75 { 76 return isParameter; 77 } 1 78 2 79 3 BOOL IsVariableTopChar(char c); 4 BOOL IsVariableChar(char c); 5 BOOL IsPtrType(int type); 6 BOOL IsSignedType(int type); 7 BOOL IsNaturalWholeNumberType(int type); 8 BOOL IsWholeNumberType(int type); 9 BOOL IsRealNumberType(int type); 10 BOOL Is64Type(int type); 11 int GetSignedType(int type); 12 int GetUnsignedType(int type); 13 int GetTypeSize(int type,LONG_PTR lpIndex); 14 int GetPtrType(int type,LONG_PTR lpIndex); 15 int GetTypeFixed(const char *TypeName,LONG_PTR *lpNum); 16 void GetOriginalTypeName(char *buffer); 17 BOOL GetTypeName(int type,LONG_PTR lpIndex,char *name); 18 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member ); 19 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember, CClass::RefType &refType ); 20 void GetArrayElement(char *buffer,char *variable,char *array_element); 21 BOOL CheckVarNameError(char *name,int NowLine); 22 int JumpSubScripts(int *ss); 23 void GetArrange(char *variable,char *variAnswer,int *SubScripts); 24 int GetTypeFromSimpleName(char *variable); 25 int GetVarType(const char *NameBuffer,LONG_PTR *plpIndex,BOOL bError); 26 BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0); 27 BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0); 28 BOOL GetDimentionFormat(const char *buffer, const bool isRef, char *VarName,int *SubScripts,TYPEINFO *pTypeInfo,char *InitBuf,char *ConstractParameter); 29 BOOL GetNowStaticVarFullName(char *VarName,char *FullName); 30 void AddGlobalVariable(bool isRef, char *name,int *SubScripts,TYPEINFO *pTypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlag); 80 int GetMemorySize() const 81 { 82 if( isRef || isParameter ){ 83 return PTR_SIZE; 84 } 31 85 86 int size = Type::GetSize(); 87 88 if( isArray ){ 89 int num = 1; 90 for( int i=0; i<MAX_ARRAYDIM; i++){ 91 if(subScripts[i]==-1) break; 92 num *= subScripts[i]+1; 93 } 94 size *= num; 95 } 96 97 if( size % PTR_SIZE ){ 98 size += PTR_SIZE-(size%PTR_SIZE); 99 } 100 101 return size; 102 } 103 104 105 /* --- オフセット --- 106 107 ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、 108 初期バッファの有無が識別される。 109 (その後、スケジュール実行により、実際の配置に並び替えられる)*/ 110 int offset; 111 112 //コンストラクタ用パラメータ 113 string paramStrForConstructor; 114 115 //レキシカルスコープ用 116 int ScopeStartAddress; 117 int ScopeEndAddress; 118 int ScopeLevel; 119 BOOL bLiving; 120 121 122 int source_code_address; 123 }; 124 125 class Variables : public vector<Variable *> 126 { 127 public: 128 Variables(){} 129 ~Variables(){ 130 clear(); 131 } 132 133 void clear(){ 134 for( int i=0; i<(int)this->size(); i++ ){ 135 delete (*this)[i]; 136 } 137 138 vector<Variable *>::clear(); 139 } 140 141 bool DuplicateCheck( const string &varName ) const 142 { 143 //レキシカルスコープを考慮して重複判定 144 for( int i=(int)this->size()-1; i>=0 ; i-- ){ 145 Variable &var = *(*this)[i]; 146 if( var.bLiving //現在のスコープで有効なもの 147 && var.ScopeLevel == obj_LexScopes.GetNowLevel() //現在のスコープと同一レベル 148 ){ 149 if( var.GetName() == varName ){ 150 return true; 151 } 152 } 153 } 154 return false; 155 } 156 157 const Variable *BackSearch( const string &varName ) const 158 { 159 //レキシカルスコープを考慮してバックサーチ 160 for( int i=(int)this->size()-1; i>=0 ; i-- ){ 161 Variable &var = *(*this)[i]; 162 if( var.bLiving //現在のスコープで有効なもの 163 && var.ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 164 ){ 165 if( var.GetName() == varName ){ 166 return &var; 167 } 168 } 169 } 170 return NULL; 171 } 172 173 const Variable *Find( const string &varName )const 174 { 175 int max = (int)this->size(); 176 for( int i=0; i<max; i++ ){ 177 Variable *pVar = (*this)[i]; 178 if( pVar->GetName() == varName ){ 179 return pVar; 180 } 181 } 182 return NULL; 183 } 184 }; 185 186 extern Variables globalVars; 187 188 -
BasicCompiler_Common/calculation.cpp
r73 r75 390 390 } 391 391 392 int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList){ 393 extern HANDLE hHeap; 392 bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList, bool *pIsMemoryAccessError){ 394 393 extern int cp; 395 394 int i,i2,i3,PareNum; … … 406 405 int sp,pnum; 407 406 407 if( pIsMemoryAccessError ) *pIsMemoryAccessError = false; 408 408 409 *pi64data=0; 409 if(Command[0]=='\0') return 0;410 if(Command[0]=='\0') return false; 410 411 411 412 for(i=0,i2=0,sp=0,pnum=0,PareNum=0;;i++,i2++){ … … 487 488 extern int cp; 488 489 if(enableerror) SetError(3,temp2,cp); 489 return 0;490 return false; 490 491 } 491 492 i64nums[pnum]=GetTypeSize(i3,lpIndex); … … 497 498 if(!GetConstCalcBuffer(temporary,temp2,Parms)){ 498 499 if(enableerror) SetError(3,temporary,cp); 499 return 0;500 return false; 500 501 } 501 502 502 type[pnum]=StaticCalculation(true, Parms,BaseType,&i64data,&before_index[pnum]); 503 if(IsRealNumberType(type[pnum])){ 504 //整数型 503 Type tempType; 504 StaticCalculation(true, Parms,BaseType,&i64data,tempType); 505 type[pnum] = tempType.GetBasicType(); 506 before_index[pnum] = tempType.GetIndex(); 507 if(tempType.IsReal()){ 508 //実数型 505 509 memcpy(&nums[pnum],&i64data,sizeof(double)); 506 510 } … … 548 552 549 553 RELATIVE_VAR RelativeVar; 550 LONG_PTR lpIndex;551 554 int ss[MAX_ARRAYDIM]; 552 555 void *offset; … … 557 560 extern HANDLE hDebugProcess; 558 561 559 i3=Debugging_GetVarOffset(Parms,&i2,&RelativeVar,&lpIndex,ss); 562 Type tempType; 563 i3=Debugging_GetVarOffset(Parms,&RelativeVar,tempType,ss); 560 564 if(i3==0){ 561 565 //式エラー 562 return 0;566 return false; 563 567 } 564 568 if(i3==-1){ 565 569 //メモリにアクセスできないとき 566 return -1; 570 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true; 571 return false; 567 572 } 568 573 … … 571 576 offset=(void *)Debugging_GetVarPtr(&RelativeVar); 572 577 573 type[pnum]= i2;574 575 if( i2==DEF_DOUBLE){578 type[pnum]=tempType.GetBasicType(); 579 580 if(tempType.IsDouble()){ 576 581 i3=ReadProcessMemory(hDebugProcess,offset,&nums[pnum],sizeof(double),&stAccBytes); 577 582 } 578 else if( i2==DEF_SINGLE){583 else if(tempType.IsSingle()){ 579 584 if(i3=ReadProcessMemory(hDebugProcess,offset,&flt,sizeof(float),&stAccBytes)){ 580 585 nums[pnum]=(double)flt; 581 586 } 582 587 } 583 else if( IsPtrType(i2)){588 else if(tempType.IsPointer()){ 584 589 LONG_PTR lpData; 585 590 if(i3=ReadProcessMemory(hDebugProcess,offset,&lpData,sizeof(LONG_PTR),&stAccBytes)){ … … 587 592 } 588 593 } 589 else if( Is64Type(i2)){594 else if(tempType.Is64()){ 590 595 type[pnum]=DEF_INT64; 591 596 … … 593 598 } 594 599 595 else if( i2==DEF_LONG){600 else if(tempType.IsLong()){ 596 601 long lData; 597 602 if(i3=ReadProcessMemory(hDebugProcess,offset,&lData,sizeof(long),&stAccBytes)){ … … 599 604 } 600 605 } 601 else if( i2==DEF_DWORD){606 else if(tempType.IsDWord()){ 602 607 if(i3=ReadProcessMemory(hDebugProcess,offset,&dwData,sizeof(DWORD),&stAccBytes)){ 603 608 i64nums[pnum]=(_int64)dwData; 604 609 } 605 610 } 606 else if( i2==DEF_INTEGER || (isUnicode&&i2==DEF_CHAR)){611 else if(tempType.IsInteger()){ 607 612 short shortData; 608 613 if(i3=ReadProcessMemory(hDebugProcess,offset,&shortData,sizeof(short),&stAccBytes)){ … … 610 615 } 611 616 } 612 else if( i2==DEF_WORD){617 else if(tempType.IsWord()){ 613 618 WORD wData; 614 619 if(i3=ReadProcessMemory(hDebugProcess,offset,&wData,sizeof(WORD),&stAccBytes)){ … … 616 621 } 617 622 } 618 else if( i2==DEF_SBYTE || (isUnicode==false&&i2==DEF_CHAR)){623 else if(tempType.IsSByte()){ 619 624 char charData; 620 625 if(i3=ReadProcessMemory(hDebugProcess,offset,&charData,sizeof(char),&stAccBytes)){ … … 622 627 } 623 628 } 624 else if( i2==DEF_BYTE){629 else if(tempType.IsByte()){ 625 630 BYTE byteData; 626 631 if(i3=ReadProcessMemory(hDebugProcess,offset,&byteData,sizeof(BYTE),&stAccBytes)){ … … 628 633 } 629 634 } 630 else if( i2==DEF_BOOLEAN){635 else if(tempType.IsBoolean()){ 631 636 BYTE byteData; 632 637 if(i3=ReadProcessMemory(hDebugProcess,offset,&byteData,sizeof(BYTE),&stAccBytes)){ … … 634 639 } 635 640 } 636 else return 0;641 else return false; 637 642 638 643 if(!i3){ 639 644 //読み込みに失敗 640 return -1; 645 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true; 646 return false; 641 647 } 642 648 goto JumpConst; … … 672 678 //エラー 673 679 if(enableerror) SetError(300,NULL,cp); 674 return -1;680 return 0; 675 681 } 676 682 goto JumpConst; … … 685 691 686 692 if(type[pnum]==-1){ 687 if(bDebuggingWatchList) return -1; 693 if(bDebuggingWatchList){ 694 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true; 695 return false; 696 } 688 697 //エラー 689 698 if(enableerror) SetError(3,Parms,cp); 690 return 0;699 return false; 691 700 } 692 701 JumpConst:; … … 713 722 if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){ 714 723 if(enableerror) SetError(1,NULL,cp); 715 return 0;724 return false; 716 725 } 717 726 if(Command[i]=='+'){ … … 898 907 //文字列ポインタ 899 908 *pi64data=(_int64)stack[0]; 900 *plpIndex=index_stack[0];901 return t ype_stack[0];909 resultType.SetType( type_stack[0], index_stack[0] ); 910 return true; 902 911 } 903 912 … … 905 914 //実数 906 915 memcpy(pi64data,&dbl_stack[0],sizeof(double)); 907 return type_stack[0]; 916 resultType.SetType( type_stack[0], index_stack[0] ); 917 return true; 908 918 } 909 919 … … 911 921 *pi64data=i64stack[0]; 912 922 913 if(plpIndex){ 914 *plpIndex=index_stack[0]; 915 if(*plpIndex==-1){ 916 if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){ 917 //整数(符号有り/無し) 918 i64data=*pi64data; 919 920 *plpIndex=GetLiteralIndex(i64data); 921 } 922 } 923 } 924 925 return type_stack[0]; 923 if(index_stack[0]==-1){ 924 if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){ 925 //整数(符号有り/無し) 926 i64data=*pi64data; 927 928 resultType.SetIndex( GetLiteralIndex(i64data) ); 929 } 930 } 931 else{ 932 resultType.SetIndex( index_stack[0] ); 933 } 934 935 resultType.SetBasicType( type_stack[0] ); 936 return true; 926 937 } 927 938 … … 1187 1198 return -1; 1188 1199 } 1189 bool IsStringObjectType(const TYPEINFO &TypeInfo){1190 if(TypeInfo.type==DEF_OBJECT){1191 if(lstrcmp(TypeInfo.u.pobj_Class->name,"String")==0){1192 return 1;1193 }1194 }1195 return 0;1196 }1197 1200 int IsStrCalculation(char *Command){ 1198 int i,i2,i3,i4, type,PareNum;1201 int i,i2,i3,i4,PareNum; 1199 1202 char temporary[VN_SIZE],temp2[8192]; 1200 1203 … … 1245 1248 } 1246 1249 if(Command[i2+i3]=='('){ 1247 TYPEINFO TypeInfo;1248 1250 1249 1251 //DLL関数の場合 1250 D ECLAREINFO *pdi;1251 p di=GetDeclareHash(temporary);1252 if(p di){1253 TypeInfo.type=pdi->ReturnType;1254 TypeInfo.u.lpIndex=pdi->u.ReturnIndex;1255 if(IsStringObjectType( TypeInfo )) return 1;1252 DllProc *pDllProc; 1253 pDllProc=GetDeclareHash(temporary); 1254 if(pDllProc){ 1255 if( pDllProc->ReturnType().IsStringObject() ){ 1256 return 1; 1257 } 1256 1258 return 0; 1257 1259 } 1258 1260 1259 1261 //ユーザー定義関数 1260 SubInfo *psi;1261 p si=GetSubHash(temporary);1262 if(p si){1263 TypeInfo.type=psi->ReturnType;1264 TypeInfo.u.lpIndex=psi->u.ReturnIndex;1265 if(IsStringObjectType(TypeInfo)) return 1;1262 UserProc *pUserProc; 1263 pUserProc=GetSubHash(temporary); 1264 if(pUserProc){ 1265 if( pUserProc->ReturnType().IsStringObject() ){ 1266 return 1; 1267 } 1266 1268 return 0; 1267 1269 } … … 1297 1299 1298 1300 //変数 1299 CClass *pobj_Class; 1300 type = GetVarType(Command+i2,(LONG_PTR *)&pobj_Class,1); 1301 if(type==-1 || type ==0){ 1301 Type varType; 1302 if( !GetVarType(Command+i2,varType,1) ){ 1302 1303 //エラー 1303 1304 return -1; 1304 1305 } 1305 if(type==DEF_OBJECT){ 1306 if(lstrcmp(pobj_Class->name,"String")==0){ 1307 return 1; 1308 } 1309 return 0; 1306 if( varType.IsStringObject() ){ 1307 return 1; 1310 1308 } 1311 1309 } -
BasicCompiler_Common/common.h
r73 r75 37 37 #include "../BasicCompiler_Common/psapi.h" 38 38 #include "../BasicCompiler_Common/BreakPoint.h" 39 #include "../BasicCompiler_Common/LexicalScoping.h" 39 40 40 41 … … 152 153 #include "Const.h" 153 154 155 // 変数管理用のクラス 156 #include "Variable.h" 157 154 158 // パラメータ管理用のクラス 155 159 #include "Parameter.h" … … 172 176 173 177 //変数 174 #define REF_PARAMETER 1175 #define OBJECT_PARAMETER 2176 #define REF_VARIABLE 4177 178 struct VARIABLE{ 178 179 char name[255]; … … 219 220 }; 220 221 221 struct PARAMETER_INFO{222 char *name;223 int type;224 union{225 LONG_PTR index;226 CClass *pobj_c;227 }u;228 229 BOOL bByVal;230 BOOL bArray;231 int SubScripts[MAX_ARRAYDIM];232 };233 234 #define DECLARE_DYNAMIC 1235 #define DECLARE_STATIC 2236 struct DECLAREINFO{237 DWORD dwType;238 239 char *file;240 char *name;241 char *alias;242 BOOL bCdecl;243 244 //パラメータ245 PARAMETER_INFO *pParmInfo;246 int ParmNum;247 248 //戻り値249 int ReturnType;250 union{251 LONG_PTR ReturnIndex;252 CClass *Return_pobj_c;253 }u;254 255 union{256 int LookupAddress;257 int StaticProc_CodeAddress;258 };259 260 BOOL bUse;261 262 int pos;263 264 DECLAREINFO *pNextData;265 };266 struct PROCPTRINFO{267 PARAMETER_INFO *pParmInfo;268 int ParmNum;269 270 int ReturnType;271 union{272 LONG_PTR ReturnIndex;273 CClass *Return_pobj_c;274 }u;275 };276 222 struct CONSTINFO{ 277 223 char *name; … … 361 307 #include "../BasicCompiler_Common/PESchedule.h" 362 308 #include "../BasicCompiler_Common/DebugSection.h" 363 #include "../BasicCompiler_Common/LexicalScoping.h" 364 #include "../BasicCompiler_Common/Variable.h" 309 #include "../BasicCompiler_Common/VariableOpe.h" 365 310 #include "../BasicCompiler_Common/Exception.h" 366 311 367 312 368 313 369 int StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList=0);314 bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList=0, bool *pIsMemoryAccessError=NULL); 370 315 371 316 … … 384 329 385 330 //hash.cpp 386 int hash_default(c har *name);331 int hash_default(const char *name); 387 332 CONSTINFO *GetConstHash(char *name); 388 D ECLAREINFO*GetDeclareHash(char *name);389 SubInfo*GetSubHash(const char *name,BOOL bError=0);390 SubInfo *GetMethodHash(char *ObjectName,char *MethodName,char *Parameter,BOOL bError=0);391 void GetOverloadSubHash( const char *lpszName, std::vector< SubInfo*> &subs );333 DllProc *GetDeclareHash(char *name); 334 UserProc *GetSubHash(const char *name,BOOL bError=0); 335 UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0); 336 void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs ); 392 337 393 338 //Object.cpp 394 void AddClassName(char *Parameter,int NowLine);395 void CallConstructor(char *VarName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter);339 void CallConstructor( const char *ObjectName,const int *SubScripts, const Type &type,const char *Parameter); 340 bool Operator_New( const char *expression, const Type &baseType, Type &resultType ); 396 341 397 342 //Overload.sbp 398 SubInfo*OverloadSolutionWithStrParam(343 UserProc *OverloadSolutionWithStrParam( 399 344 const char *name, 400 std::vector< SubInfo*> &subs,345 std::vector<UserProc *> &subs, 401 346 const char *Parameter, 402 const char *ObjectName, 403 TYPEINFO *pReturnTypeInfo); 404 SubInfo *OverloadSolution( 347 const char *ObjectName); 348 UserProc *OverloadSolution( 405 349 const char *name, 406 std::vector<SubInfo *> &subs, 407 const PARAMETER_INFO *ppi, 408 const int ParmNum, 409 TYPEINFO *pReturnTypeInfo); 350 std::vector<UserProc *> &subs, 351 const Parameters ¶ms, 352 const Type &returnType ); 410 353 411 354 //Debug.cpp … … 416 359 void Debugger_Pause(void); 417 360 ULONG_PTR rva_to_real(DWORD p); 418 SubInfo*GetSubFromObp(ULONG_PTR pos);361 UserProc *GetSubFromObp(ULONG_PTR pos); 419 362 void ReadOpBuffer(); 420 363 void DebugProgram(void); … … 428 371 ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar); 429 372 ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip); 430 int Debugging_GetVarOffset( char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss);373 int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss); 431 374 432 375 //MakeExe.cpp … … 462 405 463 406 //CommandFormat.cpp 464 void ComOpen(char *Parameter,char *buffer,int NowLine);407 void ComOpen(char *Parameter,char *buffer,int nowLine); 465 408 void ComClose(char *Parameter,char *buffer); 466 409 void ComField(char *Parameter,char *buffer); 467 void ComLine(char *Parameter,char *buffer,int NowLine);468 void ComCircle(char *Parameter,char *buffer,int NowLine);469 void ComPSet(char *Parameter,char *buffer,int NowLine);470 void ComPaint(char *Parameter,char *buffer,int NowLine);410 void ComLine(char *Parameter,char *buffer,int nowLine); 411 void ComCircle(char *Parameter,char *buffer,int nowLine); 412 void ComPSet(char *Parameter,char *buffer,int nowLine); 413 void ComPaint(char *Parameter,char *buffer,int nowLine); 471 414 472 415 // StrOperation.cpp … … 512 455 BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer); 513 456 DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex); 514 bool IsStringObjectType(const T YPEINFO&TypeInfo);457 bool IsStringObjectType(const Type &TypeInfo); 515 458 int IsStrCalculation(char *Command); 516 459 BYTE GetCalcId(const char *Command,int *pi); … … 518 461 char *values[255],long calc[255],long stack[255]); 519 462 520 //NumOpe_GetType _Old.cpp463 //NumOpe_GetType.cpp 521 464 int AutoBigCast(int BaseType,int CalcType); 522 465 BOOL CheckCalcType(int idCalc,int *type,int sp); 523 int NumOpe_GetType_Old( const char *Command, TYPEINFO *pBaseTypeInfo, LONG_PTR *plpIndex );524 466 bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ); 525 467 … … 529 471 void SplitObjectName(const char *name,char *ObjectName,int *pRefType); 530 472 bool SplitMemberName( const char *desc, char *object, char *member ); 531 int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex); 532 BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo); 533 int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex); 534 BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo); 535 bool GetReturnTypeOfIndexerGetterProc(CClass *pobj_Class,TYPEINFO &RetTypeInfo); 536 BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2); 537 SubInfo *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic=0); 473 bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true ); 474 bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType); 475 bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ); 476 bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ); 477 UserProc *AddSubData(char *buffer,int nowLine,BOOL bVirtual,CClass *pobj_c, bool isStatic = false ); 538 478 void GetSubInfo(void); 539 void DeleteSubInfo( SubInfo**ppSubHash,char **ppMacroNames,int MacroNum);479 void DeleteSubInfo(UserProc **ppSubHash,char **ppMacroNames,int MacroNum); 540 480 void DeleteDeclareInfo(void); 541 int AddProcPtrInfo( char *buffer,DWORD dwProcType);481 int AddProcPtrInfo( char *buffer, DWORD dwProcType, int nowLine ); 542 482 void DeleteProcPtrInfo(void); 543 483 … … 581 521 //error.cpp 582 522 void SetError(int ErrorNum,const char *KeyWord,int pos); 523 void SetError(int ErrorNum,const string &keyWord,int pos); 583 524 void SetError(); 584 525 void CompileMessage(char *buffer); 585 526 bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,const int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum); 527 bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum); 586 528 587 529 //Compile.cpp -
BasicCompiler_Common/error.cpp
r65 r75 93 93 //日本語 94 94 //////////////////// 95 if(num==1) lstrcpy(msg,"文法が間違っています ");96 if(num==2) sprintf(msg,"左のオペランドが、左辺値になっていません ");95 if(num==1) lstrcpy(msg,"文法が間違っています。"); 96 if(num==2) sprintf(msg,"左のオペランドが、左辺値になっていません。"); 97 97 //num==3は予約されています 98 if(num==4) sprintf(msg,"%sの相互関係が一致しません",tempKeyWord); 99 if(num==5) sprintf(msg,"ダブルクォートの数が一致しません"); 100 if(num==6) sprintf(msg,"\"%s\" ジャンプ先が不正です",tempKeyWord); 101 if(num==7) lstrcpy(msg,"DLL名が長すぎます(拡張子を含め、16文字以下にして下さい)"); 102 if(num==8) lstrcpy(msg,"コンパイラが認識できない文字コードが含まれています"); 103 if(num==9) sprintf(msg,"型が違います"); 104 if(num==10) sprintf(msg,"\"%s\" のパラメータ指定が間違っています",tempKeyWord); 105 if(num==11) sprintf(msg,"\"%s\" 型が違います",tempKeyWord); 106 if(num==12) sprintf(msg,"\"%s\" の使い方が不正です",tempKeyWord); 107 if(num==13) sprintf(msg,"\"%s\" を参照できません",tempKeyWord); 108 if(num==14) sprintf(msg,"\"%s\" 配列指定が不正です",tempKeyWord); 109 if(num==15) sprintf(msg,"\"%s\" はすでに定義されています",tempKeyWord); 110 if(num==16) sprintf(msg,"\"%s\" 配列、またはポインタ以外の変数に添え字が指定されています",tempKeyWord); 111 if(num==17) sprintf(msg,"リソース データが不正です"); 112 if(num==18) sprintf(msg,"\"%s\"はポインタ変数型です。文字列演算を指定することはできません",tempKeyWord); 113 if(num==19) sprintf(msg,"\"%s\"は値参照型です。ByVal指定することはできません",tempKeyWord); 114 if(num==20) lstrcpy(msg,"全角スペースが含まれています(全角スペースはコンパイラが認識できないので、半角スペースまたはタブ文字にしてください)"); 115 if(num==21) sprintf(msg,"If制御のブロック指定が不正です"); 116 if(num==22) sprintf(msg,"\"%s\" に対する \"End %s\" が見つかりません",tempKeyWord,tempKeyWord); 117 if(num==23) sprintf(msg,"リソース ファイル \"%s\" の読み込みに失敗",tempKeyWord); 118 if(num==24) lstrcpy(msg,"Export指定の関数のパラメータには実体オブジェクトを利用することはできません(BytePtr型などを利用して下さい)"); 119 if(num==27) sprintf(msg,"\"%s\" は定義されていません",tempKeyWord); 120 if(num==28) sprintf(msg,"構造体パラメータはポインタ参照にしてください(%s)",tempKeyWord); 121 if(num==29) sprintf(msg,"配列ポインタを要素と同時に引渡すときは、ポインタ参照(ByRef)にしてください"); 98 if(num==4) sprintf(msg,"%sの相互関係が一致しません。",tempKeyWord); 99 if(num==5) sprintf(msg,"ダブルクォートの数が一致しません。"); 100 if(num==6) sprintf(msg,"\"%s\" ジャンプ先が不正です。",tempKeyWord); 101 if(num==7) lstrcpy(msg,"DLL名が長すぎます(拡張子を含め、16文字以下にして下さい)。"); 102 if(num==8) lstrcpy(msg,"コンパイラが認識できない文字コードが含まれています。"); 103 if(num==9) sprintf(msg,"型が違います。"); 104 if(num==10) sprintf(msg,"\"%s\" のパラメータ指定が間違っています。",tempKeyWord); 105 if(num==11) sprintf(msg,"\"%s\" 型が違います。",tempKeyWord); 106 if(num==12) sprintf(msg,"\"%s\" の使い方が不正です。",tempKeyWord); 107 if(num==13) sprintf(msg,"\"%s\" を参照できません。",tempKeyWord); 108 if(num==14) sprintf(msg,"\"%s\" 配列指定が不正です。",tempKeyWord); 109 if(num==15) sprintf(msg,"\"%s\" はすでに定義されています。",tempKeyWord); 110 if(num==16) sprintf(msg,"\"%s\" 配列、またはポインタ以外の変数に添え字が指定されています。",tempKeyWord); 111 if(num==17) sprintf(msg,"リソース データが不正です。"); 112 if(num==18) sprintf(msg,"\"%s\"はポインタ変数型です。文字列演算を指定することはできません。",tempKeyWord); 113 if(num==19) sprintf(msg,"\"%s\"は値参照型です。ByVal指定することはできません。",tempKeyWord); 114 if(num==20) lstrcpy(msg,"全角スペースが含まれています(全角スペースはコンパイラが認識できないので、半角スペースまたはタブ文字にしてください)。"); 115 if(num==21) sprintf(msg,"If制御のブロック指定が不正です。"); 116 if(num==22) sprintf(msg,"\"%s\" に対する \"End %s\" が見つかりません。",tempKeyWord,tempKeyWord); 117 if(num==23) sprintf(msg,"リソース ファイル \"%s\" の読み込みに失敗。",tempKeyWord); 118 if(num==24) lstrcpy(msg,"Export指定の関数のパラメータには実体オブジェクトを利用することはできません(BytePtr型などを利用して下さい)。"); 119 if(num==25) sprintf(msg,"DLL関数にオブジェクトを引き渡すことはできません(%s)。",tempKeyWord); 120 if(num==26) sprintf(msg,"\"%s\" 戻り値の型が指定されていません。",tempKeyWord); 121 if(num==27) sprintf(msg,"\"%s\" は定義されていません。",tempKeyWord); 122 if(num==28) sprintf(msg,"構造体パラメータは参照渡しにしてください(%s)。",tempKeyWord); 123 if(num==29) sprintf(msg,"配列ポインタを要素と同時に引渡すときは、ポインタ参照(ByRef)にしてください。"); 122 124 //num==30は予約されています 123 if(num==31) sprintf(msg,"\"%s\" は構造体です(メンバの参照はピリオド \".\" で区切ってください) ",tempKeyWord);124 if(num==32) sprintf(msg,"\"%s\" は構造体ポインタです(メンバの参照は \"->\" で区切ってください) ",tempKeyWord);125 if(num==33) sprintf(msg,"定数式にリテラル値、または定数以外のものが含まれています ");126 if(num==34) sprintf(msg,"定数はモジュールレベルで宣言して下さい ");127 if(num==38) sprintf(msg,"\"%s\" 戻り値が存在しないプロシージャです ",tempKeyWord);128 if(num==39) sprintf(msg,"\"%s\" はオブジェクトポインタではありません(\"->\" 参照はできません) ",tempKeyWord);129 if(num==40) lstrcpy(msg," 関数の戻り値にオブジェクトを指定することはできません");130 if(num==41) lstrcpy(msg,"初期データが不正です ");131 if(num==42) lstrcpy(msg,"閉じカッコ \")\" の後に不正な文字が含まれています ");132 if(num==43) lstrcpy(msg,"ダブルクォートの後に不正な文字が含まれています ");133 if(num==45) sprintf(msg,"実数に対して \"%s\" 演算子は利用できません ",tempKeyWord);134 if(num==46) lstrcpy(msg,"配列の添え字に整数以外の値が与えられています ");135 if(num==47) lstrcpy(msg,"As演算子の右辺値に型名以外の識別子が指定されています ");136 if(num==48) sprintf(msg,"%s演算子に対して型名が指定されています ",tempKeyWord);137 if(num==49) lstrcpy(msg,"添え字に整数以外の型が指定されています ");138 if(num==50) sprintf(msg,"%sに変換できません ",tempKeyWord);139 if(num==51) lstrcpy(msg,"オブジェクト、構造体のアラインメント値は1,2,4,8,16のいずれかでなければなりません ");140 if(num==52) sprintf(msg,"\"%s\" オーバーロードを解決できません ",tempKeyWord);141 if(num==53) sprintf(msg,"\"%s\" 出力ファイルの書き込みに失敗しました。実行されている可能性があります ",tempKeyWord);125 if(num==31) sprintf(msg,"\"%s\" は構造体です(メンバの参照はピリオド \".\" で区切ってください)。",tempKeyWord); 126 if(num==32) sprintf(msg,"\"%s\" は構造体ポインタです(メンバの参照は \"->\" で区切ってください)。",tempKeyWord); 127 if(num==33) sprintf(msg,"定数式にリテラル値、または定数以外のものが含まれています。"); 128 if(num==34) sprintf(msg,"定数はモジュールレベルで宣言して下さい。"); 129 if(num==38) sprintf(msg,"\"%s\" 戻り値が存在しないプロシージャです。",tempKeyWord); 130 if(num==39) sprintf(msg,"\"%s\" はオブジェクトポインタではありません(\"->\" 参照はできません)。",tempKeyWord); 131 if(num==40) lstrcpy(msg,"DLL関数の戻り値としてオブジェクトを受け取ることはできません。"); 132 if(num==41) lstrcpy(msg,"初期データが不正です。"); 133 if(num==42) lstrcpy(msg,"閉じカッコ \")\" の後に不正な文字が含まれています。"); 134 if(num==43) lstrcpy(msg,"ダブルクォートの後に不正な文字が含まれています。"); 135 if(num==45) sprintf(msg,"実数に対して \"%s\" 演算子は利用できません。",tempKeyWord); 136 if(num==46) lstrcpy(msg,"配列の添え字に整数以外の値が与えられています。"); 137 if(num==47) lstrcpy(msg,"As演算子の右辺値に型名以外の識別子が指定されています。"); 138 if(num==48) sprintf(msg,"%s演算子に対して型名が指定されています。",tempKeyWord); 139 if(num==49) lstrcpy(msg,"添え字に整数以外の型が指定されています。"); 140 if(num==50) sprintf(msg,"%sに変換できません。",tempKeyWord); 141 if(num==51) lstrcpy(msg,"オブジェクト、構造体のアラインメント値は1,2,4,8,16のいずれかでなければなりません。"); 142 if(num==52) sprintf(msg,"\"%s\" オーバーロードを解決できません。",tempKeyWord); 143 if(num==53) sprintf(msg,"\"%s\" 出力ファイルの書き込みに失敗しました。実行されている可能性があります。",tempKeyWord); 142 144 if(num==54) sprintf(msg,"対応する%sが存在しません。",tempKeyWord); 143 145 if(num==55) sprintf(msg,"\"%s\" は対応するForステートメントで利用されるカウンタ変数ではありません。",tempKeyWord); … … 152 154 153 155 //オブジェクト関連 154 if(num==102) sprintf(msg,"\"%s\" オブジェクトは定義されていません ",tempKeyWord);155 if(num==103) sprintf(msg,"\"%s\" メンバは定義されていません ",tempKeyWord);156 if(num==104) sprintf(msg,"\"%s\" 参照方法が違います ",tempKeyWord);157 if(num==105) sprintf(msg,"\"%s\" 自身のクラスを継承することはできません ",tempKeyWord);158 if(num==106) sprintf(msg,"\"%s\" クラスは定義されていません ",tempKeyWord);159 if(num==107) sprintf(msg,"Privateメンバ \"%s\" にアクセスすることはできません ",tempKeyWord);160 if(num==108) sprintf(msg,"Protectedメンバ \"%s\" にアクセスすることはできません ",tempKeyWord);161 if(num==109) sprintf(msg,"Privateメンバ関数 \"%s\" を呼び出すことはできません ",tempKeyWord);162 if(num==110) sprintf(msg,"Protectedメンバ関数 \"%s\" を呼び出すことはできません ",tempKeyWord);163 if(num==111) lstrcpy(msg,"InheritsはClass定義内の先頭に記述する必要があります ");164 if(num==112) sprintf(msg,"\"%s\" はクラス型ではないため、初期パラメータを指定することはできません ",tempKeyWord);165 if(num==113) sprintf(msg,"\"%s\" コンストラクタへ渡すパラメータが不正です ",tempKeyWord);166 if(num==114) lstrcpy(msg,"デストラクタはパラメータを持てません ");167 if(num==115) lstrcpy(msg,"コンストラクタ及びデストラクタは戻り値を持てません ");168 if(num==116) lstrcpy(msg,"コンストラクタ及びデストラクタはパブリックアクセスにしなければなりません ");169 if(num==117) lstrcpy(msg,"デストラクタの名前が \"~クラス名\" になっていません ");170 if(num==118) lstrcpy(msg,"参照する基底クラスが存在しません ");171 if(num==119) sprintf(msg,"\"%s\" メンバは基底クラスで定義されていません ",tempKeyWord);172 if(num==120) lstrcpy(msg,"デストラクトするオブジェクトの型が不明です ");173 if(num==121) lstrcpy(msg,"New演算子にはクラス以外の型を指定できません ");174 if(num==122) lstrcpy(msg,"Delete演算子にポインタ以外の型が指定されています ");175 if(num==123) lstrcpy(msg,"ループ継承が行われました ");176 if(num==124) lstrcpy(msg,"循環参照が行われました ");156 if(num==102) sprintf(msg,"\"%s\" オブジェクトは定義されていません。",tempKeyWord); 157 if(num==103) sprintf(msg,"\"%s\" メンバは定義されていません。",tempKeyWord); 158 if(num==104) sprintf(msg,"\"%s\" 参照方法が違います。",tempKeyWord); 159 if(num==105) sprintf(msg,"\"%s\" 自身のクラスを継承することはできません。",tempKeyWord); 160 if(num==106) sprintf(msg,"\"%s\" クラスは定義されていません。",tempKeyWord); 161 if(num==107) sprintf(msg,"Privateメンバ \"%s\" にアクセスすることはできません。",tempKeyWord); 162 if(num==108) sprintf(msg,"Protectedメンバ \"%s\" にアクセスすることはできません。",tempKeyWord); 163 if(num==109) sprintf(msg,"Privateメンバ関数 \"%s\" を呼び出すことはできません。",tempKeyWord); 164 if(num==110) sprintf(msg,"Protectedメンバ関数 \"%s\" を呼び出すことはできません。",tempKeyWord); 165 if(num==111) lstrcpy(msg,"InheritsはClass定義内の先頭に記述する必要があります。"); 166 if(num==112) sprintf(msg,"\"%s\" はクラス型ではないため、初期パラメータを指定することはできません。",tempKeyWord); 167 if(num==113) sprintf(msg,"\"%s\" コンストラクタへ渡すパラメータが不正です。",tempKeyWord); 168 if(num==114) lstrcpy(msg,"デストラクタはパラメータを持てません。"); 169 if(num==115) lstrcpy(msg,"コンストラクタ及びデストラクタは戻り値を持てません。"); 170 if(num==116) lstrcpy(msg,"コンストラクタ及びデストラクタはパブリックアクセスにしなければなりません。"); 171 if(num==117) lstrcpy(msg,"デストラクタの名前が \"~クラス名\" になっていません。"); 172 if(num==118) lstrcpy(msg,"参照する基底クラスが存在しません。"); 173 if(num==119) sprintf(msg,"\"%s\" メンバは基底クラスで定義されていません。",tempKeyWord); 174 if(num==120) lstrcpy(msg,"デストラクトするオブジェクトの型が不明です。"); 175 if(num==121) lstrcpy(msg,"New演算子にはクラス以外の型を指定できません。"); 176 if(num==122) lstrcpy(msg,"Delete演算子にポインタ以外の型が指定されています。"); 177 if(num==123) lstrcpy(msg,"ループ継承が行われました。"); 178 if(num==124) lstrcpy(msg,"循環参照が行われました。"); 177 179 if(num==125) sprintf(msg,"\"%s\" は抽象クラスです。インスタンス化することはできません。",tempKeyWord); 178 180 if(num==126) lstrcpy(msg,"オペレータのオーバーロードをクラスの外で行うことはできません。"); … … 186 188 187 189 //Enum関連 188 if(num==150) sprintf(msg,"\"%s\" 値が定義されていません ",tempKeyWord);189 if(num==151) sprintf(msg,"\"%s\" 列挙リストに登録されていません ",tempKeyWord);190 if(num==150) sprintf(msg,"\"%s\" 値が定義されていません。",tempKeyWord); 191 if(num==151) sprintf(msg,"\"%s\" 列挙リストに登録されていません。",tempKeyWord); 190 192 191 193 //リンカ 192 if(num==200) sprintf(msg,"\"%s\" 未解決です (リンク エラー) ",tempKeyWord);193 if(num==201) sprintf(msg,"\"%s\" の読み込みに失敗 ",tempKeyWord);194 if(num==200) sprintf(msg,"\"%s\" 未解決です (リンク エラー)。",tempKeyWord); 195 if(num==201) sprintf(msg,"\"%s\" の読み込みに失敗。",tempKeyWord); 194 196 195 197 //原因不明 … … 268 270 return 1; 269 271 } 272 void SetError(int ErrorNum,const string &keyWord,int pos){ 273 SetError( ErrorNum, keyWord.c_str(), pos ); 274 } 270 275 void SetError(int num,const char *KeyWord,int pos){ 271 276 extern HANDLE hHeap; … … 523 528 return true; 524 529 } 530 bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum){ 531 return CheckDifferentType( 532 varType.GetBasicType(), 533 varType.GetIndex(), 534 calcType.GetBasicType(), 535 calcType.GetIndex(), 536 pszFuncName, 537 ParmNum ); 538 } -
BasicCompiler_Common/gc.cpp
r11 r75 12 12 void InitGCVariables(void){ 13 13 char temporary[255]; 14 int type;15 RELATIVE_VAR RelativeVar;16 LONG_PTR lpIndex;17 14 18 15 … … 24 21 OpcodeDim(temporary,0); 25 22 26 GetVarOffsetReadWrite("_System_gc_GlobalRoot_StartPtr",&type,&RelativeVar,&lpIndex); 23 Type type; 24 RELATIVE_VAR RelativeVar; 25 GetVarOffsetReadWrite("_System_gc_GlobalRoot_StartPtr",&RelativeVar,type); 27 26 28 27 //mov rax,ptr … … 44 43 OpcodeDim(temporary,0); 45 44 46 GetVarOffsetReadWrite("_System_gc_GlobalRoot_Size",& type,&RelativeVar,&lpIndex);45 GetVarOffsetReadWrite("_System_gc_GlobalRoot_Size",&RelativeVar,type); 47 46 48 47 //mov rax,ptr … … 65 64 OpcodeDim(temporary,0); 66 65 67 GetVarOffsetReadWrite("_System_gc_StackRoot_StartPtr",& type,&RelativeVar,&lpIndex);66 GetVarOffsetReadWrite("_System_gc_StackRoot_StartPtr",&RelativeVar,type); 68 67 69 68 //mov rax,rsp -
BasicCompiler_Common/hash.cpp
r73 r75 7 7 #endif 8 8 9 int hash_default(c har *name){9 int hash_default(const char *name){ 10 10 int key; 11 11 … … 35 35 } 36 36 37 D ECLAREINFO*GetDeclareHash(char *name){37 DllProc *GetDeclareHash(char *name){ 38 38 //ハッシュ値を取得 39 39 int key; … … 41 41 42 42 //格納位置を取得 43 extern DECLAREINFO **ppDeclareHash; 44 DECLAREINFO *pdi; 45 pdi=ppDeclareHash[key]; 46 while(pdi){ 47 if(lstrcmp(pdi->name,name)==0) break; 43 extern DllProc **ppDeclareHash; 44 DllProc *pDllProc; 45 pDllProc=ppDeclareHash[key]; 46 while(pDllProc){ 47 if( pDllProc->GetName() == name ){ 48 break; 49 } 48 50 49 p di=pdi->pNextData;51 pDllProc=pDllProc->pNextData; 50 52 } 51 53 52 return p di;54 return pDllProc; 53 55 } 54 56 55 void GetOverloadSubHash( const char *lpszName, std::vector< SubInfo*> &subs ){57 void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs ){ 56 58 char name[VN_SIZE]; 57 59 … … 72 74 73 75 bool isStatic = false; 74 CClass *pobj_c;76 const CClass *pobj_c = NULL; 75 77 if(lstrcmpi(ObjName,"Super")==0){ 76 78 //クラスメンバ関数内から基底クラスの呼び出し … … 79 81 else{ 80 82 //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し 81 int type = GetVarType(ObjName,(LONG_PTR *)&pobj_c,0); 82 if(!(NATURAL_TYPE(type)==DEF_OBJECT)){ 83 Type type; 84 GetVarType(ObjName,type,0); 85 pobj_c = &type.GetClass(); 86 if((NATURAL_TYPE(type.GetBasicType())!=DEF_OBJECT)){ 83 87 pobj_c=pobj_DBClass->check(ObjName); 84 88 if( pobj_c ){ … … 123 127 124 128 //格納位置を取得 125 extern SubInfo**ppSubHash;126 SubInfo *psi;127 p si=ppSubHash[key];128 while(p si){129 if(!p si->pobj_ParentClass){130 if( lstrcmp(psi->name,name)==0){131 subs.push_back( p si);129 extern UserProc **ppSubHash; 130 UserProc *pUserProc; 131 pUserProc=ppSubHash[key]; 132 while(pUserProc){ 133 if(!pUserProc->GetParentClassPtr()){ 134 if( pUserProc->GetName() == name ){ 135 subs.push_back( pUserProc ); 132 136 } 133 137 } 134 138 135 p si=psi->pNextData;139 pUserProc=pUserProc->pNextData; 136 140 } 137 141 … … 140 144 141 145 //オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持) 142 SubInfo*GetSubHash(const char *lpszName,BOOL bError){143 std::vector< SubInfo*> subs;146 UserProc *GetSubHash(const char *lpszName,BOOL bError){ 147 std::vector<UserProc *> subs; 144 148 GetOverloadSubHash(lpszName,subs); 145 149 146 150 //関数が存在しないとき 147 151 if(subs.size() == 0){ 152 if(bError){ 153 SetError(3,lpszName,cp); 154 } 148 155 return 0; 149 156 } … … 154 161 } 155 162 156 SubInfo *psi;157 p si= subs[0];163 UserProc *pUserProc; 164 pUserProc = subs[0]; 158 165 159 return p si;166 return pUserProc; 160 167 } 161 SubInfo *GetMethodHash(char *ObjectName,char *MethodName,char *Parameter,BOOL bError){168 UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){ 162 169 char temporary[VN_SIZE]; 163 170 sprintf(temporary,"%s.%s",ObjectName,MethodName); 164 171 165 std::vector< SubInfo*> subs;166 SubInfo *psi;172 std::vector<UserProc *> subs; 173 UserProc *pUserProc; 167 174 GetOverloadSubHash(temporary,subs); 168 175 … … 173 180 174 181 //オーバーロードを解決 175 p si=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName,NULL);182 pUserProc=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName); 176 183 177 return p si;184 return pUserProc; 178 185 }
Note:
See TracChangeset
for help on using the changeset viewer.