Changeset 6d53e779
- Timestamp:
- Jun 13, 2018, 4:14:10 PM (6 years ago)
- Branches:
- new-env
- Children:
- b60f9d9
- Parents:
- 1d7b0a8
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
r1d7b0a8 r6d53e779 29 29 30 30 namespace ResolvExpr { 31 const Cost Cost::zero = Cost( 0, 0, 0, 0 ); 32 const Cost Cost::infinity = Cost( -1, -1, -1, -1 ); 33 const Cost Cost::unsafe = Cost( 1, 0, 0, 0 ); 34 const Cost Cost::poly = Cost( 0, 1, 0, 0 ); 35 const Cost Cost::safe = Cost( 0, 0, 1, 0 ); 36 const Cost Cost::reference = Cost( 0, 0, 0, 1 ); 31 const Cost Cost::zero = Cost{ 0, 0, 0, 0, 0, 0 }; 32 const Cost Cost::infinity = Cost{ -1, -1, -1, 1, -1, -1 }; 33 const Cost Cost::unsafe = Cost{ 1, 0, 0, 0, 0, 0 }; 34 const Cost Cost::poly = Cost{ 0, 1, 0, 0, 0, 0 }; 35 const Cost Cost::var = Cost{ 0, 0, 1, 0, 0, 0 }; 36 const Cost Cost::spec = Cost{ 0, 0, 0, -1, 0, 0 }; 37 const Cost Cost::safe = Cost{ 0, 0, 0, 0, 1, 0 }; 38 const Cost Cost::reference = Cost{ 0, 0, 0, 0, 0, 1 }; 37 39 38 40 #if 0 -
src/ResolvExpr/Cost.h
r1d7b0a8 r6d53e779 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:35:55 201713 // Update Count : 511 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 11 16:04:00 2018 13 // Update Count : 6 14 14 // 15 15 … … 21 21 class Cost { 22 22 private: 23 Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );23 Cost( int unsafeCost, int polyCost, int varCost, int specCost, int safeCost, int referenceCost ); 24 24 25 25 public: 26 26 Cost & incUnsafe( int inc = 1 ); 27 27 Cost & incPoly( int inc = 1 ); 28 Cost & incVar( int inc = 1 ); 29 Cost & decSpec( int dec = 1 ); 28 30 Cost & incSafe( int inc = 1 ); 29 31 Cost & incReference( int inc = 1 ); … … 31 33 int get_unsafeCost() const { return unsafeCost; } 32 34 int get_polyCost() const { return polyCost; } 35 int get_varCost() const { return varCost; } 36 int get_specCost() const { return specCost; } 33 37 int get_safeCost() const { return safeCost; } 34 38 int get_referenceCost() const { return referenceCost; } … … 47 51 static const Cost unsafe; 48 52 static const Cost poly; 53 static const Cost var; 54 static const Cost spec; 49 55 static const Cost safe; 50 56 static const Cost reference; 51 57 private: 52 int compare( const Cost &other ) const;53 58 54 int unsafeCost; 55 int polyCost; 56 int safeCost; 57 int referenceCost; 59 int unsafeCost; ///< Unsafe (narrowing) conversions 60 int polyCost; ///< Count of parameters and return values bound to some poly type 61 int varCost; ///< Count of polymorphic type variables 62 int specCost; ///< Polymorphic type specializations (type assertions), negative cost 63 int safeCost; ///< Safe (widening) conversions 64 int referenceCost; ///< reference conversions 58 65 }; 59 66 60 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {} 67 inline Cost::Cost( 68 int unsafeCost, int polyCost, int varCost, int specCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), varCost( varCost ), specCost( specCost ), 69 safeCost( safeCost ), referenceCost( referenceCost ) {} 61 70 62 71 inline Cost & Cost::incUnsafe( int inc ) { … … 69 78 if ( *this == infinity ) return *this; 70 79 polyCost += inc; 80 return *this; 81 } 82 83 inline Cost & Cost::incVar( int inc ) { 84 if ( *this == infinity ) return *this; 85 varCost += inc; 86 return *this; 87 } 88 89 inline Cost& Cost::decSpec( int dec ) { 90 if ( *this == infinity ) return *this; 91 specCost -= dec; 71 92 return *this; 72 93 } … … 86 107 inline Cost Cost::operator+( const Cost &other ) const { 87 108 if ( *this == infinity || other == infinity ) return infinity; 88 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost ); 109 return Cost( 110 unsafeCost + other.unsafeCost, polyCost + other.polyCost, 111 varCost + other.varCost, specCost + other.specCost, 112 safeCost + other.safeCost, referenceCost + other.referenceCost ); 89 113 } 90 114 91 115 inline Cost Cost::operator-( const Cost &other ) const { 92 116 if ( *this == infinity || other == infinity ) return infinity; 93 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost ); 117 return Cost( 118 unsafeCost - other.unsafeCost, polyCost - other.polyCost, 119 varCost + other.varCost, specCost + other.specCost, 120 safeCost - other.safeCost, referenceCost - other.referenceCost ); 94 121 } 95 122 … … 102 129 unsafeCost += other.unsafeCost; 103 130 polyCost += other.polyCost; 131 varCost += other.varCost; 132 specCost += other.specCost; 104 133 safeCost += other.safeCost; 105 134 referenceCost += other.referenceCost; … … 119 148 } else if ( polyCost < other.polyCost ) { 120 149 return true; 150 } else if ( varCost > other.varCost ) { 151 return false; 152 } else if ( varCost < other.varCost ) { 153 return true; 154 } else if ( specCost > other.specCost ) { 155 return false; 156 } else if ( specCost < other.specCost ) { 157 return true; 121 158 } else if ( safeCost > other.safeCost ) { 122 159 return false; … … 135 172 return unsafeCost == other.unsafeCost 136 173 && polyCost == other.polyCost 174 && varCost == other.varCost 175 && specCost == other.specCost 137 176 && safeCost == other.safeCost 138 177 && referenceCost == other.referenceCost; … … 144 183 145 184 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 146 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )"; 147 return os; 185 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 186 << cost.varCost << ", " << cost.specCost << ", " 187 << cost.safeCost << ", " << cost.referenceCost << " )"; 148 188 } 149 189 } // namespace ResolvExpr
Note: See TracChangeset
for help on using the changeset viewer.