Changeset 4cf2472 for src/ResolvExpr/Cost.h
- Timestamp:
- Feb 7, 2019, 4:48:10 PM (4 years ago)
- Branches:
- deferred_resn
- Children:
- 1cc4390
- Parents:
- e1f7eef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
re1f7eef r4cf2472 21 21 class Cost { 22 22 private: 23 Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost,24 int referenceCost );23 Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 24 int varCost, int specCost, int referenceCost ); 25 25 26 26 public: … … 28 28 Cost & incPoly( int inc = 1 ); 29 29 Cost & incSafe( int inc = 1 ); 30 Cost & incSign( int inc = 1 ); 30 31 Cost & incVar( int inc = 1 ); 31 32 Cost & decSpec( int inc = 1 ); … … 35 36 int get_polyCost() const { return polyCost; } 36 37 int get_safeCost() const { return safeCost; } 38 int get_signCost() const { return signCost; } 37 39 int get_varCost() const { return varCost; } 38 40 int get_specCost() const { return specCost; } … … 40 42 41 43 Cost operator+( const Cost &other ) const; 42 Cost operator-( const Cost &other ) const;43 44 Cost &operator+=( const Cost &other ); 44 45 bool operator<( const Cost &other ) const; … … 55 56 static const Cost poly; 56 57 static const Cost safe; 58 static const Cost sign; 57 59 static const Cost var; 58 60 static const Cost spec; … … 63 65 int polyCost; ///< Count of parameters and return values bound to some poly type 64 66 int safeCost; ///< Safe (widening) conversions 67 int signCost; ///< Count of safe sign conversions 65 68 int varCost; ///< Count of polymorphic type variables 66 69 int specCost; ///< Polymorphic type specializations (type assertions), negative cost … … 68 71 }; 69 72 70 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost,71 int referenceCost )72 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), varCost( varCost ),73 specCost( specCost ), referenceCost( referenceCost ) {}73 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 74 int varCost, int specCost, int referenceCost ) 75 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), signCost( signCost ), 76 varCost( varCost ), specCost( specCost ), referenceCost( referenceCost ) {} 74 77 75 78 inline Cost & Cost::incUnsafe( int inc ) { … … 88 91 if ( *this == infinity ) return *this; 89 92 safeCost += inc; 93 return *this; 94 } 95 96 inline Cost & Cost::incSign( int inc ) { 97 if ( *this == infinity ) return *this; 98 signCost += inc; 90 99 return *this; 91 100 } … … 113 122 return Cost{ 114 123 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 115 varCost + other.varCost, specCost + other.specCost,124 signCost + other.signCost, varCost + other.varCost, specCost + other.specCost, 116 125 referenceCost + other.referenceCost }; 117 }118 119 inline Cost Cost::operator-( const Cost &other ) const {120 if ( *this == infinity || other == infinity ) return infinity;121 return Cost{122 unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost,123 varCost - other.varCost, specCost - other.specCost,124 referenceCost - other.referenceCost };125 126 } 126 127 … … 134 135 polyCost += other.polyCost; 135 136 safeCost += other.safeCost; 137 signCost += other.signCost; 136 138 varCost += other.varCost; 137 139 specCost += other.specCost; … … 156 158 } else if ( safeCost < other.safeCost ) { 157 159 return true; 160 } else if ( signCost > other.signCost ) { 161 return false; 162 } else if ( signCost < other.signCost ) { 163 return true; 158 164 } else if ( varCost > other.varCost ) { 159 165 return false; … … 180 186 c = polyCost - other.polyCost; if ( c ) return c; 181 187 c = safeCost - other.safeCost; if ( c ) return c; 188 c = signCost - other.signCost; if ( c ) return c; 182 189 c = varCost - other.varCost; if ( c ) return c; 183 190 c = specCost - other.specCost; if ( c ) return c; … … 189 196 && polyCost == other.polyCost 190 197 && safeCost == other.safeCost 198 && signCost == other.signCost 191 199 && varCost == other.varCost 192 200 && specCost == other.specCost … … 200 208 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 201 209 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 202 << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", " 210 << cost.safeCost << ", " << cost.signCost << ", " 211 << cost.varCost << ", " << cost.specCost << ", " 203 212 << cost.referenceCost << " )"; 204 213 }
Note: See TracChangeset
for help on using the changeset viewer.