Changeset 290 in dev for trunk/abdev/BasicCompiler_Common/error.cpp
- Timestamp:
- Aug 21, 2007, 11:00:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/error.cpp
r287 r290 388 388 389 389 #define STRING_SYSTEM_DECLAREHANDLE "*_System_DeclareHandle_" 390 void DifferentTypeError( const int VarType,LONG_PTR VarIndex,const int CalcType,LONG_PTR CalcIndex,const int iWarning,const char *pszFuncName,const int ParmNum){390 void DifferentTypeError( const Type &varType, const Type &calcFormalType, const int iWarning,const char *pszFuncName,const int ParmNum){ 391 391 ////////////////////////// 392 392 // キャストに関する警告 393 393 ////////////////////////// 394 char temporary[255],temp2[255],temp3[255]; 395 396 if(IS_LITERAL(CalcIndex)) CalcIndex=-1; 394 char temporary[255]; 395 Type calcType( calcFormalType ); 396 397 if(IS_LITERAL(calcType.GetIndex())) 398 { 399 calcType.SetIndex( -1 ); 400 } 397 401 398 402 if(pszFuncName) … … 400 404 else temporary[0]=0; 401 405 402 if(!GetTypeName(VarType,VarIndex,temp2)) lstrcpy(temp2,"Any"); 403 if(memcmp(temp2,STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0){ 404 memmove(temp2, 405 temp2+lstrlen(STRING_SYSTEM_DECLAREHANDLE), 406 lstrlen(temp2+lstrlen(STRING_SYSTEM_DECLAREHANDLE))+1); 407 } 408 if(!GetTypeName(CalcType,CalcIndex,temp3)) lstrcpy(temp3,"Any"); 409 if(memcmp(temp3,STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0){ 410 memmove(temp3, 411 temp3+lstrlen(STRING_SYSTEM_DECLAREHANDLE), 412 lstrlen(temp3+lstrlen(STRING_SYSTEM_DECLAREHANDLE))+1); 413 } 414 sprintf(temporary+lstrlen(temporary),"%sから%s",temp3,temp2); 406 std::string varTypeName = Compiler::TypeToString( varType ); 407 if(memcmp( varTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0) 408 { 409 varTypeName = varTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) ); 410 } 411 412 std::string calcTypeName = Compiler::TypeToString( calcType ); 413 if(memcmp( calcTypeName.c_str(),STRING_SYSTEM_DECLAREHANDLE,lstrlen(STRING_SYSTEM_DECLAREHANDLE))==0) 414 { 415 calcTypeName = calcTypeName.substr( lstrlen(STRING_SYSTEM_DECLAREHANDLE) ); 416 } 417 sprintf(temporary+lstrlen(temporary),"%sから%s",calcTypeName.c_str(),varTypeName.c_str()); 415 418 416 419 extern int cp; … … 420 423 } 421 424 422 bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum){ 423 424 if(VarType==DEF_STRUCT||CalcType==DEF_STRUCT){ 425 bool CheckDifferentType( const Type &varType,const Type &calcFormalType,const char *pszFuncName,const int ParmNum) 426 { 427 Type calcType( calcFormalType ); 428 429 if( varType.IsStruct() || calcType.IsStruct() ) 430 { 425 431 //いずれかが構造体場合 426 if( VarType != CalcType || lpVarIndex != lpCalcIndex ){ 427 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum); 432 if( !varType.Equals( calcType ) ) 433 { 434 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 428 435 return false; 429 436 } 430 437 } 431 438 432 if(VarType==DEF_OBJECT||CalcType==DEF_OBJECT){ 433 //いずれかがオブジェクトインスタンスの場合 434 if( VarType != CalcType ){ 435 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum); 439 if( varType.IsObject() || calcType.IsObject() ) 440 { 441 //いずれかがオブジェクトの場合 442 if( varType.GetBasicType() != calcType.GetBasicType() ) 443 { 444 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 436 445 return false; 437 446 } 438 447 439 CClass *pClass = (CClass *)lpVarIndex;440 if( !pClass->IsEqualsOrSubClass( (CClass *)lpCalcIndex ) ){448 if( !varType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ) 449 { 441 450 //等しくなく、派生クラスでもないとき 442 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,3,pszFuncName,ParmNum);451 DifferentTypeError( varType, calcType,3,pszFuncName,ParmNum); 443 452 return false; 444 453 } … … 449 458 if(bStrict==0) return true; 450 459 451 if(CalcType&FLAG_PTR){ 460 if( calcType.GetBasicType() & FLAG_PTR ) 461 { 452 462 //配列先頭フラグがたっている場合は、ポインタ型として扱う 453 CalcType=MAKE_PTR_TYPE(NATURAL_TYPE(CalcType),PTR_LEVEL(CalcType)+1); 454 } 455 456 if(IsPtrType(VarType)||IsPtrType(CalcType)){ 463 calcType.SetBasicType( MAKE_PTR_TYPE(NATURAL_TYPE(calcType.GetBasicType()),PTR_LEVEL(calcType.GetBasicType())+1) ); 464 } 465 466 if( varType.IsPointer() || calcType.IsPointer() ) 467 { 457 468 /* 右辺及び左辺のいずれかがポインタ型の場合は、 458 469 型チェックを行う。 459 470 ・同一の種類のポインタ型以外はエラーとする */ 460 471 461 if(IsPtrType(VarType)&&lpCalcIndex==LITERAL_NULL){ 472 if( varType.IsPointer() && calcType.GetIndex() == LITERAL_NULL ) 473 { 462 474 //リテラルNULL値の場合 463 475 return true; 464 476 } 465 477 466 if(VarType==DEF_PTR_VOID){ 478 if( varType.IsVoidPtr() ) 479 { 467 480 //左辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる 468 if(IsPtrType(CalcType)) return true; 469 } 470 471 if(CalcType==DEF_PTR_VOID){ 481 if( calcType.IsPointer() ) 482 { 483 return true; 484 } 485 } 486 487 if( calcType.IsVoidPtr() ) 488 { 472 489 //右辺がVoidPtr型の場合は、ポインタ型すべてを受け入れる 473 if(IsPtrType(VarType)) return true; 474 } 475 476 if(VarType!=CalcType){ 477 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,2,pszFuncName,ParmNum); 490 if( varType.IsPointer() ) 491 { 492 return true; 493 } 494 } 495 496 if( varType.GetBasicType() != calcType.GetBasicType() ) 497 { 498 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum); 478 499 return true; 479 500 } 480 501 481 if(VarType==DEF_PTR_OBJECT){ 502 if( varType.IsObjectPtr() ) 503 { 482 504 //双方がオブジェクトポインタ型の場合 483 if( lpVarIndex!=lpCalcIndex){484 const CClass *pobj_tempClass;485 pobj_tempClass=(CClass *)lpCalcIndex;505 if( varType.GetIndex() != calcType.GetIndex() ) 506 { 507 const CClass *pobj_tempClass = &calcType.GetClass(); 486 508 while(pobj_tempClass&&(!IS_LITERAL((LONG_PTR)pobj_tempClass))){ 487 509 pobj_tempClass=&pobj_tempClass->GetSuperClass(); 488 510 489 if(lpVarIndex==(LONG_PTR)pobj_tempClass){ 511 if( &varType.GetClass() == pobj_tempClass ) 512 { 490 513 //継承先が等しいとき 491 514 return true; 492 515 } 493 516 } 494 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,2,pszFuncName,ParmNum);517 DifferentTypeError( varType, calcType, 2,pszFuncName,ParmNum); 495 518 return true; 496 519 } … … 498 521 } 499 522 500 if(VarType==DEF_DOUBLE){ 501 if(Is64Type(CalcType)){ 523 if( varType.IsDouble() ) 524 { 525 if( calcType.Is64() ) 526 { 502 527 //64ビット整数値の場合は警告を出す 503 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 504 } 505 } 506 else if(VarType==DEF_SINGLE){ 507 if(Is64Type(CalcType)||CalcType==DEF_DOUBLE){ 528 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 529 } 530 } 531 else if( varType.IsSingle() ) 532 { 533 if( calcType.Is64() || calcType.IsDouble() ) 534 { 508 535 //64ビット整数値、またはDouble型の場合は警告を出す 509 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 510 } 511 } 512 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(char)){ 513 if(GetTypeSize(CalcType,lpCalcIndex)>sizeof(char)&& 514 lpCalcIndex!=LITERAL_NULL&& 515 lpCalcIndex!=LITERAL_M128_0&& 516 lpCalcIndex!=LITERAL_0_255){ 536 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 537 } 538 } 539 else if( varType.GetSize() == sizeof(char) ) 540 { 541 if( calcType.GetSize() > sizeof(char) 542 && calcType.GetIndex() != LITERAL_NULL 543 && calcType.GetIndex() != LITERAL_M128_0 544 && calcType.GetIndex() != LITERAL_0_255 ) 545 { 517 546 //8ビット整数値より大きな型で、リテラル値でもない場合は警告を出す 518 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 519 } 520 } 521 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(short)){ 522 if(GetTypeSize(CalcType,lpCalcIndex)>sizeof(short)&& 523 lpCalcIndex!=LITERAL_NULL&& 524 lpCalcIndex!=LITERAL_M128_0&& 525 lpCalcIndex!=LITERAL_0_255&& 526 lpCalcIndex!=LITERAL_M32768_0&& 527 lpCalcIndex!=LITERAL_0_65535){ 547 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 548 } 549 } 550 else if( varType.GetSize() == sizeof(short) ) 551 { 552 if( calcType.GetSize() > sizeof(short) 553 && calcType.GetIndex() != LITERAL_NULL 554 && calcType.GetIndex() != LITERAL_M128_0 555 && calcType.GetIndex() != LITERAL_0_255 556 && calcType.GetIndex() != LITERAL_M32768_0 557 && calcType.GetIndex() != LITERAL_0_65535 ) 558 { 528 559 //16ビット整数値より大きな型で、リテラル値でもない場合は警告を出す 529 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 530 } 531 } 532 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(long)){ 533 if(IsRealNumberType(CalcType)|| 534 (IsWholeNumberType(CalcType)&& 535 GetTypeSize(CalcType,lpCalcIndex)>sizeof(long)&& 536 lpCalcIndex!=LITERAL_NULL) 537 ){ 560 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 561 } 562 } 563 else if( varType.GetSize() == sizeof(long) ) 564 { 565 if( calcType.IsReal() 566 || ( calcType.IsWhole() && calcType.GetSize() > sizeof(long) && calcType.GetIndex() != LITERAL_NULL ) ) 567 { 538 568 /* 32ビット整数値より大きな型、または実数、 539 569 またはリテラル値でもない場合は警告を出す */ 540 DifferentTypeError(VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum); 541 } 542 } 543 else if(GetTypeSize(VarType,lpVarIndex)==sizeof(_int64)){ 544 if(IsRealNumberType(CalcType)){ 570 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 571 } 572 } 573 else if( varType.GetSize() == sizeof(_int64) ) 574 { 575 if( calcType.IsReal() ) 576 { 545 577 //実数の場合は警告を出す 546 DifferentTypeError( VarType,lpVarIndex,CalcType,lpCalcIndex,1,pszFuncName,ParmNum);578 DifferentTypeError( varType, calcType, 1,pszFuncName,ParmNum); 547 579 } 548 580 } … … 550 582 return true; 551 583 } 552 bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum){553 return CheckDifferentType(554 varType.GetBasicType(),555 varType.GetIndex(),556 calcType.GetBasicType(),557 calcType.GetIndex(),558 pszFuncName,559 ParmNum );560 }
Note:
See TracChangeset
for help on using the changeset viewer.