Changeset 75 in dev for BasicCompiler_Common/NumOpe_GetType.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.