Changeset eef8dfb for src/ResolvExpr/ConversionCost.cc
- Timestamp:
- Jan 7, 2021, 2:55:57 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:
- 58fe85a
- Parents:
- bdfc032 (diff), 44e37ef (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
rbdfc032 reef8dfb 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 : Wed Jul 29 16:11:00 2020 13 // Update Count : 28 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 } // if399 } // if400 }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 } // if407 } // if408 }409 410 394 void ConversionCost::postvisit( const EnumInstType * ) { 411 395 static Type::Qualifiers q; … … 497 481 } 498 482 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 );}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 } 510 494 511 495 Cost conversionCost( 512 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,513 const ast:: TypeEnvironment & env496 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, 497 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 514 498 ) { 515 499 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { 516 if ( const ast::EqvClass * eqv = env.lookup( inst->name) ) {500 if ( const ast::EqvClass * eqv = env.lookup( *inst ) ) { 517 501 if ( eqv->bound ) { 518 return conversionCost(src, eqv->bound, s ymtab, env );502 return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env ); 519 503 } else { 520 504 return Cost::infinity; … … 524 508 assertf( type, "Unexpected typedef." ); 525 509 if ( type->base ) { 526 return conversionCost( src, type->base, s ymtab, env ) + Cost::safe;510 return conversionCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe; 527 511 } 528 512 } … … 534 518 } else if ( const ast::ReferenceType * refType = 535 519 dynamic_cast< const ast::ReferenceType * >( dst ) ) { 536 return convertToReferenceCost( src, refType, s ymtab, env, localPtrsAssignable );520 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); 537 521 } else { 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, 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, 545 527 int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 546 NumCostCalculation func ) {528 PtrsCalculation func ) { 547 529 if ( 0 < diff ) { 548 530 Cost cost = convertToReferenceCost( 549 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, 550 dst, (diff - 1), symtab, env, func );531 strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst, 532 srcIsLvalue, (diff - 1), symtab, env, func ); 551 533 cost.incReference(); 552 534 return cost; … … 554 536 Cost cost = convertToReferenceCost( 555 537 src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, 556 (diff + 1), symtab, env, func );538 srcIsLvalue, (diff + 1), symtab, env, func ); 557 539 cost.incReference(); 558 540 return cost; … … 579 561 } 580 562 } else { 581 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost ); 582 src->accept( converter ); 583 return converter.pass.cost; 563 return ast::Pass<ConversionCost_new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost ); 584 564 } 585 565 } else { … … 588 568 assert( dstAsRef ); 589 569 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) { 590 if ( src ->is_lvalue()) {570 if ( srcIsLvalue ) { 591 571 if ( src->qualifiers == dstAsRef->base->qualifiers ) { 592 572 return Cost::reference; … … 607 587 608 588 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, 609 610 NumCostCalculation func ) {589 bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, 590 PtrsCalculation func ) { 611 591 int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); 612 return convertToReferenceCost( src, dst, s depth - ddepth, symtab, env, func );592 return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func ); 613 593 } 614 594 … … 667 647 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 668 648 669 cost = costCalc( refType->base, dst, s ymtab, env );649 cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env ); 670 650 if ( refType->base->qualifiers == dst->qualifiers ) { 671 651 cost.incReference(); … … 681 661 } 682 662 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 701 663 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 702 664 (void)enumInstType; 703 static const ast::BasicType integer( ast::BasicType::SignedInt );704 cost = costCalc( &integer, dst, symtab, env );665 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 666 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 705 667 if ( cost < Cost::unsafe ) { 706 668 cost.incSafe(); … … 713 675 714 676 void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) { 715 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) {716 cost = costCalc( eqv->bound, dst, s ymtab, env );677 if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) { 678 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); 717 679 } else if ( const ast::TypeInstType * dstAsInst = 718 680 dynamic_cast< const ast::TypeInstType * >( dst ) ) { 719 if ( typeInstType->name == dstAsInst->name) {681 if ( *typeInstType == *dstAsInst ) { 720 682 cost = Cost::zero; 721 683 } … … 724 686 assertf( type, "Unexpected typedef."); 725 687 if ( type->base ) { 726 cost = costCalc( type->base, dst, s ymtab, env ) + Cost::safe;688 cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe; 727 689 } 728 690 } … … 737 699 auto dstEnd = dstAsTuple->types.end(); 738 700 while ( srcIt != srcEnd && dstIt != dstEnd ) { 739 Cost newCost = costCalc( * srcIt++, * dstIt++, s ymtab, env );701 Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env ); 740 702 if ( newCost == Cost::infinity ) { 741 703 return; … … 772 734 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 773 735 } 736 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 737 cost = Cost::zero; 738 // +1 for zero_t ->, +1 for disambiguation 739 cost.incSafe( maxIntCost + 2 ); 774 740 } 775 741 } … … 789 755 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 790 756 } 791 } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { 792 cost = Cost::zero; 793 cost.incSafe( maxIntCost + 2 ); 794 } 795 } 796 757 } 758 } 759 // size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 797 760 798 761 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.