Changeset 7ebaa56
- Timestamp:
- Jul 17, 2017, 3:05:57 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e6cee92
- Parents:
- 89be1c68
- git-author:
- Rob Schluntz <rschlunt@…> (07/17/17 14:58:13)
- git-committer:
- Rob Schluntz <rschlunt@…> (07/17/17 15:05:57)
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r89be1c68 r7ebaa56 21 21 22 22 namespace ResolvExpr { 23 const Cost Cost::zero = Cost( 0, 0, 0 ); 24 const Cost Cost::infinity = Cost( -1, -1, -1 ); 25 const Cost Cost::unsafe = Cost( 1, 0, 0 ); 26 const Cost Cost::poly = Cost( 0, 1, 0 ); 27 const Cost Cost::safe = Cost( 0, 0, 1 ); 23 const Cost Cost::zero = Cost( 0, 0, 0, 0 ); 24 const Cost Cost::infinity = Cost( -1, -1, -1, -1 ); 25 const Cost Cost::unsafe = Cost( 1, 0, 0, 0 ); 26 const Cost Cost::poly = Cost( 0, 1, 0, 0 ); 27 const Cost Cost::safe = Cost( 0, 0, 1, 0 ); 28 const Cost Cost::reference = Cost( 0, 0, 0, 1 ); 28 29 29 30 … … 80 81 // TODO: document this 81 82 Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env ); 82 // TODO: increment reference cost 83 cost.incSafe(); 83 cost.incReference(); 84 84 return cost; 85 85 } else if ( diff < -1 ) { 86 86 // TODO: document this 87 87 Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env ); 88 // TODO: increment reference cost 89 cost.incSafe(); 88 cost.incReference(); 90 89 return cost; 91 90 } else if ( diff == 0 ) { … … 119 118 // lvalue-to-reference conversion: cv lvalue T => cv T & 120 119 if ( src->get_qualifiers() == destAsRef->get_base()->get_qualifiers() ) { 121 return Cost:: safe; // cost needs to be non-zero to add cast120 return Cost::reference; // cost needs to be non-zero to add cast 122 121 } if ( src->get_qualifiers() < destAsRef->get_base()->get_qualifiers() ) { 123 return Cost::safe + Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same122 return Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same 124 123 } else { 125 124 return Cost::unsafe; … … 273 272 // cv can be safely dropped because of 'implicit dereference' behavior. 274 273 refType->get_base()->accept( *this ); 275 // TODO: increment reference cost 276 cost.incSafe(); 274 cost.incReference(); 277 275 } 278 276 -
src/ResolvExpr/Cost.h
r89be1c68 r7ebaa56 22 22 class Cost { 23 23 private: 24 Cost( int unsafeCost, int polyCost, int safeCost );24 Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ); 25 25 26 26 public: … … 28 28 Cost & incPoly( int inc = 1 ); 29 29 Cost & incSafe( int inc = 1 ); 30 Cost & incReference( int inc = 1 ); 30 31 31 32 Cost operator+( const Cost &other ) const; … … 39 40 static const Cost zero; 40 41 static const Cost infinity; 42 41 43 static const Cost unsafe; 42 44 static const Cost poly; 43 45 static const Cost safe; 46 static const Cost reference; 44 47 private: 45 48 int compare( const Cost &other ) const; … … 48 51 int polyCost; 49 52 int safeCost; 53 int referenceCost; 50 54 }; 51 55 52 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ) {}56 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {} 53 57 54 58 inline Cost & Cost::incUnsafe( int inc ) { … … 67 71 } 68 72 73 inline Cost & Cost::incReference( int inc ) { 74 referenceCost += inc; 75 return *this; 76 } 77 69 78 inline Cost Cost::operator+( const Cost &other ) const { 70 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost );79 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost ); 71 80 } 72 81 73 82 inline Cost Cost::operator-( const Cost &other ) const { 74 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost );83 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost ); 75 84 } 76 85 … … 79 88 polyCost += other.polyCost; 80 89 safeCost += other.safeCost; 90 referenceCost += other.referenceCost; 81 91 return *this; 82 92 } … … 98 108 } else if ( safeCost < other.safeCost ) { 99 109 return true; 110 } else if ( referenceCost > other.referenceCost ) { 111 return false; 112 } else if ( referenceCost < other.referenceCost ) { 113 return true; 100 114 } else { 101 115 return false; … … 106 120 return unsafeCost == other.unsafeCost 107 121 && polyCost == other.polyCost 108 && safeCost == other.safeCost; 122 && safeCost == other.safeCost 123 && referenceCost == other.referenceCost; 109 124 } 110 125 … … 114 129 115 130 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 116 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << " )";131 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )"; 117 132 return os; 118 133 }
Note: See TracChangeset
for help on using the changeset viewer.