Changes in src/ResolvExpr/Cost.h [d97c3a4:ddf8a29]
- File:
-
- 1 edited
-
src/ResolvExpr/Cost.h (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
rd97c3a4 rddf8a29 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Fri Oct 05 14:32:00 201813 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:35:55 2017 13 // Update Count : 5 14 14 // 15 15 … … 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 referenceCost ); 25 24 26 25 public: … … 28 27 Cost & incPoly( int inc = 1 ); 29 28 Cost & incSafe( int inc = 1 ); 30 Cost & incVar( int inc = 1 );31 Cost & decSpec( int inc = 1 );32 29 Cost & incReference( int inc = 1 ); 33 30 … … 35 32 int get_polyCost() const { return polyCost; } 36 33 int get_safeCost() const { return safeCost; } 37 int get_varCost() const { return varCost; }38 int get_specCost() const { return specCost; }39 34 int get_referenceCost() const { return referenceCost; } 40 35 … … 46 41 bool operator!=( const Cost &other ) const; 47 42 friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); 48 // returns negative for *this < other, 0 for *this == other, positive for *this > other49 int compare( const Cost &other ) const;50 43 51 44 static const Cost zero; … … 55 48 static const Cost poly; 56 49 static const Cost safe; 57 static const Cost var;58 static const Cost spec;59 50 static const Cost reference; 51 private: 52 int compare( const Cost &other ) const; 60 53 61 private: 62 int unsafeCost; ///< Unsafe (narrowing) conversions 63 int polyCost; ///< Count of parameters and return values bound to some poly type 64 int safeCost; ///< Safe (widening) conversions 65 int varCost; ///< Count of polymorphic type variables 66 int specCost; ///< Polymorphic type specializations (type assertions), negative cost 67 int referenceCost; ///< reference conversions 54 int unsafeCost; 55 int polyCost; 56 int safeCost; 57 int referenceCost; 68 58 }; 69 59 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 ) {} 60 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {} 74 61 75 62 inline Cost & Cost::incUnsafe( int inc ) { … … 91 78 } 92 79 93 inline Cost & Cost::incVar( int inc ) {94 if ( *this == infinity ) return *this;95 varCost += inc;96 return *this;97 }98 99 inline Cost& Cost::decSpec( int dec ) {100 if ( *this == infinity ) return *this;101 specCost -= dec;102 return *this;103 }104 105 80 inline Cost & Cost::incReference( int inc ) { 106 81 if ( *this == infinity ) return *this; … … 111 86 inline Cost Cost::operator+( const Cost &other ) const { 112 87 if ( *this == infinity || other == infinity ) return infinity; 113 return Cost{ 114 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 115 varCost + other.varCost, specCost + other.specCost, 116 referenceCost + other.referenceCost }; 88 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost ); 117 89 } 118 90 119 91 inline Cost Cost::operator-( const Cost &other ) const { 120 92 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 }; 93 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost ); 125 94 } 126 95 … … 134 103 polyCost += other.polyCost; 135 104 safeCost += other.safeCost; 136 varCost += other.varCost;137 specCost += other.specCost;138 105 referenceCost += other.referenceCost; 139 106 return *this; … … 156 123 } else if ( safeCost < other.safeCost ) { 157 124 return true; 158 } else if ( varCost > other.varCost ) {159 return false;160 } else if ( varCost < other.varCost ) {161 return true;162 } else if ( specCost > other.specCost ) {163 return false;164 } else if ( specCost > other.specCost ) {165 return true;166 125 } else if ( referenceCost > other.referenceCost ) { 167 126 return false; … … 173 132 } 174 133 175 inline int Cost::compare( const Cost &other ) const {176 if ( *this == infinity ) return +1;177 if ( other == infinity ) return -1;178 179 int c = unsafeCost - other.unsafeCost; if ( c ) return c;180 c = polyCost - other.polyCost; if ( c ) return c;181 c = safeCost - other.safeCost; if ( c ) return c;182 c = varCost - other.varCost; if ( c ) return c;183 c = specCost - other.specCost; if ( c ) return c;184 return referenceCost - other.referenceCost;185 }186 187 134 inline bool Cost::operator==( const Cost &other ) const { 188 135 return unsafeCost == other.unsafeCost 189 136 && polyCost == other.polyCost 190 137 && safeCost == other.safeCost 191 && varCost == other.varCost192 && specCost == other.specCost193 138 && referenceCost == other.referenceCost; 194 139 } … … 199 144 200 145 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 201 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 202 << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", " 203 << cost.referenceCost << " )"; 146 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )"; 147 return os; 204 148 } 205 149 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.