Changeset 75 in dev
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- Files:
-
- 2 added
- 71 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/CParameter.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 int ParamImpl::NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){ 4 int ParamImpl::NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 5 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 6 5 7 /////////////////////////////////////////////////////// 6 8 // 一時オブジェクトをあらかじめスタックに積んでおく … … 13 15 14 16 BOOL bEllipse; 15 if(p i_num){16 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;17 if(params.size()){ 18 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 17 19 else bEllipse=0; 18 20 } … … 22 24 useTempParameters[i2] = false; 23 25 24 if(bEllipse&&i2<= pi_num-2) bEllipse=0;25 26 if(i2==0 &&ppi[i2].name){27 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){26 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 27 28 if(i2==0){ 29 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 28 30 //オブジェクトメンバの第一パラメータのThisポインタ 29 31 continue; 30 32 } 31 33 } 32 if( (i2==0||i2==1)&&ppi[i2].name){33 if( lstrcmp(ppi[i2].name,FuncName)==0){34 if( i2==0||i2==1 ){ 35 if( params[i2]->GetVarName() == procName ){ 34 36 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 35 37 continue; … … 37 39 } 38 40 39 T YPEINFODummyTypeInfo;41 Type DummyTypeInfo; 40 42 BOOL bByVal; 41 43 if(bEllipse){ … … 44 46 } 45 47 else{ 46 DummyTypeInfo.type=p pi[i2].type;47 DummyTypeInfo.u.lpIndex=p pi[i2].u.index;48 bByVal =ppi[i2].bByVal;48 DummyTypeInfo.type=params[i2]->GetBasicType(); 49 DummyTypeInfo.u.lpIndex=params[i2]->GetIndex(); 50 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 49 51 } 50 52 … … 80 82 type, 81 83 lpVarIndex, 82 FuncName, 83 i2); 84 85 if( result ){ 86 useTempParameters[i2] = true; 87 useTempObject = true; 88 89 types[i2].type = type; 90 types[i2].u.lpIndex = lpVarIndex; 91 } 92 } 93 } 94 } 95 96 return nCountOfTempObjects * PTR_SIZE; 97 } 98 int ParamImpl::NewTempParameters( const char *procName, const Parameters ¶ms, int SecondParmNum ){ 99 /////////////////////////////////////////////////////// 100 // 一時オブジェクトをあらかじめスタックに積んでおく 101 /////////////////////////////////////////////////////// 102 103 useTempObject = false; 104 105 //一時参照の数 106 nCountOfTempObjects = 0; 107 108 BOOL bEllipse; 109 if(params.size()){ 110 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 111 else bEllipse=0; 112 } 113 else bEllipse=0; 114 115 for(int i2=ParmsNum-1;i2>=0;i2--){ 116 useTempParameters[i2] = false; 117 118 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 119 120 if(i2==0){ 121 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 122 //オブジェクトメンバの第一パラメータのThisポインタ 123 continue; 124 } 125 } 126 if( i2==0||i2==1 ){ 127 if( params[i2]->GetVarName() == procName ){ 128 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 129 continue; 130 } 131 } 132 133 TYPEINFO DummyTypeInfo; 134 BOOL bByVal; 135 if(bEllipse){ 136 DummyTypeInfo.type=NumOpe_GetType_Old(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex); 137 bByVal=1; 138 } 139 else{ 140 DummyTypeInfo.type=params[i2]->GetBasicType(); 141 DummyTypeInfo.u.lpIndex=params[i2]->GetIndex(); 142 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 143 } 144 145 146 if( !bByVal ){ 147 //ポインタ参照 148 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){ 149 //ポインタ指定 150 continue; 151 } 152 153 LONG_PTR lpVarIndex; 154 if( GetVarType( Parms[i2], &lpVarIndex, FALSE ) == -1 ){ 155 //変数ではないとき 156 int reg = REG_RAX; 157 int type = NumOpe( Parms[i2], DummyTypeInfo.type, DummyTypeInfo.u.lpIndex, &lpVarIndex ); 158 //↑ここでスタックに積む 159 160 nCountOfTempObjects++; 161 162 if( type != DEF_STRUCT ){ 163 //一時参照を作成 164 165 //push esp 166 op_push( REG_ESP ); 167 168 nCountOfTempObjects++; 169 } 170 171 bool result = CheckDifferentType( 172 DummyTypeInfo.type, 173 DummyTypeInfo.u.lpIndex, 174 type, 175 lpVarIndex, 176 procName, 84 procName.c_str(), 177 85 i2); 178 86 … … 205 113 206 114 //call free 207 extern SubInfo*pSub_free;115 extern UserProc *pSub_free; 208 116 op_call(pSub_free); 209 117 } … … 232 140 233 141 //call calloc 234 extern SubInfo*pSub_calloc;142 extern UserProc *pSub_calloc; 235 143 op_call(pSub_calloc); 236 144 … … 239 147 240 148 241 T YPEINFOBaseType={DEF_STRUCT,(LONG_PTR)pobj_Class};242 T YPEINFOCalcType;149 Type BaseType={DEF_STRUCT,(LONG_PTR)pobj_Class}; 150 Type CalcType; 243 151 CalcType.type=NumOpe_GetType_Old(Parameter,&BaseType,&CalcType.u.lpIndex); 244 152 … … 276 184 277 185 //call constructor 278 op_call(pobj_Class->GetCopyConstructorMethod()->p si);186 op_call(pobj_Class->GetCopyConstructorMethod()->pUserProc); 279 187 280 188 … … 300 208 301 209 //call constructor 302 op_call(pobj_Class->GetConstructorMethod()->p si);210 op_call(pobj_Class->GetConstructorMethod()->pUserProc); 303 211 } 304 212 */ … … 313 221 } 314 222 315 int ParamImpl::SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){ 223 int ParamImpl::SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 224 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 225 316 226 /////////////////////////////////////////////////////////// 317 227 // パラメータをレジスタ及びスタックフレームにセット … … 320 230 321 231 BOOL bEllipse; 322 if( pi_num){323 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;232 if( params.size() ){ 233 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 324 234 else bEllipse=0; 325 235 } … … 328 238 BOOL bHas_System_LocalThis=0; 329 239 if(ParmsNum>=1){ 330 if( lstrcmp(ppi[0].name,"_System_LocalThis")==0)240 if( params[0]->GetVarName() == "_System_LocalThis" ){ 331 241 bHas_System_LocalThis=1; 242 } 332 243 } 333 244 334 245 //戻り値用の変数名を取得 335 const char *lpszVarNameToReturn = ( FuncName[0]==1&&FuncName[1]==ESC_OPERATOR)?"_System_ReturnValue":FuncName;246 const char *lpszVarNameToReturn = (procName[0]==1&&procName[1]==ESC_OPERATOR)?"_System_ReturnValue":procName.c_str(); 336 247 337 248 //パラメータをレジスタとスタックに格納 … … 343 254 int nCountOfNowTempObjects = 0; 344 255 for(i2=ParmsNum-1;i2>=0;i2--){ 345 if(bEllipse&&i2<= pi_num-2) bEllipse=0;346 347 if(i2==0 &&ppi[i2].name){348 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){256 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 257 258 if(i2==0){ 259 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 349 260 //オブジェクトメンバの第一パラメータのThisポインタ 350 261 continue; 351 262 } 352 263 } 353 if( (i2==0||i2==1)&&ppi[i2].name){354 if( lstrcmp(ppi[i2].name,lpszVarNameToReturn)==0){264 if(i2==0||i2==1){ 265 if( params[i2]->GetVarName() == lpszVarNameToReturn ){ 355 266 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 356 267 continue; … … 358 269 } 359 270 360 T YPEINFODummyTypeInfo;271 Type DummyTypeInfo; 361 272 BOOL bByVal; 362 273 if(bEllipse){ … … 365 276 } 366 277 else{ 367 DummyTypeInfo.type=p pi[i2].type;368 DummyTypeInfo.u.lpIndex=p pi[i2].u.index;369 bByVal =ppi[i2].bByVal;278 DummyTypeInfo.type=params[i2]->GetBasicType(); 279 DummyTypeInfo.u.lpIndex=params[i2]->GetIndex(); 280 bByVal = (params[i2]->IsRef() == false ) ? TRUE:FALSE; 370 281 } 371 282 … … 375 286 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){ 376 287 char temp2[255]; 377 sprintf(temp2,"%s関数の第%dパラメータ", FuncName,i2+1);288 sprintf(temp2,"%s関数の第%dパラメータ",procName,i2+1); 378 289 SetError(19,temp2,cp); 379 290 continue; … … 417 328 CalcType, 418 329 lpCalcIndex, 419 FuncName,330 procName.c_str(), 420 331 i3); 421 332 } … … 530 441 return ParmSize; 531 442 } 532 int ParamImpl::SetParameter( const char *procName, const Parameters ¶ms, int SecondParmNum ){533 ///////////////////////////////////////////////////////////534 // パラメータをレジスタ及びスタックフレームにセット535 ///////////////////////////////////////////////////////////536 int i2,i3;537 538 BOOL bEllipse;539 if( params.size() ){540 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1;541 else bEllipse=0;542 }543 else bEllipse=0;544 545 BOOL bHas_System_LocalThis=0;546 if(ParmsNum>=1){547 if( params[0]->GetVarName() == "_System_LocalThis" ){548 bHas_System_LocalThis=1;549 }550 }551 552 //戻り値用の変数名を取得553 const char *lpszVarNameToReturn = (procName[0]==1&&procName[1]==ESC_OPERATOR)?"_System_ReturnValue":procName;554 555 //パラメータをレジスタとスタックに格納556 int CalcType;557 LONG_PTR lpCalcIndex;558 BOOL bCalcUseHeap;559 int ParmSize=0;560 RELATIVE_VAR RelativeVar;561 int nCountOfNowTempObjects = 0;562 for(i2=ParmsNum-1;i2>=0;i2--){563 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0;564 565 if(i2==0){566 if( params[i2]->GetVarName() == "_System_LocalThis" ){567 //オブジェクトメンバの第一パラメータのThisポインタ568 continue;569 }570 }571 if(i2==0||i2==1){572 if( params[i2]->GetVarName() == lpszVarNameToReturn ){573 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト574 continue;575 }576 }577 578 TYPEINFO DummyTypeInfo;579 BOOL bByVal;580 if(bEllipse){581 DummyTypeInfo.type=NumOpe_GetType_Old(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);582 bByVal=1;583 }584 else{585 DummyTypeInfo.type=params[i2]->GetBasicType();586 DummyTypeInfo.u.lpIndex=params[i2]->GetIndex();587 bByVal = (params[i2]->IsRef() == false ) ? TRUE:FALSE;588 }589 590 if(bByVal==1){591 //値参照592 593 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){594 char temp2[255];595 sprintf(temp2,"%s関数の第%dパラメータ",procName,i2+1);596 SetError(19,temp2,cp);597 continue;598 }599 600 if(DummyTypeInfo.type==DEF_STRUCT){601 SetStructParameter(DummyTypeInfo.u.pobj_Class,Parms[i2]);602 goto next;603 }604 605 606 extern LONG_PTR ProcPtr_BaseIndex;607 LONG_PTR back_ProcPtr_BaseIndex;608 back_ProcPtr_BaseIndex=ProcPtr_BaseIndex;609 if(DummyTypeInfo.type==DEF_PTR_PROC) ProcPtr_BaseIndex=DummyTypeInfo.u.lpIndex;610 else ProcPtr_BaseIndex=-1;611 612 CalcType=NumOpe(Parms[i2],DummyTypeInfo.type,DummyTypeInfo.u.lpIndex,&lpCalcIndex,&bCalcUseHeap);613 614 ProcPtr_BaseIndex=back_ProcPtr_BaseIndex;615 616 if(CalcType==-1) break;617 618 if(CalcType==DEF_OBJECT){619 if( DummyTypeInfo.type != DEF_OBJECT620 ||621 DummyTypeInfo.type == DEF_OBJECT &&622 !DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpCalcIndex ) ){623 //キャスト演算子のオーバーロードに対応する624 CallCastOperatorProc(CalcType,lpCalcIndex,bCalcUseHeap,DummyTypeInfo.type,DummyTypeInfo.u.lpIndex);625 }626 }627 628 if(!bEllipse){629 //型チェック630 if(bHas_System_LocalThis) i3=i2-1;631 else i3=i2;632 CheckDifferentType(633 DummyTypeInfo.type,634 DummyTypeInfo.u.lpIndex,635 CalcType,636 lpCalcIndex,637 procName,638 i3);639 }640 641 if(DummyTypeInfo.type==DEF_DOUBLE){642 ChangeTypeToDouble(CalcType);643 ParmSize+=sizeof(long)*2;644 }645 else if(DummyTypeInfo.type==DEF_SINGLE){646 ChangeTypeToSingle(CalcType);647 ParmSize+=sizeof(long);648 }649 else if(DummyTypeInfo.type==DEF_INT64||DummyTypeInfo.type==DEF_QWORD){650 ChangeTypeToInt64(CalcType);651 ParmSize+=sizeof(long)*2;652 }653 else if(DummyTypeInfo.type==DEF_LONG||DummyTypeInfo.type==DEF_DWORD||DummyTypeInfo.type==DEF_OBJECT||DummyTypeInfo.type==DEF_STRUCT||654 (IsPtrType(DummyTypeInfo.type)/*&&DummyTypeInfo.type!=DEF_PTR_VOID&&DummyTypeInfo.type!=DEF_PTR_BYTE*/)){655 ChangeTypeToLong(CalcType);656 ParmSize+=sizeof(long);657 }658 else if(DummyTypeInfo.type==DEF_INTEGER||DummyTypeInfo.type==DEF_WORD || (isUnicode&&DummyTypeInfo.type==DEF_CHAR)){659 ChangeTypeToInteger(CalcType);660 ParmSize+=sizeof(long);661 }662 else if(DummyTypeInfo.type==DEF_SBYTE||DummyTypeInfo.type==DEF_BYTE||DummyTypeInfo.type==DEF_BOOLEAN || (isUnicode==false&&DummyTypeInfo.type==DEF_CHAR)){663 ChangeTypeToByte(CalcType);664 ParmSize+=sizeof(long);665 }666 else{667 SetError(300,NULL,cp);668 }669 }670 else{671 //ポインタ参照672 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){673 //ポインタ指定674 i3=NumOpe(Parms[i2]+2,0,0,0);675 676 ChangeTypeToLong(i3);677 }678 else{679 if( useTempParameters[i2] ){680 //一時オブジェクトをコピー681 682 if( types[i2].type != DEF_STRUCT ){683 // 一時参照のための領域を考慮する684 nCountOfNowTempObjects++;685 }686 687 nCountOfNowTempObjects++;688 689 //mov eax, dword ptr[esp+offset]690 op_mov_RM(691 sizeof(long),692 REG_EAX,693 REG_ESP,694 ( ( ParmsNum - i2 - 1 ) + ( nCountOfTempObjects - nCountOfNowTempObjects ) ) * PTR_SIZE,695 MOD_BASE_DISP32 );696 697 //push eax698 op_push(REG_EAX);699 }700 else{701 //変数のアドレスを取得702 int VarType;703 LONG_PTR lpVarIndex;704 if(GetVarOffset(705 false,706 false,707 Parms[i2],708 &VarType,709 &RelativeVar,710 &lpVarIndex)){711 if(DummyTypeInfo.type!=DEF_ANY){712 //型チェックを行う713 if(DummyTypeInfo.type==VarType){714 if(DummyTypeInfo.type==DEF_OBJECT){715 if( !DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpVarIndex ) ){716 SetError(11,Parms[i2],cp);717 }718 }719 else if(DummyTypeInfo.type==DEF_STRUCT){720 if( !DummyTypeInfo.u.pobj_Class->IsEquals( (CClass *)lpVarIndex ) ){721 SetError(11,Parms[i2],cp);722 }723 }724 }725 else if((VarType&FLAG_PTR)&&((int)(VarType^FLAG_PTR)==DummyTypeInfo.type)){726 //仮引数がポインタ参照で、実引数が配列の先頭ポインタのとき727 }728 else{729 SetError(11,Parms[i2],cp);730 }731 }732 733 //変数アドレスをレジスタにセット734 SetVarPtrToEax(&RelativeVar);735 736 //push eax737 op_push(REG_EAX);738 }739 }740 }741 742 ParmSize+=PTR_SIZE;743 }744 745 next:;746 }747 748 return ParmSize;749 } -
BasicCompiler32/Compile_Calc.cpp
r67 r75 415 415 int i,i2,i3; 416 416 char variable[VN_SIZE]; 417 418 419 420 ////////////////////////////////////// 421 // インクリメント・デクリメント 422 ////////////////////////////////////// 417 423 418 424 for(i=0;;i++){ … … 465 471 } 466 472 467 LONG_PTR lp; 468 if(GetVarType(variable,&lp,0)!=-1){ 473 if(GetVarType(variable,Type(),0)){ 469 474 //変数リストに該当したとき 470 475 SetError(1,NULL,cp); … … 510 515 511 516 char ObjName[VN_SIZE],array_element[VN_SIZE]; 512 CClass *pobj_c;513 517 GetArrayElement(variable,ObjName,array_element); 514 518 if(array_element[0]){ 515 i2=GetVarType(ObjName,(LONG_PTR *)&pobj_c,0);516 if( i2==DEF_OBJECT){519 Type varType; 520 if( GetVarType(ObjName,varType,0) && varType.IsObject() ){ 517 521 char temporary[VN_SIZE]; 518 522 sprintf(temporary,"%s.%c%c%c",ObjName,1,ESC_OPERATOR,CALC_ARRAY_SET); … … 522 526 523 527 int idProc; 524 void *p Info;525 idProc=GetProc(temporary, &pInfo);528 void *pProc; 529 idProc=GetProc(temporary,(void **)&pProc); 526 530 if(idProc){ 527 CallProc(idProc,p Info,temporary,temp2,NULL);531 CallProc(idProc,pProc,temporary,temp2,Type()); 528 532 return; 529 533 } … … 542 546 //////////////////////////////////////// 543 547 544 int VarType,CalcType; 545 LONG_PTR lpVarIndex,lpCalcIndex; 548 Type varType; 549 550 //型を識別 551 if( !GetVarType(variable,varType,false) ){ 552 553 // プロパティ用のメソッドを呼び出す 554 if(!CallPropertyMethod( variable, Command+i+1, Type() )){ 555 //エラーを表示 556 GetVarType(variable,varType,true); 557 } 558 559 return; 560 } 561 562 extern LONG_PTR ProcPtr_BaseIndex; 563 if(varType.IsProcPtr()) ProcPtr_BaseIndex=varType.GetIndex(); 564 else ProcPtr_BaseIndex=-1; 565 546 566 RELATIVE_VAR VarRelativeVar; 547 BOOL bCalcUseHeap; 548 549 //型を識別 550 VarType=GetVarType(variable,&lpVarIndex,0); 551 if(VarType==-1){ 552 553 // プロパティ用のメソッドを呼び出す 554 if(!CallPropertyMethod(variable,Command+i+1,NULL)){ 555 //エラーを表示 556 GetVarType(variable,&lpVarIndex,1); 557 } 558 559 return; 560 } 561 562 extern LONG_PTR ProcPtr_BaseIndex; 563 if(VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex; 564 else ProcPtr_BaseIndex=-1; 565 566 if(VarType==DEF_STRUCT){ 567 if( varType.IsStruct() ){ 567 568 //代入コピーに備える 568 569 … … 570 571 if(!GetVarOffsetReadWrite( 571 572 variable, 572 &VarType,573 573 &VarRelativeVar, 574 &lpVarIndex)) return;574 varType)) return; 575 575 576 576 SetVarPtrToEax(&VarRelativeVar); … … 582 582 583 583 //NumOpe...(スタックに答えが格納される) 584 CalcType=NumOpe(Command+i+1,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap); 585 if(VarType==-1||CalcType==-1) return; 584 BOOL bCalcUseHeap; 585 Type calcType; 586 if( !NumOpe(Command+i+1,varType,calcType,&bCalcUseHeap) ){ 587 return; 588 } 586 589 587 590 //変数アドレスを取得 588 591 if(!GetVarOffsetReadWrite( 589 592 variable, 590 &VarType,591 593 &VarRelativeVar, 592 &lpVarIndex)) return;593 594 if( VarType&FLAG_PTR){594 varType)) return; 595 596 if(varType.GetBasicType()&FLAG_PTR){ 595 597 SetError(14,variable,cp); 596 598 return; 597 599 } 598 600 599 if( VarType==DEF_STRUCT){600 // オブジェクトインスタンスへの代入601 SetStructVariable( lpVarIndex,CalcType,lpCalcIndex,bCalcUseHeap);601 if( varType.IsStruct() ){ 602 //構造体インスタンスへの代入 603 SetStructVariable(varType,calcType,bCalcUseHeap); 602 604 return; 603 605 } 604 606 605 if( CalcType==DEF_OBJECT && (CalcType!=VarType || lpCalcIndex!=lpVarIndex) ){607 if( calcType.IsObject() && !calcType.Equals( varType ) ){ 606 608 //キャスト演算子のオーバーロードに対応する 607 CallCastOperatorProc( CalcType,lpCalcIndex,bCalcUseHeap,VarType,lpVarIndex);609 CallCastOperatorProc(calcType,bCalcUseHeap,varType); 608 610 } 609 611 … … 614 616 ///////////////////////////////// 615 617 616 CheckDifferentType( VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);618 CheckDifferentType(varType,calcType,0,0); 617 619 618 620 … … 622 624 623 625 //eax、edx:eax、またはst(0)にスタック上のデータを取り出す 624 RestoreDefaultRegisterFromStackMemory( CalcType ); 625 626 SetVariableFromEax( VarType, CalcType, &VarRelativeVar ); 627 /* 628 TODO: 消す 629 if(VarType==DEF_BOOLEAN){ 630 //bool 631 SetBooleanVariable(CalcType,&VarRelativeVar); 632 } 633 else if(VarType==DEF_SBYTE||VarType==DEF_BYTE || (isUnicode==false&&VarType==DEF_CHAR)){ 634 //8ビット整数型変数へスタックの内容を格納する 635 Set8Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 636 } 637 else if(VarType==DEF_INTEGER||VarType==DEF_WORD || (isUnicode&&VarType==DEF_CHAR)){ 638 //16ビット整数型変数へスタックの内容を格納する 639 Set16Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 640 } 641 else if(VarType==DEF_LONG||VarType==DEF_DWORD||IsPtrType(VarType)){ 642 //32ビット整数型変数へスタックの内容を格納する 643 if(VarType==DEF_LONG) 644 SetLongVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 645 else 646 SetDWordVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 647 } 648 else if(VarType==DEF_INT64||VarType==DEF_QWORD){ 649 //64ビット整数型変数へスタックの内容を格納する 650 SetInt64Variable(CalcType,&VarRelativeVar); 651 } 652 else if(VarType==DEF_DOUBLE){ 653 //Double型変数へスタックの内容を格納する 654 SetDoubleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 655 } 656 else if(VarType==DEF_SINGLE){ 657 //Single型変数へスタックの内容を格納する 658 SetSingleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 659 }*/ 660 } 661 662 663 // TODO: 消す 664 /* 665 void SetRefVariable( const char *varname, const char *expression ){ 666 //////////////////////////////////////// 667 // 変数のタイプ型を識別して、演算を行う 668 //////////////////////////////////////// 669 670 int VarType,CalcType; 671 LONG_PTR lpVarIndex,lpCalcIndex; 672 RELATIVE_VAR VarRelativeVar; 673 BOOL bCalcUseHeap; 674 675 //型を識別 676 VarType=GetVarType(varname,&lpVarIndex,0); 677 if(VarType==-1){ 678 SetError(300,NULL,cp); 679 return; 680 } 681 682 extern LONG_PTR ProcPtr_BaseIndex; 683 if(VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex; 684 else ProcPtr_BaseIndex=-1; 685 686 if(VarType==DEF_OBJECT){ 687 //代入演算のオーバーロード オペレータに備える 688 689 //変数アドレスを取得 690 if(!GetVarOffsetReadWrite( 691 varname, 692 &VarType, 693 &VarRelativeVar, 694 &lpVarIndex)) return; 695 696 SetVarPtrToEax(&VarRelativeVar); 697 698 //push eax 699 op_push(REG_EAX); 700 } 701 702 703 //NumOpe...(スタックに答えが格納される) 704 CalcType=NumOpe(expression,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap); 705 if(VarType==-1||CalcType==-1) return; 706 707 //変数アドレスを取得 708 if(!GetVarOffsetReadWrite( 709 varname, 710 &VarType, 711 &VarRelativeVar, 712 &lpVarIndex)) return; 713 714 if(VarType&FLAG_PTR){ 715 SetError(14,varname,cp); 716 return; 717 } 718 719 720 if( VarType == DEF_OBJECT 721 && (VarRelativeVar.dwKind == VAR_REFLOCAL || VarRelativeVar.dwKind == VAR_REFGLOBAL ) ){ 722 // 参照型オブジェクトへの代入(初期化)はポインタ変数と同様の処理に値する 723 PTR_LEVEL_UP( VarType ); 724 725 if( VarRelativeVar.dwKind == VAR_REFGLOBAL ){ 726 VarRelativeVar.dwKind = VAR_GLOBAL; 727 } 728 else if( VarRelativeVar.dwKind == VAR_REFLOCAL ){ 729 VarRelativeVar.dwKind = VAR_LOCAL; 730 } 731 732 if( CalcType == DEF_OBJECT ){ 733 //右辺値が実体オブジェクトのときは、参照をコピー 734 PTR_LEVEL_UP( CalcType ); 735 } 736 } 737 else{ 738 SetError(300,NULL,cp); 739 } 740 741 742 ///////////////////////////////// 743 // 右辺、左辺の型チェックを行う 744 ///////////////////////////////// 745 746 CheckDifferentType(VarType,lpVarIndex,CalcType,lpCalcIndex,0,0); 747 748 749 ///////////////////////////////////////////////// 750 // スタックの内容を変数にコピーするコードを抽出 751 ///////////////////////////////////////////////// 752 753 if(VarType==DEF_BOOLEAN){ 754 //bool 755 SetBooleanVariable(CalcType,&VarRelativeVar); 756 } 757 else if(VarType==DEF_SBYTE||VarType==DEF_BYTE || (isUnicode==false&&VarType==DEF_CHAR)){ 758 //8ビット整数型変数へスタックの内容を格納する 759 Set8Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 760 } 761 else if(VarType==DEF_INTEGER||VarType==DEF_WORD || (isUnicode&&VarType==DEF_CHAR)){ 762 //16ビット整数型変数へスタックの内容を格納する 763 Set16Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 764 } 765 else if(VarType==DEF_LONG||VarType==DEF_DWORD||IsPtrType(VarType)){ 766 //32ビット整数型変数へスタックの内容を格納する 767 if(VarType==DEF_LONG) 768 SetLongVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 769 else 770 SetDWordVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 771 } 772 else if(VarType==DEF_INT64||VarType==DEF_QWORD){ 773 //64ビット整数型変数へスタックの内容を格納する 774 SetInt64Variable(CalcType,&VarRelativeVar); 775 } 776 else if(VarType==DEF_DOUBLE){ 777 //Double型変数へスタックの内容を格納する 778 SetDoubleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 779 } 780 else if(VarType==DEF_SINGLE){ 781 //Single型変数へスタックの内容を格納する 782 SetSingleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 783 } 784 } 785 */ 626 RestoreDefaultRegisterFromStackMemory( calcType.GetBasicType() ); 627 628 SetVariableFromEax(varType.GetBasicType(),calcType.GetBasicType(),&VarRelativeVar); 629 } -
BasicCompiler32/Compile_CallProc.cpp
r73 r75 8 8 void Call_DebugSys_SaveContext(){ 9 9 //call _System_GetEip 10 extern SubInfo*pSub_System_GetEip;10 extern UserProc *pSub_System_GetEip; 11 11 op_call(pSub_System_GetEip); 12 12 … … 18 18 19 19 //call _DebugSys_SaveContext 20 extern SubInfo*pSub_DebugSys_SaveContext;20 extern UserProc *pSub_DebugSys_SaveContext; 21 21 op_call(pSub_DebugSys_SaveContext); 22 22 } … … 32 32 33 33 34 int Opcode_CallProcPtr(char *variable,char *Parameter,P ROCPTRINFO *pi,LONG_PTR *plpIndex){34 int Opcode_CallProcPtr(char *variable,char *Parameter,ProcPointer *pProcPointer,LONG_PTR *plpIndex){ 35 35 extern HANDLE hHeap; 36 36 int i; … … 52 52 53 53 //エラーチェック 54 if( !pobj_parameter->ErrorCheck(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum) ){54 if( !pobj_parameter->ErrorCheck(variable,pProcPointer->Params() ) ){ 55 55 //パラメータにエラーがあるときは処理を終える 56 return p i->ReturnType;56 return pProcPointer->ReturnType().GetBasicType(); 57 57 } 58 58 59 59 //一時オブジェクトを生成 60 pobj_parameter->NewTempParameters( variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);60 pobj_parameter->NewTempParameters( variable,pProcPointer->Params() ); 61 61 62 62 //レジスタ、スタックフレームにセット 63 pobj_parameter->SetParameter(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);63 pobj_parameter->SetParameter(variable,pProcPointer->Params() ); 64 64 65 65 … … 89 89 delete pobj_parameter; 90 90 91 if(plpIndex) *plpIndex=p i->u.ReturnIndex;92 93 return p i->ReturnType;91 if(plpIndex) *plpIndex=pProcPointer->ReturnType().GetIndex(); 92 93 return pProcPointer->ReturnType().GetBasicType(); 94 94 } 95 95 96 void Opcode_CallProc(const char *Parameter, SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType){96 void Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,char *ObjectName,int RefType){ 97 97 int i2; 98 98 99 if( psi->dwType==SUBTYPE_MACRO){100 if( lstrcmpi(psi->name,"Print")==0){99 if( pUserProc->IsMacro() ){ 100 if( lstrcmpi( pUserProc->GetName().c_str(), "Print" ) == 0 ){ 101 101 Opcode_Print(Parameter,0); 102 102 return; 103 103 } 104 if( lstrcmpi(psi->name,"Input")==0){104 if( lstrcmpi( pUserProc->GetName().c_str(), "Input" ) == 0 ){ 105 105 Opcode_Input(Parameter); 106 106 return; 107 107 } 108 if( lstrcmpi(psi->name,"Write")==0){108 if( lstrcmpi( pUserProc->GetName().c_str(), "Write" ) == 0 ){ 109 109 Opcode_Print(Parameter,1); 110 110 return; … … 112 112 } 113 113 114 p si->bUse=1;114 pUserProc->Using(); 115 115 116 116 bool isStatic = false; 117 117 CClass *pobj_c = NULL; 118 118 CMethod *pMethod = NULL; 119 if( psi->pobj_ParentClass){119 if( pUserProc->GetParentClassPtr() ){ 120 120 //クラスのメンバ関数を呼び出す場合はアクセスチェックを行う 121 121 if(ObjectName[0]){ … … 141 141 if(dwFlags&PROCFLAG_NEW){ 142 142 //New演算子によるコンストラクタ呼び出し 143 pobj_c=p si->pobj_ParentClass;143 pobj_c=pUserProc->GetParentClassPtr(); 144 144 } 145 145 else{ … … 154 154 ///////////////////////////////// 155 155 pMethod = NULL; 156 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( p si);156 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( pUserProc ); 157 157 if( ! pMethod ){ 158 158 //動的メソッドが取得できなかったときは静的メソッドを当たる 159 pMethod = pobj_c->GetStaticMethodInfo( p si);159 pMethod = pobj_c->GetStaticMethodInfo( pUserProc ); 160 160 if( !pMethod ){ 161 161 SetError(300,NULL,cp); … … 178 178 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 179 179 if(dwAccess==ACCESS_NON){ 180 SetError(109,p si->name,cp);180 SetError(109,pUserProc->GetName(),cp); 181 181 return; 182 182 } … … 185 185 if(dwAccess==ACCESS_PRIVATE|| 186 186 dwAccess==ACCESS_NON){ 187 SetError(109,p si->name,cp);187 SetError(109,pUserProc->GetName(),cp); 188 188 return; 189 189 } 190 190 if(dwAccess==ACCESS_PROTECTED){ 191 SetError(110,p si->name,cp);191 SetError(110,pUserProc->GetName(),cp); 192 192 return; 193 193 } … … 197 197 //クラス内部からの呼び出し(継承によるACCESS_NONのみをエラーとする) 198 198 if(dwAccess==ACCESS_NON){ 199 SetError(109,p si->name,cp);199 SetError(109,pUserProc->GetName(),cp); 200 200 return; 201 201 } … … 210 210 211 211 char temporary[VN_SIZE]={0}; 212 if( p si->pobj_ParentClass&& isStatic == false ){212 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 213 213 //_System_LocalThis(第一パラメータ)のダミーを作成 214 214 lstrcpy(temporary,"0,"); … … 230 230 231 231 //エラーチェック 232 if( !pobj_parameter->ErrorCheck(p si->name,psi->realParams,psi->SecondParmNum) ){232 if( !pobj_parameter->ErrorCheck(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetSecondParmNum() ) ){ 233 233 //パラメータにエラーがあるときは処理を終える 234 234 return; 235 235 } 236 236 237 if(p si->dwType==SUBTYPE_MACRO){237 if(pUserProc->IsMacro()){ 238 238 //マクロ関数の場合は、パラメータ省略を考慮する 239 pobj_parameter->MacroParameterSupport( p si->realParams);239 pobj_parameter->MacroParameterSupport( pUserProc->RealParams() ); 240 240 } 241 241 242 242 //一時オブジェクトを生成 243 int tempSize = pobj_parameter->NewTempParameters( p si->name,psi->realParams,psi->RealSecondParmNum);243 int tempSize = pobj_parameter->NewTempParameters( pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 244 244 245 245 //レジスタ、スタックフレームにセット 246 int ParmSize; 247 ParmSize=pobj_parameter->SetParameter(psi->name,psi->realParams,psi->RealSecondParmNum); 248 249 if(psi->ReturnType==DEF_STRUCT && psi->isReturnRef == false){ 246 int ParmSize = pobj_parameter->SetParameter(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 247 248 if(pUserProc->ReturnType().IsStruct() ){ 250 249 ////////////////////////////////////////////////////// 251 250 // 戻り値に構造体インスタンスを持つ場合 … … 253 252 ////////////////////////////////////////////////////// 254 253 255 int object_size = p si->u.Return_pobj_c->GetSize();254 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 256 255 257 256 //push object_size … … 259 258 260 259 //call calloc 261 extern SubInfo*pSub_calloc;260 extern UserProc *pSub_calloc; 262 261 op_call(pSub_calloc); 263 262 … … 267 266 268 267 269 if( p si->pobj_ParentClass&& isStatic == false ){268 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 270 269 ////////////////////////////////////////////////////// 271 270 // メンバ関数の場合 … … 310 309 } 311 310 312 if( psi->bVirtual){311 if( pUserProc->IsVirtual() ){ 313 312 //仮想関数(オブジェクトメソッド)呼び出し 314 313 //pObj->func_table->func1 … … 320 319 OpBuffer[obp++]=(char)0x11; 321 320 322 i2 = pobj_c->GetFuncNumInVtbl( p si);321 i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 323 322 324 323 //call dword ptr[edx+func_index] … … 339 338 340 339 //call ProcAddr 341 op_call(p si);342 } 343 344 if(p si->bCdecl){340 op_call(pUserProc); 341 } 342 343 if(pUserProc->IsCdecl()){ 345 344 //add esp,ParmSize 346 345 op_add_esp(ParmSize); … … 354 353 } 355 354 356 int Opcode_CallDllProc(char *Parameter,D ECLAREINFO *pdi,LONG_PTR *plpIndex){355 int Opcode_CallDllProc(char *Parameter,DllProc *pDllProc,LONG_PTR *plpIndex){ 357 356 char *temporary; 358 357 … … 361 360 extern BOOL bDebugCompile; 362 361 extern BOOL bDebugSupportProc; 363 if(bDebugCompile&&bDebugSupportProc==0&& lstrcmp(pdi->name,"DebugBreak")!=0)362 if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->GetName() != "DebugBreak" ){ 364 363 Call_DebugSys_SaveContext(); 365 366 pdi->bUse=1; 364 } 367 365 368 366 … … 376 374 377 375 //エラーチェック 378 if( !pobj_parameter->ErrorCheck( pdi->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum) ){376 if( !pobj_parameter->ErrorCheck( pDllProc->GetName(), pDllProc->Params() ) ){ 379 377 //パラメータにエラーがあるときは処理を終える 380 return p di->ReturnType;378 return pDllProc->ReturnType().GetBasicType(); 381 379 } 382 380 383 381 //一時オブジェクトを生成 384 pobj_parameter->NewTempParameters( p di->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum);382 pobj_parameter->NewTempParameters( pDllProc->GetName(), pDllProc->Params() ); 385 383 386 384 //レジスタ、スタックフレームにセット 387 int ParmSize; 388 ParmSize=pobj_parameter->SetParameter(pdi->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum); 385 int ParmSize = pobj_parameter->SetParameter(pDllProc->GetName(), pDllProc->Params() ); 389 386 390 387 … … 392 389 393 390 //call dword ptr[LookupTable] 391 pDllProc->Using(); 394 392 OpBuffer[obp++]=(char)0xFF; 395 393 OpBuffer[obp++]=(char)0x15; 396 pobj_ImportAddrSchedule->add(p di);394 pobj_ImportAddrSchedule->add(pDllProc); 397 395 obp+=sizeof(long); 398 396 399 if(p di->bCdecl){397 if(pDllProc->IsCdecl()){ 400 398 //add esp,ParmSize 401 399 op_add_esp(ParmSize); … … 408 406 delete pobj_parameter; 409 407 410 if(plpIndex) *plpIndex=p di->u.ReturnIndex;408 if(plpIndex) *plpIndex=pDllProc->ReturnType().GetIndex(); 411 409 412 410 HeapDefaultFree(temporary); 413 411 414 return p di->ReturnType;412 return pDllProc->ReturnType().GetBasicType(); 415 413 } -
BasicCompiler32/Compile_Func.cpp
r73 r75 207 207 } 208 208 209 T YPEINFOTypeInfo={type,lpIndex};209 Type TypeInfo={type,lpIndex}; 210 210 if(IsStringObjectType(TypeInfo)){ 211 211 //Stringオブジェクトの場合 … … 243 243 void Opcode_Func_AddressOf(const char *name){ 244 244 extern int cp; 245 SubInfo *psi;245 UserProc *pUserProc; 246 246 247 247 extern LONG_PTR ProcPtr_BaseIndex; … … 249 249 //左辺の型にのっとり、オーバーロードを解決 250 250 251 std::vector< SubInfo*> subs;251 std::vector<UserProc *> subs; 252 252 GetOverloadSubHash( name, subs ); 253 253 if( subs.size() == 0 ){ … … 257 257 258 258 //オーバーロードを解決 259 extern P ROCPTRINFO *pProcPtrInfo;260 p si=OverloadSolution(name,subs,pProcPtrInfo[ProcPtr_BaseIndex].pParmInfo,pProcPtrInfo[ProcPtr_BaseIndex].ParmNum,NULL);261 262 if(!p si){259 extern ProcPointer **ppProcPtrInfo; 260 pUserProc=OverloadSolution(name,subs,ppProcPtrInfo[ProcPtr_BaseIndex]->Params(), Type() ); 261 262 if(!pUserProc){ 263 263 SetError(27,name,cp); 264 264 return; … … 266 266 } 267 267 else{ 268 p si=GetSubHash(name);269 if(!p si){268 pUserProc=GetSubHash(name); 269 if(!pUserProc){ 270 270 SetError(27,name,cp); 271 271 return; … … 273 273 } 274 274 275 276 if(psi->bVirtual){ 275 if( pUserProc->IsVirtual() ){ 277 276 /////////////////////////////// 278 277 // 仮想関数の場合 … … 324 323 OpBuffer[obp++]=(char)0x11; 325 324 326 int i2 = pobj_c->GetFuncNumInVtbl( p si);325 int i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 327 326 328 327 //mov eax,dword ptr[edx+func_index] … … 339 338 //mov eax,ProcAddr 340 339 OpBuffer[obp++]=(char)0xB8; 341 pobj_SubAddrSchedule->add(p si,0);340 pobj_SubAddrSchedule->add(pUserProc,0); 342 341 obp+=sizeof(long); 343 342 } 344 343 345 p si->bUse=1;344 pUserProc->Using(); 346 345 } 347 346 void Opcode_Func_SizeOf(const char *Parameter){ … … 361 360 op_mov_RV( REG_EAX, size ); 362 361 } 363 void Opcode_Func_VarPtr( const char *Parameter, T YPEINFO&ReturnTypeInfo ){362 void Opcode_Func_VarPtr( const char *Parameter, Type &ReturnTypeInfo ){ 364 363 RELATIVE_VAR RelativeVar; 365 364 … … 439 438 } 440 439 441 void Opcode_CallFunc( const char *Parameter, const int FuncNum, T YPEINFO&ReturnTypeInfo ){440 void Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo ){ 442 441 switch(FuncNum){ 443 442 case FUNC_FIX: -
BasicCompiler32/Compile_Object.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 void _call_constructor( CClass *pobj_c, const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){4 void _call_constructor( const CClass *pobj_c, const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){ 5 5 //////////////////////////// 6 6 // コンストラクタの呼び出し … … 31 31 //////////////////////// 32 32 33 std::vector< SubInfo*> subs;33 std::vector<UserProc *> subs; 34 34 pobj_c->EnumMethod( pobj_c->name, subs ); 35 35 36 SubInfo *psi;36 UserProc *pUserProc; 37 37 if( subs.size() > 0 ){ 38 38 //オーバーロードを解決 39 p si=OverloadSolutionWithStrParam(pobj_c->name,40 subs,CreateParameter,"" ,NULL);41 42 if(!p si) return;39 pUserProc=OverloadSolutionWithStrParam(pobj_c->name, 40 subs,CreateParameter,""); 41 42 if(!pUserProc) return; 43 43 } 44 44 45 45 //コンストラクタを呼び出す 46 46 Opcode_CallProc(CreateParameter, 47 p si,47 pUserProc, 48 48 PROCFLAG_NEW,"",0); 49 49 … … 74 74 } 75 75 } 76 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo){76 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType ){ 77 77 int typeSize = classObj.GetSize(); 78 78 … … 82 82 } 83 83 84 BOOL bSomeObjects=0; 84 85 if(objectSizeStr[0]){ 85 int type = NumOpe(objectSizeStr,0,0,0); 86 ChangeTypeToLong(type); 86 bSomeObjects=1; 87 88 Type tempType; 89 NumOpe(objectSizeStr,Type(),tempType); 90 if( !tempType.IsWhole() ) SetError(49,NULL,cp); 91 ChangeTypeToLong(tempType.GetBasicType()); 87 92 88 93 //pop eax … … 129 134 } 130 135 131 if( baseTypeInfo.type == DEF_OBJECT ){ 132 //DeleteはGCで処理 136 if( baseType.IsObject() ){ 137 // オブジェクト インスタンス 138 // ※DeleteはGCで処理 133 139 134 140 //call _System_GC_malloc_ForObject 135 extern SubInfo*pSub_System_GC_malloc_ForObject;141 extern UserProc *pSub_System_GC_malloc_ForObject; 136 142 op_call(pSub_System_GC_malloc_ForObject); 137 143 } 138 144 else{ 139 //明示的なDeleteが必要 145 // オブジェクトポインタ 146 // ※明示的なDeleteが必要 140 147 141 148 //call _System_GC_malloc_ForObjectPtr 142 extern SubInfo*pSub_System_GC_malloc_ForObjectPtr;149 extern UserProc *pSub_System_GC_malloc_ForObjectPtr; 143 150 op_call(pSub_System_GC_malloc_ForObjectPtr); 144 151 } … … 184 191 //mov ecx,DestructorProcAddr 185 192 OpBuffer[obp++]=(char)0xB9; 186 pobj_SubAddrSchedule->add(method->p si,0);187 method->p si->bUse=1;193 pobj_SubAddrSchedule->add(method->pUserProc,0); 194 method->pUserProc->Using(); 188 195 obp+=sizeof(long); 189 196 … … 209 216 //////////////////////////// 210 217 211 BOOL bSomeObjects;212 if(objectSizeStr[0]) bSomeObjects=1;213 else bSomeObjects=0;214 218 _call_constructor(&classObj,parameter,typeSize,bSomeObjects); 215 219 } 216 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ){217 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];218 int i,i2;219 220 i=0;221 222 if(Parameter[0]=='['){223 i=GetStringInBracket(objectSizeStr,Parameter);224 225 SlideString(objectSizeStr+1,-1);226 objectSizeStr[i-2]=0;227 }228 else objectSizeStr[0]=0;229 230 for(i2=0;;i++,i2++){231 if(Parameter[i]=='('){232 TypeName[i2]=0;233 234 //コンストラクタに渡すパラメータを取得235 i2=GetStringInPare(CreateParameter,Parameter+i);236 RemoveStringPare(CreateParameter);237 i+=i2;238 if(Parameter[i]!='\0'){239 SetError(42,NULL,cp);240 return -1;241 }242 break;243 }244 TypeName[i2]=Parameter[i];245 if(Parameter[i]=='\0'){246 CreateParameter[0]=0;247 break;248 }249 }250 251 int type,TypeSize;252 type=GetTypeFixed(TypeName,plpIndex);253 if(type==-1){254 SetError(3,TypeName,cp);255 return -1;256 }257 TypeSize=GetTypeSize(type,*plpIndex);258 259 if(type!=DEF_OBJECT){260 ////////////////////////261 // 通常のデータ型の場合262 ////////////////////////263 264 SetError(121,NULL,cp);265 return -1;266 }267 268 CClass *pobj_c;269 pobj_c=(CClass *)*plpIndex;270 271 Operator_New( *pobj_c, objectSizeStr, CreateParameter, baseTypeInfo );272 273 if( baseTypeInfo.type == DEF_OBJECT ){274 return DEF_OBJECT;275 }276 return DEF_PTR_OBJECT;277 }278 279 220 void OpcodeDelete(const char *Parameter, bool isSweeping){ 280 int type;281 282 type=NumOpe(Parameter,0,0,0);283 if(type==-1) return;284 if(!( type==DEF_PTR_OBJECT||type==DEF_PTR_VOID)) SetError(122,NULL,cp);221 Type tempType; 222 if( !NumOpe(Parameter,Type(),tempType) ){ 223 return; 224 } 225 if(!( tempType.IsObjectPtr() || tempType.IsVoidPtr() )) SetError(122,NULL,cp); 285 226 286 227 //pop eax … … 376 317 if( isSweeping ){ 377 318 //call _System_GC_free_for_SweepingDelete 378 extern SubInfo*pSub_System_GC_free_for_SweepingDelete;319 extern UserProc *pSub_System_GC_free_for_SweepingDelete; 379 320 op_call(pSub_System_GC_free_for_SweepingDelete); 380 321 } 381 322 else{ 382 323 //call free 383 extern SubInfo*pSub_free;324 extern UserProc *pSub_free; 384 325 op_call(pSub_free); 385 326 } -
BasicCompiler32/Compile_ProcOp.cpp
r73 r75 3 3 4 4 5 void SystemProc( char *name){5 void SystemProc( const char *name ){ 6 6 if(lstrcmp(name,"_System_GetEip")==0){ 7 7 //mov eax,dword ptr[esp] … … 69 69 cp=GlobalVar[i].source_code_address; 70 70 71 T YPEINFOTypeInfo;71 Type TypeInfo; 72 72 TypeInfo.type=GlobalVar[i].type; 73 73 TypeInfo.u.lpIndex=GlobalVar[i].u.index; … … 214 214 } 215 215 216 void CompileBufferInProcedure( SubInfo *psi){216 void CompileBufferInProcedure(UserProc *pUserProc){ 217 217 extern char *basbuf; 218 218 extern HANDLE hHeap; 219 extern SubInfo**ppSubHash;219 extern UserProc **ppSubHash; 220 220 extern BOOL bDebugCompile; 221 221 int i3,i4,VarSize,LocalVarSchedule,EspOffsetSchedule,BufferSize,BaseOffset; … … 224 224 BufferSize=128; 225 225 226 if( psi->bUse==0||psi->bCompile) return;227 228 p si->bCompile=1;226 if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return; 227 228 pUserProc->CompleteCompile(); 229 229 230 230 extern BOOL bSystemProc; 231 if(memcmp(p si->name,"_System_",8)==0) bSystemProc=1;231 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1; 232 232 else bSystemProc=0; 233 233 234 234 extern BOOL bDebugSupportProc; 235 if(memcmp(p si->name,"_DebugSys_",10)==0){235 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){ 236 236 if(!bDebugCompile){ 237 p si->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);238 p si->VarNum=0;237 pUserProc->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 238 pUserProc->VarNum=0; 239 239 return; 240 240 } … … 243 243 else bDebugSupportProc=0; 244 244 245 p si->CompileAddress=obp;246 247 if(p si->bSystem){245 pUserProc->beginOpAddress=obp; 246 247 if(pUserProc->IsSystem()){ 248 248 extern int MaxLocalVarNum; 249 249 extern int AllLocalVarSize; … … 251 251 AllLocalVarSize=0; 252 252 253 SystemProc(p si->name);254 255 p si->EndOpAddr=obp;256 p si->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);257 p si->VarNum=0;253 SystemProc(pUserProc->GetName().c_str()); 254 255 pUserProc->endOpAddress=obp; 256 pUserProc->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 257 pUserProc->VarNum=0; 258 258 return; 259 259 } 260 260 261 cp=p si->address;261 cp=pUserProc->GetCodePos(); 262 262 for(;;cp++){ 263 263 if(IsCommandDelimitation(basbuf[cp])) break; … … 280 280 281 281 //パラメータ用の変数データを考慮 282 for(i3= psi->realParams.size()-1;i3>=0;i3--){283 Parameter ¶m = *p si->realParams[i3];282 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){ 283 Parameter ¶m = *pUserProc->RealParams()[i3]; 284 284 285 285 //変数データを追加 … … 297 297 if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT 298 298 ||LocalVar[MaxLocalVarNum].type==DEF_STRUCT){ 299 if(p si->bExport)299 if(pUserProc->IsExport()) 300 300 SetError(24,NULL,cp); 301 301 } … … 340 340 341 341 //コンパイル中の関数が属するクラス 342 pobj_CompilingClass=p si->pobj_ParentClass;342 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 343 343 344 344 //コンパイルスタートをクラス管理クラスに追加 345 pobj_DBClass->StartCompile( p si);345 pobj_DBClass->StartCompile( pUserProc ); 346 346 347 347 //コンパイル中の関数 348 extern SubInfo *pCompilingSubInfo;349 pCompiling SubInfo=psi;348 extern UserProc *pCompilingUserProc; 349 pCompilingUserProc=pUserProc; 350 350 351 351 … … 373 373 OpBuffer[obp++]=(char)0x57; 374 374 375 if( psi->ReturnType!=DEF_NON){375 if( !pUserProc->ReturnType().IsNull() ){ 376 376 //戻り値が存在するとき 377 377 378 char *temp; 379 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) temp="_System_ReturnValue"; 380 else temp=psi->name; 381 382 if(psi->ReturnType==DEF_STRUCT && psi->isReturnRef == false){ 378 const char *temp = pUserProc->GetName().c_str(); 379 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){ 380 temp = "_System_ReturnValue"; 381 } 382 383 if( pUserProc->ReturnType().IsStruct() ){ 383 384 //戻り値用の構造体(値型)はパラメータで引き渡される 384 385 } 385 386 else{ 386 387 //戻り値用の変数の定義 387 if( psi->isReturnRef ){ 388 sprintf(temporary,"%c%c",1,ESC_BYREF); 389 } 390 else temporary[0]=0; 391 392 sprintf(temporary+lstrlen(temporary),"%s%c%c",temp,1,ESC_AS); 393 GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary)); 388 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() ); 394 389 395 390 OpcodeDim(temporary,0); … … 444 439 445 440 //call _DebugSys_StartProc 446 extern SubInfo*pSub_DebugSys_StartProc;441 extern UserProc *pSub_DebugSys_StartProc; 447 442 op_call(pSub_DebugSys_StartProc); 448 443 } 449 444 450 445 if(pobj_CompilingClass){ 451 if( lstrcmp(psi->name,pobj_CompilingClass->name)==0){446 if( pUserProc->GetName() == pobj_CompilingClass->name ){ 452 447 //////////////////////////////////// 453 448 // コンストラクタをコンパイルするとき … … 497 492 498 493 Opcode_CallProc(temporary, 499 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,494 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 500 495 0, 501 496 "", … … 505 500 //基底クラスのコンストラクタを暗黙的に呼び出す 506 501 Opcode_CallProc("", 507 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,502 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 508 503 0, 509 504 "", … … 548 543 } 549 544 } 550 else if( psi->name[0]=='~'){545 else if( pUserProc->IsDestructor() ){ 551 546 //デストラクタをコンパイルしたとき 552 547 … … 559 554 ////////////////////////////////////////// 560 555 ////// プロシージャ内をコンパイル //////// 561 if(psi->dwType==SUBTYPE_SUB) CompileBuffer(ESC_ENDSUB,0); 562 else if(psi->dwType==SUBTYPE_FUNCTION) CompileBuffer(ESC_ENDFUNCTION,0); 563 else if(psi->dwType==SUBTYPE_MACRO) CompileBuffer(ESC_ENDMACRO,0); 556 if(pUserProc->IsMacro()) CompileBuffer(ESC_ENDMACRO,0); 557 else{ 558 if(pUserProc->IsSub()) CompileBuffer(ESC_ENDSUB,0); 559 else if(pUserProc->IsFunction()) CompileBuffer(ESC_ENDFUNCTION,0); 560 } 564 561 ////////////////////////////////////////// 565 562 ////////////////////////////////////////// … … 573 570 pobj_CompilingClass->NotifyFinishConstructorCompile(); 574 571 } 575 else if( psi->name[0]=='~'){572 else if( pUserProc->IsDestructor() ){ 576 573 //////////////////////////////////// 577 574 //デストラクタをコンパイルしたとき … … 588 585 if( method ){ 589 586 Opcode_CallProc("", 590 method->p si,587 method->pUserProc, 591 588 0, 592 589 "", … … 631 628 632 629 //call destructor 633 op_call( method->p si);630 op_call( method->pUserProc ); 634 631 } 635 632 } … … 666 663 HeapDefaultFree(WithInfo.pWithCp); 667 664 668 //重複エラー情報管理のメモリを解放669 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);670 HeapDefaultFree(SynonymErrorWords);671 672 665 //push ebp 673 666 AllLocalVarSize+=sizeof(long); … … 686 679 687 680 //call _DebugSys_EndProc 688 extern SubInfo*pSub_DebugSys_EndProc;681 extern UserProc *pSub_DebugSys_EndProc; 689 682 op_call(pSub_DebugSys_EndProc); 690 683 } 691 684 692 if( psi->ReturnType!=DEF_NON){685 if( !pUserProc->ReturnType().IsNull() ){ 693 686 //戻り値をeax、edxに設定 694 687 RELATIVE_VAR RelativeVar; 695 688 LONG_PTR lpIndex; 696 689 697 c har *temp;698 if( psi->name[0]==1&&psi->name[1]==ESC_OPERATOR)690 const char *temp = pUserProc->GetName().c_str(); 691 if( temp[0]==1 && temp[1]==ESC_OPERATOR ){ 699 692 temp="_System_ReturnValue"; 700 else temp=psi->name;693 } 701 694 GetVarOffsetReadWrite(temp,&i3,&RelativeVar,&lpIndex); 702 695 703 i3=p si->ReturnType;696 i3=pUserProc->ReturnType().GetBasicType(); 704 697 705 698 if(i3==DEF_OBJECT || i3==DEF_STRUCT){ … … 808 801 809 802 //call _esp_error 810 extern SubInfo*pSub_esp_error;803 extern UserProc *pSub_esp_error; 811 804 op_call( pSub_esp_error ); 812 805 … … 824 817 op_add_esp(AllLocalVarSize-BaseOffset); 825 818 826 if( BaseOffset==0||psi->bCdecl){819 if( BaseOffset==0 || pUserProc->IsCdecl() ){ 827 820 //ret 0 828 821 OpBuffer[obp++]=(char)0xC3; … … 835 828 } 836 829 837 psi->EndOpAddr=obp; 838 psi->pVar=LocalVar; 839 psi->VarNum=MaxLocalVarNum; 830 pUserProc->endOpAddress=obp; 831 pUserProc->pVar=LocalVar; 832 pUserProc->VarNum=MaxLocalVarNum; 833 834 835 //重複エラー情報管理のメモリを解放 836 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]); 837 HeapDefaultFree(SynonymErrorWords); 838 SynonymErrorWords=0; 839 840 840 841 841 //ローカル変数のネーム情報は後に解放する 842 842 } 843 843 void CompileLocal(){ 844 extern SubInfo**ppSubHash;844 extern UserProc **ppSubHash; 845 845 int i2; 846 SubInfo *psi;846 UserProc *pUserProc; 847 847 848 848 extern BOOL bDll; 849 849 if(bDll){ 850 850 //DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする 851 p si=GetSubHash("_System_InitDllGlobalVariables");852 if(p si){853 CompileBufferInProcedure(p si);851 pUserProc=GetSubHash("_System_InitDllGlobalVariables"); 852 if(pUserProc){ 853 CompileBufferInProcedure(pUserProc); 854 854 } 855 855 else SetError(300,NULL,cp); … … 858 858 //_System_InitStaticLocalVariablesは一番最後にコンパイル 859 859 //※一般関数内の静的変数オブジェクトをすべて収集しなければならない 860 extern SubInfo*pSub_System_InitStaticLocalVariables;861 pSub_System_InitStaticLocalVariables-> bCompile=1;860 extern UserProc *pSub_System_InitStaticLocalVariables; 861 pSub_System_InitStaticLocalVariables->CompleteCompile(); 862 862 863 863 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 864 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;865 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=1;864 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 865 pSub_System_Call_Destructor_of_GlobalObject->CompleteCompile(); 866 866 867 867 Repeat: 868 868 for(i2=0;i2<MAX_HASH;i2++){ 869 p si=ppSubHash[i2];870 while(p si){871 CompileBufferInProcedure(p si);872 p si=psi->pNextData;869 pUserProc=ppSubHash[i2]; 870 while(pUserProc){ 871 CompileBufferInProcedure(pUserProc); 872 pUserProc=pUserProc->pNextData; 873 873 } 874 874 } … … 876 876 //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合 877 877 for(i2=0;i2<MAX_HASH;i2++){ 878 p si=ppSubHash[i2];879 while(p si){880 if( psi->bUse&&psi->bCompile==0){878 pUserProc=ppSubHash[i2]; 879 while(pUserProc){ 880 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ 881 881 goto Repeat; 882 882 } 883 883 884 p si=psi->pNextData;884 pUserProc=pUserProc->pNextData; 885 885 } 886 886 } 887 887 888 888 //_System_InitStaticLocalVariablesは一番最後にコンパイル 889 pSub_System_InitStaticLocalVariables-> bCompile=0;889 pSub_System_InitStaticLocalVariables->KillCompileStatus(); 890 890 CompileBufferInProcedure(pSub_System_InitStaticLocalVariables); 891 891 892 892 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 893 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=0;893 pSub_System_Call_Destructor_of_GlobalObject->KillCompileStatus(); 894 894 CompileBufferInProcedure(pSub_System_Call_Destructor_of_GlobalObject); 895 895 } -
BasicCompiler32/Compile_Set_Var.cpp
r73 r75 7 7 } 8 8 9 void SetStructVariable( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap){9 void SetStructVariable( const Type &varType, const Type &calcType, BOOL bUseHeap){ 10 10 /* 11 11 TODO: 消す … … 37 37 38 38 39 if( CalcType == DEF_STRUCT ){ 40 CClass *pVarClass = (CClass *)lpVarIndex; 41 CClass *pCalcClass = (CClass *)lpCalcIndex; 42 43 44 if( pVarClass->IsEquals( pCalcClass ) ){ //等しい 39 if( calcType.IsStruct() ){ 40 if( varType.GetClass().IsEquals( &calcType.GetClass() ) ){ //等しい 45 41 46 42 //双方のオブジェクト型が一致、または派生・継承関係にあるとき 47 43 //※コピーを行う 48 44 49 int object_size = pVarClass->GetSize();45 int object_size = varType.GetClass().GetSize(); 50 46 51 47 //mov ecx,object_size … … 71 67 72 68 //call free 73 extern SubInfo*pSub_free;69 extern UserProc *pSub_free; 74 70 op_call(pSub_free); 75 71 } -
BasicCompiler32/Compile_Statement.cpp
r73 r75 5 5 int i,i2; 6 6 char buffer[8192]; 7 SubInfo *psi;7 UserProc *pUserProc; 8 8 9 9 for(i=0;;i++){ … … 41 41 ////////////////////////////// 42 42 43 p si=GetSubHash(Command);43 pUserProc=GetSubHash(Command); 44 44 45 45 //GetSubHash内でエラー提示が行われた場合 46 if(p si==(SubInfo*)-1) return;47 48 if(p si==0){46 if(pUserProc==(UserProc *)-1) return; 47 48 if(pUserProc==0){ 49 49 char temporary[VN_SIZE]; 50 50 lstrcpy(temporary,Command); 51 51 52 52 CharUpper(temporary); 53 p si=GetSubHash(temporary);53 pUserProc=GetSubHash(temporary); 54 54 55 55 //GetSubHash内でエラー提示が行われた場合 56 if(p si==(SubInfo*)-1) return;57 } 58 59 if(p si){60 if( psi->dwType!=SUBTYPE_MACRO) SetError(10,Command,cp);61 62 Opcode_CallProc("",p si,0,"",0);56 if(pUserProc==(UserProc *)-1) return; 57 } 58 59 if(pUserProc){ 60 if( !pUserProc->IsMacro() ) SetError(10,Command,cp); 61 62 Opcode_CallProc("",pUserProc,0,"",0); 63 63 64 64 return; … … 963 963 964 964 int CaseTypeSize; 965 void OpcodeSelect(c har *Parameter){965 void OpcodeSelect(const char *lpszParams){ 966 966 extern DWORD *pCaseSchedule; 967 967 extern int CaseScheduleNum; … … 987 987 988 988 LONG_PTR lpIndex; 989 type1=NumOpe( Parameter,0,0,&lpIndex);989 type1=NumOpe(lpszParams,0,0,&lpIndex); 990 990 if(type1==DEF_INTEGER|| 991 991 type1==DEF_WORD|| … … 1076 1076 pobj_c=(CClass *)lpIndex; 1077 1077 1078 std::vector< SubInfo*> subs;1078 std::vector<UserProc *> subs; 1079 1079 pobj_c->EnumMethod( CALC_EQUAL, subs ); 1080 1080 if( subs.size() == 0 ){ … … 1082 1082 } 1083 1083 1084 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 1085 int iParmNum=0; 1086 ppi[iParmNum].bArray=0; 1087 ppi[iParmNum].bByVal=0; 1088 ppi[iParmNum].name=0; 1089 ppi[iParmNum].type=type2; 1090 ppi[iParmNum].u.index=lpIndex2; 1091 ppi[iParmNum].SubScripts[0]=-1; 1092 iParmNum++; 1084 Parameters params; 1085 params.push_back( new Parameter( "", Type( type2, lpIndex2 ) ) ); 1093 1086 1094 1087 //オーバーロードを解決 1095 SubInfo *psi; 1096 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL); 1097 HeapDefaultFree(ppi); 1098 1099 if(!psi){ 1088 UserProc *pUserProc; 1089 pUserProc=OverloadSolution("==",subs, params, NULL); 1090 1091 delete params[0]; 1092 1093 if(!pUserProc){ 1100 1094 //エラー 1101 1095 return; … … 1116 1110 1117 1111 //call operator_proc ※ ==演算子 1118 op_call(p si);1112 op_call(pUserProc); 1119 1113 1120 1114 //test eax,eax … … 1330 1324 //戻り値をセット 1331 1325 if(Parameter[0]){ 1332 extern SubInfo *pCompilingSubInfo; 1333 char *temp; 1334 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR) 1335 temp="_System_ReturnValue"; 1336 else temp=pCompilingSubInfo->name; 1337 1338 /* 1339 TODO: 消す 1340 if( pCompilingSubInfo->isReturnRef ){ 1341 //参照型 1342 SetRefVariable( temp, Parameter ); 1343 } 1344 else{ 1345 //値型*/ 1346 char temporary[VN_SIZE]; 1347 sprintf(temporary,"%s=%s",temp,Parameter); 1348 OpcodeCalc(temporary); 1349 //} 1326 extern UserProc *pCompilingUserProc; 1327 const char *temp = "_System_ReturnValue"; 1328 if(pCompilingUserProc->GetName()[0]==1&&pCompilingUserProc->GetName()[1]==ESC_OPERATOR) 1329 { 1330 } 1331 else temp=pCompilingUserProc->GetName().c_str(); 1332 1333 char temporary[VN_SIZE]; 1334 sprintf(temporary,"%s=%s",temp,Parameter); 1335 OpcodeCalc(temporary); 1350 1336 } 1351 1337 … … 1460 1446 OpcodeCalc(temp2); 1461 1447 1462 SubInfo *psi;1463 if(bFile) p si=GetSubHash("INPUT_FromFile");1464 else p si=GetSubHash("INPUT_FromPrompt");1465 if(!p si){1448 UserProc *pUserProc; 1449 if(bFile) pUserProc=GetSubHash("INPUT_FromFile"); 1450 else pUserProc=GetSubHash("INPUT_FromPrompt"); 1451 if(!pUserProc){ 1466 1452 SetError(3,"Input",cp); 1467 1453 return; 1468 1454 } 1469 Opcode_CallProc(buffer,p si,0,"",0);1455 Opcode_CallProc(buffer,pUserProc,0,"",0); 1470 1456 } 1471 1457 void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){ … … 1562 1548 OpcodeCalc(temp2); 1563 1549 1564 SubInfo *psi;1565 if(bFile) p si=GetSubHash("PRINTUSING_ToFile");1566 else p si=GetSubHash("PRINTUSING_ToPrompt");1567 if(!p si){1550 UserProc *pUserProc; 1551 if(bFile) pUserProc=GetSubHash("PRINTUSING_ToFile"); 1552 else pUserProc=GetSubHash("PRINTUSING_ToPrompt"); 1553 if(!pUserProc){ 1568 1554 SetError(3,"Print",cp); 1569 1555 return; 1570 1556 } 1571 Opcode_CallProc(buffer,p si,0,"",0);1557 Opcode_CallProc(buffer,pUserProc,0,"",0); 1572 1558 } 1573 1559 void Opcode_Print(const char *Parameter,BOOL bWrite){ … … 1666 1652 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\""); 1667 1653 1668 SubInfo *psi;1669 if(bFile) p si=GetSubHash("PRINT_ToFile");1670 else p si=GetSubHash("PRINT_ToPrompt");1671 if(!p si){1654 UserProc *pUserProc; 1655 if(bFile) pUserProc=GetSubHash("PRINT_ToFile"); 1656 else pUserProc=GetSubHash("PRINT_ToPrompt"); 1657 if(!pUserProc){ 1672 1658 SetError(3,"Print",cp); 1673 1659 return; 1674 1660 } 1675 Opcode_CallProc(buffer,p si,0,"",0);1661 Opcode_CallProc(buffer,pUserProc,0,"",0); 1676 1662 } 1677 1663 -
BasicCompiler32/Compile_Var.cpp
r73 r75 11 11 int AllLocalVarSize; 12 12 13 void SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){ 14 int i2; 15 13 void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){ 16 14 PushLongVariable(pRelativeVar); 17 15 18 i2=NumOpe(lpPtrOffset,0,0,0); 19 ChangeTypeToLong(i2); 16 Type type; 17 NumOpe( lpPtrOffset, Type(), type ); 18 ChangeTypeToLong( type.GetBasicType() ); 20 19 21 20 //pop ebx 22 21 op_pop(REG_EBX); 23 22 24 if( PTR_LEVEL(*pType)){25 *pType = PTR_LEVEL_DOWN( *pType);26 27 i 2=GetTypeSize(*pType,lpIndex);28 if( i2>=2){23 if( resultType.PtrLevel() ){ 24 resultType.PtrLevelDown(); 25 26 int typeSize = resultType.GetSize(); 27 if(typeSize>=2){ 29 28 //imul ebx,i2 30 op_imul_RV( REG_EBX, i2);29 op_imul_RV( REG_EBX, typeSize ); 31 30 } 32 31 } … … 58 57 } 59 58 } 60 BOOL GetArrayOffset(int *SubScripts,char *array,int type,LONG_PTR lpIndex){59 bool GetArrayOffset(const int *SubScripts,char *array, const Type &type){ 61 60 extern HANDLE hHeap; 62 int i,i2,i3,i4 ,TypeSize;61 int i,i2,i3,i4; 63 62 char temporary[VN_SIZE],*pParm[MAX_PARMS]; 64 63 … … 110 109 111 110 for(i=i3-1;i>=0;i--){ 112 T YPEINFO TypeInfo;111 Type tempType; 113 112 BOOL bUseHeap; 114 TypeInfo.type=NumOpe(pParm[i],DEF_LONG,-1,&TypeInfo.u.lpIndex,&bUseHeap);115 if( TypeInfo.type==DEF_OBJECT){113 NumOpe( pParm[i], Type( DEF_LONG ), tempType, &bUseHeap ); 114 if( tempType.IsObject() ){ 116 115 //キャスト演算子のオーバーロードに対応する 117 116 CallCastOperatorProc( 118 TypeInfo.type,TypeInfo.u.lpIndex,119 bUseHeap, DEF_LONG,-1);120 TypeInfo.type=DEF_LONG;121 } 122 ChangeTypeToLong( TypeInfo.type);117 tempType, 118 bUseHeap, Type(DEF_LONG) ); 119 tempType.SetBasicType( DEF_LONG ); 120 } 121 ChangeTypeToLong( tempType.GetBasicType() ); 123 122 124 123 //pop eax … … 144 143 op_pop(REG_EAX); 145 144 146 TypeSize=GetTypeSize(type,lpIndex);147 148 145 //imul eax,TypeSize 149 146 OpBuffer[obp++]=(char)0x69; 150 147 OpBuffer[obp++]=(char)0xC0; 151 *((long *)(OpBuffer+obp)) =TypeSize;148 *((long *)(OpBuffer+obp)) = type.GetSize(); 152 149 obp+=sizeof(long); 153 150 … … 161 158 return 1; 162 159 } 163 BOOL GetMemberOffset(bool isErrorEnabled, bool isWriteAccess, CClass *pobj_c, char *member, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpNestIndex, BOOL bPrivateAccess){160 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 164 161 int i; 165 162 166 //クラス、配列の構成要素を解析する 163 164 ////////////////////////////////////// 165 // クラス、配列の構成要素を解析する 166 ////////////////////////////////////// 167 167 168 char VarName[VN_SIZE]; //変数名 168 169 char array[VN_SIZE]; //第1次配列 … … 171 172 CClass::RefType refType; 172 173 lstrcpy(VarName,member); 173 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0; 174 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false; 175 174 176 175 177 //////////////////////////// … … 177 179 //////////////////////////// 178 180 179 int offset =pobj_c->GetMemberOffset( VarName, &i );180 if(i== pobj_c->iMemberNum){181 int offset = objClass.GetMemberOffset( VarName, &i ); 182 if(i==objClass.iMemberNum){ 181 183 if(isErrorEnabled) SetError(103,VarName,cp); 182 return 0; 183 } 184 185 CMember *pMember=pobj_c->ppobj_Member[i]; 184 return false; 185 } 186 187 CMember *pMember=objClass.ppobj_Member[i]; 188 186 189 187 190 //アクセシビリティをチェック 188 if( pobj_c==pobj_CompilingClass){191 if(&objClass==pobj_CompilingClass){ 189 192 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 190 193 if(pMember->dwAccess==ACCESS_NON){ 191 194 if(isErrorEnabled) SetError(107,VarName,cp); 192 return 0;195 return false; 193 196 } 194 197 } … … 197 200 pMember->dwAccess==ACCESS_NON){ 198 201 if(isErrorEnabled) SetError(107,VarName,cp); 199 return 0;202 return false; 200 203 } 201 204 else if(bPrivateAccess==0&&pMember->dwAccess==ACCESS_PROTECTED){ 202 205 if(isErrorEnabled) SetError(108,VarName,cp); 203 return 0;206 return false; 204 207 } 205 208 } … … 209 212 if( pMember->IsConst() && //定数メンバである 210 213 isWriteAccess && //書き込みアクセスを要求されている 211 pobj_c->IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く214 objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く 212 215 ){ 213 216 //Const定義の変数に書き込みアクセスをしようとした場合 … … 215 218 } 216 219 217 *pType=pMember->TypeInfo.type; 218 *plpNestIndex=pMember->TypeInfo.u.lpIndex; 220 resultType = *pMember; 219 221 220 222 //ポインタ変数の場合 221 if( IsPtrType(*pType)){223 if( resultType.IsPointer() ){ 222 224 if(pMember->SubScripts[0]==-1){ 223 225 lstrcpy(lpPtrOffset,array); … … 228 230 if(lpPtrOffset[0]){ 229 231 if(isErrorEnabled) SetError(16,member,cp); 230 return 0;232 return false; 231 233 } 232 234 } … … 242 244 if(array[0]){ 243 245 //配列オフセット 244 if(!GetArrayOffset(pMember->SubScripts,array,*p Type,pMember->TypeInfo.u.lpIndex))246 if(!GetArrayOffset(pMember->SubScripts,array,*pMember)){ 245 247 if(isErrorEnabled) SetError(14,member,cp); 248 } 246 249 } 247 250 else if(pMember->SubScripts[0]!=-1){ 248 *pType|=FLAG_PTR;251 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 249 252 } 250 253 … … 252 255 //入れ子構造の場合 253 256 254 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){257 if( resultType.IsObject() || resultType.IsStruct() ){ 255 258 if( refType != CClass::Dot ){ 256 259 if(isErrorEnabled) SetError(104,member,cp); 257 return 0;258 } 259 260 if( *pType==DEF_OBJECT){260 return false; 261 } 262 263 if( resultType.IsObject() ){ 261 264 // 参照内容へのポインタを抽出 262 265 SetRelativeOffset( *pRelativeVar ); 263 266 } 264 267 } 265 else if( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT){268 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 266 269 //構造体ポインタ型メンバ変数 267 270 268 271 if(lpPtrOffset[0]){ 269 272 //pObj[n].member 270 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Dot ){ 271 if(isErrorEnabled) SetError(104,member,cp); 272 return 0; 273 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() ) 274 && refType != CClass::Dot ){ 275 if(isErrorEnabled) SetError(104,member,cp); 276 return false; 273 277 } 274 278 275 279 //直接参照に切り替え 276 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);280 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 277 281 pRelativeVar->dwKind=VAR_DIRECTMEM; 278 282 … … 281 285 else{ 282 286 //pObj->member 283 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Pointer ){ 284 if(isErrorEnabled) SetError(104,member,cp); 285 return 0; 287 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() ) 288 && refType != CClass::Pointer ){ 289 if(isErrorEnabled) SetError(104,member,cp); 290 return false; 286 291 } 287 292 … … 289 294 } 290 295 } 291 else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 296 else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2) 297 || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){ 292 298 //構造体ポインタのポインタ型メンバ変数 293 299 … … 296 302 if( refType != CClass::Pointer ){ 297 303 if(isErrorEnabled) SetError(104,member,cp); 298 return 0;304 return false; 299 305 } 300 306 301 307 //直接参照に切り替え 302 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);308 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 303 309 pRelativeVar->dwKind=VAR_DIRECTMEM; 304 310 … … 311 317 else{ 312 318 if(isErrorEnabled) SetError(104,member,cp); 313 return 0;314 } 315 } 316 317 if(! GetMemberOffset(319 return false; 320 } 321 } 322 323 if(!_member_offset( 318 324 isErrorEnabled, 319 325 isWriteAccess, 320 pMember-> TypeInfo.u.pobj_Class,326 pMember->GetClass(), 321 327 NestMember, 322 pType,323 328 pRelativeVar, 324 plpNestIndex,325 0)) return 0;329 resultType, 330 0)) return false; 326 331 } 327 332 328 333 if(lpPtrOffset[0]){ 329 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);334 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 330 335 pRelativeVar->dwKind=VAR_DIRECTMEM; 331 336 } 332 337 333 return 1;338 return true; 334 339 } 335 340 void GetWithName(char *buffer){ … … 355 360 } 356 361 357 BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, const char *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){ 358 extern BOOL bCompilingGlobal; 362 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss){ 359 363 int i; 360 LONG_PTR lpIndex;361 364 char variable[VN_SIZE],member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE]; 362 365 … … 373 376 374 377 void *pInfo; 375 int idProc=GetProc(VarName, &pInfo);378 int idProc=GetProc(VarName,(void **)&pInfo); 376 379 377 380 if(idProc){ 378 381 pRelativeVar->dwKind=VAR_DIRECTMEM; 382 383 Type type; 379 384 380 385 … … 383 388 //////////////// 384 389 385 *pType=CallProc(idProc,pInfo,VarName,array,&lpIndex);390 CallProc(idProc,pInfo,VarName,array,type); 386 391 387 392 //戻り値をecxにコピー … … 389 394 390 395 391 LONG_PTR lp2; 392 if(!GetMemberOffset( 396 if(!_member_offset( 393 397 isErrorEnabled, 394 398 isWriteAccess, 395 (CClass *)lpIndex, 396 member,pType,pRelativeVar,&lp2,0)) return 0; 397 if(plpIndex) *plpIndex=lp2; 398 399 return 1; 399 type.GetClass(), 400 member,pRelativeVar,resultType,0)) return false; 401 402 return true; 400 403 } 401 404 } … … 405 408 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 406 409 407 int *pSubScripts; 408 bool bConst; 409 410 if(bCompilingGlobal==0){ 411 //////////////////// 410 const int *pSubScripts; 411 bool bConst = false; 412 413 414 if( UserProc::IsLocalAreaCompiling() ){ 415 ////////////////// 412 416 // ローカル変数 413 //////////////////// 414 415 for(i=MaxLocalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 416 if( LocalVar[i].bLiving //現在のスコープで有効なもの 417 && LocalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 418 ){ 419 if(lstrcmp(VarName,LocalVar[i].name)==0) break; 420 } 421 } 422 if(i>=0){ 417 ////////////////// 418 419 const Variable *pVar = UserProc::CompilingUserProc().localVars.BackSearch( VarName ); 420 if( pVar ){ 423 421 //ポインタ変数の場合 424 if( IsPtrType(LocalVar[i].type)){425 if( LocalVar[i].SubScripts[0]==-1){422 if( pVar->IsPointer() ){ 423 if( !pVar->IsArray() ){ 426 424 lstrcpy(lpPtrOffset,array); 427 425 array[0]=0; … … 432 430 SetError(16,variable,cp); 433 431 pRelativeVar->dwKind=NON_VAR; 434 return 0;432 return false; 435 433 } 436 434 } 437 435 438 pRelativeVar->offset=- LocalVar[i].offset;436 pRelativeVar->offset=-pVar->offset; 439 437 pRelativeVar->bOffsetOffset=0; 440 if(LocalVar[i].fRef) pRelativeVar->dwKind=VAR_REFLOCAL; 438 if( pVar->IsRef() ){ 439 // 参照型 440 pRelativeVar->dwKind = VAR_REFLOCAL; 441 } 441 442 else pRelativeVar->dwKind=VAR_LOCAL; 442 *pType=LocalVar[i].type; 443 lpIndex=LocalVar[i].u.index; 444 if(plpIndex) *plpIndex=lpIndex; 445 pSubScripts=LocalVar[i].SubScripts; 446 bConst = LocalVar[i].bConst; 443 resultType = *pVar; 444 pSubScripts=pVar->GetSubScriptsPtr(); 445 bConst = pVar->IsConst(); 447 446 448 447 goto ok; … … 461 460 SetThisPtrToReg(REG_ECX); 462 461 463 *pType=DEF_OBJECT;464 462 pRelativeVar->dwKind=VAR_DIRECTMEM; 465 463 466 if(plpIndex) *plpIndex=(LONG_PTR)pobj_CompilingClass;467 return 1;464 resultType.SetType( DEF_OBJECT, pobj_CompilingClass ); 465 return true; 468 466 } 469 467 … … 500 498 501 499 pRelativeVar->dwKind=VAR_DIRECTMEM; 502 if(! GetMemberOffset(500 if(!_member_offset( 503 501 isErrorEnabled, 504 502 isWriteAccess, 505 pobj_CompilingClass,503 *pobj_CompilingClass, 506 504 variable, 507 pType,508 505 pRelativeVar, 509 &lpIndex,1)) return 0; 510 if(plpIndex) *plpIndex=lpIndex; 511 return 1; 506 resultType,1)) return false; 507 return true; 512 508 } 513 509 514 510 NonClassMember: 515 511 516 ////////////////////////// 517 // 静的ローカル変数 518 // ※"Static.Object.Method.Variable" 519 ////////////////////////// 520 521 char temporary[VN_SIZE]; 522 extern SubInfo *pCompilingSubInfo; 523 if(pCompilingSubInfo){ 524 GetNowStaticVarFullName(VarName,temporary); 525 526 for(i=0;i<MaxGlobalVarNum;i++){ 527 if(lstrcmp(temporary,GlobalVar[i].name)==0) break; 528 } 529 if(i!=MaxGlobalVarNum){ 512 { 513 const Variable *pVar; 514 515 ////////////////////////// 516 // 静的ローカル変数 517 // ※"Static.Object.Method.Variable" 518 ////////////////////////// 519 520 char temporary[VN_SIZE]; 521 if( UserProc::IsLocalAreaCompiling() ){ 522 GetNowStaticVarFullName(VarName,temporary); 523 524 pVar = globalVars.Find( temporary ); 525 if( pVar ){ 526 goto GlobalOk; 527 } 528 } 529 530 531 ////////////////////////// 532 // クラスの静的メンバ 533 ////////////////////////// 534 535 if(member[0]){ 536 lstrcpy(temporary,member); 537 538 char tempMember[VN_SIZE]; 539 char tempArray[VN_SIZE]; 540 { 541 CClass::RefType refType; 542 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 543 } 544 545 char temp2[VN_SIZE]; 546 sprintf(temp2,"%s.%s",VarName,temporary); 547 pVar = globalVars.Find( temp2 ); 548 if( pVar ){ 549 lstrcpy(member,tempMember); 550 lstrcpy(array,tempArray); 551 goto GlobalOk; 552 } 553 } 554 555 if(pobj_CompilingClass){ 556 //自身のクラスから静的メンバを参照する場合 557 char temp2[VN_SIZE]; 558 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 559 pVar = globalVars.Find( temp2 ); 560 if( pVar ){ 561 goto GlobalOk; 562 } 563 } 564 565 ///////////////////// 566 // グローバル変数 567 ///////////////////// 568 569 pVar = globalVars.BackSearch( VarName ); 570 if( pVar ){ 530 571 goto GlobalOk; 531 572 } 532 } 533 534 535 ////////////////////////// 536 // クラスの静的メンバ 537 ////////////////////////// 538 539 if(member[0]){ 540 lstrcpy(temporary,member); 541 542 char tempMember[VN_SIZE]; 543 char tempArray[VN_SIZE]; 544 { 545 CClass::RefType refType; 546 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 547 } 548 549 char temp2[VN_SIZE]; 550 sprintf(temp2,"%s.%s",VarName,temporary); 551 for(i=0;i<MaxGlobalVarNum;i++){ 552 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 553 } 554 555 if(i!=MaxGlobalVarNum){ 556 lstrcpy(member,tempMember); 557 lstrcpy(array,tempArray); 558 goto GlobalOk; 559 } 560 } 561 562 if(pobj_CompilingClass){ 563 //自身のクラスから静的メンバを参照する場合 564 char temp2[VN_SIZE]; 565 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 566 for(i=0;i<MaxGlobalVarNum;i++){ 567 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 568 } 569 570 if(i!=MaxGlobalVarNum){ 571 goto GlobalOk; 572 } 573 } 574 575 576 //////////////////// 577 // グローバル変数 578 //////////////////// 579 580 for(i=MaxGlobalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 581 if( GlobalVar[i].bLiving //現在のスコープで有効なもの 582 && GlobalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 583 ){ 584 if(lstrcmp(VarName,GlobalVar[i].name)==0) break; 585 } 586 } 587 if(i>=0){ 588 goto GlobalOk; 589 } 590 591 592 if(isErrorEnabled) SetError(3,variable,cp); 593 pRelativeVar->dwKind=NON_VAR; 594 return 0; 573 574 if(isErrorEnabled) SetError(3,variable,cp); 575 pRelativeVar->dwKind=NON_VAR; 576 return false; 577 595 578 596 579 597 580 GlobalOk: 598 599 //ポインタ変数の場合 600 if(IsPtrType(GlobalVar[i].type)){ 601 if(GlobalVar[i].SubScripts[0]==-1){ 602 lstrcpy(lpPtrOffset,array); 603 array[0]=0; 604 } 605 } 606 else{ 607 if(lpPtrOffset[0]){ 608 SetError(16,variable,cp); 609 pRelativeVar->dwKind=NON_VAR; 610 return 0; 611 } 612 } 613 614 pRelativeVar->offset=GlobalVar[i].offset; 615 pRelativeVar->bOffsetOffset=0; 616 if(GlobalVar[i].fRef){ 617 // 参照型 618 pRelativeVar->dwKind = VAR_REFGLOBAL; 619 } 620 else pRelativeVar->dwKind=VAR_GLOBAL; 621 *pType=GlobalVar[i].type; 622 lpIndex=GlobalVar[i].u.index; 623 if(plpIndex) *plpIndex=lpIndex; 624 pSubScripts=GlobalVar[i].SubScripts; 625 bConst = GlobalVar[i].bConst; 581 //ポインタ変数の場合 582 if( pVar->IsPointer() ){ 583 if( !pVar->IsArray() ){ 584 lstrcpy(lpPtrOffset,array); 585 array[0]=0; 586 } 587 } 588 else{ 589 if(lpPtrOffset[0]){ 590 SetError(16,variable,cp); 591 pRelativeVar->dwKind=NON_VAR; 592 return false; 593 } 594 } 595 596 pRelativeVar->offset=pVar->offset; 597 pRelativeVar->bOffsetOffset=0; 598 if( pVar->IsRef() ){ 599 // 参照型 600 pRelativeVar->dwKind = VAR_REFGLOBAL; 601 } 602 else pRelativeVar->dwKind=VAR_GLOBAL; 603 resultType = *pVar; 604 pSubScripts=pVar->GetSubScriptsPtr(); 605 bConst = pVar->IsConst(); 606 } 607 626 608 627 609 … … 630 612 if( bConst && isWriteAccess ){ 631 613 //Const定義の変数に書き込みアクセスをしようとした場合 632 if( *pType == DEF_OBJECT){614 if( resultType.IsObject() ){ 633 615 //オブジェクト定数 634 616 SetError(130, VarName, cp ); … … 642 624 if(array[0]==0&&pSubScripts[0]!=-1){ 643 625 //配列の先頭ポインタを示す場合 644 *pType|=FLAG_PTR;626 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 645 627 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM); 646 return 1;628 return true; 647 629 } 648 630 … … 655 637 } 656 638 if(array[0]){ 657 if(!GetArrayOffset(pSubScripts,array, *pType,lpIndex)){639 if(!GetArrayOffset(pSubScripts,array,resultType)){ 658 640 SetError(14,variable,cp); 659 641 pRelativeVar->dwKind=NON_VAR; 660 return 0;642 return false; 661 643 } 662 644 } 663 645 if(member[0]){ 664 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){646 if( resultType.IsObject() || resultType.IsStruct() ){ 665 647 //実態オブジェクトのメンバを参照(obj.member) 666 648 if( refType != CClass::Dot ){ 667 649 SetError(104,VarName,cp); 668 650 pRelativeVar->dwKind=NON_VAR; 669 return 0;670 } 671 672 if( *pType==DEF_OBJECT){651 return false; 652 } 653 654 if( resultType.IsObject() ){ 673 655 // 参照内容へのポインタを抽出 674 656 SetRelativeOffset( *pRelativeVar ); 675 657 } 676 658 } 677 else if( *pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){659 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 678 660 //ポインタオブジェクトが示すメンバを参照 679 661 if(lpPtrOffset[0]){ … … 682 664 SetError(104,VarName,cp); 683 665 pRelativeVar->dwKind=NON_VAR; 684 return 0;666 return false; 685 667 } 686 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);668 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 687 669 pRelativeVar->dwKind=VAR_DIRECTMEM; 688 670 } … … 692 674 SetError(104,VarName,cp); 693 675 pRelativeVar->dwKind=NON_VAR; 694 return 0;676 return false; 695 677 } 696 678 … … 703 685 } 704 686 } 705 else if( *pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){687 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 706 688 //ポインタオブジェクトが示すメンバを参照 707 689 if(lpPtrOffset[0]){ … … 710 692 SetError(104,VarName,cp); 711 693 pRelativeVar->dwKind=NON_VAR; 712 return 0;694 return false; 713 695 } 714 696 715 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);697 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 716 698 pRelativeVar->dwKind=VAR_DIRECTMEM; 717 699 … … 726 708 SetError(104,VarName,cp); 727 709 pRelativeVar->dwKind=NON_VAR; 728 return 0;710 return false; 729 711 } 730 712 } … … 732 714 SetError(102,VarName,cp); 733 715 pRelativeVar->dwKind=NON_VAR; 734 return 0; 735 } 736 737 LONG_PTR lp2; 738 if(!GetMemberOffset( 716 return false; 717 } 718 719 if(!_member_offset( 739 720 isErrorEnabled, 740 721 isWriteAccess, 741 (CClass *)lpIndex, 742 member,pType,pRelativeVar,&lp2,0)) return 0; 743 if(plpIndex) *plpIndex=lp2; 744 745 return 1; 722 resultType.GetClass(), 723 member,pRelativeVar,resultType,0)) return false; 724 725 return true; 746 726 } 747 727 748 728 if(lpPtrOffset[0]){ 749 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);729 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 750 730 pRelativeVar->dwKind=VAR_DIRECTMEM; 751 731 } 752 732 753 return 1;733 return true; 754 734 } 755 735 756 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){736 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 757 737 extern BYTE *initGlobalBuf; 758 int i,i2,i3 ,TypeSize;738 int i,i2,i3; 759 739 char temporary[VN_SIZE]; 760 740 … … 763 743 InitBuf[lstrlen(InitBuf)-1]=0; 764 744 765 TypeSize=GetTypeSize(type,lpIndex);745 int typeSize = type.GetSize(); 766 746 767 747 if(SubScripts[0]!=-1){ 768 TypeSize*=JumpSubScripts(SubScripts+1);748 typeSize*=JumpSubScripts(SubScripts+1); 769 749 i=0; 770 750 i2=0; … … 776 756 i=GetOneParameter(InitBuf,i,temporary); 777 757 if(!SetInitGlobalData( 778 offset+i2* TypeSize,758 offset+i2*typeSize, 779 759 type, 780 lpIndex,781 760 SubScripts+1, 782 temporary)) return 0;761 temporary)) return false; 783 762 i2++; 784 763 if(InitBuf[i]=='\0') break; 785 764 } 786 return -1; 787 } 788 789 if(type==DEF_STRUCT){ 790 CClass *pobj_c; 791 pobj_c=(CClass *)lpIndex; 792 793 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 765 return true; 766 } 767 768 if(type.IsStruct()){ 769 const CClass &objClass = type.GetClass(); 770 771 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 794 772 i=GetOneParameter(InitBuf,i,temporary); 795 773 796 i3= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );774 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 797 775 798 776 if(!SetInitGlobalData(offset+i3, 799 pobj_c->ppobj_Member[i2]->TypeInfo.type, 800 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 801 pobj_c->ppobj_Member[i2]->SubScripts, 802 temporary)) return 0; 777 *objClass.ppobj_Member[i2], 778 objClass.ppobj_Member[i2]->SubScripts, 779 temporary)) return false; 803 780 804 781 if(InitBuf[i]=='\0') break; 805 782 } 806 if(i2+1!= pobj_c->iMemberNum){783 if(i2+1!=objClass.iMemberNum){ 807 784 SetError(41,0,cp); 808 return 0;809 } 810 return 1;785 return false; 786 } 787 return true; 811 788 } 812 789 813 790 SetError(41,0,cp); 814 return 0;791 return false; 815 792 } 816 793 … … 820 797 /////////////////////////////////////// 821 798 822 if( type == DEF_OBJECT || type == DEF_STRUCT){799 if( type.IsObject() || type.IsStruct() ){ 823 800 //オブジェクトまたは構造体の場合はありえない 824 801 SetError(300,NULL,cp); 825 return 0;802 return false; 826 803 } 827 804 828 805 if(SubScripts[0]!=-1){ 829 806 SetError(41,0,cp); 830 return 0;807 return false; 831 808 } 832 809 833 810 double dbl; 834 811 _int64 i64data; 835 int CalcType; 836 LONG_PTR lpCalcIndex; 837 CalcType=StaticCalculation(true, InitBuf,type,&i64data,&lpCalcIndex); 838 if(IsRealNumberType(CalcType)){ 812 Type calcType; 813 814 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 815 //動的データだった場合 816 return false; 817 } 818 if( calcType.IsReal() ){ 839 819 memcpy(&dbl,&i64data,sizeof(double)); 840 820 i64data=(_int64)dbl; … … 845 825 CheckDifferentType( 846 826 type, 847 lpIndex, 848 CalcType, 849 lpCalcIndex, 827 calcType, 850 828 0,0); 851 829 852 if( type==DEF_DOUBLE)830 if( type.IsDouble() ){ 853 831 *(double *)(initGlobalBuf+offset)=(double)dbl; 854 else if(type==DEF_SINGLE) 832 } 833 else if( type.IsSingle() ){ 855 834 *(float *)(initGlobalBuf+offset)=(float)dbl; 856 else if(type==DEF_INT64||type==DEF_QWORD) 835 } 836 else if( type.Is64() ){ 857 837 *(_int64 *)(initGlobalBuf+offset)=i64data; 858 else if(type==DEF_LONG||type==DEF_DWORD||IsPtrType(type)){ 859 if(type==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){ 838 } 839 else if( type.IsLong() || type.IsDWord() || type.IsPointer() ){ 840 if(type.GetBasicType()==typeOfPtrChar&&calcType.GetIndex()==LITERAL_STRING){ 860 841 //文字列定数のとき 861 842 … … 881 862 } 882 863 } 883 else if( type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR))864 else if( type.IsWord() || type.IsInteger() ){ 884 865 *(WORD *)(initGlobalBuf+offset)=(WORD)i64data; 885 else if(type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)) 866 } 867 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 886 868 *(BYTE *)(initGlobalBuf+offset)=(BYTE)i64data; 887 //String型が未完成 888 return 1; 869 } 870 871 return true; 889 872 } 890 BOOL InitLocalVar(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){891 int i,i2,i3 ,TypeSize;873 bool InitLocalVar(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 874 int i,i2,i3; 892 875 char temporary[VN_SIZE]; 893 876 … … 896 879 InitBuf[lstrlen(InitBuf)-1]=0; 897 880 898 TypeSize=GetTypeSize(type,lpIndex);881 int typeSize = type.GetSize(); 899 882 900 883 if(SubScripts[0]!=-1){ 901 TypeSize*=JumpSubScripts(SubScripts+1);884 typeSize*=JumpSubScripts(SubScripts+1); 902 885 i=0; 903 886 i2=0; … … 905 888 if(SubScripts[0]<i2){ 906 889 SetError(41,0,cp); 907 return 0;890 return false; 908 891 } 909 892 i=GetOneParameter(InitBuf,i,temporary); 910 893 if(!InitLocalVar( 911 offset+i2* TypeSize,894 offset+i2*typeSize, 912 895 type, 913 lpIndex,914 896 SubScripts+1, 915 temporary)) return 0;897 temporary)) return false; 916 898 i2++; 917 899 if(InitBuf[i]=='\0') break; 918 900 } 919 return -1; 920 } 921 922 if(type==DEF_STRUCT){ 923 CClass *pobj_c; 924 pobj_c=(CClass *)lpIndex; 925 926 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 901 return true; 902 } 903 904 if(type.IsStruct()){ 905 const CClass &objClass = type.GetClass(); 906 907 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 927 908 i=GetOneParameter(InitBuf,i,temporary); 928 909 929 i3 = pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );910 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 930 911 931 912 if(!InitLocalVar(offset+i3, 932 pobj_c->ppobj_Member[i2]->TypeInfo.type, 933 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 934 pobj_c->ppobj_Member[i2]->SubScripts, 935 temporary)) return 0; 913 *objClass.ppobj_Member[i2], 914 objClass.ppobj_Member[i2]->SubScripts, 915 temporary)) return false; 936 916 937 917 if(InitBuf[i]=='\0') break; 938 918 } 939 if(i2+1!= pobj_c->iMemberNum){919 if(i2+1!=objClass.iMemberNum){ 940 920 SetError(41,0,cp); 941 921 return 0; 942 922 } 943 return 1;923 return true; 944 924 } 945 925 946 926 SetError(41,0,cp); 947 return 0;927 return false; 948 928 } 949 929 … … 955 935 if(SubScripts[0]!=-1){ 956 936 SetError(41,0,cp); 957 return 0;937 return false; 958 938 } 959 939 960 940 double dbl; 961 941 _int64 i64data; 962 int CalcType; 963 LONG_PTR lpCalcIndex; 964 CalcType=StaticCalculation(false, InitBuf,type,&i64data,&lpCalcIndex); 965 if(!CalcType){ 942 Type calcType; 943 944 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 966 945 //動的データだった場合 967 return 0;968 } 969 if( IsRealNumberType(CalcType)){946 return false; 947 } 948 if( calcType.IsReal() ){ 970 949 memcpy(&dbl,&i64data,sizeof(double)); 971 950 i64data=(_int64)dbl; … … 976 955 CheckDifferentType( 977 956 type, 978 lpIndex, 979 CalcType, 980 lpCalcIndex, 957 calcType, 981 958 0,0); 982 959 983 if( type==DEF_DOUBLE){960 if( type.IsDouble() ){ 984 961 //mov eax,HILONG(dbl) 985 962 OpBuffer[obp++]=(char)0xB8; … … 1006 983 obp+=sizeof(long); 1007 984 } 1008 else if( type==DEF_SINGLE){985 else if( type.IsSingle() ){ 1009 986 float flt; 1010 987 flt=(float)dbl; … … 1021 998 obp+=sizeof(long); 1022 999 } 1023 else if( type==DEF_INT64||type==DEF_QWORD){1000 else if( type.Is64() ){ 1024 1001 //mov eax,HILONG(i64data) 1025 1002 OpBuffer[obp++]=(char)0xB8; … … 1046 1023 obp+=sizeof(long); 1047 1024 } 1048 else if( type==DEF_LONG||type==DEF_DWORD||IsPtrType(type)){1049 if(type ==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){1025 else if( type.IsDWord() || type.IsLong() || type.IsPointer() ){ 1026 if(type.GetBasicType()==typeOfPtrChar&&calcType.GetIndex()==LITERAL_STRING){ 1050 1027 //文字列定数のとき 1051 1028 … … 1075 1052 obp+=sizeof(long); 1076 1053 } 1077 else if( type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR)){1054 else if( type.IsWord() || type.IsInteger() ){ 1078 1055 //mov ax,InitValue 1079 1056 OpBuffer[obp++]=(char)0x66; … … 1090 1067 obp+=sizeof(long); 1091 1068 } 1092 else if( type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)){1069 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 1093 1070 //mov byte ptr[ebp+offset],InitValue 1094 1071 OpBuffer[obp++]=(char)0xC6; … … 1100 1077 obp+=sizeof(BYTE); 1101 1078 } 1102 //String型が未完成 1103 return 1;1079 1080 return true; 1104 1081 } 1105 1082 1106 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1107 extern BOOL bCompilingGlobal; 1108 if(bCompilingGlobal){ 1083 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1084 if( UserProc::IsGlobalAreaCompiling() ){ 1109 1085 ///////////////////////// 1110 1086 // グローバル変数 1111 1087 ///////////////////////// 1112 1088 1113 AddGlobalVariable(isRef,VarName,SubScripts, &TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);1089 AddGlobalVariable(isRef,VarName,SubScripts,type,InitBuf,ConstractParameter,dwFlags); 1114 1090 } 1115 1091 else{ … … 1118 1094 ///////////////// 1119 1095 1120 int i2,i3; 1121 1122 for(i2=0;i2<MaxLocalVarNum;i2++){ 1123 if(LocalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==LocalVar[i2].ScopeLevel){ 1124 if(lstrcmp(LocalVar[i2].name,VarName)==0){ 1125 //2重定義のエラー 1126 SetError(15,VarName,cp); 1127 return; 1128 } 1129 } 1130 } 1131 1132 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 1133 VARIABLE *pVar = &LocalVar[MaxLocalVarNum]; 1134 MaxLocalVarNum++; 1135 1136 if( isRef ){ 1137 //参照型 1138 pVar->fRef = REF_VARIABLE; 1139 TypeSize = PTR_SIZE; 1140 } 1141 else pVar->fRef=0; 1142 1143 for(i2=1,i3=0;i3<255;i3++){ 1144 //配列要素数 1145 pVar->SubScripts[i3]=SubScripts[i3]; 1146 1147 if(SubScripts[i3]==-1) break; 1148 i2*=SubScripts[i3]+1; 1149 } 1150 int VarSize=TypeSize*i2; 1151 if(VarSize%4) VarSize+=4-(VarSize%4); 1152 1153 //変数データを追加 1154 lstrcpy(pVar->name,VarName); 1155 if(dwFlags & DIMFLAG_CONST) pVar->bConst = true; 1156 else pVar->bConst = false; 1157 if(SubScripts[0]==-1) pVar->bArray=0; 1158 else pVar->bArray=1; 1159 pVar->type=TypeInfo.type; 1160 pVar->u.index=TypeInfo.u.lpIndex; 1161 AllLocalVarSize+=VarSize; 1162 pVar->offset=AllLocalVarSize; 1096 if( UserProc::CompilingUserProc().localVars.BackSearch( VarName ) ){ 1097 //2重定義のエラー 1098 SetError(15,VarName,cp); 1099 return; 1100 } 1101 1102 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false; 1103 1104 Variable *pVar = new Variable( VarName, type, isConst, isRef ); 1105 1106 if( SubScripts[0] != -1 ){ 1107 //配列あり 1108 pVar->SetArray( SubScripts ); 1109 } 1110 1111 //コンストラクタ用パラメータ 1112 pVar->paramStrForConstructor = ConstractParameter; 1163 1113 1164 1114 //レキシカルスコープ … … 1167 1117 pVar->bLiving=TRUE; 1168 1118 1119 //エラー用 1120 pVar->source_code_address=cp; 1121 1122 // 変数を追加 1123 UserProc::CompilingUserProc().localVars.push_back( pVar ); 1124 1125 //アラインメントを考慮 1126 if( pVar->IsStruct() ){ 1127 int alignment = pVar->GetClass().iAlign; 1128 if( alignment ){ 1129 if( AllLocalVarSize % alignment ){ 1130 AllLocalVarSize += alignment - (AllLocalVarSize % alignment); 1131 } 1132 } 1133 } 1134 1135 AllLocalVarSize += pVar->GetMemorySize(); 1136 pVar->offset = AllLocalVarSize; 1137 1138 //レキシカルスコープ 1139 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); 1140 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress(); 1141 pVar->bLiving=TRUE; 1142 1169 1143 if(InitBuf[0]){ 1170 1144 //初期代入時のみ、書き込みアクセスを許可する 1171 bool bConstBack = pVar->bConst; 1172 pVar->bConst = false; 1145 if( isConst ){ 1146 pVar->ConstOff(); 1147 } 1173 1148 1174 1149 int result = 0; 1175 if( pVar->type != DEF_OBJECT){1150 if( !pVar->IsObject() ){ 1176 1151 result = InitLocalVar(-pVar->offset, 1177 pVar->type, 1178 pVar->u.index, 1179 pVar->SubScripts, 1152 *pVar, 1153 pVar->GetSubScriptsPtr(), 1180 1154 InitBuf); 1181 1155 } … … 1188 1162 } 1189 1163 1190 pVar->bConst = bConstBack; 1164 if( isConst ){ 1165 pVar->ConstOn(); 1166 } 1191 1167 } 1192 1168 else{ … … 1195 1171 1196 1172 //push VarSize 1197 op_push_V( VarSize);1173 op_push_V( pVar->GetMemorySize() ); 1198 1174 1199 1175 //mov eax,ebp … … 1213 1189 OpBuffer[obp++]=(char)0xFF; 1214 1190 OpBuffer[obp++]=(char)0x15; 1215 DECLAREINFO *pdi; 1216 pdi=GetDeclareHash("FillMemory"); 1217 pdi->bUse=1; 1218 pobj_ImportAddrSchedule->add(pdi); 1191 DllProc *pDllProc = GetDeclareHash("FillMemory"); 1192 pDllProc->Using(); 1193 pobj_ImportAddrSchedule->add(pDllProc); 1219 1194 obp+=sizeof(long); 1220 1195 } … … 1222 1197 1223 1198 //New呼び出し 1224 if( TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){1199 if( type.IsObject() &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){ 1225 1200 char objectSize[255]; 1226 1201 if( SubScripts[0] == -1 ){ … … 1233 1208 sprintf( objectSize, "%d", SubScripts[0] ); 1234 1209 } 1235 Operator_New( *TypeInfo.u.pobj_Class, objectSize, ConstractParameter, TypeInfo);1210 Operator_New( type.GetClass(), objectSize, ConstractParameter, type ); 1236 1211 1237 1212 //pop eax 1238 1213 op_pop( REG_EAX ); 1239 1214 1240 int type;1241 LONG_PTR lpIndex;1242 1215 RELATIVE_VAR RelativeVar; 1243 GetVarOffset( true, false, VarName, & type, &RelativeVar, &lpIndex);1216 GetVarOffset( true, false, VarName, &RelativeVar, Type() ); 1244 1217 if( RelativeVar.dwKind == VAR_DIRECTMEM ){ 1245 1218 SetError(); … … 1248 1221 } 1249 1222 1250 if( TypeInfo.type==DEF_OBJECT){1251 if( TypeInfo.u.pobj_Class->IsAbstract()){1223 if( type.IsObject() ){ 1224 if( type.GetClass().IsAbstract() ){ 1252 1225 //抽象クラスだったとき 1253 SetError(125,TypeInfo.u.pobj_Class->name,cp); 1254 } 1255 } 1256 } 1257 void dim(char *Parameter,DWORD dwFlags){ 1258 extern BOOL bCompilingGlobal; 1259 extern HANDLE hHeap; 1260 int i2; 1261 char VarName[VN_SIZE]; 1262 1263 1264 //参照型かどうか 1265 bool isRef = false; 1266 1267 i2 = 0; 1268 1269 if( Parameter[i2] == 1 && Parameter[i2+1] == ESC_BYREF ){ 1270 //参照型 1271 isRef = true; 1272 Parameter += 2; 1273 } 1274 1275 1276 if(dwFlags & DIMFLAG_CONST){ 1277 ////////////////////////////////// 1278 // 定数変数の場合を考慮 1279 ////////////////////////////////// 1280 for(;;i2++){ 1281 if(Parameter[i2] == '=' || 1282 Parameter[i2] == 1 && Parameter[i2] == ESC_AS || 1283 Parameter[i2] =='('){ 1284 VarName[i2] = 0; 1285 break; 1286 } 1287 VarName[i2] = Parameter[i2]; 1288 } 1289 1290 //定数と2重定義されていないる場合は抜け出す 1291 if(CDBConst::obj.GetType(VarName)){ 1292 return; 1293 } 1294 1295 //定数マクロとして定義されている場合は抜け出す 1296 if(GetConstHash(VarName)){ 1297 return; 1298 } 1299 } 1300 1301 1302 //構文を解析 1303 int SubScripts[MAX_ARRAYDIM]; 1304 TYPEINFO TypeInfo; 1305 char InitBuf[8192]; 1306 char ConstractParameter[VN_SIZE]; 1307 if(!GetDimentionFormat(Parameter, isRef, VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter)) 1308 return; 1309 1310 1311 //定数と2重定義されていないかを調べる 1312 if(CDBConst::obj.GetType(VarName)){ 1313 SetError(15,VarName,cp); 1314 return; 1315 } 1316 1317 //定数マクロとして定義されている場合 1318 if(GetConstHash(VarName)){ 1319 SetError(15,VarName,cp); 1320 return; 1321 } 1322 1323 1324 //タイプサイズを取得 1325 int TypeSize; 1326 TypeSize=GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex); 1327 1328 if(dwFlags&DIMFLAG_STATIC){ 1329 if(bCompilingGlobal){ 1330 SetError(60,NULL,cp); 1331 return; 1332 } 1333 1334 ///////////////////// 1335 // Static変数 1336 // ※"Static.Object.Method.Variable" 1337 ///////////////////// 1338 1339 char temporary[VN_SIZE]; 1340 GetNowStaticVarFullName(VarName,temporary); 1341 1342 dim( isRef,temporary,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags ); 1343 1344 /* 1345 Note: 静的変数のコンストラクタ呼び出しは 1346 _System_InitStaticLocalVariables関数内で一括して行う 1347 */ 1348 } 1349 else{ 1350 dim( isRef,VarName,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags ); 1351 } 1352 } 1353 void OpcodeDim(char *Parameter,DWORD dwFlags){ 1354 int i,i2,i3,IsStr=0; 1355 char temporary[8192]; 1356 1357 for(i=0,i2=0;;i++,i2++){ 1358 if(Parameter[i]=='\"') IsStr^=1; 1359 if(Parameter[i]=='('&&IsStr==0){ 1360 i3=GetStringInPare(temporary+i2,Parameter+i); 1361 i+=i3-1; 1362 i2+=i3-1; 1363 continue; 1364 } 1365 if(Parameter[i]=='['&&IsStr==0){ 1366 i3=GetStringInBracket(temporary+i2,Parameter+i); 1367 i+=i3-1; 1368 i2+=i3-1; 1369 continue; 1370 } 1371 if((Parameter[i]==','&&IsStr==0)|| 1372 Parameter[i]=='\0'){ 1373 temporary[i2]=0; 1374 1375 dim(temporary,dwFlags); 1376 1377 if(Parameter[i]=='\0') break; 1378 i2=-1; 1379 continue; 1380 } 1381 temporary[i2]=Parameter[i]; 1226 SetError(125,type.GetClass().name,cp); 1227 } 1382 1228 } 1383 1229 } -
BasicCompiler32/MakePeHdr.cpp
r73 r75 8 8 // 特殊関数の構造体ポインタ 9 9 //////////////////////////// 10 SubInfo 10 UserProc 11 11 *pSub_System_StartupProgram, 12 12 *pSub_DebugSys_StartProc, … … 150 150 151 151 //関数ポインタ情報を初期化 152 extern P ROCPTRINFO *pProcPtrInfo;152 extern ProcPointer **ppProcPtrInfo; 153 153 extern int ProcPtrInfoNum; 154 p ProcPtrInfo=(PROCPTRINFO*)HeapAlloc(hHeap,0,1);154 ppProcPtrInfo=(ProcPointer **)HeapAlloc(hHeap,0,1); 155 155 ProcPtrInfoNum=0; 156 156 … … 184 184 185 185 if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1)) 186 pSub_System_StartupProgram-> bUse=1;186 pSub_System_StartupProgram->Using(); 187 187 188 188 if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1)) 189 pSub_DebugSys_StartProc-> bUse=1;189 pSub_DebugSys_StartProc->Using(); 190 190 191 191 if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1)) 192 pSub_DebugSys_EndProc-> bUse=1;192 pSub_DebugSys_EndProc->Using(); 193 193 194 194 if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1)) 195 pSub_DebugSys_SaveContext-> bUse=1;195 pSub_DebugSys_SaveContext->Using(); 196 196 197 197 if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){ 198 pSub_System_GetEip-> bUse=1;199 pSub_System_GetEip-> bSystem=1;198 pSub_System_GetEip->Using(); 199 pSub_System_GetEip->ThisIsSystemProc(); 200 200 } 201 201 202 202 if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){ 203 pSub_System_InitDllGlobalVariables-> bUse=1;204 pSub_System_InitDllGlobalVariables-> bSystem=1;203 pSub_System_InitDllGlobalVariables->Using(); 204 pSub_System_InitDllGlobalVariables->ThisIsSystemProc(); 205 205 } 206 206 207 207 if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){ 208 pSub_System_InitStaticLocalVariables-> bUse=1;209 pSub_System_InitStaticLocalVariables-> bSystem=1;208 pSub_System_InitStaticLocalVariables->Using(); 209 pSub_System_InitStaticLocalVariables->ThisIsSystemProc(); 210 210 } 211 211 212 212 if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){ 213 pSub_System_Call_Destructor_of_GlobalObject-> bUse=1;214 pSub_System_Call_Destructor_of_GlobalObject-> bSystem=1;213 pSub_System_Call_Destructor_of_GlobalObject->Using(); 214 pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc(); 215 215 } 216 216 217 217 if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){ 218 pSub_System_GetSp-> bUse=1;219 pSub_System_GetSp-> bSystem=1;218 pSub_System_GetSp->Using(); 219 pSub_System_GetSp->ThisIsSystemProc(); 220 220 } 221 221 222 222 if(pSub_pow=GetSubHash("pow",1)) 223 pSub_pow-> bUse=1;223 pSub_pow->Using(); 224 224 225 225 if(pSub_calloc=GetSubHash("calloc",1)) 226 pSub_calloc-> bUse=1;226 pSub_calloc->Using(); 227 227 228 228 if(pSub_realloc=GetSubHash("realloc",1)) 229 pSub_realloc-> bUse=1;229 pSub_realloc->Using(); 230 230 231 231 if(pSub_free=GetSubHash("free",1)) 232 pSub_free-> bUse=1;232 pSub_free->Using(); 233 233 234 234 if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) ) 235 pSub_System_GC_malloc_ForObject-> bUse = 1;235 pSub_System_GC_malloc_ForObject->Using(); 236 236 237 237 if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) ) 238 pSub_System_GC_malloc_ForObjectPtr-> bUse = 1;238 pSub_System_GC_malloc_ForObjectPtr->Using(); 239 239 240 240 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 241 pSub_System_GC_free_for_SweepingDelete-> bUse = 1;241 pSub_System_GC_free_for_SweepingDelete->Using(); 242 242 243 243 pSub_allrem=GetSubHash("_allrem"); 244 pSub_allrem-> bUse=1;245 pSub_allrem-> bSystem=1;244 pSub_allrem->Using(); 245 pSub_allrem->ThisIsSystemProc(); 246 246 247 247 pSub_aullrem=GetSubHash("_aullrem"); 248 pSub_aullrem-> bUse=1;249 pSub_aullrem-> bSystem=1;248 pSub_aullrem->Using(); 249 pSub_aullrem->ThisIsSystemProc(); 250 250 251 251 pSub_allmul=GetSubHash("_allmul"); 252 pSub_allmul-> bUse=1;253 pSub_allmul-> bSystem=1;252 pSub_allmul->Using(); 253 pSub_allmul->ThisIsSystemProc(); 254 254 255 255 pSub_alldiv=GetSubHash("_alldiv"); 256 pSub_alldiv-> bUse=1;257 pSub_alldiv-> bSystem=1;256 pSub_alldiv->Using(); 257 pSub_alldiv->ThisIsSystemProc(); 258 258 259 259 pSub_aulldiv=GetSubHash("_aulldiv"); 260 pSub_aulldiv-> bUse=1;261 pSub_aulldiv-> bSystem=1;260 pSub_aulldiv->Using(); 261 pSub_aulldiv->ThisIsSystemProc(); 262 262 263 263 pSub_allshl=GetSubHash("_allshl"); 264 pSub_allshl-> bUse=1;265 pSub_allshl-> bSystem=1;264 pSub_allshl->Using(); 265 pSub_allshl->ThisIsSystemProc(); 266 266 267 267 pSub_allshr=GetSubHash("_allshr"); 268 pSub_allshr-> bUse=1;269 pSub_allshr-> bSystem=1;268 pSub_allshr->Using(); 269 pSub_allshr->ThisIsSystemProc(); 270 270 271 271 pSub_aullshr=GetSubHash("_aullshr"); 272 pSub_aullshr-> bUse=1;273 pSub_aullshr-> bSystem=1;272 pSub_aullshr->Using(); 273 pSub_aullshr->ThisIsSystemProc(); 274 274 275 275 pSub_esp_error=GetSubHash("_esp_error"); 276 pSub_esp_error-> bUse=1;276 pSub_esp_error->Using(); 277 277 278 278 … … 391 391 392 392 //call _System_Call_Destructor_of_GlobalObject 393 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;393 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 394 394 op_call(pSub_System_Call_Destructor_of_GlobalObject); 395 395 … … 425 425 for(i=0;i<SynonymErrorNum;i++) HeapDefaultFree(SynonymErrorWords[i]); 426 426 HeapDefaultFree(SynonymErrorWords); 427 SynonymErrorWords=0; 427 428 428 429 … … 451 452 //////////////////////////////// 452 453 for(i=0;i<MAX_HASH;i++){ 453 extern DECLAREINFO **ppDeclareHash; 454 DECLAREINFO *pdi; 455 pdi=ppDeclareHash[i]; 456 while(pdi){ 457 if(pdi->bUse==0){ 458 pdi=pdi->pNextData; 454 extern DllProc **ppDeclareHash; 455 const DllProc *pDllProc = ppDeclareHash[i]; 456 while(pDllProc){ 457 if( !pDllProc->IsUsing() ){ 458 pDllProc=pDllProc->pNextData; 459 459 continue; 460 460 } … … 462 462 //エラーチェック 463 463 HINSTANCE hLib; 464 hLib=LoadLibrary( pdi->file);464 hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() ); 465 465 if(!hLib){ 466 466 extern char OutputFileName[MAX_PATH]; … … 468 468 _splitpath(OutputFileName,temp2,temp3,NULL,NULL); 469 469 lstrcat(temp2,temp3); 470 lstrcpy(temp3,p di->file);470 lstrcpy(temp3,pDllProc->GetDllFileName().c_str()); 471 471 GetFullPath(temp3,temp2); 472 472 hLib=LoadLibrary(temp3); 473 473 474 474 if(!hLib){ 475 SetError(-106,p di->file,pdi->pos);475 SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos()); 476 476 } 477 477 } 478 478 479 479 if(hLib){ 480 if(!GetProcAddress(hLib,p di->alias)){480 if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){ 481 481 FreeLibrary(hLib); 482 SetError(-107,p di->alias,pdi->pos);482 SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos()); 483 483 } 484 484 FreeLibrary(hLib); 485 485 } 486 486 487 p di=pdi->pNextData;487 pDllProc=pDllProc->pNextData; 488 488 } 489 489 } … … 522 522 ExportNamesLength=lstrlen(lpExportNames)+1; 523 523 524 extern SubInfo**ppSubHash;525 SubInfo *psi,*psi2;524 extern UserProc **ppSubHash; 525 UserProc *pUserProc,*psi2; 526 526 while(1){ 527 527 //辞書順にサーチ 528 528 temporary[0]=0; 529 529 for(i=0,psi2=0;i<MAX_HASH;i++){ 530 p si=ppSubHash[i];531 while(p si){532 if(p si->bExport){530 pUserProc=ppSubHash[i]; 531 while(pUserProc){ 532 if(pUserProc->IsExport()){ 533 533 if(temporary[0]=='\0'){ 534 lstrcpy(temporary,p si->name);535 psi2=p si;534 lstrcpy(temporary,pUserProc->GetName().c_str()); 535 psi2=pUserProc; 536 536 } 537 537 else{ 538 538 i3=lstrlen(temporary); 539 i4= lstrlen(psi->name);539 i4=(int)pUserProc->GetName().size(); 540 540 if(i3<i4) i3=i4; 541 if(memcmp(temporary,p si->name,i3)>0){542 lstrcpy(temporary,p si->name);543 psi2=p si;541 if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){ 542 lstrcpy(temporary,pUserProc->GetName().c_str()); 543 psi2=pUserProc; 544 544 } 545 545 } 546 546 } 547 p si=psi->pNextData;547 pUserProc=pUserProc->pNextData; 548 548 } 549 549 } 550 550 if(psi2==0) break; 551 psi=psi2; 552 553 psi->bExport=0; 554 555 if(lstrcmpi(psi->name,"DllMain")==0) 556 DllMain_EntryPoint=psi->CompileAddress; 551 pUserProc=psi2; 552 553 pUserProc->ExportOff(); 554 555 if( pUserProc->GetName() == "DllMain" ){ 556 DllMain_EntryPoint=pUserProc->beginOpAddress; 557 } 557 558 558 559 lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD)); 559 lpdwExportAddressTable[ExportNum]=p si->CompileAddress;560 lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress; 560 561 561 562 lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD)); … … 565 566 lpwExportOrdinalTable[ExportNum]=ExportNum; 566 567 567 lstrcpy(lpExportNames+ExportNamesLength,p si->name);568 lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str()); 568 569 ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1; 569 570 … … 598 599 //インポートDLL情報 599 600 ///////////////////// 600 extern DECLAREINFO **ppDeclareHash; 601 DECLAREINFO *pdi; 601 extern DllProc **ppDeclareHash; 602 602 char **ppDllNames; 603 603 int ImportDllNum; … … 621 621 ImportDllNum=0; 622 622 for(i=0;i<MAX_HASH;i++){ 623 pdi=ppDeclareHash[i]; 624 while(pdi){ 625 if(pdi->dwType==DECLARE_STATIC|| 626 pdi->bUse==0){ 627 pdi=pdi->pNextData; 623 const DllProc *pDllProc=ppDeclareHash[i]; 624 while(pDllProc){ 625 if( !pDllProc->IsUsing() ){ 626 pDllProc=pDllProc->pNextData; 628 627 continue; 629 628 } 630 629 631 if( lstrlen(pdi->file)>16){630 if( pDllProc->GetDllFileName().size() > 16 ){ 632 631 SetError(7,NULL,cp); 633 632 break; 634 633 } 635 634 for(i2=0;i2<ImportDllNum;i2++){ 636 if(lstrcmp(ppDllNames[i2],pdi->file)==0) break; 635 if( pDllProc->GetDllFileName() == ppDllNames[i2] ){ 636 break; 637 } 637 638 } 638 639 if(i2==ImportDllNum){ 639 640 ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **)); 640 641 ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16); 641 lstrcpy(ppDllNames[ImportDllNum],p di->file);642 lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str()); 642 643 ImportDllNum++; 643 644 } 644 645 645 p di=pdi->pNextData;646 pDllProc=pDllProc->pNextData; 646 647 } 647 648 } … … 660 661 pImportTable[i].Name=i3+i*0x10; 661 662 for(i2=0;i2<MAX_HASH;i2++){ 662 pdi=ppDeclareHash[i2]; 663 while(pdi){ 664 if(pdi->dwType==DECLARE_STATIC|| 665 pdi->bUse==0){ 666 pdi=pdi->pNextData; 663 const DllProc *pDllProc=ppDeclareHash[i2]; 664 while(pDllProc){ 665 if( !pDllProc->IsUsing() ){ 666 pDllProc=pDllProc->pNextData; 667 667 continue; 668 668 } 669 669 670 if( lstrcmp(ppDllNames[i],pdi->file)==0){670 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 671 671 //ルックアップデータのサイズを追加 672 672 LookupSize+=sizeof(DWORD); 673 673 } 674 674 675 p di=pdi->pNextData;675 pDllProc=pDllProc->pNextData; 676 676 } 677 677 } … … 691 691 for(i=0,i5=0;i<ImportDllNum;i++){ 692 692 for(i2=0;i2<MAX_HASH;i2++){ 693 pdi=ppDeclareHash[i2]; 694 while(pdi){ 695 if(pdi->dwType==DECLARE_STATIC|| 696 pdi->bUse==0){ 697 pdi=pdi->pNextData; 693 DllProc *pDllProc=ppDeclareHash[i2]; 694 while(pDllProc){ 695 if( !pDllProc->IsUsing() ){ 696 pDllProc=pDllProc->pNextData; 698 697 continue; 699 698 } 700 699 701 if( lstrcmp(ppDllNames[i],pdi->file)==0){700 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 702 701 //ルックアップの位置をセット(後にインポート アドレス テーブルにセットしなおされる) 703 p di->LookupAddress=i3+(i5*sizeof(DWORD));702 pDllProc->SetLookupAddress( i3+(i5*sizeof(DWORD)) ); 704 703 705 704 //ルックアップ テーブル … … 709 708 pHintTable[HintSize++]=0; 710 709 pHintTable[HintSize++]=0; 711 lstrcpy(pHintTable+HintSize,p di->alias);712 i4= lstrlen(pdi->alias);710 lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str()); 711 i4=(int)pDllProc->GetAlias().size(); 713 712 HintSize+=i4+1; 714 713 if(i4%2==0) pHintTable[HintSize++]=0; … … 720 719 } 721 720 722 p di=pdi->pNextData;721 pDllProc=pDllProc->pNextData; 723 722 } 724 723 } … … 993 992 994 993 for(i2=0;i2<MAX_HASH;i2++){ 995 pdi=ppDeclareHash[i2];996 while(p di){997 if( pdi->bUse==0){998 p di=pdi->pNextData;994 const DllProc *pDllProc=ppDeclareHash[i2]; 995 while(pDllProc){ 996 if( !pDllProc->IsUsing() ){ 997 pDllProc=pDllProc->pNextData; 999 998 continue; 1000 999 } 1001 1000 1002 if( lstrcmp(ppDllNames[i],pdi->file)==0){1001 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 1003 1002 //ルックアップ テーブル 1004 1003 pLookupTable[i5++]+=MemPos_ImportSection; 1005 1004 } 1006 1005 1007 p di=pdi->pNextData;1006 pDllProc=pDllProc->pNextData; 1008 1007 } 1009 1008 } … … 1028 1027 // インポートテーブルスケジュール(インポート アドレス テーブルを指し示させる) 1029 1028 for(i=0;i<pobj_ImportAddrSchedule->num;i++){ 1030 DECLAREINFO *pdi; 1031 pdi=pobj_ImportAddrSchedule->ppdi[i]; 1029 const DllProc *pDllProc=pobj_ImportAddrSchedule->ppdi[i]; 1032 1030 *((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))= 1033 1031 ImageBase+ … … 1035 1033 LookupSize+ //ルックアップテーブル 1036 1034 HintSize+ //ヒント名(関数名)テーブル 1037 p di->LookupAddress;1035 pDllProc->GetLookupAddress(); 1038 1036 } 1039 1037 delete pobj_ImportAddrSchedule; … … 1043 1041 // プロシージャポインタスケジュール 1044 1042 for(i=0;i<pobj_SubAddrSchedule->num;i++){ 1045 if(pobj_SubAddrSchedule->ppsi[i]-> CompileAddress==01046 &&pobj_SubAddrSchedule->ppsi[i]-> EndOpAddr==0){1043 if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0 1044 &&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){ 1047 1045 SetError(300,NULL,-1); 1048 1046 } … … 1050 1048 if(pobj_SubAddrSchedule->pbCall[i]){ 1051 1049 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1052 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));1050 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long)); 1053 1051 } 1054 1052 else{ 1055 1053 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1056 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress+ImageBase+MemPos_CodeSection;1054 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection; 1057 1055 } 1058 1056 } -
BasicCompiler32/NumOpe.cpp
r69 r75 78 78 79 79 extern CClass *pobj_StringClass; 80 T YPEINFObaseTypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass };80 Type baseTypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass }; 81 81 Operator_New( *pobj_StringClass, "", parameter, baseTypeInfo ); 82 82 … … 97 97 if(Command[0]==1&& Command[1]==ESC_NEW ){ 98 98 //New演算子(オブジェクト生成) 99 T YPEINFObaseTypeInfo = { BaseType, lpBaseIndex };99 Type baseTypeInfo = { BaseType, lpBaseIndex }; 100 100 int resultType = Operator_New(Command+2,plpIndex, baseTypeInfo ); 101 101 … … 157 157 if(type[sp-2]==DEF_OBJECT){ 158 158 //オーバーロードされたオペレータを呼び出す 159 T YPEINFOBaseTypeInfo={BaseType,lpBaseIndex};159 Type BaseTypeInfo={BaseType,lpBaseIndex}; 160 160 i2=CallOperatorProc(idCalc,&BaseTypeInfo,type,index_stack,bUseHeap,sp); 161 161 if(i2==0){ … … 195 195 CClass *pobj_Class; 196 196 pobj_Class=(CClass *)lpBaseIndex; 197 T YPEINFOBaseTypeInfo = {BaseType,lpBaseIndex};197 Type BaseTypeInfo = {BaseType,lpBaseIndex}; 198 198 if(IsStringObjectType(BaseTypeInfo)){ 199 199 //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合 … … 342 342 i2=GetVarType(variable,(LONG_PTR *)&pobj_c,0); 343 343 if(i2==DEF_OBJECT){ 344 T YPEINFORetTypeInfo;344 Type RetTypeInfo; 345 345 CallIndexerGetterProc(pobj_c,variable,array_element,RetTypeInfo); 346 346 type[sp]=RetTypeInfo.type; … … 500 500 501 501 if(GetSubHash(VarName,0)){ 502 T YPEINFORetTypeInfo;502 Type RetTypeInfo; 503 503 CallPropertyMethod(term,NULL,&RetTypeInfo); 504 504 -
BasicCompiler32/NumOpe_Arithmetic.cpp
r73 r75 270 270 271 271 //call _allmul 272 extern SubInfo*pSub_allmul;272 extern UserProc *pSub_allmul; 273 273 op_call(pSub_allmul); 274 274 … … 460 460 461 461 //call _aullrem 462 extern SubInfo*pSub_aullrem;462 extern UserProc *pSub_aullrem; 463 463 op_call(pSub_aullrem); 464 464 } … … 467 467 468 468 //call _allrem 469 extern SubInfo*pSub_allrem;469 extern UserProc *pSub_allrem; 470 470 op_call(pSub_allrem); 471 471 } … … 720 720 721 721 //call _aulldiv 722 extern SubInfo*pSub_aulldiv;722 extern UserProc *pSub_aulldiv; 723 723 op_call(pSub_aulldiv); 724 724 } … … 727 727 728 728 //call _alldiv 729 extern SubInfo*pSub_alldiv;729 extern UserProc *pSub_alldiv; 730 730 op_call(pSub_alldiv); 731 731 } … … 1000 1000 1001 1001 //call pow 1002 extern SubInfo*pSub_pow;1002 extern UserProc *pSub_pow; 1003 1003 op_call(pSub_pow); 1004 1004 … … 1156 1156 1157 1157 //call _allshl 1158 extern SubInfo*pSub_allshl;1158 extern UserProc *pSub_allshl; 1159 1159 op_call(pSub_allshl); 1160 1160 … … 1361 1361 1362 1362 //call _aullshr 1363 extern SubInfo*pSub_aullshr;1363 extern UserProc *pSub_aullshr; 1364 1364 op_call(pSub_aullshr); 1365 1365 } … … 1368 1368 1369 1369 //call _allshr 1370 extern SubInfo*pSub_allshr;1370 extern UserProc *pSub_allshr; 1371 1371 op_call(pSub_allshr); 1372 1372 } -
BasicCompiler32/Opcode.h
r73 r75 102 102 //NumOpe.cpp 103 103 void PushReturnValue(int type); 104 int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0); 104 bool NumOpe( const char *Command, 105 const Type &baseType, 106 Type &resultType, 107 BOOL *pbUseHeap = NULL ); 105 108 106 109 //NumOpe_Arithmetic.cpp … … 136 139 //Compile_Set_Var.cpp 137 140 BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar); 138 void SetStructVariable( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap);141 void SetStructVariable( const Type &varType, const Type &calcType, BOOL bUseHeap); 139 142 void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar); 140 143 void SetWholeVariable( int varSize,int calcType, RELATIVE_VAR *pRelative ); … … 174 177 175 178 //Compile_Object.cpp 176 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo ); 177 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ); 179 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType ); 178 180 void OpcodeDelete(const char *Parameter, bool isSweeping); 179 181 … … 182 184 void GetWithName(char *buffer); 183 185 void SetThisPtrToReg(int reg); 184 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);185 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);186 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss = 0); 187 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf); 186 188 #define DIMFLAG_INITDEBUGVAR 1 187 189 #define DIMFLAG_NONCALL_CONSTRACTOR 2 188 190 #define DIMFLAG_STATIC 4 189 191 #define DIMFLAG_CONST 8 190 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 191 void OpcodeDim(char *Parameter,DWORD dwFlag); 192 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 192 193 void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar); 193 194 … … 201 202 class ParamImpl{ 202 203 char *Parms[255]; 203 T YPEINFOtypes[255];204 Type types[255]; 204 205 int ParmsNum; 205 206 206 T YPEINFOReturnTypeInfo;207 Type ReturnTypeInfo; 207 208 208 209 //一時オブジェクト管理用 … … 213 214 public: 214 215 ParamImpl(const char *buffer); 215 ParamImpl(const PARAMETER_INFO *pParamInfo, const int ParmNum); 216 ParamImpl::ParamImpl(const Parameters ¶ms); 216 ParamImpl(const Parameters ¶ms); 217 217 ~ParamImpl(); 218 void SetReturnType( TYPEINFO *pTypeInfo);218 void SetReturnType( const Type &returnType ); 219 219 220 220 private: 221 BOOL _overload_check( Parameters ¶ms,TYPEINFO*pReturnTypeInfo,int overload_level);222 SubInfo *OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo*> &subs );221 BOOL _overload_check( const Parameters ¶ms,Type *pReturnTypeInfo,int overload_level); 222 UserProc *OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs ); 223 223 public: 224 SubInfo *OverloadSolution( const char *name, std::vector<SubInfo *> &subs ); 225 226 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum); 227 bool ErrorCheck( const char *procName, const Parameters ¶ms, int SecondParmNum ); 228 void MacroParameterSupport(PARAMETER_INFO *ppi); 224 UserProc *OverloadSolution( const char *name, std::vector<UserProc *> &subs ); 225 226 bool ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 229 227 void MacroParameterSupport( const Parameters ¶ms ); 230 228 void SetStructParameter(CClass *pobj_Class,LPSTR Parameter); 231 int SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum); 232 int SetParameter( const char *procName, const Parameters ¶ms, int SecondParmNum ); 229 int SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 233 230 234 231 //一時オブジェクトパラメータの生成と破棄 235 int NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ); 236 int NewTempParameters( const char *procName, const Parameters ¶ms, int SecondParmNum ); 232 int NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 237 233 void DeleteTempParameters(); 238 234 }; … … 241 237 void AddLocalVarAddrSchedule(); 242 238 #define PROCFLAG_NEW 1 243 int Opcode_CallProcPtr(char *variable,char *Parameter,P ROCPTRINFO *pi,LONG_PTR *plpIndex);244 void Opcode_CallProc(const char *Parameter, SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType);245 int Opcode_CallDllProc(char *Parameter,D ECLAREINFO *pdi,LONG_PTR *plpIndex);239 int Opcode_CallProcPtr(char *variable,char *Parameter,ProcPointer *pProcPointer,LONG_PTR *plpIndex); 240 void Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,char *ObjectName,int RefType); 241 int Opcode_CallDllProc(char *Parameter,DllProc *pDllProc,LONG_PTR *plpIndex); 246 242 247 243 //Compile_ProcOp.cpp … … 251 247 int GetFunctionType(int FuncNum); 252 248 int GetFunctionFromName(char *FuncName); 253 void Opcode_CallFunc( const char *Parameter, const int FuncNum, T YPEINFO&ReturnTypeInfo );249 void Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo ); 254 250 255 251 //OperatorProc.cpp 256 252 void FreeTempObject(int reg,CClass *pobj_c); 257 int CallOperatorProc(int idCalc,T YPEINFO*pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);258 void CallCastOperatorProc( int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);259 void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,T YPEINFO&RetTypeInfo);253 int CallOperatorProc(int idCalc,Type *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp); 254 void CallCastOperatorProc(Type &calcType,BOOL bCalcUseHeap,const Type &toType); 255 void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,Type &RetTypeInfo); 260 256 261 257 //Compile_Statement.cpp … … 268 264 void OpcodeContinue(void); 269 265 void OpcodeExitSub(void); 270 void OpcodeSelect(c har *Parameter);266 void OpcodeSelect(const char *Parameter); 271 267 void OpcodeCase(char *Parameter); 272 268 void OpcodeGosub(char *Parameter); … … 344 340 void fpu_cast_end(); 345 341 346 void op_call( SubInfo *psi);342 void op_call(UserProc *pUserProc); -
BasicCompiler32/OperatorProc.cpp
r73 r75 11 11 12 12 //call DestructorProcAddr 13 op_call( method->p si);13 op_call( method->pUserProc ); 14 14 } 15 15 … … 18 18 19 19 //call free 20 extern SubInfo*pSub_free;20 extern UserProc *pSub_free; 21 21 op_call(pSub_free); 22 22 } 23 23 24 int CallOperatorProc(int idCalc,T YPEINFO*pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){24 int CallOperatorProc(int idCalc,Type *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){ 25 25 //オーバーロードされたオペレータ関数を呼び出す 26 26 CClass *pobj_c; 27 27 pobj_c=(CClass *)index_stack[sp-2]; 28 28 29 std::vector< SubInfo*> subs;29 std::vector<UserProc *> subs; 30 30 pobj_c->EnumMethod( idCalc, subs ); 31 31 if( subs.size() == 0 ){ … … 41 41 int i; 42 42 BOOL bReturnTypeIsObject=1; 43 T YPEINFO ReturnType={DEF_OBJECT,subs[0]->u.ReturnIndex};44 foreach( SubInfo *psi, subs ){45 if(p si->ReturnType!=DEF_OBJECT)43 Type ReturnType={DEF_OBJECT,subs[0]->ReturnType().GetIndex()}; 44 foreach( UserProc *pUserProc, subs ){ 45 if(pUserProc->ReturnType().IsObject()) 46 46 bReturnTypeIsObject=0; 47 47 } … … 61 61 ///////////////////////////////////////////// 62 62 63 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 64 int iParmNum=0; 65 66 if(bTwoTerm){ 67 ppi[iParmNum].bArray=0; 68 ppi[iParmNum].bByVal=0; 69 ppi[iParmNum].name=0; 70 ppi[iParmNum].type=type[sp-1]; 71 ppi[iParmNum].u.index=index_stack[sp-1]; 72 ppi[iParmNum].SubScripts[0]=-1; 73 iParmNum++; 74 } 75 63 Parameters params; 64 65 if(bTwoTerm){ 66 params.push_back( new Parameter( "", Type( type[sp-1], index_stack[sp-1] ) ) ); 67 } 76 68 77 69 //オーバーロードを解決 … … 79 71 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"=="); 80 72 else GetCalcName(idCalc,temporary); 81 SubInfo *psi; 82 psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo); 83 84 if(!psi){ 85 HeapDefaultFree(ppi); 73 Type returnType; 74 if( pBaseTypeInfo ){ 75 returnType.SetBasicType( pBaseTypeInfo->type ); 76 returnType.SetIndex( pBaseTypeInfo->u.lpIndex ); 77 } 78 UserProc *pUserProc = OverloadSolution( temporary, subs, params, returnType ); 79 80 if(!pUserProc){ 81 if(bTwoTerm){ 82 delete params[0]; 83 } 86 84 return -1; 87 85 } 88 86 else{ 89 87 //オーバーロードされていないが、パラメータ個数が一致しないとき 90 if(iParmNum!=psi->params.size()){ 91 HeapDefaultFree(ppi); 88 if(params.size()!=pUserProc->Params().size()){ 89 if(bTwoTerm){ 90 delete params[0]; 91 } 92 92 return -1; 93 93 } 94 94 } 95 95 96 for(i=0;i< iParmNum;i++){96 for(i=0;i<(int)params.size();i++){ 97 97 CheckDifferentType( 98 p si->params[i]->GetBasicType(),99 p si->params[i]->GetIndex(),100 p pi[i].type,101 p pi[i].u.index,98 pUserProc->Params()[i]->GetBasicType(), 99 pUserProc->Params()[i]->GetIndex(), 100 params[i]->GetBasicType(), 101 params[i]->GetIndex(), 102 102 "", 103 103 i); 104 104 } 105 105 106 HeapDefaultFree(ppi); 106 if(bTwoTerm){ 107 delete params[0]; 108 } 107 109 108 110 int right_side_size = GetTypeSize(type[sp-1],index_stack[sp-1]); 109 111 110 112 if(bTwoTerm){ 111 if( p si->realParams[1]->IsStruct() &&psi->realParams[1]->IsRef() == false ){113 if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){ 112 114 //一時オブジェクトはメソッド内で破棄される 113 115 bUseHeap[sp-1]=0; … … 116 118 117 119 118 if( psi->ReturnType==DEF_STRUCT){120 if( pUserProc->ReturnType().IsStruct() ){ 119 121 ////////////////////////////////////////////////////// 120 122 // 戻り値に構造体インスタンスを持つ場合 … … 122 124 ////////////////////////////////////////////////////// 123 125 124 int object_size = p si->u.Return_pobj_c->GetSize();126 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 125 127 126 128 //push object_size … … 128 130 129 131 //call calloc 130 extern SubInfo*pSub_calloc;132 extern UserProc *pSub_calloc; 131 133 op_call(pSub_calloc); 132 134 … … 180 182 } 181 183 182 if( p si->realParams[1]->IsRef() ){184 if( pUserProc->RealParams()[1]->IsRef() ){ 183 185 //一時参照を作成 184 186 … … 191 193 } 192 194 193 if( psi->ReturnType==DEF_STRUCT){195 if( pUserProc->ReturnType().IsStruct() ){ 194 196 //push ebx 195 197 op_push(REG_EBX); … … 200 202 201 203 //call operator_proc 202 op_call(p si);203 204 if(bTwoTerm){ 205 if( p si->realParams[1]->IsRef() ){204 op_call(pUserProc); 205 206 if(bTwoTerm){ 207 if( pUserProc->RealParams()[1]->IsRef() ){ 206 208 //一時参照を破棄 207 209 op_pop( REG_NON ); … … 209 211 } 210 212 211 if( psi->ReturnType!=DEF_NON){213 if( !pUserProc->ReturnType().IsNull() ){ 212 214 //スタックへプッシュ 213 PushReturnValue(p si->ReturnType);215 PushReturnValue(pUserProc->ReturnType().GetBasicType()); 214 216 } 215 217 … … 222 224 223 225 sp--; 224 type[sp-1]=p si->ReturnType;225 index_stack[sp-1]=p si->u.ReturnIndex;226 227 if( psi->ReturnType==DEF_STRUCT){226 type[sp-1]=pUserProc->ReturnType().GetBasicType(); 227 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 228 229 if( pUserProc->ReturnType().IsStruct() ){ 228 230 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 229 231 //※後にfreeする必要あり … … 254 256 array_bUseHeap[1]=0; 255 257 256 T YPEINFOBaseTypeInfo={ToType,lpToIndex};258 Type BaseTypeInfo={ToType,lpToIndex}; 257 259 258 260 int iRet; … … 272 274 SetError(-1,"キャスト演算子がオーバーロードされていません。",cp); 273 275 } 274 void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,T YPEINFO&RetTypeInfo){275 std::vector< SubInfo*> subs;276 void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,Type &RetTypeInfo){ 277 std::vector<UserProc *> subs; 276 278 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs ); 277 279 if( subs.size() == 0 ){ … … 280 282 281 283 Opcode_CallProc(Parameter,subs[0],0,ObjectName,DEF_OBJECT); 282 RetTypeInfo.type = subs[0]->ReturnType ;283 RetTypeInfo.u.lpIndex = subs[0]-> u.ReturnIndex;284 } 284 RetTypeInfo.type = subs[0]->ReturnType().GetBasicType(); 285 RetTypeInfo.u.lpIndex = subs[0]->ReturnType().GetIndex(); 286 } -
BasicCompiler32/VarList.cpp
r73 r75 348 348 if(pobj_dti->lplpSpBase[i2]==0) return; 349 349 350 extern SubInfo**ppSubHash;351 SubInfo *psi;350 extern UserProc **ppSubHash; 351 UserProc *pUserProc; 352 352 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 353 p si=ppSubHash[i3];354 while(p si){355 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&356 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){353 pUserProc=ppSubHash[i3]; 354 while(pUserProc){ 355 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 356 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 357 357 sw=1; 358 358 break; 359 359 } 360 360 361 p si=psi->pNextData;361 pUserProc=pUserProc->pNextData; 362 362 } 363 363 if(sw) break; 364 364 } 365 if(!p si) return;366 367 for(i=0;i<p si->VarNum;i++){368 VARIABLE *pVar=&p si->pVar[i];365 if(!pUserProc) return; 366 367 for(i=0;i<pUserProc->VarNum;i++){ 368 VARIABLE *pVar=&pUserProc->pVar[i]; 369 369 370 370 //スコープ外の場合は無視 … … 416 416 417 417 TreeView_DeleteAllItems(hVarTree_This); 418 if(!p si->pobj_ParentClass) return;418 if(!pUserProc->GetParentClassPtr()) return; 419 419 420 420 //Thisポインタを取得 421 421 LONG_PTR pThis; 422 for(i=0;i<p si->VarNum;i++){423 if(lstrcmp(p si->pVar[i].name,"_System_LocalThis")==0) break;424 } 425 if(i==p si->VarNum) return;426 lpData=pobj_dti->lplpSpBase[i2]+p si->pVar[i].offset;422 for(i=0;i<pUserProc->VarNum;i++){ 423 if(lstrcmp(pUserProc->pVar[i].name,"_System_LocalThis")==0) break; 424 } 425 if(i==pUserProc->VarNum) return; 426 lpData=pobj_dti->lplpSpBase[i2]+pUserProc->pVar[i].offset; 427 427 ReadProcessMemory(hDebugProcess,(void *)lpData,&pThis,sizeof(LONG_PTR),&lpAccBytes); 428 428 429 for(i=0;i<p si->pobj_ParentClass->iMemberNum;i++){430 offset = p si->pobj_ParentClass->GetMemberOffset( psi->pobj_ParentClass->ppobj_Member[i]->name, &i2 );431 432 if(p si->pobj_ParentClass->ppobj_Member[i]->SubScripts[0]!=-1){429 for(i=0;i<pUserProc->GetParentClassPtr()->iMemberNum;i++){ 430 offset = pUserProc->GetParentClassPtr()->GetMemberOffset( pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, &i2 ); 431 432 if(pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts[0]!=-1){ 433 433 //配列 434 434 sprintf(temporary,"%s %s(&H%X)", 435 p si->pobj_ParentClass->ppobj_Member[i]->name,435 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 436 436 STRING_ARRAY, 437 437 offset); … … 442 442 VarList_Array(hVarTree_This,hParent, 443 443 pThis+offset, 444 p si->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type,445 p si->pobj_ParentClass->ppobj_Member[i]->SubScripts,446 p si->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex);444 pUserProc->GetParentClassPtr()->ppobj_Member[i]->TypeInfo.type, 445 pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts, 446 pUserProc->GetParentClassPtr()->ppobj_Member[i]->TypeInfo.u.lpIndex); 447 447 } 448 448 else{ 449 449 VarList_Insert(hVarTree_This,&tv, 450 p si->pobj_ParentClass->ppobj_Member[i]->name,451 p si->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type,450 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 451 pUserProc->GetParentClassPtr()->ppobj_Member[i]->TypeInfo.type, 452 452 pThis+offset, 453 p si->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex);453 pUserProc->GetParentClassPtr()->ppobj_Member[i]->TypeInfo.u.lpIndex); 454 454 } 455 455 } … … 583 583 584 584 //プロシージャ コンボボックス 585 extern SubInfo**ppSubHash;586 SubInfo *psi;585 extern UserProc **ppSubHash; 586 UserProc *pUserProc; 587 587 int sw; 588 588 SendMessage(hProcCombo,CB_RESETCONTENT,0,0); 589 589 for(i2=pobj_dti->iProcLevel;i2>=0;i2--){ 590 590 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 591 p si=ppSubHash[i3];592 while(p si){593 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&594 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){595 lstrcpy(temporary,p si->name);591 pUserProc=ppSubHash[i3]; 592 while(pUserProc){ 593 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 594 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 595 lstrcpy(temporary,pUserProc->GetName().c_str()); 596 596 sw=1; 597 597 break; 598 598 } 599 p si=psi->pNextData;599 pUserProc=pUserProc->pNextData; 600 600 } 601 601 if(sw) break; 602 602 } 603 if(!p si){603 if(!pUserProc){ 604 604 if(i2==0){ 605 605 lstrcpy(temporary,"Global"); … … 706 706 707 707 if(pobj_dti->lplpSpBase[i2]){ 708 extern SubInfo**ppSubHash;709 SubInfo *psi;708 extern UserProc **ppSubHash; 709 UserProc *pUserProc; 710 710 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 711 p si=ppSubHash[i3];712 while(p si){713 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&714 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){711 pUserProc=ppSubHash[i3]; 712 while(pUserProc){ 713 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 714 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 715 715 sw=1; 716 716 break; 717 717 } 718 718 719 p si=psi->pNextData;719 pUserProc=pUserProc->pNextData; 720 720 } 721 721 if(sw) break; … … 723 723 724 724 725 if(p si){726 LocalVar=p si->pVar;727 MaxLocalVarNum=p si->VarNum;728 729 pobj_CompilingClass=p si->pobj_ParentClass;725 if(pUserProc){ 726 LocalVar=pUserProc->pVar; 727 MaxLocalVarNum=pUserProc->VarNum; 728 729 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 730 730 } 731 731 } -
BasicCompiler32/WatchList.cpp
r73 r75 308 308 ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip){ 309 309 int i; 310 SubInfo *psi;310 UserProc *pUserProc; 311 311 312 312 //ripからプロシージャを取得 313 p si=GetSubFromObp(obp_Rip);314 315 for(i=0;i<p si->VarNum;i++){316 if(lstrcmp(p si->pVar[i].name,"_System_LocalThis")==0) break;317 } 318 if(i==p si->VarNum) return 0;319 320 return p si->pVar[i].offset;313 pUserProc=GetSubFromObp(obp_Rip); 314 315 for(i=0;i<pUserProc->VarNum;i++){ 316 if(lstrcmp(pUserProc->pVar[i].name,"_System_LocalThis")==0) break; 317 } 318 if(i==pUserProc->VarNum) return 0; 319 320 return pUserProc->pVar[i].offset; 321 321 } 322 322 int Debugging_GetVarOffset(char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){ -
BasicCompiler32/increment.cpp
r64 r75 3 3 4 4 void IncDec(int idCalc, char *lpszLeft, char *lpszRight){ 5 int VarType;6 LONG_PTR lpVarIndex;7 RELATIVE_VAR VarRelativeVar;8 9 5 10 6 /////////////////////////// … … 12 8 /////////////////////////// 13 9 10 RELATIVE_VAR VarRelativeVar; 11 Type varType; 14 12 if(!GetVarOffsetReadWrite( 15 13 lpszLeft, 16 &VarType,17 14 &VarRelativeVar, 18 &lpVarIndex)) return;15 varType)) return; 19 16 20 17 if(IsUse_ecx(&VarRelativeVar)){ … … 28 25 /////////////////////////////////// 29 26 30 if( IsRealNumberType(VarType)){27 if( varType.IsReal() ){ 31 28 //実数 32 SetReg_RealVariable( VarType,&VarRelativeVar);29 SetReg_RealVariable(varType.GetBasicType(),&VarRelativeVar); 33 30 } 34 31 else{ 35 32 //整数 36 SetReg_WholeVariable( VarType,&VarRelativeVar,REG_EAX);33 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,REG_EAX); 37 34 } 38 35 39 36 40 if( IsWholeNumberType(VarType)&&lstrcmp(lpszRight,"1")==0&&37 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&& 41 38 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){ 42 39 //////////////////////////////////////////// … … 44 41 //////////////////////////////////////////// 45 42 46 if( Is64Type(VarType)){43 if( varType.Is64() ){ 47 44 if(idCalc==CALC_ADDITION){ 48 45 //64ビット インクリメント … … 80 77 op_push(REG_ECX); 81 78 82 83 if(VarType==DEF_DOUBLE){ 79 if( varType.IsDouble() ){ 84 80 //sub esp,8 85 81 op_sub_esp(8); 86 82 87 83 //fstp qword ptr[esp] 88 op_fstp_basereg( VarType,REG_ESP);89 } 90 else if( VarType==DEF_SINGLE){84 op_fstp_basereg(varType.GetBasicType(),REG_ESP); 85 } 86 else if( varType.IsSingle() ){ 91 87 //sub esp,4 92 88 op_sub_esp(4); 93 89 94 90 //fstp dword ptr[esp] 95 op_fstp_basereg( VarType,REG_ESP);96 } 97 else if( Is64Type(VarType)){91 op_fstp_basereg(varType.GetBasicType(),REG_ESP); 92 } 93 else if( varType.Is64() ){ 98 94 //push edx 99 95 op_push(REG_EDX); … … 107 103 } 108 104 109 int CalcType; 110 CalcType=NumOpe(lpszRight,VarType,lpVarIndex,0); 111 112 if(VarType==DEF_DOUBLE) ChangeTypeToDouble(CalcType); 113 else if(VarType==DEF_SINGLE) ChangeTypeToSingle(CalcType); 114 else ChangeTypeToWhole(CalcType,VarType); 115 116 int type[255],sp; 105 Type calcType; 106 if( !NumOpe(lpszRight,varType,calcType) ){ 107 return; 108 } 109 110 if( varType.IsDouble() ) ChangeTypeToDouble(calcType.GetBasicType()); 111 else if( varType.IsSingle() ) ChangeTypeToSingle(calcType.GetBasicType()); 112 else ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType()); 113 114 int type_stack[255],sp; 117 115 LONG_PTR index_stack[255]; 118 type [0]=VarType;119 type [1]=VarType;120 index_stack[0]= lpVarIndex;121 index_stack[1]= lpVarIndex;116 type_stack[0]=varType.GetBasicType(); 117 type_stack[1]=varType.GetBasicType(); 118 index_stack[0]=varType.GetIndex(); 119 index_stack[1]=varType.GetIndex(); 122 120 sp=2; 123 121 124 122 switch(idCalc){ 125 123 case CALC_XOR: 126 Calc_Xor(type ,index_stack,&sp);124 Calc_Xor(type_stack,index_stack,&sp); 127 125 break; 128 126 case CALC_OR: 129 Calc_Or(type ,index_stack,&sp);127 Calc_Or(type_stack,index_stack,&sp); 130 128 break; 131 129 case CALC_AND: 132 Calc_And(type ,index_stack,&sp);130 Calc_And(type_stack,index_stack,&sp); 133 131 break; 134 132 case CALC_SHL: 135 Calc_SHL(type ,&sp);133 Calc_SHL(type_stack,&sp); 136 134 break; 137 135 case CALC_SHR: 138 Calc_SHR(type ,&sp);136 Calc_SHR(type_stack,&sp); 139 137 break; 140 138 case CALC_ADDITION: 141 139 case CALC_SUBTRACTION: 142 140 case CALC_PRODUCT: 143 CalcTwoTerm_Arithmetic(idCalc,type ,index_stack,&sp);141 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp); 144 142 break; 145 143 case CALC_MOD: 146 Calc_Mod(type ,&sp);144 Calc_Mod(type_stack,&sp); 147 145 break; 148 146 case CALC_QUOTIENT: 149 Calc_Divide(type ,&sp,VarType);147 Calc_Divide(type_stack,&sp,varType.GetBasicType()); 150 148 break; 151 149 case CALC_INTQUOTIENT: 152 Calc_IntDivide(type ,index_stack,&sp);150 Calc_IntDivide(type_stack,index_stack,&sp); 153 151 break; 154 152 case CALC_POWER: 155 Calc_Power(type ,&sp);156 break; 157 } 158 159 160 if( VarType==DEF_DOUBLE){153 Calc_Power(type_stack,&sp); 154 break; 155 } 156 157 158 if( varType.IsDouble() ){ 161 159 //fld qword ptr[esp] 162 op_fld_basereg( VarType,REG_ESP);160 op_fld_basereg(varType.GetBasicType(),REG_ESP); 163 161 164 162 //add esp,8 165 163 op_add_esp(8); 166 164 } 167 else if( VarType==DEF_SINGLE){165 else if( varType.IsSingle() ){ 168 166 //fld dword ptr[esp] 169 op_fld_basereg( VarType,REG_ESP);167 op_fld_basereg(varType.GetBasicType(),REG_ESP); 170 168 171 169 //add esp,4 172 170 op_add_esp(4); 173 171 } 174 else if( Is64Type(VarType)){172 else if( varType.Is64() ){ 175 173 //pop eax 176 174 op_pop(REG_EAX); … … 200 198 } 201 199 202 SetVariableFromEax( VarType,VarType,&VarRelativeVar);200 SetVariableFromEax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar); 203 201 } -
BasicCompiler32/op32_main.cpp
r73 r75 974 974 ///////////////////////////// 975 975 976 void op_call( SubInfo *psi){976 void op_call(UserProc *pUserProc){ 977 977 OpBuffer[obp++]=(char)0xE8; 978 pobj_SubAddrSchedule->add(p si,1);979 p si->bUse=1;978 pobj_SubAddrSchedule->add(pUserProc,1); 979 pUserProc->Using(); 980 980 obp+=sizeof(long); 981 981 } -
BasicCompiler64/BasicCompiler.vcproj
r71 r75 22 22 UseOfMFC="0" 23 23 ATLMinimizesCRunTimeLibraryUsage="false" 24 CharacterSet=" 0"24 CharacterSet="2" 25 25 > 26 26 <Tool … … 52 52 MinimalRebuild="true" 53 53 BasicRuntimeChecks="0" 54 RuntimeLibrary=" 3"54 RuntimeLibrary="1" 55 55 UsePrecompiledHeader="0" 56 56 PrecompiledHeaderFile=".\Debug/BasicCompiler.pch" … … 125 125 UseOfMFC="0" 126 126 ATLMinimizesCRunTimeLibraryUsage="false" 127 CharacterSet=" 0"127 CharacterSet="2" 128 128 > 129 129 <Tool … … 322 322 UseOfMFC="0" 323 323 ATLMinimizesCRunTimeLibraryUsage="false" 324 CharacterSet=" 0"324 CharacterSet="2" 325 325 > 326 326 <Tool … … 473 473 > 474 474 <File 475 RelativePath="..\BasicCompiler_Common\Parameter.h" 476 > 477 </File> 478 <File 479 RelativePath="..\BasicCompiler_Common\Procedure.h" 480 > 481 </File> 482 <File 475 483 RelativePath="..\BasicCompiler_Common\Type.h" 484 > 485 </File> 486 <File 487 RelativePath="..\BasicCompiler_Common\Variable.h" 476 488 > 477 489 </File> … … 1522 1534 > 1523 1535 <File 1524 RelativePath="..\BasicCompiler_Common\Variable .cpp"1525 > 1526 </File> 1527 <File 1528 RelativePath="..\BasicCompiler_Common\Variable .h"1536 RelativePath="..\BasicCompiler_Common\VariableOpe.cpp" 1537 > 1538 </File> 1539 <File 1540 RelativePath="..\BasicCompiler_Common\VariableOpe.h" 1529 1541 > 1530 1542 </File> … … 1545 1557 Name="Procedure" 1546 1558 > 1547 <File1548 RelativePath="..\BasicCompiler_Common\Parameter.h"1549 >1550 </File>1551 1559 <File 1552 1560 RelativePath="..\BasicCompiler_Common\ParamImpl.cpp" … … 1563 1571 > 1564 1572 <File 1573 RelativePath="..\BasicCompiler_Common\Procedure.cpp" 1574 > 1575 </File> 1576 <File 1565 1577 RelativePath="..\BasicCompiler_Common\Type.cpp" 1578 > 1579 </File> 1580 <File 1581 RelativePath="..\BasicCompiler_Common\Variable.cpp" 1566 1582 > 1567 1583 </File> -
BasicCompiler64/CParameter.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 int ParamImpl::NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){ 4 int ParamImpl::NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 5 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 6 5 7 /////////////////////////////////////////////////////// 6 8 // 一時オブジェクトをあらかじめスタックに積んでおく … … 12 14 13 15 BOOL bEllipse; 14 if(p i_num){15 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;16 if(params.size()){ 17 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 16 18 else bEllipse=0; 17 19 } … … 21 23 useTempParameters[i2] = false; 22 24 23 if(bEllipse&&i2<= pi_num-2) bEllipse=0;24 25 if(i2==0 &&ppi[i2].name){26 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){25 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 26 27 if(i2==0){ 28 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 27 29 //オブジェクトメンバの第一パラメータのThisポインタ 28 30 continue; 29 31 } 30 32 } 31 if( (i2==0||i2==1)&&ppi[i2].name){32 if( lstrcmp(ppi[i2].name,FuncName)==0){33 if( i2==0||i2==1 ){ 34 if( params[i2]->GetVarName() == procName ){ 33 35 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 34 36 continue; … … 36 38 } 37 39 38 T YPEINFO DummyTypeInfo;40 Type dummyType; 39 41 BOOL bByVal; 40 42 if(bEllipse){ 41 DummyTypeInfo.type=NumOpe_GetType(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);43 NumOpe_GetType( Parms[i2], Type(), dummyType ); 42 44 bByVal=1; 43 45 } 44 46 else{ 45 DummyTypeInfo.type=ppi[i2].type; 46 DummyTypeInfo.u.lpIndex=ppi[i2].u.index; 47 bByVal=ppi[i2].bByVal; 47 dummyType = *params[i2]; 48 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 48 49 } 49 50 … … 56 57 } 57 58 58 LONG_PTR lpVarIndex; 59 if( GetVarType( Parms[i2], &lpVarIndex, FALSE ) == -1 ){ 59 if( !GetVarType( Parms[i2], Type(), FALSE ) ){ 60 60 //変数ではないとき 61 61 int reg = REG_RAX; 62 int type = NumOpe( ®, Parms[i2], DummyTypeInfo.type, DummyTypeInfo.u.lpIndex, &lpVarIndex ); 63 64 if( type != DEF_STRUCT ){ 62 Type calcType; 63 NumOpe( ®, Parms[i2], dummyType, calcType ); 64 65 if( !calcType.IsStruct() ){ 65 66 //一時参照を作成 66 67 pobj_sf->push( reg ); … … 76 77 77 78 bool result = CheckDifferentType( 78 DummyTypeInfo.type, 79 DummyTypeInfo.u.lpIndex, 80 type, 81 lpVarIndex, 82 FuncName, 79 dummyType, 80 calcType, 81 procName.c_str(), 83 82 i2); 84 83 … … 87 86 useTempObject = true; 88 87 89 types[i2].type = type; 90 types[i2].u.lpIndex = lpVarIndex; 88 types[i2] = calcType; 91 89 } 92 90 } … … 104 102 for(int i2=ParmsNum-1;i2>=0;i2--){ 105 103 if( useTempParameters[i2] ){ 106 if( types[i2]. type == DEF_STRUCT){104 if( types[i2].IsStruct() ){ 107 105 // 構造体の一時メモリ 108 106 … … 112 110 113 111 //call free 114 extern SubInfo*pSub_free;112 extern UserProc *pSub_free; 115 113 op_call(pSub_free); 116 114 } … … 123 121 } 124 122 125 void ParamImpl::SetStructParameter( int reg,CClass *pobj_Class,LPSTR Parameter){123 void ParamImpl::SetStructParameter( int reg, const Type &baseType, const char *expression ){ 126 124 ////////////////////////////////////////////////////// 127 125 ///// レジスタ資源のバックアップ … … 129 127 ////////////////////////////////////////////////////// 130 128 131 int object_size = pobj_Class->GetSize();129 int object_size = baseType.GetClass().GetSize(); 132 130 133 131 //mov rcx,object_size … … 135 133 136 134 //call calloc 137 extern SubInfo*pSub_calloc;135 extern UserProc *pSub_calloc; 138 136 op_call(pSub_calloc); 139 137 … … 144 142 pobj_sf->push(REG_R11); 145 143 146 TYPEINFO BaseType={DEF_STRUCT,(LONG_PTR)pobj_Class}; 147 TYPEINFO CalcType; 148 CalcType.type=NumOpe_GetType(Parameter,&BaseType,&CalcType.u.lpIndex); 149 150 /* 151 TODO: 消す 152 if( pobj_Class->GetCopyConstructorMethod() 153 && CalcType.type==DEF_OBJECT&&CalcType.u.pobj_Class==pobj_Class){ 154 //////////////////////////////////// 155 // コピーコンストラクタを呼び出す 156 //////////////////////////////////// 157 158 BOOL bUseHeap; 159 int temp_reg=REG_RDX; 160 CalcType.type=NumOpe(&temp_reg,Parameter,DEF_OBJECT,(LONG_PTR)pobj_Class,&CalcType.u.lpIndex,&bUseHeap); 161 162 if(bUseHeap){ 163 //mov r14,rdx 164 op_mov_RR(REG_R14,REG_RDX); 165 } 166 167 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 168 pobj_sf->ref(REG_R11); 169 170 //mov rcx,this 171 op_mov_RR(REG_RCX,REG_R11); 172 173 //call constructor 174 op_call(pobj_Class->GetCopyConstructorMethod()->psi); 175 176 177 if(bUseHeap){ 178 FreeTempObject(REG_R14,pobj_Class); 179 } 180 } 181 else{ 182 if( pobj_Class->GetConstructorMethod() ){ 183 //////////////////////////////// 184 // コンストラクタを呼び出す 185 //////////////////////////////// 186 187 //mov rcx,this 188 op_mov_RR(REG_RCX,REG_R11); 189 190 //call constructor 191 op_call(pobj_Class->GetConstructorMethod()->psi); 192 } 193 */ 194 195 196 BOOL bUseHeap; 197 int temp_reg=REG_RAX; 198 CalcType.type=NumOpe(&temp_reg,Parameter,DEF_STRUCT,(LONG_PTR)pobj_Class,&CalcType.u.lpIndex,&bUseHeap); 199 200 201 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 202 pobj_sf->ref(REG_R11); 203 204 205 RELATIVE_VAR RelativeVar; 206 RelativeVar.bOffsetOffset=0; 207 RelativeVar.offset=0; 208 RelativeVar.dwKind=VAR_DIRECTMEM; 209 210 SetStructVariableFromRax((LONG_PTR)pobj_Class,CalcType.type,CalcType.u.lpIndex,&RelativeVar,bUseHeap); 211 212 //} 144 145 Type calcType; 146 BOOL bUseHeap; 147 int temp_reg=REG_RAX; 148 NumOpe( &temp_reg, 149 expression, 150 baseType, 151 calcType, 152 &bUseHeap ); 153 154 155 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 156 pobj_sf->ref(REG_R11); 157 158 159 RELATIVE_VAR RelativeVar; 160 RelativeVar.bOffsetOffset=0; 161 RelativeVar.offset=0; 162 RelativeVar.dwKind=VAR_DIRECTMEM; 163 164 SetStructVariableFromRax( 165 baseType, 166 calcType, 167 &RelativeVar,bUseHeap); 168 213 169 214 170 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 … … 225 181 226 182 227 void ParamImpl::SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){ 183 void ParamImpl::SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 184 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 185 228 186 /////////////////////////////////////////////////////////// 229 187 // パラメータをレジスタ及びスタックフレームにセット … … 232 190 233 191 BOOL bEllipse; 234 if( pi_num){235 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;192 if( params.size() ){ 193 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 236 194 else bEllipse=0; 237 195 } … … 240 198 BOOL bHas_System_LocalThis=0; 241 199 if(ParmsNum>=1){ 242 if( lstrcmp(ppi[0].name,"_System_LocalThis")==0)200 if( params[0]->GetVarName() == "_System_LocalThis" ){ 243 201 bHas_System_LocalThis=1; 202 } 244 203 } 245 204 246 205 //戻り値用の変数名を取得 247 const char *lpszVarNameToReturn = ( FuncName[0]==1&&FuncName[1]==ESC_OPERATOR)?"_System_ReturnValue":FuncName;206 const char *lpszVarNameToReturn = (procName[0]==1&&procName[1]==ESC_OPERATOR)?"_System_ReturnValue":procName.c_str(); 248 207 249 208 //パラメータをレジスタとスタックに格納 250 int CalcType;251 LONG_PTR lpCalcIndex;252 BOOL bCalcUseHeap;253 209 int ParmSize=0; 254 210 int reg,temp_reg; 255 211 RELATIVE_VAR RelativeVar; 256 212 for(i2=ParmsNum-1;i2>=0;i2--){ 257 if(bEllipse&&i2<= pi_num-2) bEllipse=0;258 259 if(i2==0 &&ppi[i2].name){260 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){213 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 214 215 if(i2==0){ 216 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 261 217 //オブジェクトメンバの第一パラメータのThisポインタ 262 218 continue; 263 219 } 264 220 } 265 if( (i2==0||i2==1)&&ppi[i2].name){266 if( lstrcmp(ppi[i2].name,lpszVarNameToReturn)==0){221 if(i2==0||i2==1){ 222 if( params[i2]->GetVarName() == lpszVarNameToReturn ){ 267 223 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 268 224 continue; … … 270 226 } 271 227 272 T YPEINFO DummyTypeInfo;228 Type dummyType; 273 229 BOOL bByVal; 274 230 if(bEllipse){ 275 DummyTypeInfo.type=NumOpe_GetType(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);231 NumOpe_GetType( Parms[i2], Type(), dummyType ); 276 232 bByVal=1; 277 233 } 278 234 else{ 279 DummyTypeInfo.type=ppi[i2].type; 280 DummyTypeInfo.u.lpIndex=ppi[i2].u.index; 281 bByVal=ppi[i2].bByVal; 235 dummyType = *params[i2]; 236 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 282 237 } 283 238 284 239 int xmm_temp_sw=0; 285 if( IsRealNumberType(DummyTypeInfo.type)&&bByVal){240 if(dummyType.IsReal()&&bByVal){ 286 241 //実数型 287 242 if(i2==0) reg=REG_XMM0; … … 308 263 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){ 309 264 char temp2[255]; 310 sprintf(temp2,"%s関数の第%dパラメータ", FuncName,i2+1);265 sprintf(temp2,"%s関数の第%dパラメータ",procName,i2+1); 311 266 SetError(19,temp2,cp); 312 267 continue; 313 268 } 314 269 315 if( DummyTypeInfo.type==DEF_STRUCT){316 SetStructParameter( reg,DummyTypeInfo.u.pobj_Class,Parms[i2]);270 if( dummyType.IsStruct() ){ 271 SetStructParameter( reg, dummyType, Parms[i2] ); 317 272 goto next; 318 273 } … … 321 276 322 277 extern LONG_PTR ProcPtr_BaseIndex; 323 LONG_PTR back_ProcPtr_BaseIndex; 324 back_ProcPtr_BaseIndex=ProcPtr_BaseIndex; 325 if(DummyTypeInfo.type==DEF_PTR_PROC) ProcPtr_BaseIndex=DummyTypeInfo.u.lpIndex; 326 else ProcPtr_BaseIndex=-1; 327 328 CalcType=NumOpe(&temp_reg,Parms[i2],DummyTypeInfo.type,DummyTypeInfo.u.lpIndex,&lpCalcIndex,&bCalcUseHeap); 278 LONG_PTR back_ProcPtr_BaseIndex = ProcPtr_BaseIndex; 279 if( dummyType.IsProcPtr() ){ 280 ProcPtr_BaseIndex = dummyType.GetIndex(); 281 } 282 else{ 283 ProcPtr_BaseIndex=-1; 284 } 285 286 BOOL bCalcUseHeap; 287 Type calcType; 288 if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){ 289 break; 290 } 329 291 330 292 ProcPtr_BaseIndex=back_ProcPtr_BaseIndex; 331 293 332 if(CalcType==-1) break; 333 334 if(CalcType==DEF_OBJECT){ 335 if( DummyTypeInfo.type != DEF_OBJECT 294 if( calcType.IsObject() ){ 295 if( !dummyType.IsObject() 336 296 || 337 DummyTypeInfo.type == DEF_OBJECT&&338 ! DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpCalcIndex) ){297 dummyType.IsObject() && 298 !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){ 339 299 //キャスト演算子のオーバーロードに対応する 340 CallCastOperatorProc( reg,CalcType,lpCalcIndex,bCalcUseHeap,DummyTypeInfo.type,DummyTypeInfo.u.lpIndex);300 CallCastOperatorProc( reg, calcType, bCalcUseHeap,dummyType ); 341 301 } 342 302 } … … 344 304 345 305 if(bEllipse){ 346 if( IsRealNumberType(CalcType)){306 if( calcType.IsReal() ){ 347 307 //整数レジスタへコピー 348 308 //※cdeclの拡張パラメータは実数の場合も汎用レジスタで引渡し … … 358 318 } 359 319 } 360 else if( IsWholeNumberType(CalcType)){320 else if( calcType.IsWhole() ){ 361 321 //整数型の場合は、64ビットへ拡張する 362 ExtendTypeTo64( CalcType,temp_reg);322 ExtendTypeTo64( calcType.GetBasicType(), temp_reg ); 363 323 } 364 324 } … … 369 329 else i3=i2; 370 330 CheckDifferentType( 371 DummyTypeInfo.type, 372 DummyTypeInfo.u.lpIndex, 373 CalcType, 374 lpCalcIndex, 375 FuncName, 331 dummyType, 332 calcType, 333 procName.c_str(), 376 334 i3); 377 335 378 379 if(DummyTypeInfo.type==DEF_DOUBLE){ 336 if( dummyType.IsDouble() ){ 380 337 //Double型へ変換 381 ChangeTypeToXmm_Double( CalcType,reg,temp_reg);382 } 383 else if( DummyTypeInfo.type==DEF_SINGLE){338 ChangeTypeToXmm_Double(calcType.GetBasicType(),reg,temp_reg); 339 } 340 else if( dummyType.IsSingle() ){ 384 341 //Single型へ変換 385 ChangeTypeToXmm_Single( CalcType,reg,temp_reg);386 } 387 else if( IsWholeNumberType(DummyTypeInfo.type)){342 ChangeTypeToXmm_Single(calcType.GetBasicType(),reg,temp_reg); 343 } 344 else if( dummyType.IsWhole() ){ 388 345 //実数型 → 整数型 389 ChangeTypeToWhole( CalcType,DummyTypeInfo.type,reg,temp_reg);346 ChangeTypeToWhole(calcType.GetBasicType(),dummyType.GetBasicType(),reg,temp_reg); 390 347 } 391 348 } … … 397 354 398 355 temp_reg=reg; 399 CalcType=NumOpe(&temp_reg,Parms[i2]+2,0,0,&lpCalcIndex); 400 if(CalcType==-1) break; 401 402 int ptr_type; 403 ptr_type=GetPtrType(DummyTypeInfo.type,DummyTypeInfo.u.lpIndex); 356 Type calcType; 357 if( !NumOpe(&temp_reg, Parms[i2]+2, dummyType, calcType) ){ 358 break; 359 } 360 361 dummyType.PtrLevelUp(); 404 362 405 363 //型チェック … … 407 365 else i3=i2; 408 366 CheckDifferentType( 409 ptr_type, 410 DummyTypeInfo.u.lpIndex, 411 CalcType, 412 lpCalcIndex, 413 FuncName, 367 dummyType, 368 calcType, 369 procName.c_str(), 414 370 i3); 415 371 416 if( IsRealNumberType(CalcType)){372 if( calcType.IsReal() ){ 417 373 //実数型 → 整数型 418 ChangeTypeToWhole( CalcType,DEF_QWORD,reg,temp_reg);374 ChangeTypeToWhole( calcType.GetBasicType(), DEF_QWORD,reg,temp_reg); 419 375 } 420 376 } … … 428 384 else{ 429 385 //変数のアドレスを取得 430 int VarType; 431 LONG_PTR lpVarIndex; 386 Type varType; 432 387 if(GetVarOffset( 433 388 false, 434 389 false, 435 390 Parms[i2], 436 &VarType,437 391 &RelativeVar, 438 &lpVarIndex)){439 440 if( DummyTypeInfo.type!=DEF_ANY){392 varType)){ 393 394 if( !dummyType.IsAny() ){ 441 395 //型チェックを行う 442 if( DummyTypeInfo.type==VarType){443 if( DummyTypeInfo.type==DEF_OBJECT){444 if( ! DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpVarIndex) ){396 if( dummyType.GetBasicType() == varType.GetBasicType() ){ 397 if( dummyType.IsObject() ){ 398 if( !dummyType.GetClass().IsEqualsOrSubClass( &varType.GetClass() ) ){ 445 399 SetError(11,Parms[i2],cp); 446 400 } 447 401 } 448 else if( DummyTypeInfo.type==DEF_STRUCT){449 if( ! DummyTypeInfo.u.pobj_Class->IsEquals( (CClass *)lpVarIndex) ){402 else if( dummyType.IsStruct() ){ 403 if( !dummyType.GetClass().IsEquals( &varType.GetClass() ) ){ 450 404 SetError(11,Parms[i2],cp); 451 405 } 452 406 } 453 407 } 454 else if((VarType&FLAG_PTR)&&((VarType^FLAG_PTR)==DummyTypeInfo.type)){ 408 else if( (varType.GetBasicType()&FLAG_PTR) 409 &&((varType.GetBasicType()^FLAG_PTR)==dummyType.GetBasicType())){ 455 410 //仮引数がポインタ参照で、実引数が配列の先頭ポインタのとき 456 411 } … … 494 449 495 450 //パラメータが収まるだけのスタックフレームを確保 496 pobj_sf->parameter_allocate( pi_num*sizeof(_int64)+ sizeof(_int64)/*ret用*/ );451 pobj_sf->parameter_allocate((int)params.size()*sizeof(_int64)+ sizeof(_int64)/*ret用*/ ); 497 452 } 498 453 void ParamImpl::BackupParameter(int pi_num){ -
BasicCompiler64/Compile_Calc.cpp
r64 r75 84 84 } 85 85 86 LONG_PTR lp; 87 if(GetVarType(variable,&lp,0)!=-1){ 86 if(GetVarType(variable,Type(),0)){ 88 87 //変数リストに該当したとき 89 88 SetError(1,NULL,cp); … … 129 128 130 129 char ObjName[VN_SIZE],array_element[VN_SIZE]; 131 CClass *pobj_c;132 130 GetArrayElement(variable,ObjName,array_element); 133 131 if(array_element[0]){ 134 i2=GetVarType(ObjName,(LONG_PTR *)&pobj_c,0);135 if( i2==DEF_OBJECT){132 Type varType; 133 if( GetVarType(ObjName,varType,0) && varType.IsObject() ){ 136 134 char temporary[VN_SIZE]; 137 135 sprintf(temporary,"%s.%c%c%c",ObjName,1,ESC_OPERATOR,CALC_ARRAY_SET); … … 141 139 142 140 int idProc; 143 void *p Info;144 idProc=GetProc(temporary, &pInfo);141 void *pProc; 142 idProc=GetProc(temporary,(void **)&pProc); 145 143 if(idProc){ 146 CallProc(idProc,p Info,temporary,temp2,NULL);144 CallProc(idProc,pProc,temporary,temp2,Type()); 147 145 return; 148 146 } … … 161 159 //////////////////////////////////////// 162 160 163 int VarType,CalcType; 164 LONG_PTR lpVarIndex,lpCalcIndex; 165 BOOL bCalcUseHeap; 161 Type varType; 166 162 167 163 //型を識別 168 VarType=GetVarType(variable,&lpVarIndex,0); 169 if(VarType==-1){ 164 if( !GetVarType(variable,varType,false) ){ 170 165 171 166 // プロパティ用のメソッドを呼び出す 172 if(!CallPropertyMethod( variable,Command+i+1,NULL)){167 if(!CallPropertyMethod( variable, Command+i+1, Type() )){ 173 168 //エラーを表示 174 GetVarType(variable, &lpVarIndex,1);169 GetVarType(variable,varType,true); 175 170 } 176 171 … … 179 174 180 175 extern LONG_PTR ProcPtr_BaseIndex; 181 if( VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex;176 if(varType.IsProcPtr()) ProcPtr_BaseIndex=varType.GetIndex(); 182 177 else ProcPtr_BaseIndex=-1; 183 178 184 179 //NumOpe...(rax、またはxmm0に答えが格納される) 185 180 int reg=REG_RAX; 186 CalcType=NumOpe(®,Command+i+1,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap); 187 188 if(reg!=REG_RAX&&IsWholeNumberType(CalcType)){ 181 BOOL bCalcUseHeap; 182 Type calcType; 183 if( !NumOpe(®,Command+i+1,varType,calcType,&bCalcUseHeap) ){ 184 return; 185 } 186 187 if(reg!=REG_RAX&&calcType.IsWhole()|| 188 varType.IsNull()||calcType.IsNull()){ 189 189 SetError(300,NULL,cp); 190 190 } 191 192 if(VarType==-1||CalcType==-1) return;193 191 194 192 //結果を格納しているレジスタをブロッキング … … 199 197 if(!GetVarOffsetReadWrite( 200 198 variable, 201 &VarType,202 199 &VarRelativeVar, 203 &lpVarIndex, 204 NULL)) return; 200 varType)) return; 205 201 206 202 //レジスタのブロッキングを解除 207 203 pobj_BlockReg->clear(); 208 204 209 if( VarType&FLAG_PTR){205 if(varType.GetBasicType()&FLAG_PTR){ 210 206 SetError(14,variable,cp); 211 207 return; 212 208 } 213 209 214 if( VarType==DEF_STRUCT){210 if( varType.IsStruct() ){ 215 211 //構造体インスタンスへの代入 216 SetStructVariableFromRax( lpVarIndex,CalcType,lpCalcIndex,&VarRelativeVar,bCalcUseHeap);217 return; 218 } 219 220 if( CalcType==DEF_OBJECT && (CalcType!=VarType || lpCalcIndex!=lpVarIndex) ){212 SetStructVariableFromRax(varType,calcType,&VarRelativeVar,bCalcUseHeap); 213 return; 214 } 215 216 if( calcType.IsObject() && !calcType.Equals( varType ) ){ 221 217 //キャスト演算子のオーバーロードに対応する 222 CallCastOperatorProc(REG_RAX, CalcType,lpCalcIndex,bCalcUseHeap,VarType,lpVarIndex);218 CallCastOperatorProc(REG_RAX,calcType,bCalcUseHeap,varType); 223 219 } 224 220 … … 228 224 ///////////////////////////////// 229 225 230 CheckDifferentType( VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);226 CheckDifferentType(varType,calcType,0,0); 231 227 232 228 … … 234 230 // rax(実数はxmm0)の内容を変数にコピー 235 231 ///////////////////////////////////////////////// 236 SetVariableFromRax( VarType,CalcType,&VarRelativeVar);232 SetVariableFromRax(varType.GetBasicType(),calcType.GetBasicType(),&VarRelativeVar); 237 233 } 238 239 // TODO: 消す240 /*241 void SetRefVariable( const char *varname, const char *expression ){242 ////////////////////////////////////////243 // 変数のタイプ型を識別して、演算を行う244 ////////////////////////////////////////245 246 int VarType,CalcType;247 LONG_PTR lpVarIndex,lpCalcIndex;248 BOOL bCalcUseHeap;249 250 //型を識別251 VarType=GetVarType(varname,&lpVarIndex,0);252 if(VarType==-1){253 SetError(300,NULL,cp);254 return;255 }256 257 extern LONG_PTR ProcPtr_BaseIndex;258 if(VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex;259 else ProcPtr_BaseIndex=-1;260 261 //NumOpe...(rax、またはxmm0に答えが格納される)262 int reg=REG_RAX;263 CalcType=NumOpe(®,expression,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap);264 265 //結果を格納しているレジスタをブロッキング266 pobj_BlockReg->lock(reg);267 268 if(VarType==-1||CalcType==-1) return;269 270 //変数アドレスを取得271 RELATIVE_VAR VarRelativeVar;272 if(!GetVarOffsetReadWrite(273 varname,274 &VarType,275 &VarRelativeVar,276 &lpVarIndex)) return;277 278 //レジスタのブロッキングを解除279 pobj_BlockReg->clear();280 281 if(VarType&FLAG_PTR){282 SetError(14,varname,cp);283 return;284 }285 286 if( VarType == DEF_OBJECT287 && (VarRelativeVar.dwKind == VAR_REFLOCAL || VarRelativeVar.dwKind == VAR_REFGLOBAL ) ){288 // 参照型オブジェクトへの代入(初期化)はポインタ変数と同様の処理に値する289 PTR_LEVEL_UP( VarType );290 291 if( VarRelativeVar.dwKind == VAR_REFGLOBAL ){292 VarRelativeVar.dwKind = VAR_GLOBAL;293 }294 else if( VarRelativeVar.dwKind == VAR_REFLOCAL ){295 VarRelativeVar.dwKind = VAR_LOCAL;296 }297 298 if( CalcType == DEF_OBJECT ){299 //右辺値が実体オブジェクトのときは、参照をコピー300 PTR_LEVEL_UP( CalcType );301 }302 }303 else{304 SetError(300,NULL,cp);305 }306 307 308 /////////////////////////////////309 // 右辺、左辺の型チェックを行う310 /////////////////////////////////311 312 CheckDifferentType(VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);313 314 315 /////////////////////////////////////////////////316 // rax(実数はxmm0)の内容を変数にコピー317 /////////////////////////////////////////////////318 SetVariableFromRax(VarType,CalcType,&VarRelativeVar);319 }320 */ -
BasicCompiler64/Compile_CallProc.cpp
r73 r75 8 8 void Call_DebugSys_SaveContext(){ 9 9 //call _System_GetEip 10 extern SubInfo*pSub_System_GetEip;10 extern UserProc *pSub_System_GetEip; 11 11 op_call(pSub_System_GetEip); 12 12 … … 18 18 19 19 //call _DebugSys_SaveContext 20 extern SubInfo*pSub_DebugSys_SaveContext;20 extern UserProc *pSub_DebugSys_SaveContext; 21 21 op_call(pSub_DebugSys_SaveContext); 22 22 } … … 32 32 33 33 34 int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex){ 35 extern HANDLE hHeap; 36 int i; 37 34 bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer){ 38 35 39 36 extern BOOL bDebugCompile; … … 49 46 //パラメータオブジェクトを生成 50 47 ParamImpl *pobj_parameter=0; 51 pobj_parameter=new ParamImpl( Parameter);48 pobj_parameter=new ParamImpl(lpszParms); 52 49 53 50 //エラーチェック 54 if( !pobj_parameter->ErrorCheck(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum) ){51 if( !pobj_parameter->ErrorCheck(variable,pProcPointer->Params() ) ){ 55 52 //パラメータにエラーがあるときは処理を終える 56 return pi->ReturnType;53 return false; 57 54 } 58 55 59 56 //スタックフレームに存在する既存のパラメータをバックアップ 60 pobj_parameter->BackupParameter( pi->ParmNum);57 pobj_parameter->BackupParameter( (int)pProcPointer->Params().size() ); 61 58 62 59 //一時オブジェクトを生成 63 pobj_parameter->NewTempParameters( variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);60 pobj_parameter->NewTempParameters( variable,pProcPointer->Params() ); 64 61 65 62 //レジスタ、スタックフレームにセット 66 pobj_parameter->SetParameter(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);63 pobj_parameter->SetParameter(variable,pProcPointer->Params() ); 67 64 68 65 69 66 70 67 RELATIVE_VAR RelativeVar; 71 LONG_PTR lp; 72 GetVarOffsetReadOnly(variable,&i,&RelativeVar,&lp); 68 GetVarOffsetReadOnly(variable,&RelativeVar,Type()); 73 69 SetVarPtrToReg(REG_RAX,&RelativeVar); 74 70 … … 88 84 89 85 //スタックフレームに存在する既存のパラメータを復元 90 pobj_parameter->RestoreParameter( pi->ParmNum);86 pobj_parameter->RestoreParameter( (int)pProcPointer->Params().size() ); 91 87 92 88 //パラメータオブジェクトを破棄 93 89 delete pobj_parameter; 94 90 95 return pi->ReturnType;91 return true; 96 92 } 97 93 98 void Opcode_CallProc(const char *Parameter,SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType){94 bool Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType){ 99 95 int i2; 100 96 101 if( psi->dwType==SUBTYPE_MACRO){102 if( lstrcmpi(psi->name,"Print")==0){97 if( pUserProc->IsMacro() ){ 98 if( lstrcmpi( pUserProc->GetName().c_str(), "Print" ) == 0 ){ 103 99 Opcode_Print(Parameter,0); 104 return ;105 } 106 if( lstrcmpi(psi->name,"Input")==0){100 return true; 101 } 102 if( lstrcmpi( pUserProc->GetName().c_str(), "Input" ) == 0 ){ 107 103 Opcode_Input(Parameter); 108 return ;109 } 110 if( lstrcmpi(psi->name,"Write")==0){104 return true; 105 } 106 if( lstrcmpi( pUserProc->GetName().c_str(), "Write" ) == 0 ){ 111 107 Opcode_Print(Parameter,1); 112 return ;113 } 114 } 115 116 p si->bUse=1;108 return true; 109 } 110 } 111 112 pUserProc->Using(); 117 113 118 114 bool isStatic = false; 119 CClass *pobj_c = NULL;115 const CClass *pobj_c = NULL; 120 116 CMethod *pMethod = NULL; 121 if( psi->pobj_ParentClass){117 if( pUserProc->GetParentClassPtr() ){ 122 118 //クラスのメンバ関数を呼び出す場合はアクセスチェックを行う 123 119 if(ObjectName[0]){ … … 128 124 else{ 129 125 //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し 130 int type = GetVarType(ObjectName,(LONG_PTR *)&pobj_c,0); 131 if(!(NATURAL_TYPE(type)==DEF_OBJECT)){ 126 Type varType; 127 GetVarType( ObjectName, varType, false ); 128 pobj_c = &varType.GetClass(); 129 if( NATURAL_TYPE( varType.GetBasicType() ) != DEF_OBJECT ){ 132 130 pobj_c=pobj_DBClass->check(ObjectName); 133 131 if( pobj_c ){ … … 143 141 if(dwFlags&PROCFLAG_NEW){ 144 142 //New演算子によるコンストラクタ呼び出し 145 pobj_c=p si->pobj_ParentClass;143 pobj_c=pUserProc->GetParentClassPtr(); 146 144 } 147 145 else{ … … 156 154 ///////////////////////////////// 157 155 pMethod = NULL; 158 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( p si);156 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( pUserProc ); 159 157 if( ! pMethod ){ 160 158 //動的メソッドが取得できなかったときは静的メソッドを当たる 161 pMethod = pobj_c->GetStaticMethodInfo( p si);159 pMethod = pobj_c->GetStaticMethodInfo( pUserProc ); 162 160 if( !pMethod ){ 163 161 SetError(300,NULL,cp); 164 return ;162 return false; 165 163 } 166 164 … … 180 178 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 181 179 if(dwAccess==ACCESS_NON){ 182 SetError(109,p si->name,cp);183 return ;180 SetError(109,pUserProc->GetName(),cp); 181 return false; 184 182 } 185 183 } … … 187 185 if(dwAccess==ACCESS_PRIVATE|| 188 186 dwAccess==ACCESS_NON){ 189 SetError(109,p si->name,cp);190 return ;187 SetError(109,pUserProc->GetName(),cp); 188 return false; 191 189 } 192 190 if(dwAccess==ACCESS_PROTECTED){ 193 SetError(110,p si->name,cp);194 return ;191 SetError(110,pUserProc->GetName(),cp); 192 return false; 195 193 } 196 194 } … … 199 197 //クラス内部からの呼び出し(継承によるACCESS_NONのみをエラーとする) 200 198 if(dwAccess==ACCESS_NON){ 201 SetError(109,p si->name,cp);202 return ;199 SetError(109,pUserProc->GetName(),cp); 200 return false; 203 201 } 204 202 } … … 211 209 212 210 char temporary[VN_SIZE]={0}; 213 if( p si->pobj_ParentClass&& isStatic == false ){211 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 214 212 //_System_LocalThis(第一パラメータ)のダミーを作成 215 213 lstrcpy(temporary,"0,"); … … 234 232 235 233 //エラーチェック 236 if( !pobj_parameter->ErrorCheck(p si->name,psi->realParams,psi->SecondParmNum) ){234 if( !pobj_parameter->ErrorCheck(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetSecondParmNum() ) ){ 237 235 //パラメータにエラーがあるときは処理を終える 238 return ;239 } 240 241 if(p si->dwType==SUBTYPE_MACRO){236 return false; 237 } 238 239 if(pUserProc->IsMacro()){ 242 240 //マクロ関数の場合は、パラメータ省略を考慮する 243 pobj_parameter->MacroParameterSupport( psi->realParams);241 pobj_parameter->MacroParameterSupport( pUserProc->RealParams() ); 244 242 } 245 243 246 244 //スタックフレームに存在する既存のパラメータをバックアップ 247 pobj_parameter->BackupParameter( psi->RealParmNum);245 pobj_parameter->BackupParameter( (int)pUserProc->RealParams().size() ); 248 246 249 247 //一時オブジェクトを生成 250 pobj_parameter->NewTempParameters( p si->name,psi->realParams,psi->RealSecondParmNum);248 pobj_parameter->NewTempParameters( pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 251 249 252 250 //レジスタ、スタックフレームにセット 253 pobj_parameter->SetParameter(p si->name,psi->realParams,psi->RealSecondParmNum);254 255 if(p si->ReturnType==DEF_STRUCT && psi->isReturnRef == false){251 pobj_parameter->SetParameter(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 252 253 if(pUserProc->ReturnType().IsStruct() ){ 256 254 ////////////////////////////////////////////////////// 257 255 // 戻り値に構造体インスタンスを持つ場合 … … 265 263 ////////////////////////////////////////////////////// 266 264 267 int object_size = p si->u.Return_pobj_c->GetSize();265 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 268 266 269 267 //mov rcx,object_size … … 271 269 272 270 //call calloc 273 extern SubInfo*pSub_calloc;271 extern UserProc *pSub_calloc; 274 272 op_call(pSub_calloc); 275 273 … … 282 280 }//////////////////////////////////////////// 283 281 284 if( p si->pobj_ParentClass&& isStatic == false ){282 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 285 283 //mov rdx,r13 286 284 op_mov_RR(REG_RDX,REG_R13); … … 293 291 294 292 295 if( p si->pobj_ParentClass&& isStatic == false ){293 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 296 294 /////////////////////////////// 297 295 // メンバ関数の場合 … … 305 303 if( pMethod->isConst ){ 306 304 //Constアクセスが可能なメソッドの場合 307 if( !GetVarOffsetReadOnly( ObjectName, &i2, &RelativeVar, 0 ) ) return; 305 if( !GetVarOffsetReadOnly( ObjectName, &RelativeVar, Type() ) ){ 306 return false; 307 } 308 308 } 309 309 else{ 310 310 //Constアクセスが不可能なメソッドの場合 311 if( !GetVarOffsetReadWrite( ObjectName, &i2, &RelativeVar, 0 ) ) return; 311 if( !GetVarOffsetReadWrite( ObjectName, &RelativeVar, Type() ) ){ 312 return false; 313 } 312 314 } 313 315 … … 334 336 } 335 337 336 if( psi->bVirtual){338 if( pUserProc->IsVirtual() ){ 337 339 //仮想関数(オブジェクトメソッド)呼び出し 338 340 //pObj->func_table->func1 … … 343 345 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 344 346 345 i2 = pobj_c->GetFuncNumInVtbl( p si);347 i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 346 348 347 349 //call qword ptr[r11+func_index] … … 364 366 365 367 //call ProcAddr 366 op_call(p si);368 op_call(pUserProc); 367 369 } 368 370 369 371 /* 64コンパイラでは不要 370 if(p di->bCdecl){372 if(pDllProc->bCdecl){ 371 373 //add esp,ParmSize 372 374 }*/ … … 380 382 381 383 //スタックフレームに存在する既存のパラメータを復元 382 pobj_parameter->RestoreParameter( psi->RealParmNum);384 pobj_parameter->RestoreParameter( (int)pUserProc->RealParams().size() ); 383 385 384 386 //パラメータオブジェクトを破棄 385 387 delete pobj_parameter; 388 389 return true; 386 390 } 387 391 388 int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex){ 389 char *temporary; 390 391 temporary=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter)+1); 392 bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc ){ 392 393 393 394 extern BOOL bDebugCompile; 394 395 extern BOOL bDebugSupportProc; 395 if(bDebugCompile&&bDebugSupportProc==0&& lstrcmp(pdi->name,"DebugBreak")!=0)396 if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->GetName() != "DebugBreak" ){ 396 397 Call_DebugSys_SaveContext(); 397 398 } 398 399 399 400 … … 404 405 //パラメータオブジェクトを生成 405 406 ParamImpl *pobj_parameter=0; 406 pobj_parameter=new ParamImpl( Parameter);407 pobj_parameter=new ParamImpl(lpszParms); 407 408 408 409 //エラーチェック 409 if( !pobj_parameter->ErrorCheck( pdi->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum) ){410 if( !pobj_parameter->ErrorCheck( pDllProc->GetName(), pDllProc->Params() ) ){ 410 411 //パラメータにエラーがあるときは処理を終える 411 return pdi->ReturnType;412 return false; 412 413 } 413 414 414 415 //スタックフレームに存在する既存のパラメータをバックアップ 415 pobj_parameter->BackupParameter( pdi->ParmNum);416 pobj_parameter->BackupParameter( (int)pDllProc->Params().size() ); 416 417 417 418 //一時オブジェクトを生成 418 pobj_parameter->NewTempParameters( p di->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum);419 pobj_parameter->NewTempParameters( pDllProc->GetName(), pDllProc->Params() ); 419 420 420 421 //レジスタ、スタックフレームにセット 421 pobj_parameter->SetParameter(p di->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum);422 pobj_parameter->SetParameter(pDllProc->GetName(), pDllProc->Params() ); 422 423 423 424 … … 429 430 430 431 //call dword ptr[ImportTable] 431 op_call( p di);432 op_call( pDllProc ); 432 433 433 434 /* 64コンパイラでは不要 434 if(p di->bCdecl){435 if(pDllProc->bCdecl){ 435 436 //add esp,ParmSize 436 437 }*/ … … 440 441 441 442 //スタックフレームに存在する既存のパラメータを復元 442 pobj_parameter->RestoreParameter( pdi->ParmNum);443 pobj_parameter->RestoreParameter( (int)pDllProc->Params().size() ); 443 444 444 445 //パラメータオブジェクトを破棄 445 446 delete pobj_parameter; 446 447 447 if(plpIndex) *plpIndex=pdi->u.ReturnIndex; 448 449 HeapDefaultFree(temporary); 450 451 return pdi->ReturnType; 448 return true; 452 449 } -
BasicCompiler64/Compile_Func.cpp
r73 r75 40 40 } 41 41 void Opcode_Func_Len( const char *Parameter ){ 42 int type,TypeSize;43 LONG_PTR lpIndex;44 42 BOOL bArrayHead; 45 46 type=GetVarType(Parameter,&lpIndex,0);47 43 48 44 const char *tempParm=Parameter; 49 45 char temporary[VN_SIZE]; 50 46 char temp2[32]; 51 if(type==-1){ 47 Type type; 48 if( !GetVarType(Parameter,type,0) ){ 52 49 sprintf(temporary,"_System_DummyStr2=%s",Parameter); 53 50 OpcodeCalc(temporary); … … 57 54 58 55 extern CClass *pobj_StringClass; 59 type=DEF_OBJECT; 60 lpIndex=(LONG_PTR)pobj_StringClass; 61 } 62 63 TYPEINFO TypeInfo={type,lpIndex}; 64 if(IsStringObjectType(TypeInfo)){ 56 type.SetType( DEF_OBJECT, pobj_StringClass ); 57 } 58 59 if( type.IsStringObject() ){ 65 60 //Stringオブジェクトの場合 66 61 sprintf(temporary,"%s.Length",tempParm); 67 62 68 63 int reg=REG_RAX; 69 NumOpe(®,temporary, 0,0,NULL,NULL);64 NumOpe(®,temporary,Type(),Type(),NULL); 70 65 return; 71 66 } … … 74 69 int SubScripts[MAX_ARRAYDIM]; 75 70 RELATIVE_VAR RelativeVar; 76 if(!GetVarOffsetReadOnly(tempParm,& type,&RelativeVar,&lpIndex,SubScripts)) return;77 78 79 if(type &FLAG_PTR){80 type &=~FLAG_PTR;71 if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,SubScripts)) return; 72 73 74 if(type.GetBasicType()&FLAG_PTR){ 75 type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) ); 81 76 82 77 bArrayHead=1; … … 84 79 else bArrayHead=0; 85 80 86 TypeSize=GetTypeSize(type,lpIndex);87 88 if(bArrayHead) TypeSize*=JumpSubScripts(SubScripts);81 int typeSize = type.GetSize(); 82 83 if(bArrayHead) typeSize*=JumpSubScripts(SubScripts); 89 84 90 85 //mov rax,TypeSize 91 op_mov_RV(sizeof(_int64),REG_RAX, TypeSize);86 op_mov_RV(sizeof(_int64),REG_RAX,typeSize); 92 87 93 88 return; … … 95 90 void Opcode_Func_AddressOf( const char *name ){ 96 91 extern int cp; 97 SubInfo *psi;92 UserProc *pUserProc; 98 93 99 94 extern LONG_PTR ProcPtr_BaseIndex; … … 101 96 //左辺の型にのっとり、オーバーロードを解決 102 97 103 std::vector< SubInfo*> subs;98 std::vector<UserProc *> subs; 104 99 GetOverloadSubHash( name, subs ); 105 100 if( subs.size() == 0 ){ … … 109 104 110 105 //オーバーロードを解決 111 extern P ROCPTRINFO *pProcPtrInfo;112 p si=OverloadSolution(name,subs,pProcPtrInfo[ProcPtr_BaseIndex].pParmInfo,pProcPtrInfo[ProcPtr_BaseIndex].ParmNum,NULL);113 114 if(!p si){106 extern ProcPointer **ppProcPointer; 107 pUserProc=OverloadSolution(name,subs,ppProcPointer[ProcPtr_BaseIndex]->Params(), Type() ); 108 109 if(!pUserProc){ 115 110 SetError(27,name,cp); 116 111 return; … … 118 113 } 119 114 else{ 120 p si=GetSubHash(name);121 if(!p si){115 pUserProc=GetSubHash(name); 116 if(!pUserProc){ 122 117 SetError(27,name,cp); 123 118 return; … … 125 120 } 126 121 127 128 if(psi->bVirtual){ 122 if( pUserProc->IsVirtual() ){ 129 123 /////////////////////////////// 130 124 // 仮想関数の場合 … … 142 136 else{ 143 137 RELATIVE_VAR RelativeVar; 144 inttype;145 if(!GetVarOffsetReadOnly(ObjectName,& type,&RelativeVar,(LONG_PTR *)&pobj_c)) return;138 Type type; 139 if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return; 146 140 SetVarPtrToReg(REG_RCX,&RelativeVar); 147 141 148 142 //参照タイプが整合しているかをチェック 149 if(type !=RefType) SetError(104,ObjectName,cp);150 151 if(type ==DEF_PTR_OBJECT){143 if(type.GetBasicType()!=RefType) SetError(104,ObjectName,cp); 144 145 if(type.IsObjectPtr()){ 152 146 //mov rcx,qword ptr[rcx] 153 147 op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); … … 172 166 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 173 167 174 int i2 = pobj_c->GetFuncNumInVtbl( p si);168 int i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 175 169 176 170 //mov rax,qword ptr[r11+func_index] … … 188 182 op_mov_RV(sizeof(_int64),REG_RAX,0); 189 183 obp-=sizeof(long); 190 pobj_SubAddrSchedule->add(p si,0);184 pobj_SubAddrSchedule->add(pUserProc,0); 191 185 obp+=sizeof(long); 192 186 } 193 187 194 p si->bUse=1;188 pUserProc->Using(); 195 189 } 196 190 void Opcode_Func_SizeOf( const char *Parameter ){ … … 210 204 op_mov_RV(sizeof(_int64),REG_RAX,size); 211 205 } 212 void Opcode_Func_VarPtr( const char *Parameter, TYPEINFO &ReturnTypeInfo ){ 206 void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ 207 if( isCallOn == false ){ 208 // 戻り値の型を取得するだけ 209 210 //変数のアドレスを取得 211 if(!GetVarType( Parameter, resultType, true )) return; 212 213 resultType.PtrLevelUp(); 214 215 return; 216 } 217 213 218 RELATIVE_VAR RelativeVar; 214 219 215 220 //変数のアドレスを取得 216 if(!GetVarOffsetReadOnly( Parameter, &Re turnTypeInfo.type, &RelativeVar, &ReturnTypeInfo.u.lpIndex)) return;217 218 int beforeType = ReturnTypeInfo.type;219 220 PTR_LEVEL_UP( ReturnTypeInfo.type);221 if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; 222 223 int beforeType = resultType.GetBasicType(); 224 225 resultType.PtrLevelUp(); 221 226 222 227 SetVarPtrToReg(REG_RAX,&RelativeVar); … … 230 235 } 231 236 void Opcode_Func_GetPtrData( const char *Parameter, const int type ){ 232 int i2;233 234 237 int reg=REG_RAX; 235 i2=NumOpe(®,Parameter,0,0,0); 236 if(!IsWholeNumberType(i2)){ 237 extern int cp; 238 Type tempType; 239 if( !NumOpe(®,Parameter,Type(),tempType) ){ 240 return; 241 } 242 if(!tempType.IsWhole()){ 238 243 SetError(11,Parameter,cp); 239 244 return; … … 254 259 } 255 260 256 void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo){261 bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &resultType, bool isCallOn ){ 257 262 switch(FuncNum){ 258 263 case FUNC_LEN: 259 Opcode_Func_Len(Parameter);260 ReturnTypeInfo.type = DEF_LONG;264 if( isCallOn ) Opcode_Func_Len(Parameter); 265 resultType.SetBasicType( DEF_LONG ); 261 266 break; 262 267 case FUNC_ADDRESSOF: 263 Opcode_Func_AddressOf(Parameter);264 ReturnTypeInfo.type = DEF_PTR_VOID;268 if( isCallOn ) Opcode_Func_AddressOf(Parameter); 269 resultType.SetBasicType( DEF_PTR_VOID ); 265 270 break; 266 271 case FUNC_SIZEOF: 267 Opcode_Func_SizeOf(Parameter);268 ReturnTypeInfo.type = DEF_LONG;272 if( isCallOn ) Opcode_Func_SizeOf(Parameter); 273 resultType.SetBasicType( DEF_LONG ); 269 274 break; 270 275 case FUNC_VARPTR: 271 Opcode_Func_VarPtr( Parameter, ReturnTypeInfo);276 Opcode_Func_VarPtr( Parameter, resultType, isCallOn ); 272 277 break; 273 278 274 279 case FUNC_GETDOUBLE: 275 Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);276 ReturnTypeInfo.type = DEF_DOUBLE;280 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE); 281 resultType.SetBasicType( DEF_DOUBLE ); 277 282 break; 278 283 case FUNC_GETSINGLE: 279 Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);280 ReturnTypeInfo.type = DEF_SINGLE;284 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE); 285 resultType.SetBasicType( DEF_SINGLE ); 281 286 break; 282 287 case FUNC_GETQWORD: 283 Opcode_Func_GetPtrData(Parameter,DEF_QWORD);284 ReturnTypeInfo.type = DEF_QWORD;288 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD); 289 resultType.SetBasicType( DEF_QWORD ); 285 290 break; 286 291 case FUNC_GETDWORD: 287 Opcode_Func_GetPtrData(Parameter,DEF_DWORD);288 ReturnTypeInfo.type = DEF_DWORD;292 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD); 293 resultType.SetBasicType( DEF_DWORD ); 289 294 break; 290 295 case FUNC_GETWORD: 291 Opcode_Func_GetPtrData(Parameter,DEF_WORD);292 ReturnTypeInfo.type = DEF_WORD;296 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD); 297 resultType.SetBasicType( DEF_WORD ); 293 298 break; 294 299 case FUNC_GETBYTE: 295 Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 296 ReturnTypeInfo.type = DEF_BYTE; 297 break; 298 } 299 } 300 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 301 resultType.SetBasicType( DEF_BYTE ); 302 break; 303 default: 304 return false; 305 } 306 return true; 307 } -
BasicCompiler64/Compile_Object.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 void _call_constructor( CClass *pobj_c,const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){4 void _call_constructor( const CClass *pobj_c,const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){ 5 5 //////////////////////////// 6 6 // コンストラクタの呼び出し … … 32 32 //////////////////////// 33 33 34 std::vector< SubInfo*> subs;34 std::vector<UserProc *> subs; 35 35 pobj_c->EnumMethod( pobj_c->name, subs ); 36 36 37 SubInfo *psi;37 UserProc *pUserProc; 38 38 if( subs.size() > 0 ){ 39 39 //オーバーロードを解決 40 p si=OverloadSolutionWithStrParam(pobj_c->name,41 subs,CreateParameter,"" ,NULL);42 43 if(!p si) return;40 pUserProc=OverloadSolutionWithStrParam(pobj_c->name, 41 subs,CreateParameter,""); 42 43 if(!pUserProc) return; 44 44 } 45 45 46 46 //コンストラクタを呼び出す 47 47 Opcode_CallProc(CreateParameter, 48 p si,48 pUserProc, 49 49 PROCFLAG_NEW,"",0); 50 50 … … 73 73 } 74 74 } 75 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo){75 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType ){ 76 76 int typeSize = classObj.GetSize(); 77 77 … … 86 86 87 87 int reg=REG_RAX; 88 int type = NumOpe(®,objectSizeStr,0,0,0); 89 if(!IsWholeNumberType(type)) SetError(49,NULL,cp); 88 Type tempType; 89 NumOpe(®,objectSizeStr,Type(),tempType); 90 if( !tempType.IsWhole() ) SetError(49,NULL,cp); 90 91 91 92 //※添え字上限値であることを考慮 … … 117 118 } 118 119 119 if( baseTypeInfo.type == DEF_OBJECT ){ 120 //DeleteはGCで処理 120 if( baseType.IsObject() ){ 121 // オブジェクト インスタンス 122 // ※DeleteはGCで処理 121 123 122 124 //call _System_GC_malloc_ForObject 123 extern SubInfo*pSub_System_GC_malloc_ForObject;125 extern UserProc *pSub_System_GC_malloc_ForObject; 124 126 op_call(pSub_System_GC_malloc_ForObject); 125 127 } 126 128 else{ 127 //明示的なDeleteが必要 129 // オブジェクトポインタ 130 // ※明示的なDeleteが必要 128 131 129 132 //call _System_GC_malloc_ForObjectPtr 130 extern SubInfo*pSub_System_GC_malloc_ForObjectPtr;133 extern UserProc *pSub_System_GC_malloc_ForObjectPtr; 131 134 op_call(pSub_System_GC_malloc_ForObjectPtr); 132 135 } … … 162 165 op_mov_RV(sizeof(_int64),REG_RCX,0); 163 166 obp-=sizeof(long); 164 pobj_SubAddrSchedule->add(method->p si,0);165 method->p si->bUse=1;167 pobj_SubAddrSchedule->add(method->pUserProc,0); 168 method->pUserProc->Using(); 166 169 obp+=sizeof(long); 167 170 … … 190 193 pobj_sf->pop(REG_RAX); 191 194 } 192 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ){193 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];194 int i,i2;195 196 i=0;197 198 if(Parameter[0]=='['){199 i=GetStringInBracket(objectSizeStr,Parameter);200 201 SlideString(objectSizeStr+1,-1);202 objectSizeStr[i-2]=0;203 }204 else objectSizeStr[0]=0;205 206 for(i2=0;;i++,i2++){207 if(Parameter[i]=='('){208 TypeName[i2]=0;209 210 //コンストラクタに渡すパラメータを取得211 i2=GetStringInPare(CreateParameter,Parameter+i);212 RemoveStringPare(CreateParameter);213 i+=i2;214 if(Parameter[i]!='\0'){215 SetError(42,NULL,cp);216 return 0;217 }218 break;219 }220 TypeName[i2]=Parameter[i];221 if(Parameter[i]=='\0'){222 CreateParameter[0]=0;223 break;224 }225 }226 227 int type;228 type=GetTypeFixed(TypeName,plpIndex);229 if(type==-1){230 SetError(3,TypeName,cp);231 return 0;232 }233 234 if(type!=DEF_OBJECT){235 ////////////////////////236 // 通常のデータ型の場合237 ////////////////////////238 239 SetError(121,NULL,cp);240 return 0;241 }242 243 CClass *pobj_c;244 pobj_c=(CClass *)*plpIndex;245 246 Operator_New( *pobj_c, objectSizeStr, CreateParameter, baseTypeInfo );247 248 if( baseTypeInfo.type == DEF_OBJECT ){249 return DEF_OBJECT;250 }251 return DEF_PTR_OBJECT;252 }253 254 195 void OpcodeDelete(const char *Parameter, bool isSweeping){ 255 int type;256 257 196 int reg=REG_RAX; 258 type=NumOpe(®,Parameter,0,0,0); 259 if(type==-1) return; 260 if(!(type==DEF_PTR_OBJECT||type==DEF_PTR_VOID)) SetError(122,NULL,cp); 197 Type tempType; 198 if( !NumOpe(®,Parameter,Type(),tempType) ){ 199 return; 200 } 201 if(!( tempType.IsObjectPtr() || tempType.IsVoidPtr() )) SetError(122,NULL,cp); 261 202 262 203 //sub rax,PTR_SIZE*3 … … 328 269 if( isSweeping ){ 329 270 //call _System_GC_free_for_SweepingDelete 330 extern SubInfo*pSub_System_GC_free_for_SweepingDelete;271 extern UserProc *pSub_System_GC_free_for_SweepingDelete; 331 272 op_call(pSub_System_GC_free_for_SweepingDelete); 332 273 } 333 274 else{ 334 275 //call free 335 extern SubInfo*pSub_free;276 extern UserProc *pSub_free; 336 277 op_call(pSub_free); 337 278 } -
BasicCompiler64/Compile_ProcOp.cpp
r73 r75 2 2 #include "Opcode.h" 3 3 4 void SystemProc( char *name){4 void SystemProc( const char *name ){ 5 5 if(lstrcmp(name,"_System_GetEip")==0){ 6 6 //mov rax,qword ptr[rsp] … … 22 22 } 23 23 24 extern BOOL bCompilingGlobal; 25 BOOL bBackCompilingGlobal; 26 bBackCompilingGlobal=bCompilingGlobal; 27 bCompilingGlobal=1; 24 UserProc *pBackUserProc; 25 pBackUserProc = &UserProc::CompilingUserProc(); 26 UserProc::CompileStartForGlobalArea(); 28 27 29 28 int BackCp; … … 56 55 *((long *)(OpBuffer+StackFrameSchedule))=pobj_sf->GetFrameSize(); 57 56 58 bCompilingGlobal=bBackCompilingGlobal;57 UserProc::CompileStartForUserProc( pBackUserProc ); 59 58 cp=BackCp; 60 59 … … 70 69 StackFrameSchedule=obp-sizeof(long); 71 70 72 extern int MaxGlobalVarNum; 73 extern VARIABLE *GlobalVar; 74 int i; 75 for(i=0;i<MaxGlobalVarNum;i++){ 76 if(memicmp(GlobalVar[i].name,"Static%",7)==0){ 71 foreach( Variable *pVar, globalVars ){ 72 if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){ 77 73 //コンストラクタ呼び出し 78 if( GlobalVar[i].type==DEF_OBJECT){74 if( pVar->IsObject() ){ 79 75 80 76 //エラー用 81 cp=GlobalVar[i].source_code_address; 82 83 TYPEINFO TypeInfo; 84 TypeInfo.type=GlobalVar[i].type; 85 TypeInfo.u.lpIndex=GlobalVar[i].u.index; 77 cp=pVar->source_code_address; 78 86 79 CallConstructor( 87 GlobalVar[i].name,88 GlobalVar[i].SubScripts,89 TypeInfo,90 GlobalVar[i].ConstractParameter);80 pVar->GetName().c_str(), 81 pVar->GetSubScriptsPtr(), 82 *pVar, 83 pVar->paramStrForConstructor.c_str()); 91 84 } 92 85 } … … 107 100 108 101 109 extern BOOL bCompilingGlobal; 110 BOOL bBackCompilingGlobal; 111 bBackCompilingGlobal=bCompilingGlobal; 112 bCompilingGlobal=1; 102 UserProc *pBackUserProc; 103 pBackUserProc = &UserProc::CompilingUserProc(); 104 UserProc::CompileStartForGlobalArea(); 113 105 114 106 obj_LexScopes.CallDestructorsOfScopeEnd(); 115 107 116 bCompilingGlobal=bBackCompilingGlobal;108 UserProc::CompileStartForUserProc( pBackUserProc ); 117 109 118 110 … … 204 196 } 205 197 } 206 void CompileBufferInProcedure( SubInfo *psi){198 void CompileBufferInProcedure(UserProc *pUserProc){ 207 199 extern char *basbuf; 208 200 extern HANDLE hHeap; 209 extern SubInfo**ppSubHash;201 extern UserProc **ppSubHash; 210 202 extern BOOL bDebugCompile; 211 int i3,i4, VarSize,BufferSize;203 int i3,i4,BufferSize; 212 204 char temporary[VN_SIZE]; 213 205 214 206 BufferSize=128; 215 207 216 if(psi->bUse==0||psi->bCompile) return; 217 218 219 psi->bCompile=1; 208 if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return; 209 210 pUserProc->CompleteCompile(); 220 211 221 212 extern BOOL bSystemProc; 222 if(memcmp(p si->name,"_System_",8)==0) bSystemProc=1;213 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1; 223 214 else bSystemProc=0; 224 215 225 216 extern BOOL bDebugSupportProc; 226 if(memcmp(p si->name,"_DebugSys_",10)==0){217 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){ 227 218 if(!bDebugCompile){ 228 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 229 psi->VarNum=0; 219 pUserProc->localVars.clear(); 230 220 return; 231 221 } … … 234 224 else bDebugSupportProc=0; 235 225 236 p si->CompileAddress=obp;237 238 if(p si->bSystem){226 pUserProc->beginOpAddress=obp; 227 228 if(pUserProc->IsSystem()){ 239 229 //////////////////// 240 230 // 特殊関数 … … 250 240 pobj_sf=new CStackFrame(); 251 241 252 SystemProc(p si->name);242 SystemProc(pUserProc->GetName().c_str()); 253 243 254 244 //スタックフレーム管理用オブジェクトを破棄 … … 256 246 pobj_sf=0; 257 247 258 psi->EndOpAddr=obp; 259 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 260 psi->VarNum=0; 248 pUserProc->endOpAddress=obp; 249 pUserProc->localVars.clear(); 261 250 return; 262 251 } 263 252 264 cp=p si->address;253 cp=pUserProc->GetCodePos(); 265 254 for(;;cp++){ 266 255 if(IsCommandDelimitation(basbuf[cp])) break; … … 303 292 304 293 //ローカル変数に関する情報 305 extern VARIABLE *LocalVar;306 extern int MaxLocalVarNum;307 294 extern int AllLocalVarSize; 308 LocalVar=(VARIABLE *)HeapAlloc(hHeap,0,sizeof(VARIABLE));309 MaxLocalVarNum=0;310 295 AllLocalVarSize=0; 296 pUserProc->localVars.clear(); 311 297 312 298 //ローカル変数アドレススケジュール … … 324 310 ///////////////////////////////////// 325 311 326 for(i3=psi->RealParmNum-1;i3>=0;i3--){ 327 //変数データを追加 328 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 329 330 lstrcpy(LocalVar[MaxLocalVarNum].name,psi->realParams[i3].GetVarName.c_str()); 331 332 // TODO: パラメータのConst定義の指定が未完成 333 LocalVar[MaxLocalVarNum].bConst=false; 334 335 LocalVar[MaxLocalVarNum].bArray=psi->realParams[i3].IsArray()?TRUE:FALSE; 336 memcpy(LocalVar[MaxLocalVarNum].SubScripts,psi->realParams[i3].GetSubScriptsPtr(),MAX_ARRAYDIM*sizeof(int)); 337 338 LocalVar[MaxLocalVarNum].type=psi->realParams[i3].GetBasicType(); 339 if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT 340 ||LocalVar[MaxLocalVarNum].type==DEF_STRUCT){ 341 if(psi->bExport) 342 SetError(24,NULL,cp); 343 } 344 345 LocalVar[MaxLocalVarNum].u.index=psi->realParams[i3].GetIndex(); 346 347 if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsStruct()){ 312 //パラメータ用の変数データを考慮 313 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){ 314 Parameter ¶m = *pUserProc->RealParams()[i3]; 315 316 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef() ); 317 318 if( param.IsArray() ){ 319 pVar->SetArray( param.GetSubScriptsPtr() ); 320 } 321 322 int varSize; 323 if( param.IsRef() == false && param.IsStruct() ){ 348 324 //構造体のByValパラメータ 349 LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER | OBJECT_PARAMETER;350 VarSize=PTR_SIZE;325 pVar->ThisIsParameter(); 326 varSize=PTR_SIZE; 351 327 } 352 328 else{ 353 if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsArray()){ 354 LocalVar[MaxLocalVarNum].fRef=0; 355 VarSize=GetTypeSize(LocalVar[MaxLocalVarNum].type,LocalVar[MaxLocalVarNum].u.index); 356 if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE); 329 if( param.IsArray() == false ){ 330 varSize = pVar->GetMemorySize(); 357 331 } 358 332 else{ 359 LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER; 360 VarSize=PTR_SIZE; 361 } 362 } 363 AllLocalVarSize+=VarSize; 364 LocalVar[MaxLocalVarNum].offset=AllLocalVarSize; 333 varSize=PTR_SIZE; 334 } 335 } 336 AllLocalVarSize+=varSize; 337 pVar->offset=AllLocalVarSize; 365 338 366 339 //レキシカルスコープ情報 367 LocalVar[MaxLocalVarNum].ScopeLevel=obj_LexScopes.GetNowLevel();368 LocalVar[MaxLocalVarNum].ScopeStartAddress=obj_LexScopes.GetStartAddress();369 LocalVar[MaxLocalVarNum].bLiving=TRUE;370 371 MaxLocalVarNum++;340 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); 341 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress(); 342 pVar->bLiving=TRUE; 343 344 pUserProc->localVars.push_back( pVar ); 372 345 } 373 346 … … 377 350 378 351 //コンパイル中の関数が属するクラス 379 pobj_CompilingClass=p si->pobj_ParentClass;380 352 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 353 381 354 //コンパイルスタートをクラス管理クラスに追加 382 pobj_DBClass->StartCompile( p si);355 pobj_DBClass->StartCompile( pUserProc ); 383 356 384 357 //コンパイル中の関数 385 extern SubInfo *pCompilingSubInfo; 386 pCompilingSubInfo=psi; 358 UserProc::CompileStartForUserProc( pUserProc ); 387 359 388 360 //スタックフレーム管理用クラスを初期化 … … 394 366 // ここからコード生成 395 367 396 for(i3=psi->RealParmNum-1;i3>=0;i3--){ 368 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){ 369 Parameter ¶m = *pUserProc->RealParams()[i3]; 397 370 if(i3==3){ 398 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){371 if(param.IsReal()&¶m.IsRef() == false){ 399 372 //movsd qword ptr[rsp+0x20],xmm3 400 373 op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32); … … 406 379 } 407 380 if(i3==2){ 408 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){381 if(param.IsReal()&¶m.IsRef() == false){ 409 382 //movsd qword ptr[rsp+0x18],xmm2 410 383 op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32); … … 416 389 } 417 390 if(i3==1){ 418 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){391 if(param.IsReal()&¶m.IsRef() == false){ 419 392 //movsd qword ptr[rsp+0x10],xmm1 420 393 op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32); … … 426 399 } 427 400 if(i3==0){ 428 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){401 if(param.IsReal()&¶m.IsRef() == false){ 429 402 //movsd qword ptr[rsp+0x8],xmm0 430 403 op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32); … … 458 431 BaseLocalVar=AllLocalVarSize; 459 432 460 if( psi->ReturnType!=DEF_NON){433 if( !pUserProc->ReturnType().IsNull() ){ 461 434 //戻り値が存在するとき 462 435 463 char *temp; 464 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) temp="_System_ReturnValue"; 465 else temp=psi->name; 466 467 if(psi->ReturnType==DEF_STRUCT && psi->isReturnRef == false){ 436 const char *temp = pUserProc->GetName().c_str(); 437 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){ 438 temp = "_System_ReturnValue"; 439 } 440 441 if( pUserProc->ReturnType().IsStruct() ){ 468 442 //戻り値用の構造体(値型)はパラメータで引き渡される 469 443 } 470 444 else{ 471 445 //戻り値用の変数の定義 472 if( psi->isReturnRef ){ 473 sprintf(temporary,"%c%c",1,ESC_BYREF); 474 } 475 else temporary[0]=0; 476 477 sprintf(temporary+lstrlen(temporary),"%s%c%c",temp,1,ESC_AS); 478 GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary)); 446 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() ); 479 447 480 448 OpcodeDim(temporary,0); … … 497 465 498 466 //call _DebugSys_StartProc 499 extern SubInfo*pSub_DebugSys_StartProc;467 extern UserProc *pSub_DebugSys_StartProc; 500 468 op_call(pSub_DebugSys_StartProc); 501 469 } 502 470 503 471 if(pobj_CompilingClass){ 504 if( lstrcmp(psi->name,pobj_CompilingClass->name)==0){472 if( pUserProc->GetName() == pobj_CompilingClass->name ){ 505 473 //////////////////////////////////// 506 474 // コンストラクタをコンパイルするとき … … 550 518 551 519 Opcode_CallProc(temporary, 552 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,520 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 553 521 0, 554 522 "", … … 558 526 //基底クラスのコンストラクタを暗黙的に呼び出す 559 527 Opcode_CallProc("", 560 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,528 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 561 529 0, 562 530 "", … … 568 536 for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){ 569 537 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3]; 570 if(pMember-> TypeInfo.type==DEF_OBJECT){538 if(pMember->IsObject()){ 571 539 // オブジェクトメンバを発見したとき 572 540 … … 574 542 pMember->name, 575 543 1, ESC_NEW, 576 pMember-> TypeInfo.u.pobj_Class->name );544 pMember->GetClass().name ); 577 545 OpcodeCalc( temporary ); 578 546 } … … 598 566 } 599 567 } 600 else if( psi->name[0]=='~'){568 else if( pUserProc->IsDestructor() ){ 601 569 //デストラクタをコンパイルしたとき 602 570 … … 609 577 ////////////////////////////////////////// 610 578 ////// プロシージャ内をコンパイル //////// 611 if(psi->dwType==SUBTYPE_SUB) CompileBuffer(ESC_ENDSUB,0); 612 else if(psi->dwType==SUBTYPE_FUNCTION) CompileBuffer(ESC_ENDFUNCTION,0); 613 else if(psi->dwType==SUBTYPE_MACRO) CompileBuffer(ESC_ENDMACRO,0); 579 if(pUserProc->IsMacro()) CompileBuffer(ESC_ENDMACRO,0); 580 else{ 581 if(pUserProc->IsSub()) CompileBuffer(ESC_ENDSUB,0); 582 else if(pUserProc->IsFunction()) CompileBuffer(ESC_ENDFUNCTION,0); 583 } 614 584 ////////////////////////////////////////// 615 585 ////////////////////////////////////////// … … 623 593 pobj_CompilingClass->NotifyFinishConstructorCompile(); 624 594 } 625 else if( psi->name[0]=='~'){595 else if( pUserProc->IsDestructor() ){ 626 596 //////////////////////////////////// 627 597 //デストラクタをコンパイルしたとき … … 638 608 if( method ){ 639 609 Opcode_CallProc("", 640 method->p si,610 method->pUserProc, 641 611 0, 642 612 "", … … 659 629 int offset = pobj_CompilingClass->GetMemberOffset( pMember->name, NULL ); 660 630 661 if(pMember-> TypeInfo.type==DEF_OBJECT){662 CMethod *method = pMember-> TypeInfo.u.pobj_Class->GetDestructorMethod();631 if(pMember->IsObject()){ 632 CMethod *method = pMember->GetClass().GetDestructorMethod(); 663 633 if( method ){ 664 634 for(i4=MemberObjectNum-1;i4>=0;i4--){ … … 670 640 671 641 //call destructor 672 op_call(method->p si);642 op_call(method->pUserProc); 673 643 } 674 644 } … … 705 675 HeapDefaultFree(WithInfo.pWithCp); 706 676 707 //重複エラー情報管理のメモリを解放708 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);709 HeapDefaultFree(SynonymErrorWords);710 711 677 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理 712 678 obj_LexScopes.CallDestructorsOfScopeEnd(); … … 720 686 if(bDebugCompile&&bDebugSupportProc==0){ 721 687 //call _DebugSys_EndProc 722 extern SubInfo*pSub_DebugSys_EndProc;688 extern UserProc *pSub_DebugSys_EndProc; 723 689 op_call(pSub_DebugSys_EndProc); 724 690 } 725 691 726 if( psi->ReturnType!=DEF_NON){692 if( !pUserProc->ReturnType().IsNull() ){ 727 693 ////////////////////////////////// 728 694 // 戻り値をraxまたはxmm0に設定 … … 730 696 731 697 RELATIVE_VAR RelativeVar; 732 LONG_PTR lpIndex; 733 734 char *temp; 735 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) 698 699 const char *temp = pUserProc->GetName().c_str(); 700 if( temp[0]==1 && temp[1]==ESC_OPERATOR ){ 736 701 temp="_System_ReturnValue"; 737 else temp=psi->name;738 GetVarOffsetReadWrite(temp,& i3,&RelativeVar,&lpIndex);739 740 i3=p si->ReturnType;702 } 703 GetVarOffsetReadWrite(temp,&RelativeVar,Type()); 704 705 i3=pUserProc->ReturnType().GetBasicType(); 741 706 742 707 if(i3==DEF_OBJECT || i3==DEF_STRUCT){ … … 772 737 } 773 738 HeapDefaultFree(pLocalVarAddrSchedule); 774 for (i3=0;i3<MaxLocalVarNum;i3++){739 foreach( Variable *pVar, pUserProc->localVars ){ 775 740 //後にデバッグで利用する 776 LocalVar[i3].offset=AllLocalVarSize+pobj_sf->GetFrameSize()-LocalVar[i3].offset;741 pVar->offset = AllLocalVarSize + pobj_sf->GetFrameSize() - pVar->offset; 777 742 } 778 743 … … 812 777 813 778 814 psi->EndOpAddr=obp; 815 psi->pVar=LocalVar; 816 psi->VarNum=MaxLocalVarNum; 817 818 //ローカル変数のネーム情報は後に解放する 779 pUserProc->endOpAddress=obp; 780 781 782 //重複エラー情報管理のメモリを解放 783 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]); 784 HeapDefaultFree(SynonymErrorWords); 819 785 } 820 786 void CompileLocal(){ 821 extern SubInfo**ppSubHash;787 extern UserProc **ppSubHash; 822 788 int i2; 823 SubInfo *psi;789 UserProc *pUserProc; 824 790 825 791 extern BOOL bDll; 826 792 if(bDll){ 827 793 //DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする 828 p si=GetSubHash("_System_InitDllGlobalVariables");829 if(p si){830 CompileBufferInProcedure(p si);794 pUserProc=GetSubHash("_System_InitDllGlobalVariables"); 795 if(pUserProc){ 796 CompileBufferInProcedure(pUserProc); 831 797 } 832 798 else SetError(300,NULL,cp); … … 835 801 //_System_InitStaticLocalVariablesは一番最後にコンパイル 836 802 //※一般関数内の静的変数オブジェクトをすべて収集しなければならない 837 extern SubInfo*pSub_System_InitStaticLocalVariables;838 pSub_System_InitStaticLocalVariables-> bCompile=1;803 extern UserProc *pSub_System_InitStaticLocalVariables; 804 pSub_System_InitStaticLocalVariables->CompleteCompile(); 839 805 840 806 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 841 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;842 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=1;807 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 808 pSub_System_Call_Destructor_of_GlobalObject->CompleteCompile(); 843 809 844 810 Repeat: 845 811 for(i2=0;i2<MAX_HASH;i2++){ 846 p si=ppSubHash[i2];847 while(p si){848 CompileBufferInProcedure(p si);849 p si=psi->pNextData;812 pUserProc=ppSubHash[i2]; 813 while(pUserProc){ 814 CompileBufferInProcedure(pUserProc); 815 pUserProc=pUserProc->pNextData; 850 816 } 851 817 } … … 853 819 //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合 854 820 for(i2=0;i2<MAX_HASH;i2++){ 855 p si=ppSubHash[i2];856 while(p si){857 if( psi->bUse&&psi->bCompile==0&&psi->bVirtual==0){821 pUserProc=ppSubHash[i2]; 822 while(pUserProc){ 823 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ 858 824 goto Repeat; 859 825 } 860 826 861 p si=psi->pNextData;827 pUserProc=pUserProc->pNextData; 862 828 } 863 829 } 864 830 865 831 //_System_InitStaticLocalVariablesは一番最後にコンパイル 866 pSub_System_InitStaticLocalVariables-> bCompile=0;832 pSub_System_InitStaticLocalVariables->KillCompileStatus(); 867 833 CompileBufferInProcedure(pSub_System_InitStaticLocalVariables); 868 834 869 835 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 870 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=0;836 pSub_System_Call_Destructor_of_GlobalObject->KillCompileStatus(); 871 837 CompileBufferInProcedure(pSub_System_Call_Destructor_of_GlobalObject); 872 838 } -
BasicCompiler64/Compile_Set_Var.cpp
r73 r75 7 7 } 8 8 9 void SetStructVariableFromRax( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap){9 void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap){ 10 10 int RightTermReg; 11 11 pobj_reg=new CRegister(REG_RCX); … … 17 17 18 18 //右辺 19 if( IsRealNumberType(CalcType)){19 if( calcType.IsReal() ){ 20 20 RightTermReg=pobj_reg->LockXmmReg(); 21 21 22 if( CalcType==DEF_DOUBLE){22 if( calcType.IsDouble() ){ 23 23 //movlsd RightTermReg,xmm0 24 24 op_movsd_RR(RightTermReg,REG_XMM0); 25 25 } 26 else if( CalcType==DEF_SINGLE){26 else if( calcType.IsSingle() ){ 27 27 //movlss RightTermReg,xmm0 28 28 op_movss_RR(RightTermReg,REG_XMM0); … … 62 62 */ 63 63 //右辺用レジスタを解除 64 if( IsRealNumberType(CalcType)) pobj_reg->UnlockXmmReg();64 if( calcType.IsReal() ) pobj_reg->UnlockXmmReg(); 65 65 else pobj_reg->UnlockReg(); 66 66 … … 73 73 74 74 75 if( CalcType == DEF_STRUCT ){ 76 CClass *pVarClass = (CClass *)lpVarIndex; 77 CClass *pCalcClass = (CClass *)lpCalcIndex; 78 79 if( pVarClass->IsEquals( pCalcClass ) ){ //等しい 75 if( calcType.IsStruct() ){ 76 if( varType.GetClass().IsEquals( &calcType.GetClass() ) ){ //等しい 80 77 81 78 //双方のオブジェクト型が一致、または派生・継承関係にあるとき … … 88 85 op_mov_RR(REG_RDI,VarReg); 89 86 90 CClass *pClass = (CClass *)lpVarIndex; 91 int object_size = pClass->GetSize(); 87 int object_size = varType.GetClass().GetSize(); 92 88 93 89 //mov rcx,object_size … … 107 103 108 104 //call free 109 extern SubInfo*pSub_free;105 extern UserProc *pSub_free; 110 106 op_call(pSub_free); 111 107 } -
BasicCompiler64/Compile_Statement.cpp
r73 r75 5 5 int i,i2; 6 6 char buffer[8192]; 7 SubInfo *psi;7 UserProc *pUserProc; 8 8 9 9 for(i=0;;i++){ … … 41 41 ////////////////////////////// 42 42 43 p si=GetSubHash(Command);43 pUserProc=GetSubHash(Command); 44 44 45 45 //GetSubHash内でエラー提示が行われた場合 46 if(p si==(SubInfo*)-1) return;47 48 if(p si==0){46 if(pUserProc==(UserProc *)-1) return; 47 48 if(pUserProc==0){ 49 49 char temporary[VN_SIZE]; 50 50 lstrcpy(temporary,Command); 51 51 52 52 CharUpper(temporary); 53 p si=GetSubHash(temporary);53 pUserProc=GetSubHash(temporary); 54 54 55 55 //GetSubHash内でエラー提示が行われた場合 56 if(p si==(SubInfo*)-1) return;57 } 58 59 if(p si){60 if( psi->dwType!=SUBTYPE_MACRO) SetError(10,Command,cp);61 62 Opcode_CallProc("",p si,0,"",0);56 if(pUserProc==(UserProc *)-1) return; 57 } 58 59 if(pUserProc){ 60 if( !pUserProc->IsMacro() ) SetError(10,Command,cp); 61 62 Opcode_CallProc("",pUserProc,0,"",0); 63 63 64 64 return; … … 72 72 73 73 int idProc; 74 void *p Info;75 idProc=GetProc(buffer, &pInfo);74 void *pProc; 75 idProc=GetProc(buffer,(void **)&pProc); 76 76 77 77 int i4; … … 91 91 //////////////// 92 92 93 LONG_PTR lp;94 i2=CallProc(idProc,pInfo,buffer,temp2,&lp);93 Type resultType; 94 CallProc(idProc,pProc,buffer,temp2,resultType); 95 95 96 96 … … 99 99 ///////////////////// 100 100 101 if( i2==DEF_STRUCT){101 if( resultType.IsStruct() ){ 102 102 //mov r14,rax 103 103 op_mov_RR(REG_R14,REG_RAX); 104 104 105 FreeTempObject(REG_R14, (CClass *)lp);105 FreeTempObject(REG_R14,&resultType.GetClass()); 106 106 } 107 107 return; … … 116 116 117 117 void Judgment(char *buffer){ 118 int reg=REG_RAX,type; 119 type=NumOpe(®,buffer,0,0,0); 118 int reg=REG_RAX; 119 Type resultType; 120 if( !NumOpe(®,buffer,Type(),resultType) ){ 121 return; 122 } 120 123 121 124 int offset; 122 125 123 if( type==DEF_DOUBLE){126 if(resultType.IsDouble()){ 124 127 double dbl=0; 125 128 offset=dataTable.Add( dbl ); … … 135 138 obp+=sizeof(long); 136 139 } 137 else if( type==DEF_SINGLE){140 else if(resultType.IsSingle()){ 138 141 float flt=0; 139 142 offset=dataTable.Add( flt ); … … 152 155 153 156 //cmp rax,0 154 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);157 op_cmp_value(resultType.GetSize(),REG_RAX,0); 155 158 } 156 159 } … … 340 343 void OpcodeFor(char *Parameter){ 341 344 extern HANDLE hHeap; 345 Type resultType; 342 346 int i,i2,i3; 343 347 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE]; … … 400 404 sprintf(temporary,"(%s)>=0",StepNum); 401 405 402 int reg ,type;406 int reg; 403 407 reg=REG_RAX; 404 type=NumOpe(®,temporary,0,0,0); 408 if( !NumOpe(®,temporary,Type(),resultType) ){ 409 return; 410 } 405 411 406 412 //cmp rax,0 407 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);413 op_cmp_value(resultType.GetSize(),REG_RAX,0); 408 414 409 415 //je [カウンタ減少の場合の判定] … … 417 423 418 424 reg=REG_RAX; 419 type=NumOpe(®,temporary,0,0,0);425 NumOpe(®,temporary,Type(),Type()); 420 426 421 427 //jmp [カウンタ減少の場合の判定を飛び越す] … … 430 436 431 437 reg=REG_RAX; 432 type=NumOpe(®,temporary,0,0,0);438 NumOpe(®,temporary,Type(),resultType); 433 439 434 440 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値 435 441 436 442 //cmp rax,0 437 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);443 op_cmp_value(resultType.GetSize(),REG_RAX,0); 438 444 439 445 ErrorStep: … … 583 589 extern HANDLE hHeap; 584 590 585 extern BOOL bCompilingGlobal; 586 if(bCompilingGlobal){ 591 if( UserProc::IsGlobalAreaCompiling() ){ 587 592 SetError(12,"Exit Sub/Function",cp); 588 593 return; … … 611 616 CaseScheduleNum++; 612 617 } 613 void OpcodeSelect( char *Parameter){618 void OpcodeSelect( const char *lpszParms ){ 614 619 extern DWORD *pCaseSchedule; 615 620 extern int CaseScheduleNum; … … 631 636 NowCaseSchedule=0; 632 637 633 int reg1=REG_RAX,type1; 634 LONG_PTR lpIndex; 635 type1=NumOpe(®1,Parameter,0,0,&lpIndex); 636 637 if(type1==DEF_DOUBLE){ 638 int reg1=REG_RAX; 639 Type type1; 640 if( !NumOpe(®1,lpszParms,Type(), type1 ) ){ 641 return; 642 } 643 644 if(type1.IsDouble()){ 638 645 //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 639 646 pobj_sf->push(reg1,sizeof(double)); 640 647 } 641 else if(type1 ==DEF_SINGLE){648 else if(type1.IsSingle()){ 642 649 //movss dword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 643 650 pobj_sf->push(reg1,sizeof(float)); 644 651 } 645 652 else{ 646 ExtendTypeTo64(type1 ,reg1);653 ExtendTypeTo64(type1.GetBasicType(),reg1); 647 654 648 655 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用 … … 712 719 cp=NowCaseCp; 713 720 714 int reg2=REG_RDX,type2; 715 LONG_PTR lpIndex2; 716 type2=NumOpe(®2,temporary,type1,lpIndex,&lpIndex2); 721 int reg2=REG_RDX; 722 Type type2; 723 if( !NumOpe(®2,temporary,type1,type2) ){ 724 return; 725 } 717 726 718 727 cp=i2; 719 728 720 if(type1==DEF_OBJECT){ 721 CClass *pobj_c; 722 pobj_c=(CClass *)lpIndex; 723 724 std::vector<SubInfo *> subs; 725 pobj_c->EnumMethod( CALC_EQUAL, subs ); 729 if(type1.IsObject()){ 730 std::vector<UserProc *> subs; 731 type1.GetClass().EnumMethod( CALC_EQUAL, subs ); 726 732 if( subs.size() == 0 ){ 727 733 return; 728 734 } 729 735 730 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 731 int iParmNum=0; 732 ppi[iParmNum].bArray=0; 733 ppi[iParmNum].bByVal=0; 734 ppi[iParmNum].name=0; 735 ppi[iParmNum].type=type2; 736 ppi[iParmNum].u.index=lpIndex2; 737 ppi[iParmNum].SubScripts[0]=-1; 738 iParmNum++; 736 Parameters params; 737 params.push_back( new Parameter( "", Type( type2 ) ) ); 739 738 740 739 //オーバーロードを解決 741 SubInfo *psi; 742 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL); 743 HeapDefaultFree(ppi); 744 745 if(!psi){ 740 UserProc *pUserProc; 741 pUserProc=OverloadSolution("==",subs, params, NULL); 742 743 delete params[0]; 744 745 if(!pUserProc){ 746 746 //エラー 747 747 return; … … 759 759 760 760 //call operator_proc ※ ==演算子 761 op_call(p si);761 op_call(pUserProc); 762 762 763 763 //test rax,rax … … 769 769 } 770 770 else{ 771 if(type1 ==DEF_DOUBLE){771 if(type1.IsDouble()){ 772 772 int xmm_reg; 773 773 if(IsXmmReg(reg2)) xmm_reg=reg2; 774 774 else xmm_reg=REG_XMM5; 775 ChangeTypeToXmm_Double(type2 ,xmm_reg,reg2);775 ChangeTypeToXmm_Double(type2.GetBasicType(),xmm_reg,reg2); 776 776 777 777 //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照 … … 781 781 op_comisd(xmm_reg,REG_XMM4); 782 782 } 783 else if(type1 ==DEF_SINGLE){783 else if(type1.IsSingle()){ 784 784 int xmm_reg; 785 785 if(IsXmmReg(reg2)) xmm_reg=reg2; 786 786 else xmm_reg=REG_XMM5; 787 ChangeTypeToXmm_Single(type2 ,xmm_reg,reg2);787 ChangeTypeToXmm_Single(type2.GetBasicType(),xmm_reg,reg2); 788 788 789 789 //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照 … … 796 796 //その他整数型 797 797 798 i2=NeutralizationType(type1 ,-1,type2,-1);798 i2=NeutralizationType(type1.GetBasicType(),-1,type2.GetBasicType(),-1); 799 799 800 800 //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照 … … 883 883 884 884 //call _System_GetEip 885 extern SubInfo*pSub_System_GetEip;885 extern UserProc *pSub_System_GetEip; 886 886 op_call(pSub_System_GetEip); 887 887 … … 938 938 } 939 939 void OpcodeReturn(char *Parameter){ 940 extern BOOL bCompilingGlobal; 941 if(bCompilingGlobal){ 940 if( UserProc::IsGlobalAreaCompiling() ){ 942 941 SetError(62,NULL,cp); 943 942 } … … 945 944 //戻り値をセット 946 945 if(Parameter[0]){ 947 extern SubInfo *pCompilingSubInfo; 948 char *temp; 949 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR) 950 temp="_System_ReturnValue"; 951 else temp=pCompilingSubInfo->name; 952 953 /* 954 TODO: 消す 955 if( pCompilingSubInfo->isReturnRef ){ 956 //参照型 957 SetRefVariable( temp, Parameter ); 946 UserProc &proc = UserProc::CompilingUserProc(); 947 948 const char *temp = "_System_ReturnValue"; 949 if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR) 950 { 958 951 } 959 952 else{ 960 //値型*/ 961 char temporary[VN_SIZE]; 962 sprintf(temporary,"%s=%s",temp,Parameter); 963 OpcodeCalc(temporary); 964 //} 953 temp=proc.GetName().c_str(); 954 } 955 956 char temporary[VN_SIZE]; 957 sprintf(temporary,"%s=%s",temp,Parameter); 958 OpcodeCalc(temporary); 965 959 } 966 960 … … 972 966 void Opcode_Input(const char *Parameter){ 973 967 extern int cp; 974 int i2,i3,i4,i5 ,type;968 int i2,i3,i4,i5; 975 969 BOOL bFile; 976 970 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE]; … … 1054 1048 } 1055 1049 1056 LONG_PTR lpIndex; 1057 type = GetVarType(temporary, &lpIndex, 1); 1050 Type varType; 1051 if( !GetVarType(temporary, varType, 1) ){ 1052 return; 1053 } 1058 1054 1059 1055 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary); 1060 1056 OpcodeCalc(temp2); 1061 1057 1062 if(type==DEF_LONG) type=DEF_DWORD; 1063 else if(type==DEF_INTEGER) type=DEF_WORD; 1064 else if(type==DEF_OBJECT){ 1065 CClass *pobj_Class=(CClass *)lpIndex; 1066 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING; 1067 } 1068 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type); 1058 if(varType.IsLong()) varType.SetBasicType( DEF_DWORD ); 1059 else if(varType.IsInteger()) varType.SetBasicType( DEF_WORD ); 1060 else if(varType.IsObject()){ 1061 varType.SetBasicType( DEF_OBJECT ); 1062 if( varType.IsStringObject() ){ 1063 varType.SetBasicType( DEF_STRING ); 1064 } 1065 } 1066 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,varType.GetBasicType()); 1069 1067 OpcodeCalc(temp2); 1070 1068 … … 1075 1073 OpcodeCalc(temp2); 1076 1074 1077 SubInfo *psi;1078 if(bFile) p si=GetSubHash("INPUT_FromFile");1079 else p si=GetSubHash("INPUT_FromPrompt");1080 if(!p si){1075 UserProc *pUserProc; 1076 if(bFile) pUserProc=GetSubHash("INPUT_FromFile"); 1077 else pUserProc=GetSubHash("INPUT_FromPrompt"); 1078 if(!pUserProc){ 1081 1079 SetError(3,"Input",cp); 1082 1080 return; 1083 1081 } 1084 Opcode_CallProc(buffer,p si,0,"",0);1082 Opcode_CallProc(buffer,pUserProc,0,"",0); 1085 1083 } 1086 1084 void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){ … … 1177 1175 OpcodeCalc(temp2); 1178 1176 1179 SubInfo *psi;1180 if(bFile) p si=GetSubHash("PRINTUSING_ToFile");1181 else p si=GetSubHash("PRINTUSING_ToPrompt");1182 if(!p si){1177 UserProc *pUserProc; 1178 if(bFile) pUserProc=GetSubHash("PRINTUSING_ToFile"); 1179 else pUserProc=GetSubHash("PRINTUSING_ToPrompt"); 1180 if(!pUserProc){ 1183 1181 SetError(3,"Print",cp); 1184 1182 return; 1185 1183 } 1186 Opcode_CallProc(buffer,p si,0,"",0);1184 Opcode_CallProc(buffer,pUserProc,0,"",0); 1187 1185 } 1188 1186 void Opcode_Print(const char *Parameter,BOOL bWrite){ … … 1281 1279 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\""); 1282 1280 1283 SubInfo *psi;1284 if(bFile) p si=GetSubHash("PRINT_ToFile");1285 else p si=GetSubHash("PRINT_ToPrompt");1286 if(!p si){1281 UserProc *pUserProc; 1282 if(bFile) pUserProc=GetSubHash("PRINT_ToFile"); 1283 else pUserProc=GetSubHash("PRINT_ToPrompt"); 1284 if(!pUserProc){ 1287 1285 SetError(3,"Print",cp); 1288 1286 return; 1289 1287 } 1290 Opcode_CallProc(buffer,p si,0,"",0);1288 Opcode_CallProc(buffer,pUserProc,0,"",0); 1291 1289 } 1292 1290 … … 1299 1297 1300 1298 void OpcodeSetPtrData(char *Parameter,int type){ 1301 int i ,i2;1299 int i; 1302 1300 char temporary[VN_SIZE]; 1303 1301 … … 1321 1319 1322 1320 int reg_ptr=REG_RAX; 1323 i2=NumOpe(®_ptr,temporary,0,0,0); 1324 if(!IsWholeNumberType(i2)){ 1321 Type resultType; 1322 if( !NumOpe(®_ptr,temporary,Type(),resultType) ){ 1323 return; 1324 } 1325 if(!resultType.IsWhole()){ 1325 1326 SetError(11,Parameter,cp); 1326 1327 return; … … 1338 1339 1339 1340 int temp_reg=REG_NON; 1340 i2=NumOpe(&temp_reg,temporary,0,0,0); 1341 if( !NumOpe(&temp_reg,temporary,Type(),resultType) ){ 1342 return; 1343 } 1341 1344 1342 1345 //レジスタのブロッキングを解除 … … 1344 1347 1345 1348 if(type==DEF_DOUBLE){ 1346 ChangeTypeToXmm_Double( i2,REG_XMM0,temp_reg);1349 ChangeTypeToXmm_Double(resultType.GetBasicType(),REG_XMM0,temp_reg); 1347 1350 1348 1351 //movsd qword ptr[reg_ptr],xmm0 … … 1350 1353 } 1351 1354 else if(type==DEF_SINGLE){ 1352 ChangeTypeToXmm_Single( i2,REG_XMM0,temp_reg);1355 ChangeTypeToXmm_Single(resultType.GetBasicType(),REG_XMM0,temp_reg); 1353 1356 1354 1357 //movss dword ptr[reg_ptr],xmm0 … … 1356 1359 } 1357 1360 else{ 1358 ChangeTypeToWhole( i2,type,REG_RCX,temp_reg);1361 ChangeTypeToWhole(resultType.GetBasicType(),type,REG_RCX,temp_reg); 1359 1362 1360 1363 //mov ptr[reg_ptr],rcx -
BasicCompiler64/Compile_Var.cpp
r73 r75 3 3 4 4 //変数 5 V ARIABLE *GlobalVar;5 Variables globalVars; 6 6 int MaxGlobalVarNum; 7 7 int AllGlobalVarSize; 8 8 int AllInitGlobalVarSize; 9 VARIABLE *LocalVar; 9 10 10 int MaxLocalVarNum; 11 11 int AllLocalVarSize; 12 12 13 13 14 void SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){ 15 int i2; 16 17 14 void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){ 18 15 ///////////////////////////////////////////// 19 16 // 先頭ポインタをr12に取得してメモリへ退避 … … 31 28 32 29 int reg=REG_NON; 33 i2=NumOpe(®,lpPtrOffset,0,0,0); 34 if(!IsWholeNumberType(i2)) SetError(46,NULL,cp); 35 ExtendTypeTo64(i2,reg); 30 Type type; 31 NumOpe( ®, lpPtrOffset, Type(), type ); 32 if( !type.IsWhole() ){ 33 SetError(46,NULL,cp); 34 } 35 ExtendTypeTo64(type.GetBasicType(),reg); 36 36 37 37 if(reg==REG_R14){ … … 40 40 } 41 41 42 if( PTR_LEVEL(*pType)){43 *pType = PTR_LEVEL_DOWN( *pType);44 45 i 2=GetTypeSize(*pType,lpIndex);46 if( i2>=2){42 if( resultType.PtrLevel() ){ 43 resultType.PtrLevelDown(); 44 45 int typeSize = resultType.GetSize(); 46 if(typeSize>=2){ 47 47 //imul reg,i2 48 op_imul_RV(sizeof(_int64),reg, i2);48 op_imul_RV(sizeof(_int64),reg,typeSize); 49 49 } 50 50 } … … 80 80 } 81 81 } 82 BOOL GetArrayOffset(int *SubScripts,char *array,int type,LONG_PTR lpIndex){82 bool GetArrayOffset(const int *SubScripts,char *array, const Type &type){ 83 83 extern HANDLE hHeap; 84 int i,i2,i3,i4 ,TypeSize;84 int i,i2,i3,i4; 85 85 char temporary[VN_SIZE],*pParm[MAX_PARMS]; 86 86 … … 101 101 if(SubScripts[i3]==-1){ 102 102 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 103 return 0;103 return false; 104 104 } 105 105 … … 114 114 if(SubScripts[i3]!=-1){ 115 115 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 116 return 0;116 return false; 117 117 } 118 118 break; … … 136 136 137 137 int reg=REG_NON; 138 T YPEINFO TypeInfo;138 Type type; 139 139 BOOL bUseHeap; 140 TypeInfo.type=NumOpe(®,pParm[i],DEF_LONG,-1,&TypeInfo.u.lpIndex,&bUseHeap);141 if( TypeInfo.type==DEF_OBJECT){140 NumOpe( ®, pParm[i], Type( DEF_LONG ), type, &bUseHeap ); 141 if( type.IsObject() ){ 142 142 //キャスト演算子のオーバーロードに対応する 143 143 CallCastOperatorProc(reg, 144 TypeInfo.type,TypeInfo.u.lpIndex, 145 bUseHeap,DEF_LONG,-1); 146 TypeInfo.type=DEF_LONG; 147 } 148 149 if(!IsWholeNumberType(TypeInfo.type)) SetError(46,NULL,cp); 150 ExtendTypeTo64(TypeInfo.type,reg); 144 type, 145 bUseHeap, Type(DEF_LONG) ); 146 type.SetBasicType( DEF_LONG ); 147 } 148 149 if( !type.IsWhole() ){ 150 SetError(46,NULL,cp); 151 } 152 ExtendTypeTo64( type.GetBasicType(), reg ); 151 153 152 154 if(reg==REG_R14){ … … 168 170 HeapDefaultFree(pParm[i]); 169 171 } 170 171 TypeSize=GetTypeSize(type,lpIndex);172 172 173 173 //imul r12,TypeSize … … 175 175 OpBuffer[obp++]=(char)0x69; 176 176 OpBuffer[obp++]=(char)0xE4; 177 *((long *)(OpBuffer+obp))= TypeSize;177 *((long *)(OpBuffer+obp))=type.GetSize(); 178 178 obp+=sizeof(long); 179 179 … … 186 186 OpBuffer[obp++]=(char)0xDC; 187 187 188 return 1;188 return true; 189 189 } 190 BOOL GetMemberOffset(bool isErrorEnabled, bool isWriteAccess, CClass *pobj_c, char *member, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpNestIndex, BOOL bPrivateAccess){190 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 191 191 int i; 192 192 … … 202 202 CClass::RefType refType; 203 203 lstrcpy(VarName,member); 204 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0;204 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false; 205 205 206 206 … … 209 209 //////////////////////////// 210 210 211 int offset = pobj_c->GetMemberOffset( VarName, &i );212 if(i== pobj_c->iMemberNum){211 int offset = objClass.GetMemberOffset( VarName, &i ); 212 if(i==objClass.iMemberNum){ 213 213 if(isErrorEnabled) SetError(103,VarName,cp); 214 return 0;215 } 216 217 CMember *pMember= pobj_c->ppobj_Member[i];214 return false; 215 } 216 217 CMember *pMember=objClass.ppobj_Member[i]; 218 218 219 219 220 220 //アクセシビリティをチェック 221 if( pobj_c==pobj_CompilingClass){221 if(&objClass==pobj_CompilingClass){ 222 222 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 223 223 if(pMember->dwAccess==ACCESS_NON){ 224 224 if(isErrorEnabled) SetError(107,VarName,cp); 225 return 0;225 return false; 226 226 } 227 227 } … … 230 230 pMember->dwAccess==ACCESS_NON){ 231 231 if(isErrorEnabled) SetError(107,VarName,cp); 232 return 0;232 return false; 233 233 } 234 234 else if(bPrivateAccess==0&&pMember->dwAccess==ACCESS_PROTECTED){ 235 235 if(isErrorEnabled) SetError(108,VarName,cp); 236 return 0;236 return false; 237 237 } 238 238 } … … 242 242 if( pMember->IsConst() && //定数メンバである 243 243 isWriteAccess && //書き込みアクセスを要求されている 244 pobj_c->IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く244 objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く 245 245 ){ 246 246 //Const定義の変数に書き込みアクセスをしようとした場合 … … 248 248 } 249 249 250 *pType=pMember->TypeInfo.type; 251 *plpNestIndex=pMember->TypeInfo.u.lpIndex; 250 resultType = *pMember; 252 251 253 252 //ポインタ変数の場合 254 if( IsPtrType(*pType)){253 if( resultType.IsPointer() ){ 255 254 if(pMember->SubScripts[0]==-1){ 256 255 lstrcpy(lpPtrOffset,array); … … 261 260 if(lpPtrOffset[0]){ 262 261 if(isErrorEnabled) SetError(16,member,cp); 263 return 0;262 return false; 264 263 } 265 264 } … … 276 275 if(array[0]){ 277 276 //配列オフセット 278 if(!GetArrayOffset(pMember->SubScripts,array,*p Type,pMember->TypeInfo.u.lpIndex)){277 if(!GetArrayOffset(pMember->SubScripts,array,*pMember)){ 279 278 if(isErrorEnabled) SetError(14,member,cp); 280 279 } 281 280 } 282 281 else if(pMember->SubScripts[0]!=-1){ 283 *pType|=FLAG_PTR;282 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 284 283 } 285 284 … … 287 286 //入れ子構造の場合 288 287 289 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){288 if( resultType.IsObject() || resultType.IsStruct() ){ 290 289 if( refType != CClass::Dot ){ 291 290 if(isErrorEnabled) SetError(104,member,cp); 292 return 0;293 } 294 295 if( *pType==DEF_OBJECT){291 return false; 292 } 293 294 if( resultType.IsObject() ){ 296 295 // 参照内容へのポインタを抽出 297 296 SetRelativeOffset( *pRelativeVar ); 298 297 } 299 298 } 300 else if( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT){299 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 301 300 //構造体ポインタ型メンバ変数 302 301 303 302 if(lpPtrOffset[0]){ 304 303 //pObj[n].member 305 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Dot ){ 306 if(isErrorEnabled) SetError(104,member,cp); 307 return 0; 304 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() ) 305 && refType != CClass::Dot ){ 306 if(isErrorEnabled) SetError(104,member,cp); 307 return false; 308 308 } 309 309 310 310 //直接参照に切り替え 311 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);311 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 312 312 pRelativeVar->dwKind=VAR_DIRECTMEM; 313 313 … … 316 316 else{ 317 317 //pObj->member 318 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Pointer ){ 319 if(isErrorEnabled) SetError(104,member,cp); 320 return 0; 318 if( (resultType.IsObjectPtr() || resultType.IsStructPtr() ) 319 && refType != CClass::Pointer ){ 320 if(isErrorEnabled) SetError(104,member,cp); 321 return false; 321 322 } 322 323 … … 324 325 } 325 326 } 326 else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 327 else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2) 328 || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){ 327 329 //構造体ポインタのポインタ型メンバ変数 328 330 … … 331 333 if( refType != CClass::Pointer ){ 332 334 if(isErrorEnabled) SetError(104,member,cp); 333 return 0;335 return false; 334 336 } 335 337 336 338 //直接参照に切り替え 337 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);339 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 338 340 pRelativeVar->dwKind=VAR_DIRECTMEM; 339 341 … … 345 347 else{ 346 348 if(isErrorEnabled) SetError(104,member,cp); 347 return 0;348 } 349 } 350 351 if(! GetMemberOffset(349 return false; 350 } 351 } 352 353 if(!_member_offset( 352 354 isErrorEnabled, 353 355 isWriteAccess, 354 pMember-> TypeInfo.u.pobj_Class,356 pMember->GetClass(), 355 357 NestMember, 356 pType,357 358 pRelativeVar, 358 plpNestIndex,359 0)) return 0;359 resultType, 360 0)) return false; 360 361 } 361 362 362 363 if(lpPtrOffset[0]){ 363 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);364 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 364 365 pRelativeVar->dwKind=VAR_DIRECTMEM; 365 366 } 366 367 367 return 1;368 return true; 368 369 } 369 370 void GetWithName(char *buffer){ … … 380 381 //自身のオブジェクトのThisポインタをregにコピー 381 382 382 extern VARIABLE *LocalVar;383 383 RELATIVE_VAR RelativeVar; 384 384 RelativeVar.dwKind=VAR_LOCAL; … … 388 388 SetReg_WholeVariable(DEF_PTR_VOID,&RelativeVar,reg); 389 389 } 390 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){ 391 extern BOOL bCompilingGlobal; 390 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss){ 392 391 int i; 393 LONG_PTR lpIndex;394 392 char variable[VN_SIZE],member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE]; 395 393 … … 406 404 407 405 void *pInfo; 408 int idProc=GetProc(VarName, &pInfo);406 int idProc=GetProc(VarName,(void **)&pInfo); 409 407 410 408 if(idProc){ 411 409 pRelativeVar->dwKind=VAR_DIRECTMEM; 410 411 Type type; 412 412 413 413 ////////////////////////////////////////////////////// … … 420 420 //////////////// 421 421 422 *pType=CallProc(idProc,pInfo,VarName,array,&lpIndex);422 CallProc(idProc,pInfo,VarName,array,type); 423 423 424 424 //戻り値をr11にコピー … … 430 430 }//////////////////////////////////////////// 431 431 432 LONG_PTR lp2; 433 if(!GetMemberOffset( 432 if(!_member_offset( 434 433 isErrorEnabled, 435 434 isWriteAccess, 436 (CClass *)lpIndex, 437 member,pType,pRelativeVar,&lp2,0)) return 0; 438 if(plpIndex) *plpIndex=lp2; 439 440 return 1; 435 type.GetClass(), 436 member,pRelativeVar,resultType,0)) return false; 437 438 return true; 441 439 } 442 440 } … … 447 445 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 448 446 449 int *pSubScripts;447 const int *pSubScripts; 450 448 bool bConst = false; 451 449 452 450 453 if( bCompilingGlobal==0){451 if( UserProc::IsLocalAreaCompiling() ){ 454 452 ////////////////// 455 453 // ローカル変数 456 454 ////////////////// 457 455 458 for(i=MaxLocalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 459 if( LocalVar[i].bLiving //現在のスコープで有効なもの 460 && LocalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 461 ){ 462 if(lstrcmp(VarName,LocalVar[i].name)==0) break; 463 } 464 } 465 if(i>=0){ 456 const Variable *pVar = UserProc::CompilingUserProc().localVars.BackSearch( VarName ); 457 if( pVar ){ 466 458 //ポインタ変数の場合 467 if( IsPtrType(LocalVar[i].type)){468 if( LocalVar[i].SubScripts[0]==-1){459 if( pVar->IsPointer() ){ 460 if( !pVar->IsArray() ){ 469 461 lstrcpy(lpPtrOffset,array); 470 462 array[0]=0; … … 475 467 SetError(16,variable,cp); 476 468 pRelativeVar->dwKind=NON_VAR; 477 return 0;469 return false; 478 470 } 479 471 } 480 472 481 pRelativeVar->offset=- LocalVar[i].offset;473 pRelativeVar->offset=-pVar->offset; 482 474 pRelativeVar->bOffsetOffset=0; 483 if( LocalVar[i].fRef){475 if( pVar->IsRef() ){ 484 476 // 参照型 485 477 pRelativeVar->dwKind = VAR_REFLOCAL; 486 478 } 487 479 else pRelativeVar->dwKind=VAR_LOCAL; 488 *pType=LocalVar[i].type; 489 lpIndex=LocalVar[i].u.index; 490 if(plpIndex) *plpIndex=lpIndex; 491 pSubScripts=LocalVar[i].SubScripts; 492 bConst = LocalVar[i].bConst; 480 resultType = *pVar; 481 pSubScripts=pVar->GetSubScriptsPtr(); 482 bConst = pVar->IsConst(); 493 483 494 484 goto ok; … … 506 496 SetThisPtrToReg(REG_R11); 507 497 508 *pType=DEF_OBJECT;509 498 pRelativeVar->dwKind=VAR_DIRECTMEM; 510 499 511 if(plpIndex) *plpIndex=(LONG_PTR)pobj_CompilingClass;512 return 1;500 resultType.SetType( DEF_OBJECT, pobj_CompilingClass ); 501 return true; 513 502 } 514 503 … … 542 531 543 532 pRelativeVar->dwKind=VAR_DIRECTMEM; 544 if(! GetMemberOffset(533 if(!_member_offset( 545 534 isErrorEnabled, 546 535 isWriteAccess, 547 pobj_CompilingClass,536 *pobj_CompilingClass, 548 537 variable, 549 pType,550 538 pRelativeVar, 551 &lpIndex,1)) return 0; 552 if(plpIndex) *plpIndex=lpIndex; 553 return 1; 539 resultType,1)) return false; 540 return true; 554 541 } 555 542 556 543 NonClassMember: 557 544 558 ////////////////////////// 559 // 静的ローカル変数 560 // ※"Static.Object.Method.Variable" 561 ////////////////////////// 562 563 char temporary[VN_SIZE]; 564 extern SubInfo *pCompilingSubInfo; 565 if(pCompilingSubInfo){ 566 GetNowStaticVarFullName(VarName,temporary); 567 568 for(i=0;i<MaxGlobalVarNum;i++){ 569 if(lstrcmp(temporary,GlobalVar[i].name)==0) break; 570 } 571 if(i!=MaxGlobalVarNum){ 545 { 546 const Variable *pVar; 547 548 ////////////////////////// 549 // 静的ローカル変数 550 // ※"Static.Object.Method.Variable" 551 ////////////////////////// 552 553 char temporary[VN_SIZE]; 554 if( UserProc::IsLocalAreaCompiling() ){ 555 GetNowStaticVarFullName(VarName,temporary); 556 557 pVar = globalVars.Find( temporary ); 558 if( pVar ){ 559 goto GlobalOk; 560 } 561 } 562 563 564 ////////////////////////// 565 // クラスの静的メンバ 566 ////////////////////////// 567 568 if(member[0]){ 569 lstrcpy(temporary,member); 570 571 char tempMember[VN_SIZE]; 572 char tempArray[VN_SIZE]; 573 { 574 CClass::RefType refType; 575 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 576 } 577 578 char temp2[VN_SIZE]; 579 sprintf(temp2,"%s.%s",VarName,temporary); 580 pVar = globalVars.Find( temp2 ); 581 if( pVar ){ 582 lstrcpy(member,tempMember); 583 lstrcpy(array,tempArray); 584 goto GlobalOk; 585 } 586 } 587 588 if(pobj_CompilingClass){ 589 //自身のクラスから静的メンバを参照する場合 590 char temp2[VN_SIZE]; 591 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 592 pVar = globalVars.Find( temp2 ); 593 if( pVar ){ 594 goto GlobalOk; 595 } 596 } 597 598 ///////////////////// 599 // グローバル変数 600 ///////////////////// 601 602 pVar = globalVars.BackSearch( VarName ); 603 if( pVar ){ 572 604 goto GlobalOk; 573 605 } 574 } 575 576 577 ////////////////////////// 578 // クラスの静的メンバ 579 ////////////////////////// 580 581 if(member[0]){ 582 lstrcpy(temporary,member); 583 584 char tempMember[VN_SIZE]; 585 char tempArray[VN_SIZE]; 586 { 587 CClass::RefType refType; 588 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 589 } 590 591 char temp2[VN_SIZE]; 592 sprintf(temp2,"%s.%s",VarName,temporary); 593 for(i=0;i<MaxGlobalVarNum;i++){ 594 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 595 } 596 597 if(i!=MaxGlobalVarNum){ 598 lstrcpy(member,tempMember); 599 lstrcpy(array,tempArray); 600 goto GlobalOk; 601 } 602 } 603 604 if(pobj_CompilingClass){ 605 //自身のクラスから静的メンバを参照する場合 606 char temp2[VN_SIZE]; 607 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 608 for(i=0;i<MaxGlobalVarNum;i++){ 609 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 610 } 611 612 if(i!=MaxGlobalVarNum){ 613 goto GlobalOk; 614 } 615 } 616 617 ///////////////////// 618 // グローバル変数 619 ///////////////////// 620 621 for(i=MaxGlobalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 622 if( GlobalVar[i].bLiving //現在のスコープで有効なもの 623 && GlobalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 624 ){ 625 if(lstrcmp(VarName,GlobalVar[i].name)==0) break; 626 } 627 } 628 if(i>=0){ 629 goto GlobalOk; 630 } 631 632 if(isErrorEnabled) SetError(3,variable,cp); 633 pRelativeVar->dwKind=NON_VAR; 634 return 0; 606 607 if(isErrorEnabled) SetError(3,variable,cp); 608 pRelativeVar->dwKind=NON_VAR; 609 return false; 635 610 636 611 637 612 638 613 GlobalOk: 639 //ポインタ変数の場合 640 if(IsPtrType(GlobalVar[i].type)){ 641 if(GlobalVar[i].SubScripts[0]==-1){ 642 lstrcpy(lpPtrOffset,array); 643 array[0]=0; 644 } 645 } 646 else{ 647 if(lpPtrOffset[0]){ 648 SetError(16,variable,cp); 649 pRelativeVar->dwKind=NON_VAR; 650 return 0; 651 } 652 } 653 654 pRelativeVar->offset=GlobalVar[i].offset; 655 pRelativeVar->bOffsetOffset=0; 656 if(GlobalVar[i].fRef){ 657 // 参照型 658 pRelativeVar->dwKind = VAR_REFGLOBAL; 659 } 660 else pRelativeVar->dwKind=VAR_GLOBAL; 661 *pType=GlobalVar[i].type; 662 lpIndex=GlobalVar[i].u.index; 663 if(plpIndex) *plpIndex=lpIndex; 664 pSubScripts=GlobalVar[i].SubScripts; 665 bConst = GlobalVar[i].bConst; 614 //ポインタ変数の場合 615 if( pVar->IsPointer() ){ 616 if( !pVar->IsArray() ){ 617 lstrcpy(lpPtrOffset,array); 618 array[0]=0; 619 } 620 } 621 else{ 622 if(lpPtrOffset[0]){ 623 SetError(16,variable,cp); 624 pRelativeVar->dwKind=NON_VAR; 625 return false; 626 } 627 } 628 629 pRelativeVar->offset=pVar->offset; 630 pRelativeVar->bOffsetOffset=0; 631 if( pVar->IsRef() ){ 632 // 参照型 633 pRelativeVar->dwKind = VAR_REFGLOBAL; 634 } 635 else pRelativeVar->dwKind=VAR_GLOBAL; 636 resultType = *pVar; 637 pSubScripts=pVar->GetSubScriptsPtr(); 638 bConst = pVar->IsConst(); 639 } 666 640 667 641 … … 671 645 if( bConst && isWriteAccess ){ 672 646 //Const定義の変数に書き込みアクセスをしようとした場合 673 if( *pType == DEF_OBJECT){647 if( resultType.IsObject() ){ 674 648 //オブジェクト定数 675 649 SetError(130, VarName, cp ); … … 683 657 if(array[0]==0&&pSubScripts[0]!=-1){ 684 658 //配列の先頭ポインタを示す場合 685 *pType|=FLAG_PTR;659 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 686 660 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM); 687 return 1;661 return true; 688 662 } 689 663 … … 696 670 } 697 671 if(array[0]){ 698 if(!GetArrayOffset(pSubScripts,array, *pType,lpIndex)){672 if(!GetArrayOffset(pSubScripts,array,resultType)){ 699 673 SetError(14,variable,cp); 700 674 pRelativeVar->dwKind=NON_VAR; 701 return 0;675 return false; 702 676 } 703 677 } 704 678 if(member[0]){ 705 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){679 if( resultType.IsObject() || resultType.IsStruct() ){ 706 680 //実態オブジェクトのメンバを参照(obj.member) 707 681 if( refType != CClass::Dot ){ 708 682 SetError(104,VarName,cp); 709 683 pRelativeVar->dwKind=NON_VAR; 710 return 0;711 } 712 713 if( *pType==DEF_OBJECT){684 return false; 685 } 686 687 if( resultType.IsObject() ){ 714 688 // 参照内容へのポインタを抽出 715 689 SetRelativeOffset( *pRelativeVar ); 716 690 } 717 691 } 718 else if( *pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){692 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 719 693 //ポインタオブジェクトが示すメンバを参照 720 694 if(lpPtrOffset[0]){ … … 723 697 SetError(104,VarName,cp); 724 698 pRelativeVar->dwKind=NON_VAR; 725 return 0;699 return false; 726 700 } 727 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);701 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 728 702 pRelativeVar->dwKind=VAR_DIRECTMEM; 729 703 } … … 733 707 SetError(104,VarName,cp); 734 708 pRelativeVar->dwKind=NON_VAR; 735 return 0;709 return false; 736 710 } 737 711 … … 743 717 } 744 718 } 745 else if( *pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){719 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 746 720 //ポインタオブジェクトが示すメンバを参照 747 721 if(lpPtrOffset[0]){ … … 750 724 SetError(104,VarName,cp); 751 725 pRelativeVar->dwKind=NON_VAR; 752 return 0;726 return false; 753 727 } 754 728 755 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);729 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 756 730 pRelativeVar->dwKind=VAR_DIRECTMEM; 757 731 … … 765 739 SetError(104,VarName,cp); 766 740 pRelativeVar->dwKind=NON_VAR; 767 return 0;741 return false; 768 742 } 769 743 } … … 771 745 SetError(102,VarName,cp); 772 746 pRelativeVar->dwKind=NON_VAR; 773 return 0; 774 } 775 776 LONG_PTR lp2; 777 if(!GetMemberOffset( 747 return false; 748 } 749 750 if(!_member_offset( 778 751 isErrorEnabled, 779 752 isWriteAccess, 780 (CClass *)lpIndex, 781 member,pType,pRelativeVar,&lp2,0)) return 0; 782 if(plpIndex) *plpIndex=lp2; 783 784 return 1; 753 resultType.GetClass(), 754 member,pRelativeVar,resultType,0)) return false; 755 756 return true; 785 757 } 786 758 787 759 if(lpPtrOffset[0]){ 788 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);760 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 789 761 pRelativeVar->dwKind=VAR_DIRECTMEM; 790 762 } 791 763 792 return 1;764 return true; 793 765 } 794 766 795 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){767 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 796 768 extern BYTE *initGlobalBuf; 797 int i,i2,i3 ,TypeSize;769 int i,i2,i3; 798 770 char temporary[VN_SIZE]; 799 771 … … 802 774 InitBuf[lstrlen(InitBuf)-1]=0; 803 775 804 TypeSize=GetTypeSize(type,lpIndex);776 int typeSize = type.GetSize(); 805 777 806 778 if(SubScripts[0]!=-1){ 807 TypeSize*=JumpSubScripts(SubScripts+1);779 typeSize*=JumpSubScripts(SubScripts+1); 808 780 i=0; 809 781 i2=0; … … 815 787 i=GetOneParameter(InitBuf,i,temporary); 816 788 if(!SetInitGlobalData( 817 offset+i2* TypeSize,789 offset+i2*typeSize, 818 790 type, 819 lpIndex,820 791 SubScripts+1, 821 temporary)) return 0;792 temporary)) return false; 822 793 i2++; 823 794 if(InitBuf[i]=='\0') break; 824 795 } 825 return -1; 826 } 827 828 if(type==DEF_STRUCT){ 829 CClass *pobj_c; 830 pobj_c=(CClass *)lpIndex; 831 832 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 796 return true; 797 } 798 799 if(type.IsStruct()){ 800 const CClass &objClass = type.GetClass(); 801 802 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 833 803 i=GetOneParameter(InitBuf,i,temporary); 834 804 835 i3= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );805 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 836 806 837 807 if(!SetInitGlobalData(offset+i3, 838 pobj_c->ppobj_Member[i2]->TypeInfo.type, 839 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 840 pobj_c->ppobj_Member[i2]->SubScripts, 841 temporary)) return 0; 808 *objClass.ppobj_Member[i2], 809 objClass.ppobj_Member[i2]->SubScripts, 810 temporary)) return false; 842 811 843 812 if(InitBuf[i]=='\0') break; 844 813 } 845 if(i2+1!= pobj_c->iMemberNum){814 if(i2+1!=objClass.iMemberNum){ 846 815 SetError(41,0,cp); 847 return 0;848 } 849 return 1;816 return false; 817 } 818 return true; 850 819 } 851 820 852 821 SetError(41,0,cp); 853 return 0;822 return false; 854 823 } 855 824 … … 859 828 /////////////////////////////////////// 860 829 861 if( type == DEF_OBJECT || type == DEF_STRUCT){830 if( type.IsObject() || type.IsStruct() ){ 862 831 //オブジェクトまたは構造体の場合はありえない 863 832 SetError(300,NULL,cp); 864 return 0;833 return false; 865 834 } 866 835 867 836 if(SubScripts[0]!=-1){ 868 837 SetError(41,0,cp); 869 return 0;838 return false; 870 839 } 871 840 872 841 double dbl; 873 842 _int64 i64data; 874 int CalcType; 875 LONG_PTR lpCalcIndex; 876 877 CalcType=StaticCalculation(false, InitBuf,type,&i64data,&lpCalcIndex); 878 if(!CalcType){ 843 Type calcType; 844 845 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 879 846 //動的データだった場合 880 return 0;881 } 882 if( IsRealNumberType(CalcType)){847 return false; 848 } 849 if( calcType.IsReal() ){ 883 850 memcpy(&dbl,&i64data,sizeof(double)); 884 851 i64data=(_int64)dbl; … … 889 856 CheckDifferentType( 890 857 type, 891 lpIndex, 892 CalcType, 893 lpCalcIndex, 858 calcType, 894 859 0,0); 895 860 896 if( type==DEF_DOUBLE)861 if( type.IsDouble() ){ 897 862 *(double *)(initGlobalBuf+offset)=(double)dbl; 898 else if(type==DEF_SINGLE) 899 *(float *)(initGlobalBuf+offset)=(float)dbl; 900 else if(type==DEF_INT64||type==DEF_QWORD||IsPtrType(type)){ 901 if(type==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){ 863 } 864 else if( type.IsSingle() ){ 865 *(float *)(initGlobalBuf+offset)=(float)dbl; 866 } 867 else if( type.Is64() || type.IsPointer() ){ 868 if(type.GetBasicType()==typeOfPtrChar && type.GetIndex()==LITERAL_STRING){ 902 869 //文字列定数のとき 903 870 … … 923 890 } 924 891 } 925 else if( type==DEF_LONG||type==DEF_DWORD)892 else if( type.IsDWord() || type.IsLong() ){ 926 893 *(DWORD *)(initGlobalBuf+offset)=(DWORD)i64data; 927 else if(type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR)) 894 } 895 else if( type.IsWord() || type.IsInteger() ){ 928 896 *(WORD *)(initGlobalBuf+offset)=(WORD)i64data; 929 else if(type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)) 897 } 898 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 930 899 *(BYTE *)(initGlobalBuf+offset)=(BYTE)i64data; 931 932 return 1; 900 } 901 902 return true; 933 903 } 934 BOOL InitLocalVar(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){935 int i,i2,i3 ,TypeSize;904 bool InitLocalVar(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 905 int i,i2,i3; 936 906 char temporary[VN_SIZE]; 937 907 … … 940 910 InitBuf[lstrlen(InitBuf)-1]=0; 941 911 942 TypeSize=GetTypeSize(type,lpIndex);912 int typeSize = type.GetSize(); 943 913 944 914 if(SubScripts[0]!=-1){ 945 TypeSize*=JumpSubScripts(SubScripts+1);915 typeSize*=JumpSubScripts(SubScripts+1); 946 916 i=0; 947 917 i2=0; … … 949 919 if(SubScripts[0]<i2){ 950 920 SetError(41,0,cp); 951 return 0;921 return false; 952 922 } 953 923 i=GetOneParameter(InitBuf,i,temporary); 954 924 if(!InitLocalVar( 955 offset+i2* TypeSize,925 offset+i2*typeSize, 956 926 type, 957 lpIndex,958 927 SubScripts+1, 959 temporary)) return 0;928 temporary)) return false; 960 929 i2++; 961 930 if(InitBuf[i]=='\0') break; 962 931 } 963 return -1; 964 } 965 966 if(type==DEF_STRUCT){ 967 CClass *pobj_c; 968 pobj_c=(CClass *)lpIndex; 969 970 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 932 return true; 933 } 934 935 if(type.IsStruct()){ 936 const CClass &objClass = type.GetClass(); 937 938 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 971 939 i=GetOneParameter(InitBuf,i,temporary); 972 940 973 i3= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );941 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 974 942 975 943 if(!InitLocalVar(offset+i3, 976 pobj_c->ppobj_Member[i2]->TypeInfo.type, 977 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 978 pobj_c->ppobj_Member[i2]->SubScripts, 979 temporary)) return 0; 944 *objClass.ppobj_Member[i2], 945 objClass.ppobj_Member[i2]->SubScripts, 946 temporary)) return false; 980 947 981 948 if(InitBuf[i]=='\0') break; 982 949 } 983 if(i2+1!= pobj_c->iMemberNum){950 if(i2+1!=objClass.iMemberNum){ 984 951 SetError(41,0,cp); 985 952 return 0; 986 953 } 987 return 1;954 return true; 988 955 } 989 956 990 957 SetError(41,0,cp); 991 return 0;958 return false; 992 959 } 993 960 … … 999 966 if(SubScripts[0]!=-1){ 1000 967 SetError(41,0,cp); 1001 return 0;968 return false; 1002 969 } 1003 970 1004 971 double dbl; 1005 972 _int64 i64data; 1006 int CalcType; 1007 LONG_PTR lpCalcIndex; 1008 CalcType=StaticCalculation(false, InitBuf,type,&i64data,&lpCalcIndex); 1009 if(!CalcType){ 973 Type calcType; 974 975 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 1010 976 //動的データだった場合 1011 return 0;1012 } 1013 if( IsRealNumberType(CalcType)){977 return false; 978 } 979 if( calcType.IsReal() ){ 1014 980 memcpy(&dbl,&i64data,sizeof(double)); 1015 981 i64data=(_int64)dbl; … … 1020 986 CheckDifferentType( 1021 987 type, 1022 lpIndex, 1023 CalcType, 1024 lpCalcIndex, 988 calcType, 1025 989 0,0); 1026 990 1027 if( type==DEF_DOUBLE){991 if( type.IsDouble() ){ 1028 992 memcpy(&i64data,&dbl,sizeof(double)); 1029 993 … … 1037 1001 obp+=sizeof(long); 1038 1002 } 1039 else if( type==DEF_SINGLE){1003 else if( type.IsSingle() ){ 1040 1004 float flt; 1041 1005 flt=(float)dbl; … … 1047 1011 obp+=sizeof(long)+sizeof(long); 1048 1012 } 1049 else if( type==DEF_INT64||type==DEF_QWORD||IsPtrType(type)){1050 if(type ==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){1013 else if( type.Is64() || type.IsPointer() ){ 1014 if(type.GetBasicType()==typeOfPtrChar && type.GetIndex()==LITERAL_STRING){ 1051 1015 //文字列定数のとき 1052 1016 … … 1088 1052 } 1089 1053 } 1090 else if( type==DEF_LONG||type==DEF_DWORD){1054 else if( type.IsDWord() || type.IsLong() ){ 1091 1055 //mov dword ptr[rsp+offset],value 1092 1056 op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1095 1059 obp+=sizeof(long)+sizeof(long); 1096 1060 } 1097 else if( type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR)){1061 else if( type.IsWord() || type.IsInteger() ){ 1098 1062 //mov word ptr[rsp+offset],value 1099 1063 op_mov_MV(sizeof(short),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1102 1066 obp+=sizeof(long)+sizeof(short); 1103 1067 } 1104 else if( type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)){1068 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 1105 1069 //mov byte ptr[rsp+offset],value 1106 1070 op_mov_MV(sizeof(char),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1109 1073 obp+=sizeof(long)+sizeof(char); 1110 1074 } 1111 return 1;1075 return true; 1112 1076 } 1113 1077 1114 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1115 extern BOOL bCompilingGlobal; 1116 if(bCompilingGlobal){ 1078 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1079 if( UserProc::IsGlobalAreaCompiling() ){ 1117 1080 ///////////////////////// 1118 1081 // グローバル変数 1119 1082 ///////////////////////// 1120 1083 1121 AddGlobalVariable(isRef,VarName,SubScripts, &TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);1084 AddGlobalVariable(isRef,VarName,SubScripts,type,InitBuf,ConstractParameter,dwFlags); 1122 1085 } 1123 1086 else{ … … 1126 1089 ///////////////// 1127 1090 1128 int i2,i3; 1129 1130 for(i2=0;i2<MaxLocalVarNum;i2++){ 1131 if(LocalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==LocalVar[i2].ScopeLevel){ 1132 if(lstrcmp(LocalVar[i2].name,VarName)==0){ 1133 //2重定義のエラー 1134 SetError(15,VarName,cp); 1135 return; 1136 } 1137 } 1138 } 1139 1140 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 1141 VARIABLE *pVar = &LocalVar[MaxLocalVarNum]; 1142 MaxLocalVarNum++; 1143 1144 if( isRef ){ 1145 //参照型 1146 pVar->fRef = REF_VARIABLE; 1147 TypeSize = PTR_SIZE; 1148 } 1149 else pVar->fRef=0; 1150 1151 for(i2=1,i3=0;i3<255;i3++){ 1152 //配列要素数 1153 pVar->SubScripts[i3]=SubScripts[i3]; 1154 1155 if(SubScripts[i3]==-1) break; 1156 i2*=SubScripts[i3]+1; 1157 } 1158 int VarSize=TypeSize*i2; 1159 if(VarSize%8) VarSize+=8-(VarSize%8); 1160 1161 //変数データを追加 1162 lstrcpy(pVar->name,VarName); 1163 if(dwFlags & DIMFLAG_CONST) pVar->bConst = true; 1164 else pVar->bConst = false; 1165 if(SubScripts[0]==-1) pVar->bArray=0; 1166 else pVar->bArray=1; 1167 pVar->type=TypeInfo.type; 1168 pVar->u.index=TypeInfo.u.lpIndex; 1091 if( UserProc::CompilingUserProc().localVars.DuplicateCheck( VarName ) ){ 1092 //2重定義のエラー 1093 SetError(15,VarName,cp); 1094 return; 1095 } 1096 1097 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false; 1098 1099 Variable *pVar = new Variable( VarName, type, isConst, isRef ); 1100 1101 if( SubScripts[0] != -1 ){ 1102 //配列あり 1103 pVar->SetArray( SubScripts ); 1104 } 1105 1106 //コンストラクタ用パラメータ 1107 pVar->paramStrForConstructor = ConstractParameter; 1108 1109 //レキシカルスコープ 1110 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); 1111 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress(); 1112 pVar->bLiving=TRUE; 1113 1114 //エラー用 1115 pVar->source_code_address=cp; 1116 1117 // 変数を追加 1118 UserProc::CompilingUserProc().localVars.push_back( pVar ); 1169 1119 1170 1120 //アラインメントを考慮 1171 if( pVar-> type==DEF_STRUCT){1172 int alignment = pVar-> u.pobj_c->iAlign;1121 if( pVar->IsStruct() ){ 1122 int alignment = pVar->GetClass().iAlign; 1173 1123 if( alignment ){ 1174 1124 if( AllLocalVarSize % alignment ){ … … 1178 1128 } 1179 1129 1180 AllLocalVarSize +=VarSize;1181 pVar->offset =AllLocalVarSize;1130 AllLocalVarSize += pVar->GetMemorySize(); 1131 pVar->offset = AllLocalVarSize; 1182 1132 1183 1133 //レキシカルスコープ … … 1188 1138 if(InitBuf[0]){ 1189 1139 //初期代入時のみ、書き込みアクセスを許可する 1190 bool bConstBack = pVar->bConst; 1191 pVar->bConst = false; 1140 if( isConst ){ 1141 pVar->ConstOff(); 1142 } 1192 1143 1193 1144 int result = 0; 1194 if( pVar->type != DEF_OBJECT){1145 if( !pVar->IsObject() ){ 1195 1146 result = InitLocalVar(-pVar->offset, 1196 pVar->type, 1197 pVar->u.index, 1198 pVar->SubScripts, 1147 *pVar, 1148 pVar->GetSubScriptsPtr(), 1199 1149 InitBuf); 1200 1150 } … … 1207 1157 } 1208 1158 1209 pVar->bConst = bConstBack; 1159 if( isConst ){ 1160 pVar->ConstOn(); 1161 } 1210 1162 } 1211 1163 else{ … … 1216 1168 1217 1169 //mov rdx, VarSize 1218 op_mov_RV( sizeof(_int64), REG_RDX, VarSize);1170 op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() ); 1219 1171 1220 1172 //mov rcx, rsp … … 1228 1180 1229 1181 //call FillMemory 1230 D ECLAREINFO *pdi;1231 p di=GetDeclareHash("FillMemory");1232 op_call( p di);1182 DllProc *pDllProc; 1183 pDllProc=GetDeclareHash("FillMemory"); 1184 op_call( pDllProc ); 1233 1185 } 1234 1186 } 1235 1187 1236 1188 //コンストラクタ呼び出し 1237 if( TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){1189 if( type.IsObject() &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){ 1238 1190 char objectSize[255]; 1239 1191 if( SubScripts[0] == -1 ){ … … 1246 1198 sprintf( objectSize, "%d", SubScripts[0] ); 1247 1199 } 1248 Operator_New( *TypeInfo.u.pobj_Class, objectSize, ConstractParameter, TypeInfo ); 1249 1250 int type; 1251 LONG_PTR lpIndex; 1200 Operator_New( type.GetClass(), objectSize, ConstractParameter, type ); 1201 1202 Type tempType; 1252 1203 RELATIVE_VAR RelativeVar; 1253 GetVarOffset( true, false, VarName, & type, &RelativeVar, &lpIndex);1204 GetVarOffset( true, false, VarName, &RelativeVar, tempType ); 1254 1205 if( RelativeVar.dwKind == VAR_DIRECTMEM ){ 1255 1206 SetError(); … … 1258 1209 } 1259 1210 1260 if( TypeInfo.type==DEF_OBJECT){1261 if( TypeInfo.u.pobj_Class->IsAbstract()){1211 if( type.IsObject() ){ 1212 if( type.GetClass().IsAbstract() ){ 1262 1213 //抽象クラスだったとき 1263 SetError(125, TypeInfo.u.pobj_Class->name,cp);1214 SetError(125,type.GetClass().name,cp); 1264 1215 } 1265 1216 } 1266 1217 } 1267 void dim(char *Parameter,DWORD dwFlags){1268 extern BOOL bCompilingGlobal;1269 extern HANDLE hHeap;1270 int i2;1271 char VarName[VN_SIZE];1272 1273 //参照型かどうか1274 bool isRef = false;1275 1276 i2 = 0;1277 1278 if( Parameter[i2] == 1 && Parameter[i2+1] == ESC_BYREF ){1279 //参照型1280 isRef = true;1281 Parameter += 2;1282 }1283 1284 if(dwFlags & DIMFLAG_CONST){1285 1286 //////////////////////////////////1287 // 定数変数の場合を考慮1288 //////////////////////////////////1289 for(;;i2++){1290 if(Parameter[i2] == '=' ||1291 Parameter[i2] == 1 && Parameter[i2] == ESC_AS ||1292 Parameter[i2] =='('){1293 VarName[i2] = 0;1294 break;1295 }1296 VarName[i2] = Parameter[i2];1297 }1298 1299 //定数と2重定義されていないる場合は抜け出す1300 if(CDBConst::obj.GetType(VarName)){1301 return;1302 }1303 1304 //定数マクロとして定義されている場合は抜け出す1305 if(GetConstHash(VarName)){1306 return;1307 }1308 }1309 1310 1311 //構文を解析1312 int SubScripts[MAX_ARRAYDIM];1313 TYPEINFO TypeInfo;1314 char InitBuf[8192];1315 char ConstractParameter[VN_SIZE];1316 if(!GetDimentionFormat(Parameter, isRef , VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter))1317 return;1318 1319 1320 //定数と2重定義されていないかを調べる1321 if(CDBConst::obj.GetType(VarName)){1322 SetError(15,VarName,cp);1323 return;1324 }1325 1326 //定数マクロとして定義されている場合1327 if(GetConstHash(VarName)){1328 SetError(15,VarName,cp);1329 return;1330 }1331 1332 1333 //タイプサイズを取得1334 int TypeSize;1335 TypeSize=GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex);1336 1337 extern BOOL bCompilingGlobal;1338 if(dwFlags&DIMFLAG_STATIC){1339 if(bCompilingGlobal){1340 SetError(60,NULL,cp);1341 return;1342 }1343 1344 /////////////////////1345 // Static変数1346 // ※"Static.Object.Method.Variable"1347 /////////////////////1348 1349 char temporary[VN_SIZE];1350 GetNowStaticVarFullName(VarName,temporary);1351 1352 dim( isRef,temporary,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );1353 1354 /*1355 Note: 静的変数のコンストラクタ呼び出しは1356 _System_InitStaticLocalVariables関数内で一括して行う1357 */1358 }1359 else{1360 dim( isRef,VarName,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );1361 }1362 }1363 void OpcodeDim(char *Parameter,DWORD dwFlags){1364 int i,i2,i3,IsStr=0;1365 char temporary[8192];1366 1367 for(i=0,i2=0;;i++,i2++){1368 if(Parameter[i]=='\"') IsStr^=1;1369 if(Parameter[i]=='('&&IsStr==0){1370 i3=GetStringInPare(temporary+i2,Parameter+i);1371 i+=i3-1;1372 i2+=i3-1;1373 continue;1374 }1375 if(Parameter[i]=='['&&IsStr==0){1376 i3=GetStringInBracket(temporary+i2,Parameter+i);1377 i+=i3-1;1378 i2+=i3-1;1379 continue;1380 }1381 if((Parameter[i]==','&&IsStr==0)||1382 Parameter[i]=='\0'){1383 temporary[i2]=0;1384 1385 dim(temporary,dwFlags);1386 1387 if(Parameter[i]=='\0') break;1388 i2=-1;1389 continue;1390 }1391 temporary[i2]=Parameter[i];1392 }1393 }1394 1395 1218 void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){ 1396 1219 if(!IsGeneralReg(reg)) SetError(300,NULL,cp); -
BasicCompiler64/MakePeHdr.cpp
r73 r75 6 6 // 特殊関数の構造体ポインタ 7 7 //////////////////////////// 8 SubInfo 8 UserProc 9 9 *pSub_System_StartupProgram, 10 10 *pSub_DebugSys_StartProc, … … 136 136 137 137 //関数ポインタ情報を初期化 138 extern P ROCPTRINFO *pProcPtrInfo;138 extern ProcPointer **ppProcPointer; 139 139 extern int ProcPtrInfoNum; 140 p ProcPtrInfo=(PROCPTRINFO*)HeapAlloc(hHeap,0,1);140 ppProcPointer=(ProcPointer **)HeapAlloc(hHeap,0,1); 141 141 ProcPtrInfoNum=0; 142 142 … … 170 170 171 171 if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1)) 172 pSub_System_StartupProgram-> bUse=1;172 pSub_System_StartupProgram->Using(); 173 173 174 174 if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1)) 175 pSub_DebugSys_StartProc-> bUse=1;175 pSub_DebugSys_StartProc->Using(); 176 176 177 177 if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1)) 178 pSub_DebugSys_EndProc-> bUse=1;178 pSub_DebugSys_EndProc->Using(); 179 179 180 180 if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1)) 181 pSub_DebugSys_SaveContext-> bUse=1;181 pSub_DebugSys_SaveContext->Using(); 182 182 183 183 if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){ 184 pSub_System_GetEip-> bUse=1;185 pSub_System_GetEip-> bSystem=1;184 pSub_System_GetEip->Using(); 185 pSub_System_GetEip->ThisIsSystemProc(); 186 186 } 187 187 188 188 if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){ 189 pSub_System_InitDllGlobalVariables-> bUse=1;190 pSub_System_InitDllGlobalVariables-> bSystem=1;189 pSub_System_InitDllGlobalVariables->Using(); 190 pSub_System_InitDllGlobalVariables->ThisIsSystemProc(); 191 191 } 192 192 193 193 if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){ 194 pSub_System_InitStaticLocalVariables-> bUse=1;195 pSub_System_InitStaticLocalVariables-> bSystem=1;194 pSub_System_InitStaticLocalVariables->Using(); 195 pSub_System_InitStaticLocalVariables->ThisIsSystemProc(); 196 196 } 197 197 198 198 if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){ 199 pSub_System_Call_Destructor_of_GlobalObject-> bUse=1;200 pSub_System_Call_Destructor_of_GlobalObject-> bSystem=1;199 pSub_System_Call_Destructor_of_GlobalObject->Using(); 200 pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc(); 201 201 } 202 202 203 203 if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){ 204 pSub_System_GetSp-> bUse=1;205 pSub_System_GetSp-> bSystem=1;204 pSub_System_GetSp->Using(); 205 pSub_System_GetSp->ThisIsSystemProc(); 206 206 } 207 207 208 208 if(pSub_pow=GetSubHash("pow",1)) 209 pSub_pow-> bUse=1;209 pSub_pow->Using(); 210 210 211 211 if(pSub_calloc=GetSubHash("calloc",1)) 212 pSub_calloc-> bUse=1;212 pSub_calloc->Using(); 213 213 214 214 if(pSub_realloc=GetSubHash("realloc",1)) 215 pSub_realloc-> bUse=1;215 pSub_realloc->Using(); 216 216 217 217 if(pSub_free=GetSubHash("free",1)) 218 pSub_free-> bUse=1;218 pSub_free->Using(); 219 219 220 220 if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) ) 221 pSub_System_GC_malloc_ForObject-> bUse = 1;221 pSub_System_GC_malloc_ForObject->Using(); 222 222 223 223 if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) ) 224 pSub_System_GC_malloc_ForObjectPtr-> bUse = 1;224 pSub_System_GC_malloc_ForObjectPtr->Using(); 225 225 226 226 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 227 pSub_System_GC_free_for_SweepingDelete-> bUse = 1;227 pSub_System_GC_free_for_SweepingDelete->Using(); 228 228 229 229 … … 271 271 272 272 cp=-1; 273 extern BOOL bCompilingGlobal; 274 bCompilingGlobal=1; 273 UserProc::CompileStartForGlobalArea(); 275 274 276 275 if(!bDll){ … … 352 351 353 352 //call _System_Call_Destructor_of_GlobalObject 354 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;353 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 355 354 op_call(pSub_System_Call_Destructor_of_GlobalObject); 356 355 … … 405 404 ///////////////////// 406 405 407 bCompilingGlobal=0;408 409 406 //プロシージャをコンパイル開始 410 407 cp=0; … … 429 426 //////////////////////////////// 430 427 for(i=0;i<MAX_HASH;i++){ 431 extern DECLAREINFO **ppDeclareHash; 432 DECLAREINFO *pdi; 433 pdi=ppDeclareHash[i]; 434 while(pdi){ 435 if(pdi->bUse==0){ 436 pdi=pdi->pNextData; 428 extern DllProc **ppDeclareHash; 429 const DllProc *pDllProc = ppDeclareHash[i]; 430 while(pDllProc){ 431 if( !pDllProc->IsUsing() ){ 432 pDllProc=pDllProc->pNextData; 437 433 continue; 438 434 } … … 440 436 //エラーチェック 441 437 HINSTANCE hLib; 442 hLib=LoadLibrary( pdi->file);438 hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() ); 443 439 if(!hLib){ 444 440 extern char OutputFileName[MAX_PATH]; … … 446 442 _splitpath(OutputFileName,temp2,temp3,NULL,NULL); 447 443 lstrcat(temp2,temp3); 448 lstrcpy(temp3,p di->file);444 lstrcpy(temp3,pDllProc->GetDllFileName().c_str()); 449 445 GetFullPath(temp3,temp2); 450 446 hLib=LoadLibrary(temp3); 451 447 452 448 if(!hLib){ 453 SetError(-106,p di->file,pdi->pos);449 SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos()); 454 450 } 455 451 } 456 452 457 453 if(hLib){ 458 if(!GetProcAddress(hLib,p di->alias)){454 if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){ 459 455 FreeLibrary(hLib); 460 SetError(-107,p di->alias,pdi->pos);456 SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos()); 461 457 } 462 458 FreeLibrary(hLib); 463 459 } 464 460 465 p di=pdi->pNextData;461 pDllProc=pDllProc->pNextData; 466 462 } 467 463 } … … 500 496 ExportNamesLength=lstrlen(lpExportNames)+1; 501 497 502 extern SubInfo**ppSubHash;503 SubInfo *psi,*psi2;498 extern UserProc **ppSubHash; 499 UserProc *pUserProc,*psi2; 504 500 while(1){ 505 501 //辞書順にサーチ 506 502 temporary[0]=0; 507 503 for(i=0,psi2=0;i<MAX_HASH;i++){ 508 p si=ppSubHash[i];509 while(p si){510 if(p si->bExport){504 pUserProc=ppSubHash[i]; 505 while(pUserProc){ 506 if(pUserProc->IsExport()){ 511 507 if(temporary[0]=='\0'){ 512 lstrcpy(temporary,p si->name);513 psi2=p si;508 lstrcpy(temporary,pUserProc->GetName().c_str()); 509 psi2=pUserProc; 514 510 } 515 511 else{ 516 512 i3=lstrlen(temporary); 517 i4= lstrlen(psi->name);513 i4=(int)pUserProc->GetName().size(); 518 514 if(i3<i4) i3=i4; 519 if(memcmp(temporary,p si->name,i3)>0){520 lstrcpy(temporary,p si->name);521 psi2=p si;515 if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){ 516 lstrcpy(temporary,pUserProc->GetName().c_str()); 517 psi2=pUserProc; 522 518 } 523 519 } 524 520 } 525 p si=psi->pNextData;521 pUserProc=pUserProc->pNextData; 526 522 } 527 523 } 528 524 if(psi2==0) break; 529 psi=psi2; 530 531 psi->bExport=0; 532 533 if(lstrcmpi(psi->name,"DllMain")==0) 534 DllMain_EntryPoint=psi->CompileAddress; 525 pUserProc=psi2; 526 527 pUserProc->ExportOff(); 528 529 if( pUserProc->GetName() == "DllMain" ){ 530 DllMain_EntryPoint=pUserProc->beginOpAddress; 531 } 535 532 536 533 lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD)); 537 lpdwExportAddressTable[ExportNum]=p si->CompileAddress;534 lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress; 538 535 539 536 lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD)); … … 543 540 lpwExportOrdinalTable[ExportNum]=ExportNum; 544 541 545 lstrcpy(lpExportNames+ExportNamesLength,p si->name);542 lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str()); 546 543 ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1; 547 544 … … 576 573 //インポートDLL情報 577 574 ///////////////////// 578 extern D ECLAREINFO**ppDeclareHash;579 D ECLAREINFO *pdi;575 extern DllProc **ppDeclareHash; 576 DllProc *pDllProc; 580 577 char **ppDllNames; 581 578 int ImportDllNum; … … 613 610 ImportDllNum=0; 614 611 for(i=0;i<MAX_HASH;i++){ 615 pdi=ppDeclareHash[i]; 616 while(pdi){ 617 if(pdi->dwType==DECLARE_STATIC|| 618 pdi->bUse==0){ 619 pdi=pdi->pNextData; 612 const DllProc *pDllProc=ppDeclareHash[i]; 613 while(pDllProc){ 614 if( !pDllProc->IsUsing() ){ 615 pDllProc=pDllProc->pNextData; 620 616 continue; 621 617 } 622 618 623 if( lstrlen(pdi->file)>16){619 if( pDllProc->GetDllFileName().size() > 16 ){ 624 620 SetError(7,NULL,cp); 625 621 break; 626 622 } 627 623 for(i2=0;i2<ImportDllNum;i2++){ 628 if(lstrcmp(ppDllNames[i2],pdi->file)==0) break; 624 if( pDllProc->GetDllFileName() == ppDllNames[i2] ){ 625 break; 626 } 629 627 } 630 628 if(i2==ImportDllNum){ 631 629 ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **)); 632 630 ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16); 633 lstrcpy(ppDllNames[ImportDllNum],p di->file);631 lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str()); 634 632 ImportDllNum++; 635 633 } 636 634 637 p di=pdi->pNextData;635 pDllProc=pDllProc->pNextData; 638 636 } 639 637 } … … 651 649 pImportDescriptor[i].Name=i*0x10; //※すぐ下で再計算 652 650 for(i2=0;i2<MAX_HASH;i2++){ 653 pdi=ppDeclareHash[i2]; 654 while(pdi){ 655 if(pdi->dwType==DECLARE_STATIC|| 656 pdi->bUse==0){ 657 pdi=pdi->pNextData; 651 pDllProc=ppDeclareHash[i2]; 652 while(pDllProc){ 653 if( !pDllProc->IsUsing() ){ 654 pDllProc=pDllProc->pNextData; 658 655 continue; 659 656 } 660 657 661 if( lstrcmp(ppDllNames[i],pdi->file)==0){658 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 662 659 //ルックアップデータのサイズを追加 663 660 LookupSize+=sizeof(_int64); 664 661 } 665 662 666 p di=pdi->pNextData;663 pDllProc=pDllProc->pNextData; 667 664 } 668 665 } … … 691 688 for(i=0,i5=0;i<ImportDllNum;i++){ 692 689 for(i2=0;i2<MAX_HASH;i2++){ 693 pdi=ppDeclareHash[i2]; 694 while(pdi){ 695 if(pdi->dwType==DECLARE_STATIC|| 696 pdi->bUse==0){ 697 pdi=pdi->pNextData; 690 pDllProc=ppDeclareHash[i2]; 691 while(pDllProc){ 692 if( !pDllProc->IsUsing() ){ 693 pDllProc=pDllProc->pNextData; 698 694 continue; 699 695 } 700 696 701 if( lstrcmp(ppDllNames[i],pdi->file)==0){697 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 702 698 //ルックアップの位置をセット(後にインポート アドレス テーブルにセットしなおされる) 703 p di->LookupAddress=i5*sizeof(_int64);699 pDllProc->SetLookupAddress( i5*sizeof(_int64) ); 704 700 705 701 //ルックアップ テーブルの値をセット … … 714 710 pHintTable[HintSize++]=0; 715 711 pHintTable[HintSize++]=0; 716 lstrcpy(pHintTable+HintSize,p di->alias);717 i4= lstrlen(pdi->alias);712 lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str()); 713 i4=(int)pDllProc->GetAlias().size(); 718 714 HintSize+=i4+1; 719 715 if(i4%2==0) pHintTable[HintSize++]=0; … … 725 721 } 726 722 727 p di=pdi->pNextData;723 pDllProc=pDllProc->pNextData; 728 724 } 729 725 } … … 742 738 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 743 739 //(デバッグ情報で利用される) 744 extern int MaxGlobalVarNum;745 extern VARIABLE *GlobalVar;746 740 extern int AllInitGlobalVarSize; 747 for (i=0;i<MaxGlobalVarNum;i++){748 if( GlobalVar[i].offset&0x80000000){749 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize;741 foreach( Variable *pVar, globalVars ){ 742 if(pVar->offset&0x80000000){ 743 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 750 744 } 751 745 } … … 997 991 998 992 for(i2=0;i2<MAX_HASH;i2++){ 999 pdi=ppDeclareHash[i2];1000 while(p di){1001 if( pdi->bUse==0){1002 p di=pdi->pNextData;993 const DllProc *pDllProc=ppDeclareHash[i2]; 994 while(pDllProc){ 995 if( !pDllProc->IsUsing() ){ 996 pDllProc=pDllProc->pNextData; 1003 997 continue; 1004 998 } 1005 999 1006 if( lstrcmp(ppDllNames[i],pdi->file)==0){1000 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 1007 1001 //ルックアップ テーブル 1008 1002 pLookupTable[i5++]+=MemPos_ImportSection; 1009 1003 } 1010 1004 1011 p di=pdi->pNextData;1005 pDllProc=pDllProc->pNextData; 1012 1006 } 1013 1007 } … … 1033 1027 // ※x86はRVAからのオフセット。x64はRPI(実行中アドレス)からのオフセット 1034 1028 for(i=0;i<pobj_ImportAddrSchedule->num;i++){ 1035 D ECLAREINFO *pdi;1036 p di=pobj_ImportAddrSchedule->ppdi[i];1029 DllProc *pDllProc; 1030 pDllProc=pobj_ImportAddrSchedule->ppdi[i]; 1037 1031 *((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))= 1038 1032 MemPos_ImportSection+ 1039 p di->LookupAddress1033 pDllProc->GetLookupAddress() 1040 1034 -(MemPos_CodeSection+pobj_ImportAddrSchedule->pObpValues[i]+sizeof(long)); 1041 1035 } … … 1046 1040 // プロシージャポインタスケジュール 1047 1041 for(i=0;i<pobj_SubAddrSchedule->num;i++){ 1048 if(pobj_SubAddrSchedule->ppsi[i]-> CompileAddress==01049 &&pobj_SubAddrSchedule->ppsi[i]-> EndOpAddr==0){1042 if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0 1043 &&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){ 1050 1044 SetError(300,NULL,-1); 1051 1045 } … … 1053 1047 if(pobj_SubAddrSchedule->pbCall[i]){ 1054 1048 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1055 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));1049 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long)); 1056 1050 } 1057 1051 else{ 1058 1052 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1059 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress+ImageBase+MemPos_CodeSection;1053 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection; 1060 1054 } 1061 1055 } … … 1098 1092 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 1099 1093 //(デバッグ情報で利用される) 1100 extern int MaxGlobalVarNum; 1101 extern VARIABLE *GlobalVar; 1102 for(i=0;i<MaxGlobalVarNum;i++){ 1103 if(GlobalVar[i].offset&0x80000000){ 1104 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1094 foreach( Variable *pVar, globalVars ){ 1095 if(pVar->offset&0x80000000){ 1096 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1105 1097 } 1106 1098 } -
BasicCompiler64/NumOpe.cpp
r69 r75 19 19 20 20 extern CClass *pobj_StringClass; 21 TYPEINFO baseTypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass }; 22 Operator_New( *pobj_StringClass, "", parameter, baseTypeInfo ); 21 Operator_New( *pobj_StringClass, "", parameter, Type( DEF_OBJECT, *pobj_StringClass ) ); 23 22 24 23 free( parameter ); … … 70 69 } 71 70 72 int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap){ 73 extern HANDLE hHeap; 71 void ExtendRegToBigType( int reg, int bigBasicType, int baseBasicType ){ 72 switch( Type::GetBasicSize( bigBasicType ) ){ 73 case sizeof(_int64): 74 ExtendTypeTo64(baseBasicType,reg); 75 break; 76 case sizeof(long): 77 ExtendTypeTo32(baseBasicType,reg); 78 break; 79 case sizeof(short): 80 ExtendTypeTo16(baseBasicType,reg); 81 break; 82 } 83 } 84 85 bool NumOpe( int *pReg, 86 const char *expression, 87 const Type &baseType, 88 Type &resultType, 89 BOOL *pbUseHeap ){ 90 74 91 int i,i2,i3,i4; 75 92 char temporary[1024],temp2[1024],temp3[1024]; 76 93 77 if( Command[0]=='\0'){94 if(expression[0]=='\0'){ 78 95 SetError(1,NULL,cp); 79 return 0;80 } 81 82 if( Command[0]==1&& Command[1]==ESC_NEW ){96 return false; 97 } 98 99 if(expression[0]==1&& expression[1]==ESC_NEW ){ 83 100 //New演算子(オブジェクト生成) 84 TYPEINFO baseTypeInfo = { BaseType, lpBaseIndex }; 85 int resultType = Operator_New(Command+2,plpIndex, baseTypeInfo ); 101 102 if( !Operator_New( expression+2, baseType, resultType ) ){ 103 return false; 104 } 86 105 87 106 //mov reg,rax 88 107 op_mov_RR( *pReg, REG_RAX ); 89 108 90 return resultType;109 return true; 91 110 } 92 111 … … 100 119 long stack[255]; 101 120 int pnum; 102 if(!GetNumOpeElements( Command,&pnum,values,calc,stack)){121 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){ 103 122 for(i=0;i<pnum;i++){ 104 123 if(values[i]) HeapDefaultFree(values[i]); … … 156 175 double dbl; 157 176 int sp; 158 int type [255];177 int type_stack[255]; 159 178 LONG_PTR index_stack[255]; 160 179 BOOL bUseHeap[255]; … … 167 186 168 187 if(idCalc){ 169 if(type [sp-2]==DEF_OBJECT){188 if(type_stack[sp-2]==DEF_OBJECT){ 170 189 //オーバーロードされたオペレータを呼び出す 171 TYPEINFO BaseTypeInfo={BaseType,lpBaseIndex}; 172 i2=CallOperatorProc(idCalc,&BaseTypeInfo,type,index_stack,bUseHeap,sp); 190 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp); 173 191 if(i2==0){ 174 192 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"=="); … … 183 201 } 184 202 185 if(!CheckCalcType(idCalc,type ,sp)) goto error;203 if(!CheckCalcType(idCalc,type_stack,sp)) goto error; 186 204 } 187 205 … … 209 227 StrLiteral: 210 228 211 if(BaseType==DEF_OBJECT){ 212 CClass *pobj_Class; 213 pobj_Class=(CClass *)lpBaseIndex; 214 TYPEINFO BaseTypeInfo = {BaseType,lpBaseIndex}; 215 if(IsStringObjectType(BaseTypeInfo)){ 229 if( baseType.IsObject() ){ 230 if( baseType.IsStringObject() ){ 216 231 //要求タイプがStringのとき 217 232 … … 220 235 221 236 extern CClass *pobj_StringClass; 222 type [sp]=DEF_OBJECT;237 type_stack[sp]=DEF_OBJECT; 223 238 index_stack[sp]=(LONG_PTR)pobj_StringClass; 224 239 bLiteralCalculation=0; … … 232 247 } 233 248 234 type [sp]=typeOfPtrChar;249 type_stack[sp]=typeOfPtrChar; 235 250 bLiteralCalculation=0; 236 251 … … 277 292 int idProc; 278 293 void *pInfo; 279 idProc=GetProc(temporary,&pInfo); 280 294 idProc=GetProc(temporary,(void **)&pInfo); 295 296 Type resultType; 281 297 if(idProc){ 282 298 //閉じカッコ")"に続く文字がNULLでないとき … … 302 318 //////////////// 303 319 304 i2=CallProc(idProc,pInfo,temporary,temp2,&index_stack[sp]);305 if( i2==-1){320 CallProc(idProc,pInfo,temporary,temp2,resultType); 321 if(resultType.IsNull()){ 306 322 //戻り値が存在しないとき 307 323 for(i2=2;;i2++){ … … 325 341 326 342 //大きな型への暗黙の変換 327 type[sp]=AutoBigCast(BaseType,i2); 343 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType()); 344 index_stack[sp] = resultType.GetIndex(); 328 345 bLiteralCalculation=0; 329 346 330 SetUseRegFromRax(i2,UseReg,XmmReg); 331 332 if(IsRealNumberType(i2)) bXmm=1; 347 if( type_stack[sp] != resultType.GetBasicType() ){ 348 // 大きな型へ変換された場合 349 // ※レジスタの値をキャストする 350 ExtendRegToBigType( REG_RAX, type_stack[sp], resultType.GetBasicType() ); 351 } 352 353 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg); 354 355 if(resultType.IsReal()) bXmm=1; 333 356 else bXmm=0; 334 357 … … 342 365 else pobj_reg->LockReg(); 343 366 344 if( i2==DEF_STRUCT){367 if(resultType.IsStruct()){ 345 368 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 346 369 //※後にfreeする必要あり … … 360 383 361 384 //マクロ関数の場合 362 i2=NumOpe(&UseReg,temp3,0,0,&index_stack[sp]);363 364 if(!IS_LITERAL( index_stack[sp])){385 NumOpe(&UseReg,temp3,Type(),resultType); 386 387 if(!IS_LITERAL(resultType.GetIndex())){ 365 388 //リテラル値ではなかったとき 366 389 bLiteralCalculation=0; 367 390 } 368 391 369 type[sp]=i2; 370 371 if(IsRealNumberType(i2)) pobj_reg->LockXmmReg(); 392 type_stack[sp] = resultType.GetBasicType(); 393 index_stack[sp] = resultType.GetIndex(); 394 395 if(resultType.IsReal()) pobj_reg->LockXmmReg(); 372 396 else pobj_reg->LockReg(); 373 397 … … 381 405 //インデクサ(getアクセサ) 382 406 char variable[VN_SIZE],array_element[VN_SIZE]; 383 CClass *pobj_c;384 407 GetArrayElement(term,variable,array_element); 385 408 if(array_element[0]){ 386 i2=GetVarType(variable,(LONG_PTR *)&pobj_c,0);387 if(i2==DEF_OBJECT){388 TYPEINFO RetTypeInfo;389 CallIndexerGetterProc(UseReg, pobj_c,variable,array_element,RetTypeInfo);390 type [sp]=RetTypeInfo.type;391 index_stack[sp]= RetTypeInfo.u.lpIndex;409 Type resultType; 410 GetVarType(variable,resultType,0); 411 if( resultType.IsObject() ){ 412 CallIndexerGetterProc(UseReg,&resultType.GetClass(),variable,array_element,resultType); 413 type_stack[sp]=resultType.GetBasicType(); 414 index_stack[sp]=resultType.GetIndex(); 392 415 bLiteralCalculation=0; 393 416 394 if( IsRealNumberType(RetTypeInfo.type)) pobj_reg->LockXmmReg();417 if(resultType.IsReal()) pobj_reg->LockXmmReg(); 395 418 else pobj_reg->LockReg(); 396 419 sp++; … … 402 425 // Nothing 403 426 if( lstrcmp( term, "Nothing" ) == 0 ){ 404 type [sp] = DEF_OBJECT;405 if( BaseType == DEF_OBJECT){406 index_stack[sp] = lpBaseIndex;427 type_stack[sp] = DEF_OBJECT; 428 if( baseType.IsObject() ){ 429 index_stack[sp] = baseType.GetIndex(); 407 430 } 408 431 else{ … … 427 450 428 451 RELATIVE_VAR RelativeVar; 452 Type varType; 429 453 if(GetVarOffset( 430 454 false, //エラー表示あり 431 455 false, //読み込み専用 432 456 term, 433 & i2,&RelativeVar,&index_stack[sp])){457 &RelativeVar,varType)){ 434 458 ////////// 435 459 // 変数 … … 437 461 438 462 //大きな型への暗黙の変換 439 type[sp]=AutoBigCast(BaseType,i2); 463 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),varType.GetBasicType()); 464 index_stack[sp] = varType.GetIndex(); 440 465 bLiteralCalculation=0; 441 466 442 if(type[sp]!=i2){ 443 //大きな型へ変換された場合(レジスタを0に初期化する) 444 445 //xor reg,reg 446 op_zero_reg(UseReg); 447 } 448 449 if(i2&FLAG_PTR){ 467 if(varType.GetBasicType()&FLAG_PTR){ 450 468 //配列ポインタ 451 type [sp]=GetPtrType(i2^FLAG_PTR,index_stack[sp]);469 type_stack[sp]=GetPtrType(varType.GetBasicType()^FLAG_PTR); 452 470 453 471 SetVarPtrToReg(UseReg,&RelativeVar); 454 472 } 455 else if( IsRealNumberType(i2)){473 else if(varType.IsReal()){ 456 474 //実数型 457 475 bXmm=1; 458 476 459 if( i2==DEF_DOUBLE)477 if( varType.IsDouble() ) 460 478 SetXmmReg_DoubleVariable(&RelativeVar,XmmReg); 461 if( i2==DEF_SINGLE)479 if( varType.IsSingle() ) 462 480 SetXmmReg_SingleVariable(&RelativeVar,XmmReg); 463 481 } 464 else if( IsWholeNumberType(i2) || i2==DEF_OBJECT){482 else if( varType.IsWhole() || varType.IsObject()){ 465 483 //整数型 466 SetReg_WholeVariable( i2,&RelativeVar,UseReg);467 } 468 else if( i2==DEF_STRUCT){484 SetReg_WholeVariable(varType.GetBasicType(),&RelativeVar,UseReg); 485 } 486 else if( varType.IsStruct() ){ 469 487 //構造体ポインタをUseRegへ格納(構造体は値型) 470 488 SetVarPtrToReg(UseReg,&RelativeVar); 471 489 } 472 490 else SetError(11,term,cp); 491 492 if( type_stack[sp] != varType.GetBasicType() ){ 493 // 大きな型へ変換された場合 494 // ※レジスタの値をキャストする 495 ExtendRegToBigType( UseReg, type_stack[sp], varType.GetBasicType() ); 496 } 473 497 474 498 if(bXmm==0&&UseReg==REG_R14){ … … 477 501 } 478 502 if(bXmm&&XmmReg==REG_XMM4){ 479 if( i2==DEF_DOUBLE){503 if(varType.IsDouble()){ 480 504 //movsd qword ptr[rsp+offset],xmm4 ※スタックフレームを利用 481 505 pobj_sf->push(REG_XMM4,sizeof(double)); 482 506 } 483 if( i2==DEF_SINGLE){507 if(varType.IsSingle()){ 484 508 //movss dword ptr[rsp+offset],xmm4 ※スタックフレームを利用 485 509 pobj_sf->push(REG_XMM4,sizeof(float)); … … 500 524 i3 = CDBConst::obj.GetType(term); 501 525 if(i3){ 502 type [sp] = i3;526 type_stack[sp] = i3; 503 527 if(IsRealNumberType(i3)){ 504 528 //実数 … … 536 560 i3=GetTypeFixed(term,&lp); 537 561 if(i3!=-1){ 538 type [sp]=i3|FLAG_CAST;562 type_stack[sp]=i3|FLAG_CAST; 539 563 index_stack[sp]=lp; 540 564 sp++; … … 559 583 ////////////////////////////////////////////////////// 560 584 561 T YPEINFO RetTypeInfo;562 CallPropertyMethod(term,NULL, &RetTypeInfo);585 Type resultType; 586 CallPropertyMethod(term,NULL,resultType); 563 587 564 588 //大きな型への暗黙の変換 565 type[sp]=AutoBigCast(BaseType,RetTypeInfo.type); 566 567 index_stack[sp]=RetTypeInfo.u.lpIndex; 589 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType()); 590 index_stack[sp]=resultType.GetIndex(); 568 591 bLiteralCalculation=0; 569 592 570 SetUseRegFromRax(RetTypeInfo.type,UseReg,XmmReg); 571 572 if(IsRealNumberType(type[sp])) bXmm=1; 593 if( type_stack[sp] != resultType.GetBasicType() ){ 594 // 大きな型へ変換された場合 595 // ※レジスタの値をキャストする 596 ExtendRegToBigType( REG_RAX, type_stack[sp], resultType.GetBasicType() ); 597 } 598 599 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg); 600 601 if(IsRealNumberType(type_stack[sp])) bXmm=1; 573 602 else bXmm=0; 574 603 … … 578 607 }//////////////////////////////////////////// 579 608 580 if(type [sp]==DEF_STRUCT){609 if(type_stack[sp]==DEF_STRUCT){ 581 610 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 582 611 //※後にfreeする必要あり … … 595 624 bError=1; 596 625 SetError(3,term,cp); 597 type [sp]=DEF_DOUBLE;626 type_stack[sp]=DEF_DOUBLE; 598 627 } 599 628 else{ 600 629 //リテラル値 601 type [sp]=GetLiteralValue(term,&i64data,BaseType);630 type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType()); 602 631 Literal: 603 if(type [sp]==DEF_DOUBLE){632 if(type_stack[sp]==DEF_DOUBLE){ 604 633 //64ビット浮動小数型 605 634 bXmm=1; … … 627 656 } 628 657 } 629 else if(type [sp]==DEF_SINGLE){658 else if(type_stack[sp]==DEF_SINGLE){ 630 659 //32ビット浮動小数型 631 660 bXmm=1; … … 680 709 case CALC_OR: 681 710 case CALC_AND: 682 if(!CalcTwoTerm_Logical(idCalc,type ,index_stack,&sp)) goto error;711 if(!CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp)) goto error; 683 712 break; 684 713 case CALC_NOT: 685 714 //value[sp-1]=Not value[sp-1] 686 715 //NOT演算子 687 if(!Calc_Not(type ,sp)) goto error;716 if(!Calc_Not(type_stack,sp)) goto error; 688 717 break; 689 718 … … 695 724 case CALC_NOTEQUAL: //value[sp-2] <> value[sp-1] 696 725 case CALC_EQUAL: //value[sp-2] = value[sp-1] 697 if(!CalcTwoTerm_Relational(idCalc,type ,index_stack,&sp)) goto error;726 if(!CalcTwoTerm_Relational(idCalc,type_stack,index_stack,&sp)) goto error; 698 727 break; 699 728 … … 701 730 case CALC_SHL: //value[sp-2] << value[sp-1] 702 731 case CALC_SHR: //value[sp-2] >> value[sp-1] 703 if(!Calc_Shift(idCalc,type ,&sp)) goto error;732 if(!Calc_Shift(idCalc,type_stack,&sp)) goto error; 704 733 break; 705 734 … … 708 737 case CALC_SUBTRACTION: 709 738 case CALC_PRODUCT: 710 if(!CalcTwoTerm_Arithmetic(idCalc,type ,index_stack,&sp)) goto error;739 if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error; 711 740 break; 712 741 case CALC_MOD: 713 742 //value[sp-2]%=value[sp-1] 714 743 //剰余演算 715 if(!Calc_Mod(type ,index_stack,&sp)) goto error;744 if(!Calc_Mod(type_stack,index_stack,&sp)) goto error; 716 745 break; 717 746 case CALC_QUOTIENT: 718 747 //value[sp-2]/=value[sp-1]; 719 748 //除算 720 if(!Calc_Divide(type ,&sp,BaseType)) goto error;749 if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error; 721 750 break; 722 751 case CALC_INTQUOTIENT: 723 752 //value[sp-2]/=value[sp-1] 724 753 //整数除算 725 if(!Calc_IntDivide(type ,index_stack,&sp)) goto error;754 if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error; 726 755 break; 727 756 case CALC_MINUSMARK: 728 757 //value[sp-1]=-value[sp-1] 729 758 //符号反転 730 if(!Calc_MinusMark(type ,sp)) goto error;759 if(!Calc_MinusMark(type_stack,sp)) goto error; 731 760 break; 732 761 case CALC_POWER: 733 762 //べき乗演算(浮動小数点演算のみ) 734 if(!Calc_Power(type ,&sp)) goto error;763 if(!Calc_Power(type_stack,&sp)) goto error; 735 764 break; 736 765 case CALC_AS: 737 766 //キャスト 738 if(!Calc_Cast(type ,index_stack,&sp)) goto error;767 if(!Calc_Cast(type_stack,index_stack,&sp)) goto error; 739 768 break; 740 769 case CALC_BYVAL: 741 770 //ポインタ型→参照型 742 if( PTR_LEVEL( type [sp-1] ) <= 0 ){771 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){ 743 772 //ポインタ型ではないとき 744 773 SetError( 3, NULL, cp ); … … 746 775 } 747 776 748 type [sp-1] = PTR_LEVEL_DOWN( type[sp-1] );777 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] ); 749 778 750 779 break; … … 765 794 if(bLiteralCalculation){ 766 795 //右辺値が数値の定数式の場合 767 LONG_PTR lpClassIndex;768 i2=StaticCalculation(true, Command,BaseType,&i64data,&lpClassIndex);796 Type resultType; 797 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType); 769 798 770 799 obp=BeforeObp; … … 775 804 *pobj_reg=objReg_Backup; 776 805 777 if( IsRealNumberType(i2)){778 if( IsRealNumberType(BaseType)) i2=BaseType;806 if(resultType.IsReal()){ 807 if(baseType.IsReal()) resultType=baseType; 779 808 780 809 XmmReg=pobj_reg->LockXmmReg(); 781 810 782 if( i2==DEF_DOUBLE){811 if(resultType.IsDouble()){ 783 812 i3 = dataTable.Add( i64data ); 784 813 … … 793 822 obp+=sizeof(long); 794 823 } 795 if( i2==DEF_SINGLE){824 if(resultType.IsSingle()){ 796 825 memcpy(&dbl,&i64data,sizeof(_int64)); 797 826 … … 815 844 } 816 845 else{ 817 if(! Is64Type(i2)){846 if(!resultType.Is64()){ 818 847 //整数(符号有り/無し) 819 848 820 849 i3=(long)i64data; 821 850 822 if( GetTypeSize(i2,-1)==sizeof(char)) i3=i3&0x000000FF;823 if( GetTypeSize(i2,-1)==sizeof(short)) i3=i3&0x0000FFFF;851 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF; 852 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF; 824 853 825 854 i64data=(_int64)i3; … … 832 861 } 833 862 834 type [0]=i2;835 index_stack[0]= lpClassIndex;863 type_stack[0]=resultType.GetBasicType(); 864 index_stack[0]=resultType.GetIndex(); 836 865 } 837 866 else{ … … 840 869 } 841 870 842 if(plpIndex) *plpIndex=index_stack[0];843 871 if(pbUseHeap) *pbUseHeap=bUseHeap[0]; 844 872 845 if(IsRealNumberType(type [0]))873 if(IsRealNumberType(type_stack[0])) 846 874 *pReg=pobj_reg->UnlockXmmReg(); 847 875 else … … 858 886 } 859 887 860 int RetType; 861 RetType=type[0]; 888 resultType.SetType( type_stack[0], index_stack[0] ); 889 890 bool isSuccessful = true; 862 891 goto finish; 863 892 … … 878 907 } 879 908 880 RetType=-1;909 isSuccessful = false; 881 910 goto finish; 882 911 … … 893 922 delete pobj_BackReloc; 894 923 895 return RetType;924 return isSuccessful; 896 925 } -
BasicCompiler64/NumOpe_Arithmetic.cpp
r73 r75 559 559 560 560 //call pow 561 extern SubInfo*pSub_pow;561 extern UserProc *pSub_pow; 562 562 op_call(pSub_pow); 563 563 -
BasicCompiler64/Opcode.h
r73 r75 251 251 252 252 //NumOpe.cpp 253 int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0); 253 bool NumOpe( int *pReg, 254 const char *Command, 255 const Type &baseType, 256 Type &resultType, 257 BOOL *pbUseHeap = NULL ); 254 258 255 259 //NumOpe_Arithmetic.cpp … … 286 290 //Compile_Set_Var.cpp 287 291 BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar); 288 void SetStructVariableFromRax( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);292 void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap); 289 293 void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar); 290 294 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative); … … 307 311 308 312 //Compile_Object.cpp 309 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter,const TYPEINFO &baseTypeInfo ); 310 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ); 313 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter,const Type &baseTypeInfo ); 311 314 void OpcodeDelete(const char *Parameter, bool isSweeping); 312 315 … … 314 317 void GetWithName(char *buffer); 315 318 void SetThisPtrToReg(int reg); 316 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);317 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);319 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss = NULL); 320 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf); 318 321 #define DIMFLAG_INITDEBUGVAR 0x01 319 322 #define DIMFLAG_NONCALL_CONSTRACTOR 0x02 320 323 #define DIMFLAG_STATIC 0x04 321 324 #define DIMFLAG_CONST 0x08 322 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 323 void OpcodeDim(char *Parameter,DWORD dwFlag); 325 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 324 326 void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar); 325 327 … … 333 335 class ParamImpl{ 334 336 char *Parms[255]; 335 TYPEINFO types[255];337 vector<Type> types; 336 338 int ParmsNum; 337 339 338 T YPEINFO ReturnTypeInfo;340 Type returnType; 339 341 340 342 //一時オブジェクト管理用 … … 345 347 public: 346 348 ParamImpl(const char *buffer); 347 ParamImpl(const P ARAMETER_INFO *pParamInfo, const int ParmNum);349 ParamImpl(const Parameters ¶ms); 348 350 ~ParamImpl(); 349 void SetReturnType( TYPEINFO *pTypeInfo);351 void SetReturnType( const Type &returnType ); 350 352 351 353 private: 352 BOOL _overload_check( Parameters ¶ms, TYPEINFO *pReturnTypeInfo,int overload_level);353 SubInfo *OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo*> &subs );354 bool _overload_check( int level, const Parameters ¶ms, const Type &returnType ); 355 UserProc *OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs ); 354 356 public: 355 SubInfo *OverloadSolution( const char *name, std::vector<SubInfo *> &subs ); 356 357 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum); 358 void MacroParameterSupport(PARAMETER_INFO *ppi); 359 void SetStructParameter(int reg,CClass *pobj_Class,LPSTR Parameter); 357 UserProc *OverloadSolution( const char *name, std::vector<UserProc *> &subs ); 358 359 bool ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 360 void MacroParameterSupport( const Parameters ¶ms ); 361 void SetStructParameter( int reg, const Type &baseType, const char *expression ); 362 void SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 360 363 361 364 //一時オブジェクトパラメータの生成と破棄 362 int NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);365 int NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 363 366 void DeleteTempParameters(); 364 365 void SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);366 367 367 368 void BackupParameter(int pi_num); … … 384 385 void AddLocalVarAddrSchedule(); 385 386 #define PROCFLAG_NEW 1 386 int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);387 void Opcode_CallProc(const char *Parameter,SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType);388 int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);387 bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer); 388 bool Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType); 389 bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc); 389 390 390 391 //Compile_ProcOp.cpp … … 394 395 int GetFunctionType(int FuncNum); 395 396 int GetFunctionFromName(char *FuncName); 396 void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo);397 bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo, bool isCallOn = true ); 397 398 398 399 //OperatorProc.cpp 399 void FreeTempObject(int reg, CClass *pobj_c);400 int CallOperatorProc(int idCalc, TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);401 void CallCastOperatorProc(int reg, int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);402 void CallIndexerGetterProc(int reg, CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);400 void FreeTempObject(int reg,const CClass *pobj_c); 401 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp); 402 void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType); 403 void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType); 403 404 404 405 //Compile_Statement.cpp … … 411 412 void OpcodeContinue(void); 412 413 void OpcodeExitSub(void); 413 void OpcodeSelect( char *Parameter);414 void OpcodeSelect( const char *Parameter ); 414 415 void OpcodeCase(char *Parameter); 415 416 void OpcodeGosub(char *Parameter); … … 512 513 void op_fld_ptr_esp(int type); 513 514 void op_zero_reg(int reg); 514 void op_call( SubInfo *psi);515 void op_call( D ECLAREINFO *pdi);515 void op_call( UserProc *pUserProc ); 516 void op_call( DllProc *pDllProc ); -
BasicCompiler64/OperatorProc.cpp
r73 r75 2 2 #include "Opcode.h" 3 3 4 void FreeTempObject(int reg, CClass *pobj_c){4 void FreeTempObject(int reg,const CClass *pobj_c){ 5 5 if(!IsSafeReg(reg)) SetError(300,NULL,cp); 6 6 … … 16 16 17 17 //call DestructorProcAddr 18 op_call( method->p si);18 op_call( method->pUserProc ); 19 19 } 20 20 … … 23 23 24 24 //call free 25 extern SubInfo*pSub_free;25 extern UserProc *pSub_free; 26 26 op_call(pSub_free); 27 27 } 28 28 29 int CallOperatorProc(int idCalc, TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){29 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){ 30 30 //オーバーロードされたオペレータ関数を呼び出す 31 31 CClass *pobj_c; 32 32 pobj_c=(CClass *)index_stack[sp-2]; 33 33 34 std::vector< SubInfo*> subs;34 std::vector<UserProc *> subs; 35 35 pobj_c->EnumMethod( idCalc, subs ); 36 36 if( subs.size() == 0 ){ … … 45 45 46 46 int i; 47 BOOL bReturnTypeIsObject=1;48 TYPEINFO ReturnType={DEF_OBJECT,subs[0]->u.ReturnIndex};49 for(i=0;i<subs.size();i++){50 if(subs[i]->ReturnType!=DEF_OBJECT)51 bReturnTypeIsObject=0;52 }53 54 if(bReturnTypeIsObject==0){55 if(pBaseTypeInfo){56 if(pBaseTypeInfo->type==DEF_OBJECT){57 ReturnType.u.lpIndex=pBaseTypeInfo->u.lpIndex;58 }59 }60 }61 62 47 63 48 … … 66 51 ///////////////////////////////////////////// 67 52 68 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 69 int iParmNum=0; 70 71 if(bTwoTerm){ 72 ppi[iParmNum].bArray=0; 73 ppi[iParmNum].bByVal=0; 74 ppi[iParmNum].name=0; 75 ppi[iParmNum].type=type[sp-1]; 76 ppi[iParmNum].u.index=index_stack[sp-1]; 77 ppi[iParmNum].SubScripts[0]=-1; 78 iParmNum++; 79 } 80 53 Parameters params; 54 55 if(bTwoTerm){ 56 params.push_back( new Parameter( "", Type( type_stack[sp-1], index_stack[sp-1] ) ) ); 57 } 81 58 82 59 //オーバーロードを解決 … … 84 61 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"=="); 85 62 else GetCalcName(idCalc,temporary); 86 SubInfo *psi;87 psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo); 88 89 90 if(!psi){91 HeapDefaultFree(ppi);63 UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType ); 64 65 if(!pUserProc){ 66 if(bTwoTerm){ 67 delete params[0]; 68 } 92 69 return -1; 93 70 } 94 71 else{ 95 72 //オーバーロードされていないが、パラメータ個数が一致しないとき 96 if(iParmNum!=psi->params.size()){ 97 HeapDefaultFree(ppi); 73 if(params.size()!=pUserProc->Params().size()){ 74 if(bTwoTerm){ 75 delete params[0]; 76 } 98 77 return -1; 99 78 } 100 79 } 101 80 102 for(i=0;i< iParmNum;i++){81 for(i=0;i<(int)params.size();i++){ 103 82 CheckDifferentType( 104 p si->params[i]->GetBasicType(),105 p si->params[i]->GetIndex(),106 p pi[i].type,107 p pi[i].u.index,83 pUserProc->Params()[i]->GetBasicType(), 84 pUserProc->Params()[i]->GetIndex(), 85 params[i]->GetBasicType(), 86 params[i]->GetIndex(), 108 87 "", 109 88 i); 110 89 } 111 90 112 HeapDefaultFree(ppi); 113 114 if(bTwoTerm){ 115 if( psi->realParams[1]->IsStruct() && psi->realParams[1]->IsRef() == false ){ 91 if(bTwoTerm){ 92 delete params[0]; 93 } 94 95 int right_side_size = GetTypeSize(type_stack[sp-1],index_stack[sp-1]); 96 97 if(bTwoTerm){ 98 if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){ 116 99 //一時オブジェクトはメソッド内で破棄される 117 100 bUseHeap[sp-1]=0; … … 119 102 } 120 103 121 if(psi->ReturnType==DEF_STRUCT){ 104 105 if( pUserProc->ReturnType().IsStruct() ){ 122 106 ////////////////////////////////////////////////////// 123 107 // 戻り値に構造体インスタンスを持つ場合 … … 131 115 ////////////////////////////////////////////////////// 132 116 133 int object_size = p si->u.Return_pobj_c->GetSize();117 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 134 118 135 119 //mov rcx,object_size … … 137 121 138 122 //call calloc 139 extern SubInfo*pSub_calloc;123 extern UserProc *pSub_calloc; 140 124 op_call(pSub_calloc); 141 125 … … 152 136 if(bTwoTerm){ 153 137 //右の項(実数の場合が未完成) 154 SetOneTermToReg_Whole64Calc(type [sp-1],®2);138 SetOneTermToReg_Whole64Calc(type_stack[sp-1],®2); 155 139 pobj_reg->UnlockReg(); 156 if( !p si->realParams[1]->IsRef() == false ){140 if( !pUserProc->RealParams()[1]->IsRef() == false ){ 157 141 //一時参照を作成 158 142 pobj_sf->push( reg2 ); … … 190 174 191 175 if(bTwoTerm){ 192 if( psi->ReturnType==DEF_STRUCT){176 if( pUserProc->ReturnType().IsStruct() ){ 193 177 //mov r8,reg2 194 178 op_mov_RR(REG_R8,reg2); … … 200 184 } 201 185 202 if( psi->ReturnType==DEF_STRUCT){186 if( pUserProc->ReturnType().IsStruct() ){ 203 187 //mov rdx,r13 204 188 op_mov_RR(REG_RDX,REG_R13); … … 209 193 210 194 //call operator_proc 211 op_call(p si);212 213 if( psi->ReturnType!=DEF_NON){195 op_call(pUserProc); 196 197 if( !pUserProc->ReturnType().IsNull() ){ 214 198 //戻り値を一時的に退避 215 199 … … 253 237 254 238 if(bTwoTerm){ 255 if( !p si->realParams[1]->IsRef() == false ){239 if( !pUserProc->RealParams()[1]->IsRef() == false ){ 256 240 //一時参照を破棄 257 241 pobj_sf->pop(); … … 259 243 } 260 244 261 if( psi->ReturnType!=DEF_NON){245 if( !pUserProc->ReturnType().IsNull() ){ 262 246 //戻り値をreg1にセット 263 247 reg1=pobj_reg->LockReg(); … … 268 252 269 253 sp--; 270 type [sp-1]=psi->ReturnType;271 index_stack[sp-1]=p si->u.ReturnIndex;272 273 if( psi->ReturnType==DEF_STRUCT){254 type_stack[sp-1]=pUserProc->ReturnType().GetBasicType(); 255 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 256 257 if( pUserProc->ReturnType().IsStruct() ){ 274 258 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 275 259 //※後にfreeする必要あり … … 281 265 } 282 266 283 void CallCastOperatorProc(int reg, int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex){284 int type [10];267 void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType){ 268 int type_stack[10]; 285 269 LONG_PTR index_stack[10]; 286 270 BOOL array_bUseHeap[10]; … … 304 288 305 289 //左辺 306 type [0]=CalcType;307 index_stack[0]= lpCalcIndex;290 type_stack[0]=calcType.GetBasicType(); 291 index_stack[0]=calcType.GetIndex(); 308 292 array_bUseHeap[0]=0; 309 type [1]=ToType;310 index_stack[1]= lpToIndex;293 type_stack[1]=toType.GetBasicType(); 294 index_stack[1]=toType.GetIndex(); 311 295 array_bUseHeap[1]=0; 312 296 313 TYPEINFO BaseTypeInfo={ToType,lpToIndex}; 314 315 iRet=CallOperatorProc(CALC_AS,&BaseTypeInfo,type,index_stack,array_bUseHeap,sp); 297 iRet=CallOperatorProc(CALC_AS,toType,type_stack,index_stack,array_bUseHeap,sp); 316 298 317 299 pobj_reg->UnlockReg(); … … 325 307 if(iRet==1){ 326 308 //成功したとき 327 CalcType=type[0]; 328 lpCalcIndex=index_stack[0]; 309 calcType.SetType( type_stack[0], index_stack[0] ); 329 310 return; 330 311 } … … 339 320 340 321 //インデクサ(getter)を呼び出す 341 void CallIndexerGetterProc(int reg, CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo){342 343 std::vector< SubInfo*> subs;322 void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType ){ 323 324 std::vector<UserProc *> subs; 344 325 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs ); 345 326 if( subs.size() == 0 ){ … … 353 334 354 335 Opcode_CallProc(Parameter,subs[0],0,ObjectName,DEF_OBJECT); 355 RetTypeInfo.type = subs[0]->ReturnType; 356 RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex; 336 resultType = subs[0]->ReturnType(); 357 337 358 338 //mov reg,rax -
BasicCompiler64/WatchList.cpp
r73 r75 5 5 #include "../BasicCompiler_Common/debug.h" 6 6 7 int Debugging_GetArray( int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset);7 int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset); 8 8 9 9 ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar){ … … 61 61 } 62 62 63 BOOL Debugging_SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){63 bool Debugging_SetRelativeOffset( Type &type,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){ 64 64 int array_num; 65 65 66 66 _int64 i64data; 67 i nt type;68 type=StaticCalculation(true, lpPtrOffset,0,&i64data,0,1);69 if(!type) return 0;70 if( IsRealNumberType(type)){67 if( !StaticCalculation( true, lpPtrOffset, 0, &i64data, Type(), 1 ) ){ 68 return false; 69 } 70 if( type.IsReal() ){ 71 71 double dbl; 72 72 memcpy(&dbl,&i64data,sizeof(double)); … … 76 76 array_num=(int)i64data; 77 77 78 if( PTR_LEVEL(*pType)){79 *pType=MAKE_PTR_TYPE(NATURAL_TYPE(*pType),PTR_LEVEL(*pType)-1);80 array_num *= GetTypeSize(*pType,-1);78 if( type.PtrLevel() ){ 79 type.PtrLevelDown(); 80 array_num *= type.GetSize(); 81 81 } 82 82 else{ 83 83 //エラー 84 return 0;84 return false; 85 85 } 86 86 … … 89 89 SIZE_T stAccBytes; 90 90 lpData=Debugging_GetVarPtr(pRelativeVar); 91 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)) return 0; 91 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)){ 92 return false; 93 } 92 94 pRelativeVar->dwKind=VAR_DIRECTMEM; 93 95 94 96 pRelativeVar->offset+=array_num; 95 return 1;97 return true; 96 98 } 97 99 98 BOOL Debugging_GetMember(CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){100 int Debugging_GetMember( const CClass &objClass,char *member,RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 99 101 int i,i2; 100 102 … … 117 119 //////////////////////////// 118 120 119 int offset = pobj_c->GetMemberOffset( VarName, &i );120 if(i== pobj_c->iMemberNum) return 0;121 int offset = objClass.GetMemberOffset( VarName, &i ); 122 if(i==objClass.iMemberNum) return 0; 121 123 122 124 123 125 //アクセシビリティをチェック 124 if((bPrivateAccess==0&& pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||125 pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){126 if((bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)|| 127 objClass.ppobj_Member[i]->dwAccess==ACCESS_NON){ 126 128 return 0; 127 129 } 128 else if(bPrivateAccess==0&& pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED)130 else if(bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PROTECTED) 129 131 return 0; 130 132 131 *pType=pobj_c->ppobj_Member[i]->TypeInfo.type; 132 *plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex; 133 resultType = *objClass.ppobj_Member[i]; 133 134 134 135 //ポインタ変数の場合 135 if( IsPtrType(*pType)){136 if( pobj_c->ppobj_Member[i]->SubScripts[0]==-1){136 if( resultType.IsPointer() ){ 137 if(objClass.ppobj_Member[i]->SubScripts[0]==-1){ 137 138 lstrcpy(lpPtrOffset,array); 138 139 array[0]=0; … … 148 149 //配列オフセット 149 150 i2=Debugging_GetArray( 150 pobj_c->ppobj_Member[i]->SubScripts,151 objClass.ppobj_Member[i]->SubScripts, 151 152 array, 152 *pType, 153 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex, 153 resultType, 154 154 &pRelativeVar->offset); 155 155 if(i2==0){ … … 162 162 } 163 163 } 164 else if( pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){165 *pType|=FLAG_PTR;164 else if(objClass.ppobj_Member[i]->SubScripts[0]!=-1){ 165 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 166 166 } 167 167 … … 169 169 //入れ子構造の場合 170 170 171 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){171 if( resultType.IsObject() || resultType.IsStruct() ){ 172 172 if( refType != CClass::Dot ) return 0; 173 173 174 if( *pType==DEF_OBJECT){174 if( resultType.IsObject() ){ 175 175 extern HANDLE hDebugProcess; 176 176 LONG_PTR lpData; … … 181 181 } 182 182 } 183 else if( *pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){183 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 184 184 //構造体ポインタ型メンバ変数 185 185 … … 188 188 189 189 //直接参照に切り替え 190 Debugging_SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);190 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 191 191 192 192 lpPtrOffset[0]=0; … … 204 204 } 205 205 206 i2=Debugging_GetMember( pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,206 i2=Debugging_GetMember(objClass.ppobj_Member[i]->GetClass(), 207 207 NestMember, 208 pType,209 208 pRelativeVar, 210 plpNestIndex,209 resultType, 211 210 0); 212 211 if(i2==0){ … … 221 220 222 221 if(lpPtrOffset[0]){ 223 Debugging_SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);222 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 224 223 } 225 224 226 225 return 1; 227 226 } 228 int Debugging_GetArray( int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset){227 int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset){ 229 228 extern HANDLE hHeap; 230 int i,i2,i3,i4,i5,array_offset ,TypeSize;229 int i,i2,i3,i4,i5,array_offset; 231 230 char temporary[VN_SIZE],*pParm[MAX_PARMS]; 232 231 … … 275 274 for(i=i3-1;i>=0;i--){ 276 275 _int64 i64data; 277 i2=StaticCalculation(true, pParm[i],0,&i64data,0,1); 278 if(i2==0){ 276 Type resultType; 277 bool isMemoryAccessError; 278 if( !StaticCalculation(true, pParm[i],0,&i64data,resultType,1, &isMemoryAccessError ) ){ 279 279 //式エラー 280 280 return 0; 281 281 } 282 if(i 2==-1){282 if(isMemoryAccessError){ 283 283 //アクセスエラー 284 284 return -1; 285 285 } 286 286 287 if( IsRealNumberType(i2)){287 if(resultType.IsReal()){ 288 288 double dbl; 289 289 memcpy(&dbl,&i64data,sizeof(double)); … … 299 299 } 300 300 301 TypeSize=GetTypeSize(type,lpIndex); 302 303 array_offset*=TypeSize; 301 array_offset *= type.GetSize(); 304 302 305 303 *plpOffset+=array_offset; … … 308 306 } 309 307 ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip){ 310 int i; 311 SubInfo *psi; 312 313 //ripからプロシージャを取得 314 psi=GetSubFromObp(obp_Rip); 315 316 for(i=0;i<psi->VarNum;i++){ 317 if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break; 318 } 319 if(i==psi->VarNum) return 0; 320 321 return psi->pVar[i].offset; 308 UserProc *pUserProc = GetSubFromObp(obp_Rip); 309 310 foreach( Variable *pVar, pUserProc->localVars ){ 311 if( pVar->GetName() == "_System_LocalThis" ){ 312 return pVar->offset; 313 } 314 } 315 return 0; 322 316 } 323 int Debugging_GetVarOffset( char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){317 int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss){ 324 318 extern HANDLE hDebugProcess; 325 319 int i,i2,i3; … … 332 326 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 333 327 334 LONG_PTR lpIndex; 335 int *pSubScripts; 336 BOOL bArray; 328 const int *pSubScripts; 329 bool isArray; 337 330 338 331 … … 340 333 // ローカル変数 341 334 ///////////////// 342 extern VARIABLE *LocalVar; 343 extern int MaxLocalVarNum; 344 for(i=0;i<MaxLocalVarNum;i++){ 345 if(lstrcmp(VarName,LocalVar[i].name)==0) break; 346 } 347 if(i!=MaxLocalVarNum){ 335 const Variable *pVar = UserProc::CompilingUserProc().localVars.Find( VarName ); 336 if( pVar ){ 348 337 //ポインタ変数の場合 349 if( IsPtrType(LocalVar[i].type)){350 if( !LocalVar[i].bArray){338 if( pVar->IsPointer() ){ 339 if( !pVar->IsArray() ){ 351 340 lstrcpy(lpPtrOffset,array); 352 341 array[0]=0; … … 357 346 } 358 347 359 pRelativeVar->offset=LocalVar[i].offset; 360 if(LocalVar[i].fRef) pRelativeVar->dwKind=VAR_REFLOCAL; 361 else pRelativeVar->dwKind=VAR_LOCAL; 362 *pType=LocalVar[i].type; 363 lpIndex=LocalVar[i].u.index; 364 *plpIndex=lpIndex; 365 bArray=LocalVar[i].bArray; 366 pSubScripts=LocalVar[i].SubScripts; 348 pRelativeVar->offset = pVar->offset; 349 if( pVar->IsRef() ){ 350 pRelativeVar->dwKind=VAR_REFLOCAL; 351 } 352 else{ 353 pRelativeVar->dwKind=VAR_LOCAL; 354 } 355 resultType = *pVar; 356 isArray = pVar->IsArray(); 357 pSubScripts = pVar->GetSubScriptsPtr(); 367 358 } 368 359 else{ … … 406 397 pRelativeVar->dwKind=VAR_DIRECTMEM; 407 398 408 LONG_PTR lp2; 409 i3=Debugging_GetMember(pobj_CompilingClass,variable,pType,pRelativeVar,&lp2,1); 399 i3=Debugging_GetMember(*pobj_CompilingClass,variable,pRelativeVar,resultType,1); 410 400 if(i3==0){ 411 401 //式エラー … … 417 407 } 418 408 419 *plpIndex=lp2;420 409 return 1; 421 410 } … … 426 415 // グローバル変数 427 416 /////////////////// 428 extern VARIABLE *GlobalVar; 429 extern int MaxGlobalVarNum; 430 431 for(i=0;i<MaxGlobalVarNum;i++){ 432 if(lstrcmp(VarName,GlobalVar[i].name)==0) break; 433 } 434 if(i==MaxGlobalVarNum){ 417 418 const Variable *pVar = globalVars.Find( VarName ); 419 if( !pVar ){ 435 420 //一致しないとき 436 421 return 0; … … 438 423 439 424 //ポインタ変数の場合 440 if( IsPtrType(GlobalVar[i].type)){441 if( !GlobalVar[i].bArray){425 if( pVar->IsPointer() ){ 426 if( !pVar->IsArray() ){ 442 427 lstrcpy(lpPtrOffset,array); 443 428 array[0]=0; … … 448 433 } 449 434 450 pRelativeVar->offset= GlobalVar[i].offset;451 if( GlobalVar[i].fRef) pRelativeVar->dwKind=VAR_REFGLOBAL;435 pRelativeVar->offset=pVar->offset; 436 if(pVar->IsRef()) pRelativeVar->dwKind=VAR_REFGLOBAL; 452 437 else pRelativeVar->dwKind=VAR_GLOBAL; 453 *pType=GlobalVar[i].type; 454 lpIndex=GlobalVar[i].u.index; 455 *plpIndex=lpIndex; 456 bArray=GlobalVar[i].bArray; 457 pSubScripts=GlobalVar[i].SubScripts; 458 } 459 460 461 if(array[0]==0&&bArray){ 438 resultType = *pVar; 439 isArray = pVar->IsArray(); 440 pSubScripts=pVar->GetSubScriptsPtr(); 441 } 442 443 444 if(array[0]==0&&isArray){ 462 445 //配列の先頭ポインタを示す場合 463 *pType|=FLAG_PTR;464 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM );446 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 447 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM*sizeof(int)); 465 448 return 1; 466 449 } 467 450 468 451 if(array[0]){ 469 i3=Debugging_GetArray(pSubScripts,array, *pType,lpIndex,&pRelativeVar->offset);452 i3=Debugging_GetArray(pSubScripts,array,resultType,&pRelativeVar->offset); 470 453 if(i3==0){ 471 454 //式エラー … … 478 461 } 479 462 if(member[0]){ 480 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){463 if( resultType.IsObject() || resultType.IsStruct() ){ 481 464 //実態オブジェクトのメンバを参照(obj.member) 482 465 if( refType != CClass::Dot ){ … … 484 467 } 485 468 486 LONG_PTR lp2; 487 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 469 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 488 470 if(i3==0){ 489 471 //式エラー … … 494 476 return -1; 495 477 } 496 497 *plpIndex=lp2; 498 } 499 else if(*pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){ 478 } 479 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 500 480 //ポインタオブジェクトが示すメンバを参照 501 481 if(lpPtrOffset[0]){ 502 482 //pObj[n].member 503 483 if( refType != CClass::Dot ) return 0; 504 Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset); 505 506 LONG_PTR lp2; 507 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 484 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 485 486 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 508 487 if(i3==0){ 509 488 //式エラー … … 514 493 return -1; 515 494 } 516 517 *plpIndex=lp2;518 495 } 519 496 else{ … … 527 504 pRelativeVar->offset=lpData; 528 505 529 LONG_PTR lp2; 530 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 506 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 531 507 if(i3==0){ 532 508 //式エラー … … 537 513 return -1; 538 514 } 539 540 *plpIndex=lp2;541 515 } 542 516 } … … 548 522 549 523 if(lpPtrOffset[0]){ 550 if(!Debugging_SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset)) return 0;524 if(!Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset)) return 0; 551 525 } 552 526 -
BasicCompiler64/amd64_main.cpp
r73 r75 1791 1791 ///////////////////////////// 1792 1792 1793 void op_call( SubInfo *psi){1793 void op_call( UserProc *pUserProc ){ 1794 1794 OpBuffer[obp++] = (char)0xE8; 1795 pobj_SubAddrSchedule->add( p si, 1 );1796 p si->bUse = 1;1795 pobj_SubAddrSchedule->add( pUserProc, 1 ); 1796 pUserProc->Using(); 1797 1797 obp += sizeof(long); 1798 1798 } 1799 void op_call( D ECLAREINFO *pdi){1799 void op_call( DllProc *pDllProc ){ 1800 1800 OpBuffer[obp++] = (char)0xFF; 1801 1801 OpBuffer[obp++] = (char)0x15; 1802 pobj_ImportAddrSchedule->add(p di);1802 pobj_ImportAddrSchedule->add(pDllProc); 1803 1803 obp += sizeof(long); 1804 1804 1805 p di->bUse=1;1806 } 1805 pDllProc->Using(); 1806 } -
BasicCompiler64/increment.cpp
r11 r75 3 3 4 4 void IncDec(int idCalc, char *lpszLeft, char *lpszRight){ 5 int VarType;6 LONG_PTR lpVarIndex;7 RELATIVE_VAR VarRelativeVar;8 9 5 10 6 /////////////////////////// … … 12 8 /////////////////////////// 13 9 10 RELATIVE_VAR VarRelativeVar; 11 Type varType; 14 12 if(!GetVarOffsetReadWrite( 15 13 lpszLeft, 16 &VarType,17 14 &VarRelativeVar, 18 &lpVarIndex)) return;15 varType)) return; 19 16 20 17 //変数オフセットを一時退避 … … 30 27 31 28 int reg; 32 if( VarType==DEF_DOUBLE){29 if( varType.IsDouble() ){ 33 30 reg=REG_XMM0; 34 31 SetXmmReg_DoubleVariable(&VarRelativeVar,reg); 35 32 } 36 else if( VarType==DEF_SINGLE){33 else if( varType.IsSingle() ){ 37 34 reg=REG_XMM0; 38 35 SetXmmReg_SingleVariable(&VarRelativeVar,reg); … … 40 37 else{ 41 38 reg=REG_RAX; 42 SetReg_WholeVariable( VarType,&VarRelativeVar,reg);39 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,reg); 43 40 } 44 41 45 42 46 if( IsWholeNumberType(VarType)&&lstrcmp(lpszRight,"1")==0&&43 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&& 47 44 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){ 48 45 if(idCalc==CALC_ADDITION){ … … 60 57 61 58 //右辺を計算 62 int CalcType; 63 LONG_PTR lpCalcIndex; 59 Type calcType; 64 60 if(reg==REG_RAX) reg=REG_RCX; 65 61 else reg=REG_RAX; 66 CalcType=NumOpe(®,lpszRight,VarType,lpVarIndex,&lpCalcIndex);62 NumOpe(®,lpszRight,varType,calcType); 67 63 68 64 //レジスタのブロッキングを解除 … … 70 66 71 67 72 if( IsPtrType(VarType)&&IsWholeNumberType(CalcType)&&(!IsPtrType(CalcType))){68 if(varType.IsPointer()&&calcType.IsWhole()&&(!calcType.IsPointer())){ 73 69 //左辺がポインタ型、右辺が整数型の場合は、エラーをださないようにする 74 CalcType=VarType; 75 lpCalcIndex=lpVarIndex; 70 calcType = varType; 76 71 } 77 72 … … 81 76 ///////////////////////////////// 82 77 83 CheckDifferentType( VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);78 CheckDifferentType(varType,calcType,0,0); 84 79 85 80 … … 88 83 89 84 //左辺用レジスタ 90 if( IsRealNumberType(VarType))85 if(varType.IsReal()) 91 86 pobj_reg->LockXmmReg(); 92 87 else … … 94 89 95 90 //右辺値レジスタ 96 if( VarType==DEF_DOUBLE)97 ChangeTypeToXmm_Double( CalcType,91 if(varType.IsDouble()) 92 ChangeTypeToXmm_Double(calcType.GetBasicType(), 98 93 pobj_reg->LockXmmReg(), 99 94 pobj_reg->GetNextReg()); 100 else if( VarType==DEF_SINGLE)101 ChangeTypeToXmm_Single( CalcType,95 else if(varType.IsSingle()) 96 ChangeTypeToXmm_Single(calcType.GetBasicType(), 102 97 pobj_reg->LockXmmReg(), 103 98 pobj_reg->GetNextReg()); 104 99 else 105 ChangeTypeToWhole( CalcType,VarType,100 ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType(), 106 101 pobj_reg->LockReg(), 107 102 pobj_reg->GetNextXmmReg()); 108 103 109 int type [255],sp;104 int type_stack[255],sp; 110 105 LONG_PTR index_stack[255]; 111 type [0]=VarType;112 type [1]=VarType;113 index_stack[0]= lpVarIndex;114 index_stack[1]= lpVarIndex;106 type_stack[0]=varType.GetBasicType(); 107 type_stack[1]=varType.GetBasicType(); 108 index_stack[0]=varType.GetIndex(); 109 index_stack[1]=varType.GetIndex(); 115 110 sp=2; 116 111 … … 119 114 case CALC_OR: 120 115 case CALC_AND: 121 CalcTwoTerm_Logical(idCalc,type ,index_stack,&sp);116 CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp); 122 117 break; 123 118 case CALC_SHL: 124 119 case CALC_SHR: 125 Calc_Shift(idCalc,type ,&sp);120 Calc_Shift(idCalc,type_stack,&sp); 126 121 break; 127 122 case CALC_ADDITION: 128 123 case CALC_SUBTRACTION: 129 124 case CALC_PRODUCT: 130 CalcTwoTerm_Arithmetic(idCalc,type ,index_stack,&sp);125 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp); 131 126 break; 132 127 case CALC_MOD: 133 Calc_Mod(type ,index_stack,&sp);128 Calc_Mod(type_stack,index_stack,&sp); 134 129 break; 135 130 case CALC_QUOTIENT: 136 Calc_Divide(type ,&sp,VarType);131 Calc_Divide(type_stack,&sp,varType.GetBasicType()); 137 132 break; 138 133 case CALC_INTQUOTIENT: 139 Calc_IntDivide(type ,index_stack,&sp);134 Calc_IntDivide(type_stack,index_stack,&sp); 140 135 break; 141 136 case CALC_POWER: 142 Calc_Power(type ,&sp);137 Calc_Power(type_stack,&sp); 143 138 break; 144 139 } … … 160 155 } 161 156 162 SetVariableFromRax( VarType,VarType,&VarRelativeVar);157 SetVariableFromRax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar); 163 158 } -
BasicCompiler64/varlist.cpp
r73 r75 7 7 HWND hVarTree_Global,hVarTree_Local,hVarTree_This; 8 8 9 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset, int type,int *SubScripts,LONG_PTR lpIndex);10 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset, CClass *pobj_c,BOOL bPtr);11 void VarList_Insert(HWND hVarTree,TV_INSERTSTRUCT *lptv,c har *VarName,int type,LONG_PTR offset,LONG_PTR lpIndex){9 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,const Type &type,const int *SubScripts); 10 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset,const CClass &objClass,BOOL bPtr); 11 void VarList_Insert(HWND hVarTree,TV_INSERTSTRUCT *lptv,const char *VarName,const Type &type,LONG_PTR offset){ 12 12 extern HANDLE hDebugProcess; 13 13 int i2; … … 22 22 _int64 i64data; 23 23 24 if( type==DEF_OBJECT||type==DEF_STRUCT){25 if( type ==DEF_OBJECT){24 if( type.IsObject() || type.IsStruct() ){ 25 if( type.IsObject() ){ 26 26 // 参照型ということを考慮する 27 27 ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes); … … 34 34 hParent=TreeView_InsertItem(hVarTree,lptv); 35 35 36 VarList_Member(hVarTree,hParent,offset, (CClass *)lpIndex,0);36 VarList_Member(hVarTree,hParent,offset,type.GetClass(),0); 37 37 return; 38 38 } 39 if(type==DEF_PTR_OBJECT||type==DEF_PTR_STRUCT){39 else if( type.IsObjectPtr() || type.IsStructPtr() ){ 40 40 i2=ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes); 41 41 … … 45 45 hParent=TreeView_InsertItem(hVarTree,lptv); 46 46 47 if(i2) VarList_Member(hVarTree,hParent,pData, (CClass *)lpIndex,1);47 if(i2) VarList_Member(hVarTree,hParent,pData,type.GetClass(),1); 48 48 return; 49 49 } 50 50 else{ 51 if(type ==MAKE_PTR_TYPE(DEF_SBYTE,1)||type==MAKE_PTR_TYPE(DEF_BYTE,1)){51 if(type.GetBasicType()==MAKE_PTR_TYPE(DEF_SBYTE,1)||type.GetBasicType()==MAKE_PTR_TYPE(DEF_BYTE,1)){ 52 52 if(ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes)){ 53 53 for(i2=0;;i2++){ … … 67 67 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 68 68 } 69 else if(type ==DEF_DOUBLE){69 else if(type.IsDouble()){ 70 70 if(ReadProcessMemory(hDebugProcess,(void *)offset,&dbl,sizeof(double),&stAccBytes)){ 71 71 sprintf(lptv->item.pszText,"%s %.15g",VarName,dbl); … … 73 73 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 74 74 } 75 else if(type ==DEF_SINGLE){75 else if(type.IsSingle()){ 76 76 if(ReadProcessMemory(hDebugProcess,(void *)offset,&flt,sizeof(float),&stAccBytes)){ 77 77 sprintf(lptv->item.pszText,"%s %.6g",VarName,flt); … … 79 79 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 80 80 } 81 else if(type ==DEF_INT64){81 else if(type.IsInt64()){ 82 82 _int64 i64data; 83 83 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ … … 89 89 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 90 90 } 91 else if(type ==DEF_QWORD||IsPtrType(type)){91 else if(type.IsQWord()||type.IsPointer()){ 92 92 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 93 93 _ui64toa(i64data,temporary,10); … … 98 98 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 99 99 } 100 else if(type ==DEF_LONG){100 else if(type.IsLong()){ 101 101 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 102 102 sprintf(lptv->item.pszText,"%s %d(&H%X)",VarName,i64data,i64data); … … 104 104 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 105 105 } 106 else if(type ==DEF_DWORD){106 else if(type.IsDWord()){ 107 107 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 108 108 sprintf(lptv->item.pszText,"%s %u(&H%X)",VarName,i64data,i64data); … … 110 110 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 111 111 } 112 else if(type ==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){112 else if(type.IsInteger()){ 113 113 if(ReadProcessMemory(hDebugProcess,(void *)offset,&wData,sizeof(WORD),&stAccBytes)){ 114 114 sprintf(lptv->item.pszText,"%s %d(&H%X)",VarName,(short)wData,(short)wData); … … 116 116 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 117 117 } 118 else if(type ==DEF_WORD){118 else if(type.IsWord()){ 119 119 if(ReadProcessMemory(hDebugProcess,(void *)offset,&wData,sizeof(WORD),&stAccBytes)){ 120 120 sprintf(lptv->item.pszText,"%s %u(&H%X)",VarName,wData,wData); … … 122 122 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 123 123 } 124 else if(type ==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){124 else if(type.IsSByte()){ 125 125 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 126 126 temporary[0]=byteData; … … 130 130 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 131 131 } 132 else if(type ==DEF_BYTE){132 else if(type.IsByte()){ 133 133 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 134 134 temporary[0]=byteData; … … 138 138 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 139 139 } 140 else if(type ==DEF_BOOLEAN){140 else if(type.IsBoolean()){ 141 141 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 142 142 if( byteData ) lstrcpy( temporary, "True" ); … … 152 152 TreeView_InsertItem(hVarTree,lptv); 153 153 } 154 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset, CClass *pobj_c,BOOL bPtr){154 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset,const CClass &objClass,BOOL bPtr){ 155 155 int i,i2; 156 156 char VarData[VN_SIZE],VarName[VN_SIZE]; … … 163 163 tv.item.pszText=VarData; 164 164 165 for(i=0;i< pobj_c->iMemberNum;i++){165 for(i=0;i<objClass.iMemberNum;i++){ 166 166 if(bPtr){ 167 167 lstrcpy(VarName,"->"); 168 lstrcat(VarName, pobj_c->ppobj_Member[i]->name);168 lstrcat(VarName,objClass.ppobj_Member[i]->name); 169 169 } 170 170 else{ 171 171 lstrcpy(VarName,"."); 172 lstrcat(VarName, pobj_c->ppobj_Member[i]->name);172 lstrcat(VarName,objClass.ppobj_Member[i]->name); 173 173 } 174 174 175 175 LONG_PTR offset; 176 offset= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i]->name, &i2 );177 178 if( pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){176 offset=objClass.GetMemberOffset( objClass.ppobj_Member[i]->name, &i2 ); 177 178 if(objClass.ppobj_Member[i]->SubScripts[0]!=-1){ 179 179 //構造体内の配列 180 180 sprintf(VarData,"%s %s(&H%X)",VarName,STRING_ARRAY,pTopOffset+offset); … … 185 185 i2=VarList_Array(hVarTree,hParent, 186 186 pTopOffset+offset, 187 pobj_c->ppobj_Member[i]->TypeInfo.type, 188 pobj_c->ppobj_Member[i]->SubScripts, 189 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex); 187 *objClass.ppobj_Member[i], 188 objClass.ppobj_Member[i]->SubScripts); 190 189 } 191 190 else{ … … 194 193 &tv, 195 194 VarName, 196 pobj_c->ppobj_Member[i]->TypeInfo.type, 197 pTopOffset+offset, 198 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex); 199 } 200 } 201 } 202 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,int type,int *SubScripts,LONG_PTR lpIndex){ 203 int i,i2,i3,ElementNum,MemCounter,UseCount[255],TypeSize; 195 *objClass.ppobj_Member[i], 196 pTopOffset+offset); 197 } 198 } 199 } 200 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,const Type &type,const int *SubScripts ){ 201 int i,i2,i3,ElementNum,MemCounter,UseCount[255]; 204 202 char temporary[VN_SIZE],temp2[DIGIT_SIZE]; 205 203 … … 210 208 tv.hParent=hParent; 211 209 tv.item.pszText=temporary; 212 213 TypeSize=GetTypeSize(type,lpIndex);214 210 215 211 for(i=0;i<255;i++){ … … 240 236 241 237 VarList_Insert(hVarTree,&tv,temporary,type, 242 offset+MemCounter*TypeSize, 243 lpIndex); 238 offset+MemCounter*type.GetSize()); 244 239 } 245 240 … … 254 249 void RefreshGlobalVar(void){ 255 250 extern DWORD ImageBase; 256 int i;257 251 char temporary[VN_SIZE]; 258 252 TV_INSERTSTRUCT tv; … … 269 263 extern HANDLE hDebugProcess; 270 264 extern int MemPos_RWSection; 271 extern int MaxGlobalVarNum; 272 extern VARIABLE *GlobalVar; 273 274 for(i=0;i<MaxGlobalVarNum;i++){ 275 VARIABLE *pVar=&GlobalVar[i]; 265 266 foreach( Variable *pVar, globalVars ){ 276 267 277 268 //スコープ外の場合は無視 … … 289 280 290 281 if(!pobj_nv->bShow_DefaultSystem_Var){ 291 if(memcmp(pVar-> name,"_System_",8)==0||292 memcmp(pVar-> name,"_DebugSys_",10)==0||293 memcmp(pVar-> name,"_PromptSys_",11)==0) continue;282 if(memcmp(pVar->GetName().c_str(),"_System_",8)==0|| 283 memcmp(pVar->GetName().c_str(),"_DebugSys_",10)==0|| 284 memcmp(pVar->GetName().c_str(),"_PromptSys_",11)==0) continue; 294 285 } 295 286 if(!pobj_nv->bShow_Rad_Var){ 296 if(memcmp(pVar-> name,"_RadSys_",8)==0) continue;287 if(memcmp(pVar->GetName().c_str(),"_RadSys_",8)==0) continue; 297 288 } 298 289 if(!pobj_nv->bShow_GUID_Var){ 299 if(memcmp(pVar-> name,"GUID_",5)==0||300 memcmp(pVar-> name,"IID_",4)==0||301 memcmp(pVar-> name,"CLSID_",6)==0) continue;290 if(memcmp(pVar->GetName().c_str(),"GUID_",5)==0|| 291 memcmp(pVar->GetName().c_str(),"IID_",4)==0|| 292 memcmp(pVar->GetName().c_str(),"CLSID_",6)==0) continue; 302 293 } 303 294 304 295 //静的メンバ 305 if(strstr(pVar-> name,".")) continue;306 307 if(pVar-> bArray){296 if(strstr(pVar->GetName().c_str(),".")) continue; 297 298 if(pVar->IsArray()){ 308 299 sprintf(temporary,"%s %s(&H%X)", 309 pVar-> name,300 pVar->GetName().c_str(), 310 301 STRING_ARRAY, 311 302 ImageBase+MemPos_RWSection+pVar->offset); … … 316 307 VarList_Array(hVarTree_Global,hParent, 317 308 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset), 318 pVar->type, 319 pVar->SubScripts, 320 pVar->u.index); 309 *pVar, 310 pVar->GetSubScriptsPtr()); 321 311 } 322 312 else{ 323 313 VarList_Insert(hVarTree_Global, 324 314 &tv, 325 pVar->name, 326 pVar->type, 327 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset), 328 pVar->u.index); 315 pVar->GetName().c_str(), 316 *pVar, 317 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset)); 329 318 } 330 319 } … … 354 343 if(pobj_dti->lplpSpBase[i2]==0) return; 355 344 356 extern SubInfo**ppSubHash;357 SubInfo *psi;345 extern UserProc **ppSubHash; 346 UserProc *pUserProc; 358 347 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 359 p si=ppSubHash[i3];360 while(p si){361 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&362 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){348 pUserProc=ppSubHash[i3]; 349 while(pUserProc){ 350 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 351 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 363 352 sw=1; 364 353 break; 365 354 } 366 355 367 p si=psi->pNextData;356 pUserProc=pUserProc->pNextData; 368 357 } 369 358 if(sw) break; 370 359 } 371 if(!psi) return; 372 373 for(i=0;i<psi->VarNum;i++){ 374 VARIABLE *pVar=&psi->pVar[i]; 360 if(!pUserProc) return; 361 362 foreach( Variable *pVar, UserProc::CompilingUserProc().localVars ){ 375 363 376 364 //スコープ外の場合は無視 … … 386 374 } 387 375 388 if(pVar-> bArray){376 if(pVar->IsArray()){ 389 377 sprintf(temporary,"%s %s(&H%X)", 390 pVar-> name,378 pVar->GetName().c_str(), 391 379 STRING_ARRAY, 392 380 pobj_dti->lplpSpBase[i2]+pVar->offset); … … 397 385 VarList_Array(hVarTree_Local,hParent, 398 386 pobj_dti->lplpSpBase[i2]+pVar->offset, 399 pVar->type, 400 pVar->SubScripts, 401 pVar->u.index); 387 *pVar, 388 pVar->GetSubScriptsPtr()); 402 389 } 403 390 else{ 404 391 offset=pobj_dti->lplpSpBase[i2]+pVar->offset; 405 if(pVar-> fRef){392 if(pVar->IsRef()){ 406 393 ReadProcessMemory(hDebugProcess,(void *)offset,&lpData,sizeof(LONG_PTR),&stAccBytes); 407 394 offset=lpData; 408 395 } 409 396 VarList_Insert(hVarTree_Local,&tv, 410 pVar->name, 411 pVar->type, 412 offset, 413 pVar->u.index); 397 pVar->GetName().c_str(), 398 *pVar, 399 offset); 414 400 } 415 401 } … … 422 408 423 409 TreeView_DeleteAllItems(hVarTree_This); 424 if(!p si->pobj_ParentClass) return;410 if(!pUserProc->GetParentClassPtr()) return; 425 411 426 412 //Thisポインタを取得 427 413 LONG_PTR pThis; 428 for(i=0;i<psi->VarNum;i++){429 if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break;430 }431 if(i==psi->VarNum) return;432 lpData=pobj_dti->lplpSpBase[i2]+p si->pVar[i].offset;414 const Variable *pVar = UserProc::CompilingUserProc().localVars.Find( "_System_LocalThis" ); 415 if( !pVar ){ 416 return; 417 } 418 lpData=pobj_dti->lplpSpBase[i2]+pVar->offset; 433 419 ReadProcessMemory(hDebugProcess,(void *)lpData,&pThis,sizeof(LONG_PTR),&stAccBytes); 434 420 435 for(i=0;i<p si->pobj_ParentClass->iMemberNum;i++){436 offset=p si->pobj_ParentClass->GetMemberOffset( psi->pobj_ParentClass->ppobj_Member[i]->name,&i2);437 438 if(p si->pobj_ParentClass->ppobj_Member[i]->SubScripts[0]!=-1){421 for(i=0;i<pUserProc->GetParentClassPtr()->iMemberNum;i++){ 422 offset=pUserProc->GetParentClassPtr()->GetMemberOffset( pUserProc->GetParentClassPtr()->ppobj_Member[i]->name,&i2); 423 424 if(pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts[0]!=-1){ 439 425 //配列 440 426 sprintf(temporary,"%s %s(&H%X)", 441 p si->pobj_ParentClass->ppobj_Member[i]->name,427 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 442 428 STRING_ARRAY, 443 429 (DWORD64)offset); … … 448 434 VarList_Array(hVarTree_This,hParent, 449 435 pThis+offset, 450 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type, 451 psi->pobj_ParentClass->ppobj_Member[i]->SubScripts, 452 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex); 436 *pUserProc->GetParentClassPtr()->ppobj_Member[i], 437 pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts); 453 438 } 454 439 else{ 455 440 VarList_Insert(hVarTree_This,&tv, 456 psi->pobj_ParentClass->ppobj_Member[i]->name, 457 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type, 458 pThis+offset, 459 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex); 441 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 442 *pUserProc->GetParentClassPtr()->ppobj_Member[i], 443 pThis+offset); 460 444 } 461 445 } … … 489 473 490 474 void SetCalcToWatchList(HWND hListView,int iItem,char *buffer){ 491 int i;492 475 char temporary[255],temp2[255]; 493 476 … … 498 481 499 482 //カッコを相互チェック 500 if(!CheckParenthesis2(buffer)){ 501 ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 483 if(!CheckParenthesis2(buffer)){ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 502 484 return; 503 485 } … … 505 487 double dbl; 506 488 _int64 i64data; 507 i=StaticCalculation(true, buffer,0,&i64data,0,1); 508 if(IsRealNumberType(i)){ 509 memcpy(&dbl,&i64data,sizeof(double)); 510 } 511 512 if(i==0){ 489 Type resultType; 490 bool isMemoryAccessError; 491 if( !StaticCalculation(true, buffer,0,&i64data,resultType,1,&isMemoryAccessError) ){ 513 492 ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 514 493 } 515 else if(i ==-1){494 else if(isMemoryAccessError){ 516 495 ListView_SetItemText(hListView,iItem,1,"アクセスできません"); 517 496 } 518 497 else{ 519 if(IsRealNumberType(i)) 498 if(resultType.IsReal()){ 499 memcpy(&dbl,&i64data,sizeof(double)); 520 500 sprintf(temporary,"%.15g (&H%08X)",dbl,(int)dbl); 521 else if(Is64Type(i)){ 501 } 502 else if(resultType.Is64()){ 522 503 _i64toa(i64data,temporary,10); 523 504 _i64toa(i64data,temp2,16); … … 586 567 587 568 //プロシージャ コンボボックス 588 extern SubInfo**ppSubHash;589 SubInfo *psi;569 extern UserProc **ppSubHash; 570 UserProc *pUserProc; 590 571 int sw; 591 572 SendMessage(hProcCombo,CB_RESETCONTENT,0,0); 592 573 for(i2=pobj_dti->iProcLevel;i2>=0;i2--){ 593 574 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 594 p si=ppSubHash[i3];595 while(p si){596 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&597 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){598 lstrcpy(temporary,psi->name);599 sw=1;600 break;575 pUserProc=ppSubHash[i3]; 576 while(pUserProc){ 577 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 578 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 579 lstrcpy(temporary,pUserProc->GetName().c_str()); 580 sw=1; 581 break; 601 582 } 602 p si=psi->pNextData;583 pUserProc=pUserProc->pNextData; 603 584 } 604 585 if(sw) break; 605 586 } 606 if(!p si){587 if(!pUserProc){ 607 588 if(i2==0){ 608 589 lstrcpy(temporary,"Global"); … … 699 680 /////////////////////////////////////////////// 700 681 701 extern VARIABLE *LocalVar;702 extern int MaxLocalVarNum;703 682 int sw; 704 705 MaxLocalVarNum=0;706 683 707 684 i2=(int)SendDlgItemMessage(hDebugWnd,IDC_PROCCOMBO,CB_GETCURSEL,0,0); … … 709 686 710 687 if(pobj_dti->lplpSpBase[i2]){ 711 extern SubInfo**ppSubHash;712 SubInfo *psi;688 extern UserProc **ppSubHash; 689 UserProc *pUserProc; 713 690 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 714 p si=ppSubHash[i3];715 while(p si){716 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&717 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){691 pUserProc=ppSubHash[i3]; 692 while(pUserProc){ 693 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 694 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 718 695 sw=1; 719 696 break; 720 697 } 721 698 722 p si=psi->pNextData;699 pUserProc=pUserProc->pNextData; 723 700 } 724 701 if(sw) break; … … 726 703 727 704 728 if(psi){ 729 LocalVar=psi->pVar; 730 MaxLocalVarNum=psi->VarNum; 731 732 pobj_CompilingClass=psi->pobj_ParentClass; 705 if(pUserProc){ 706 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 707 UserProc::CompileStartForUserProc( pUserProc ); 733 708 } 734 709 } -
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.