Changes in src/ResolvExpr/Cost.h [9504a89:b10c39a0]
- File:
-
- 1 edited
-
src/ResolvExpr/Cost.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
r9504a89 rb10c39a0 10 10 // Created On : Sun May 17 09:39:50 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 21 11:39:13201913 // Update Count : 6312 // Last Modified On : Mon Apr 29 18:33:44 2019 13 // Update Count : 49 14 14 // 15 15 … … 21 21 22 22 namespace ResolvExpr { 23 #if 0 24 25 //*************************** OLD *************************** 26 27 class Cost { 28 private: 29 Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 30 int varCost, int specCost, int referenceCost ); 31 public: 32 Cost & incUnsafe( int inc = 1 ); 33 Cost & incPoly( int inc = 1 ); 34 Cost & incSafe( int inc = 1 ); 35 Cost & incSign( int inc = 1 ); 36 Cost & incVar( int inc = 1 ); 37 Cost & decSpec( int inc = 1 ); 38 Cost & incReference( int inc = 1 ); 39 40 int get_unsafeCost() const { return unsafeCost; } 41 int get_polyCost() const { return polyCost; } 42 int get_safeCost() const { return safeCost; } 43 int get_signCost() const { return signCost; } 44 int get_varCost() const { return varCost; } 45 int get_specCost() const { return specCost; } 46 int get_referenceCost() const { return referenceCost; } 47 48 Cost operator+( const Cost &other ) const; 49 Cost &operator+=( const Cost &other ); 50 bool operator<( const Cost &other ) const; 51 bool operator==( const Cost &other ) const; 52 bool operator!=( const Cost &other ) const; 53 friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); 54 // returns negative for *this < other, 0 for *this == other, positive for *this > other 55 int compare( const Cost &other ) const; 56 57 static const Cost zero; 58 static const Cost infinity; 59 60 static const Cost unsafe; 61 static const Cost poly; 62 static const Cost safe; 63 static const Cost sign; 64 static const Cost var; 65 static const Cost spec; 66 static const Cost reference; 67 68 private: 69 int unsafeCost; ///< Unsafe (narrowing) conversions 70 int polyCost; ///< Count of parameters and return values bound to some poly type 71 int safeCost; ///< Safe (widening) conversions 72 int signCost; ///< Count of safe sign conversions 73 int varCost; ///< Count of polymorphic type variables 74 int specCost; ///< Polymorphic type specializations (type assertions), negative cost 75 int referenceCost; ///< reference conversions 76 }; 77 78 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 79 int varCost, int specCost, int referenceCost ) 80 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), signCost( signCost ), 81 varCost( varCost ), specCost( specCost ), referenceCost( referenceCost ) {} 82 83 inline Cost & Cost::incUnsafe( int inc ) { 84 if ( *this == infinity ) return *this; 85 unsafeCost += inc; 86 return *this; 87 } 88 89 inline Cost & Cost::incPoly( int inc ) { 90 if ( *this == infinity ) return *this; 91 polyCost += inc; 92 return *this; 93 } 94 95 inline Cost & Cost::incSafe( int inc ) { 96 if ( *this == infinity ) return *this; 97 safeCost += inc; 98 return *this; 99 } 100 101 inline Cost & Cost::incSign( int inc ) { 102 if ( *this == infinity ) return *this; 103 signCost += inc; 104 return *this; 105 } 106 107 inline Cost & Cost::incVar( int inc ) { 108 if ( *this == infinity ) return *this; 109 varCost += inc; 110 return *this; 111 } 112 113 inline Cost& Cost::decSpec( int dec ) { 114 if ( *this == infinity ) return *this; 115 specCost -= dec; 116 return *this; 117 } 118 119 inline Cost & Cost::incReference( int inc ) { 120 if ( *this == infinity ) return *this; 121 referenceCost += inc; 122 return *this; 123 } 124 125 inline Cost Cost::operator+( const Cost &other ) const { 126 if ( *this == infinity || other == infinity ) return infinity; 127 return Cost{ 128 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 129 signCost + other.signCost, varCost + other.varCost, specCost + other.specCost, 130 referenceCost + other.referenceCost }; 131 } 132 133 inline Cost &Cost::operator+=( const Cost &other ) { 134 if ( *this == infinity ) return *this; 135 if ( other == infinity ) { 136 *this = infinity; 137 return *this; 138 } 139 unsafeCost += other.unsafeCost; 140 polyCost += other.polyCost; 141 safeCost += other.safeCost; 142 signCost += other.signCost; 143 varCost += other.varCost; 144 specCost += other.specCost; 145 referenceCost += other.referenceCost; 146 return *this; 147 } 148 149 inline bool Cost::operator<( const Cost &other ) const { 150 if ( *this == infinity ) return false; 151 if ( other == infinity ) return true; 152 153 if ( unsafeCost > other.unsafeCost ) { 154 return false; 155 } else if ( unsafeCost < other.unsafeCost ) { 156 return true; 157 } else if ( polyCost > other.polyCost ) { 158 return false; 159 } else if ( polyCost < other.polyCost ) { 160 return true; 161 } else if ( safeCost > other.safeCost ) { 162 return false; 163 } else if ( safeCost < other.safeCost ) { 164 return true; 165 } else if ( signCost > other.signCost ) { 166 return false; 167 } else if ( signCost < other.signCost ) { 168 return true; 169 } else if ( varCost > other.varCost ) { 170 return false; 171 } else if ( varCost < other.varCost ) { 172 return true; 173 } else if ( specCost > other.specCost ) { 174 return false; 175 } else if ( specCost > other.specCost ) { 176 return true; 177 } else if ( referenceCost > other.referenceCost ) { 178 return false; 179 } else if ( referenceCost < other.referenceCost ) { 180 return true; 181 } else { 182 return false; 183 } // if 184 } 185 186 inline int Cost::compare( const Cost &other ) const { 187 if ( *this == infinity ) return +1; 188 if ( other == infinity ) return -1; 189 190 int c = unsafeCost - other.unsafeCost; if ( c ) return c; 191 c = polyCost - other.polyCost; if ( c ) return c; 192 c = safeCost - other.safeCost; if ( c ) return c; 193 c = signCost - other.signCost; if ( c ) return c; 194 c = varCost - other.varCost; if ( c ) return c; 195 c = specCost - other.specCost; if ( c ) return c; 196 return referenceCost - other.referenceCost; 197 } 198 199 inline bool Cost::operator==( const Cost &other ) const { 200 return unsafeCost == other.unsafeCost 201 && polyCost == other.polyCost 202 && safeCost == other.safeCost 203 && signCost == other.signCost 204 && varCost == other.varCost 205 && specCost == other.specCost 206 && referenceCost == other.referenceCost; 207 } 208 209 inline bool Cost::operator!=( const Cost &other ) const { 210 return !( *this == other ); 211 } 212 213 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 214 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 215 << cost.safeCost << ", " << cost.signCost << ", " 216 << cost.varCost << ", " << cost.specCost << ", " 217 << cost.referenceCost << " )"; 218 } 219 220 #else 221 222 //*************************** NEW *************************** 223 23 224 // To maximize performance and space, the 7 resolution costs are packed into a single 64-bit word. However, the 24 225 // specialization cost is a negative value so a correction is needed is a few places. … … 170 371 << ", " << cost.get_referenceCost() << " )"; 171 372 } 373 #endif // 0 172 374 } // namespace ResolvExpr 173 375
Note:
See TracChangeset
for help on using the changeset viewer.