- File:
-
- 1 edited
-
src/ResolvExpr/ConversionCost.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r3e5dd913 r849720f 10 10 // Created On : Sun May 17 07:06:19 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 29 16:11:00 202013 // Update Count : 2 812 // Last Modified On : Mon Aug 12 10:21:00 2019 13 // Update Count : 27 14 14 // 15 15 … … 392 392 void ConversionCost::postvisit( const FunctionType * ) {} 393 393 394 void ConversionCost::postvisit( const StructInstType * inst ) { 395 if ( const StructInstType * destAsInst = dynamic_cast< const StructInstType * >( dest ) ) { 396 if ( inst->name == destAsInst->name ) { 397 cost = Cost::zero; 398 } // if 399 } // if 400 } 401 402 void ConversionCost::postvisit( const UnionInstType * inst ) { 403 if ( const UnionInstType * destAsInst = dynamic_cast< const UnionInstType * >( dest ) ) { 404 if ( inst->name == destAsInst->name ) { 405 cost = Cost::zero; 406 } // if 407 } // if 408 } 409 394 410 void ConversionCost::postvisit( const EnumInstType * ) { 395 411 static Type::Qualifiers q; … … 481 497 } 482 498 483 namespace { 484 # warning For overload resolution between the two versions.485 int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2,486 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 487 return ptrsAssignable( t1, t2, env ); 488 } 489 Cost localConversionCost( 490 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 491 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env492 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); }493 }499 static int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 500 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 501 return ptrsAssignable( t1, t2, env ); 502 } 503 504 // TODO: This is used for overload resolution. It might be able to be dropped once the old system 505 // is removed. 506 static Cost localConversionCost( 507 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 508 const ast::TypeEnvironment & env 509 ) { return conversionCost( src, dst, symtab, env ); } 494 510 495 511 Cost conversionCost( 496 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,497 const ast:: SymbolTable & symtab, const ast::TypeEnvironment & env512 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 513 const ast::TypeEnvironment & env 498 514 ) { 499 515 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { 500 if ( const ast::EqvClass * eqv = env.lookup( *inst) ) {516 if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) { 501 517 if ( eqv->bound ) { 502 return conversionCost(src, eqv->bound, s rcIsLvalue, symtab, env );518 return conversionCost(src, eqv->bound, symtab, env ); 503 519 } else { 504 520 return Cost::infinity; … … 508 524 assertf( type, "Unexpected typedef." ); 509 525 if ( type->base ) { 510 return conversionCost( src, type->base, s rcIsLvalue, symtab, env ) + Cost::safe;526 return conversionCost( src, type->base, symtab, env ) + Cost::safe; 511 527 } 512 528 } … … 518 534 } else if ( const ast::ReferenceType * refType = 519 535 dynamic_cast< const ast::ReferenceType * >( dst ) ) { 520 return convertToReferenceCost( src, refType, s rcIsLvalue, symtab, env, localPtrsAssignable );536 return convertToReferenceCost( src, refType, symtab, env, localPtrsAssignable ); 521 537 } else { 522 return ast::Pass<ConversionCost_new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost ); 523 } 524 } 525 526 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 538 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost ); 539 src->accept( converter ); 540 return converter.pass.cost; 541 } 542 } 543 544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, 527 545 int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 528 PtrsCalculation func ) {546 NumCostCalculation func ) { 529 547 if ( 0 < diff ) { 530 548 Cost cost = convertToReferenceCost( 531 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst,532 srcIsLvalue, (diff - 1), symtab, env, func );549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, 550 dst, (diff - 1), symtab, env, func ); 533 551 cost.incReference(); 534 552 return cost; … … 536 554 Cost cost = convertToReferenceCost( 537 555 src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, 538 srcIsLvalue,(diff + 1), symtab, env, func );556 (diff + 1), symtab, env, func ); 539 557 cost.incReference(); 540 558 return cost; … … 561 579 } 562 580 } else { 563 return ast::Pass<ConversionCost_new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost ); 581 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost ); 582 src->accept( converter ); 583 return converter.pass.cost; 564 584 } 565 585 } else { … … 568 588 assert( dstAsRef ); 569 589 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) { 570 if ( src IsLvalue) {590 if ( src->is_lvalue() ) { 571 591 if ( src->qualifiers == dstAsRef->base->qualifiers ) { 572 592 return Cost::reference; … … 587 607 588 608 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, 589 bool srcIsLvalue,const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,590 PtrsCalculation func ) {609 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 610 NumCostCalculation func ) { 591 611 int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); 592 return convertToReferenceCost( src, dst, s rcIsLvalue, sdepth - ddepth, symtab, env, func );612 return convertToReferenceCost( src, dst, sdepth - ddepth, symtab, env, func ); 593 613 } 594 614 … … 647 667 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 648 668 649 cost = costCalc( refType->base, dst, s rcIsLvalue, symtab, env );669 cost = costCalc( refType->base, dst, symtab, env ); 650 670 if ( refType->base->qualifiers == dst->qualifiers ) { 651 671 cost.incReference(); … … 661 681 } 662 682 683 void ConversionCost_new::postvisit( const ast::StructInstType * structInstType ) { 684 if ( const ast::StructInstType * dstAsInst = 685 dynamic_cast< const ast::StructInstType * >( dst ) ) { 686 if ( structInstType->name == dstAsInst->name ) { 687 cost = Cost::zero; 688 } 689 } 690 } 691 692 void ConversionCost_new::postvisit( const ast::UnionInstType * unionInstType ) { 693 if ( const ast::UnionInstType * dstAsInst = 694 dynamic_cast< const ast::UnionInstType * >( dst ) ) { 695 if ( unionInstType->name == dstAsInst->name ) { 696 cost = Cost::zero; 697 } 698 } 699 } 700 663 701 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 664 702 (void)enumInstType; 665 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };666 cost = costCalc( integer, dst, srcIsLvalue, symtab, env );703 static const ast::BasicType integer( ast::BasicType::SignedInt ); 704 cost = costCalc( &integer, dst, symtab, env ); 667 705 if ( cost < Cost::unsafe ) { 668 706 cost.incSafe(); … … 675 713 676 714 void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) { 677 if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) {678 cost = costCalc( eqv->bound, dst, s rcIsLvalue, symtab, env );715 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) { 716 cost = costCalc( eqv->bound, dst, symtab, env ); 679 717 } else if ( const ast::TypeInstType * dstAsInst = 680 718 dynamic_cast< const ast::TypeInstType * >( dst ) ) { 681 if ( *typeInstType == *dstAsInst) {719 if ( typeInstType->name == dstAsInst->name ) { 682 720 cost = Cost::zero; 683 721 } … … 686 724 assertf( type, "Unexpected typedef."); 687 725 if ( type->base ) { 688 cost = costCalc( type->base, dst, s rcIsLvalue, symtab, env ) + Cost::safe;726 cost = costCalc( type->base, dst, symtab, env ) + Cost::safe; 689 727 } 690 728 } … … 699 737 auto dstEnd = dstAsTuple->types.end(); 700 738 while ( srcIt != srcEnd && dstIt != dstEnd ) { 701 Cost newCost = costCalc( * srcIt++, * dstIt++, s rcIsLvalue, symtab, env );739 Cost newCost = costCalc( * srcIt++, * dstIt++, symtab, env ); 702 740 if ( newCost == Cost::infinity ) { 703 741 return; … … 734 772 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 735 773 } 736 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {737 cost = Cost::zero;738 // +1 for zero_t ->, +1 for disambiguation739 cost.incSafe( maxIntCost + 2 );740 774 } 741 775 } … … 755 789 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 756 790 } 757 } 758 } 759 // size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 791 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 792 cost = Cost::zero; 793 cost.incSafe( maxIntCost + 2 ); 794 } 795 } 796 760 797 761 798 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.