Changeset e67a82d for src/ResolvExpr/ConversionCost.cc
- Timestamp:
- Aug 20, 2020, 11:48:15 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d685cb0
- Parents:
- 67ca73e (diff), 013b028 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r67ca73e re67a82d 481 481 } 482 482 483 static int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 484 const ast::SymbolTable &, const ast::TypeEnvironment & env ) {485 return ptrsAssignable( t1, t2, env );486 } 487 488 // TODO: This is used for overload resolution. It might be able to be dropped once the old system 489 // is removed. 490 static Cost localConversionCost( 491 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,492 const ast::TypeEnvironment & env493 ) { return conversionCost( src, dst, symtab, env );}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 & env 492 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); } 493 } 494 494 495 495 Cost conversionCost( 496 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,497 const ast:: TypeEnvironment & env496 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 497 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 498 498 ) { 499 499 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { 500 500 if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) { 501 501 if ( eqv->bound ) { 502 return conversionCost(src, eqv->bound, s ymtab, env );502 return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env ); 503 503 } else { 504 504 return Cost::infinity; … … 508 508 assertf( type, "Unexpected typedef." ); 509 509 if ( type->base ) { 510 return conversionCost( src, type->base, s ymtab, env ) + Cost::safe;510 return conversionCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe; 511 511 } 512 512 } … … 518 518 } else if ( const ast::ReferenceType * refType = 519 519 dynamic_cast< const ast::ReferenceType * >( dst ) ) { 520 return convertToReferenceCost( src, refType, s ymtab, env, localPtrsAssignable );520 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); 521 521 } else { 522 ast::Pass<ConversionCost_new> converter( dst, s ymtab, env, localConversionCost );522 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost ); 523 523 src->accept( converter ); 524 return converter. pass.cost;525 } 526 } 527 528 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, 524 return converter.core.cost; 525 } 526 } 527 528 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 529 529 int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 530 NumCostCalculation func ) {530 PtrsCalculation func ) { 531 531 if ( 0 < diff ) { 532 532 Cost cost = convertToReferenceCost( 533 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, 534 dst, (diff - 1), symtab, env, func );533 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst, 534 srcIsLvalue, (diff - 1), symtab, env, func ); 535 535 cost.incReference(); 536 536 return cost; … … 538 538 Cost cost = convertToReferenceCost( 539 539 src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, 540 (diff + 1), symtab, env, func );540 srcIsLvalue, (diff + 1), symtab, env, func ); 541 541 cost.incReference(); 542 542 return cost; … … 563 563 } 564 564 } else { 565 ast::Pass<ConversionCost_new> converter( dst, s ymtab, env, localConversionCost );565 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost ); 566 566 src->accept( converter ); 567 return converter. pass.cost;567 return converter.core.cost; 568 568 } 569 569 } else { … … 572 572 assert( dstAsRef ); 573 573 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) { 574 if ( src ->is_lvalue()) {574 if ( srcIsLvalue ) { 575 575 if ( src->qualifiers == dstAsRef->base->qualifiers ) { 576 576 return Cost::reference; … … 591 591 592 592 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, 593 594 NumCostCalculation func ) {593 bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 594 PtrsCalculation func ) { 595 595 int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); 596 return convertToReferenceCost( src, dst, s depth - ddepth, symtab, env, func );596 return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func ); 597 597 } 598 598 … … 651 651 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 652 652 653 cost = costCalc( refType->base, dst, s ymtab, env );653 cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env ); 654 654 if ( refType->base->qualifiers == dst->qualifiers ) { 655 655 cost.incReference(); … … 667 667 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 668 668 (void)enumInstType; 669 static const ast::BasicType integer( ast::BasicType::SignedInt );670 cost = costCalc( &integer, dst, symtab, env );669 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 670 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 671 671 if ( cost < Cost::unsafe ) { 672 672 cost.incSafe(); … … 680 680 void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) { 681 681 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) { 682 cost = costCalc( eqv->bound, dst, s ymtab, env );682 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); 683 683 } else if ( const ast::TypeInstType * dstAsInst = 684 684 dynamic_cast< const ast::TypeInstType * >( dst ) ) { … … 690 690 assertf( type, "Unexpected typedef."); 691 691 if ( type->base ) { 692 cost = costCalc( type->base, dst, s ymtab, env ) + Cost::safe;692 cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe; 693 693 } 694 694 } … … 703 703 auto dstEnd = dstAsTuple->types.end(); 704 704 while ( srcIt != srcEnd && dstIt != dstEnd ) { 705 Cost newCost = costCalc( * srcIt++, * dstIt++, s ymtab, env );705 Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env ); 706 706 if ( newCost == Cost::infinity ) { 707 707 return; … … 738 738 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 739 739 } 740 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 741 cost = Cost::zero; 742 // +1 for zero_t ->, +1 for disambiguation 743 cost.incSafe( maxIntCost + 2 ); 740 744 } 741 745 } … … 755 759 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 756 760 } 757 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 758 cost = Cost::zero; 759 cost.incSafe( maxIntCost + 2 ); 760 } 761 } 762 761 } 762 } 763 // size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 763 764 764 765 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.