- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r849720f rcf32116 10 10 // Created On : Sun May 17 07:06:19 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Aug 12 10:21:00 201913 // Update Count : 2 712 // Last Modified On : Fri Oct 4 14:45:00 2019 13 // Update Count : 28 14 14 // 15 15 … … 497 497 } 498 498 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 & env509 ) { return conversionCost( src, dst, symtab, env );}499 namespace { 500 # warning For overload resolution between the two versions. 501 int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 502 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 503 return ptrsAssignable( t1, t2, env ); 504 } 505 Cost localConversionCost( 506 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 507 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 508 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); } 509 } 510 510 511 511 Cost conversionCost( 512 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,513 const ast:: TypeEnvironment & env512 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 513 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 514 514 ) { 515 515 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { 516 516 if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) { 517 517 if ( eqv->bound ) { 518 return conversionCost(src, eqv->bound, s ymtab, env );518 return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env ); 519 519 } else { 520 520 return Cost::infinity; … … 524 524 assertf( type, "Unexpected typedef." ); 525 525 if ( type->base ) { 526 return conversionCost( src, type->base, s ymtab, env ) + Cost::safe;526 return conversionCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe; 527 527 } 528 528 } … … 534 534 } else if ( const ast::ReferenceType * refType = 535 535 dynamic_cast< const ast::ReferenceType * >( dst ) ) { 536 return convertToReferenceCost( src, refType, s ymtab, env, localPtrsAssignable );536 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); 537 537 } else { 538 ast::Pass<ConversionCost_new> converter( dst, s ymtab, env, localConversionCost );538 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost ); 539 539 src->accept( converter ); 540 540 return converter.pass.cost; … … 542 542 } 543 543 544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, 544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 545 545 int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 546 NumCostCalculation func ) {546 PtrsCalculation func ) { 547 547 if ( 0 < diff ) { 548 548 Cost cost = convertToReferenceCost( 549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, 550 dst, (diff - 1), symtab, env, func );549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst, 550 srcIsLvalue, (diff - 1), symtab, env, func ); 551 551 cost.incReference(); 552 552 return cost; … … 554 554 Cost cost = convertToReferenceCost( 555 555 src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, 556 (diff + 1), symtab, env, func );556 srcIsLvalue, (diff + 1), symtab, env, func ); 557 557 cost.incReference(); 558 558 return cost; … … 579 579 } 580 580 } else { 581 ast::Pass<ConversionCost_new> converter( dst, s ymtab, env, localConversionCost );581 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost ); 582 582 src->accept( converter ); 583 583 return converter.pass.cost; … … 588 588 assert( dstAsRef ); 589 589 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) { 590 if ( src ->is_lvalue()) {590 if ( srcIsLvalue ) { 591 591 if ( src->qualifiers == dstAsRef->base->qualifiers ) { 592 592 return Cost::reference; … … 607 607 608 608 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, 609 610 NumCostCalculation func ) {609 bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 610 PtrsCalculation func ) { 611 611 int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); 612 return convertToReferenceCost( src, dst, s depth - ddepth, symtab, env, func );612 return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func ); 613 613 } 614 614 … … 667 667 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 668 668 669 cost = costCalc( refType->base, dst, s ymtab, env );669 cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env ); 670 670 if ( refType->base->qualifiers == dst->qualifiers ) { 671 671 cost.incReference(); … … 701 701 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 702 702 (void)enumInstType; 703 static const ast::BasicType integer( ast::BasicType::SignedInt );704 cost = costCalc( &integer, dst, symtab, env );703 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 704 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 705 705 if ( cost < Cost::unsafe ) { 706 706 cost.incSafe(); … … 714 714 void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) { 715 715 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) { 716 cost = costCalc( eqv->bound, dst, s ymtab, env );716 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); 717 717 } else if ( const ast::TypeInstType * dstAsInst = 718 718 dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 724 724 assertf( type, "Unexpected typedef."); 725 725 if ( type->base ) { 726 cost = costCalc( type->base, dst, s ymtab, env ) + Cost::safe;726 cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe; 727 727 } 728 728 } … … 737 737 auto dstEnd = dstAsTuple->types.end(); 738 738 while ( srcIt != srcEnd && dstIt != dstEnd ) { 739 Cost newCost = costCalc( * srcIt++, * dstIt++, s ymtab, env );739 Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env ); 740 740 if ( newCost == Cost::infinity ) { 741 741 return; … … 772 772 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 773 773 } 774 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 775 cost = Cost::zero; 776 // +1 for zero_t ->, +1 for disambiguation 777 cost.incSafe( maxIntCost + 2 ); 774 778 } 775 779 } … … 789 793 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 790 794 } 791 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {792 cost = Cost::zero;793 cost.incSafe( maxIntCost + 2 );794 795 } 795 796 }
Note: See TracChangeset
for help on using the changeset viewer.