Changeset d97c3a4 for src/ResolvExpr
- Timestamp:
- Jan 11, 2019, 2:16:53 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 52ffa30
- Parents:
- e99e43f
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
re99e43f rd97c3a4 1229 1229 Alternative newAlt{ 1230 1230 restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), 1231 alt.env, openVars, needAssertions, alt.cost , thisCost };1231 alt.env, openVars, needAssertions, alt.cost + thisCost, thisCost }; 1232 1232 inferParameters( newAlt, back_inserter( candidates ) ); 1233 1233 } // if -
src/ResolvExpr/ConversionCost.cc
re99e43f rd97c3a4 29 29 namespace ResolvExpr { 30 30 const Cost Cost::zero = Cost{ 0, 0, 0, 0, 0, 0 }; 31 const Cost Cost::infinity = Cost{ -1, -1, -1, 1, -1, -1 };31 const Cost Cost::infinity = Cost{ -1, -1, -1, -1, 1, -1 }; 32 32 const Cost Cost::unsafe = Cost{ 1, 0, 0, 0, 0, 0 }; 33 33 const Cost Cost::poly = Cost{ 0, 1, 0, 0, 0, 0 }; 34 const Cost Cost:: var =Cost{ 0, 0, 1, 0, 0, 0 };35 const Cost Cost:: spec = Cost{ 0, 0, 0, -1, 0, 0 };36 const Cost Cost::s afe = Cost{ 0, 0, 0, 0,1, 0 };34 const Cost Cost::safe = Cost{ 0, 0, 1, 0, 0, 0 }; 35 const Cost Cost::var = Cost{ 0, 0, 0, 1, 0, 0 }; 36 const Cost Cost::spec = Cost{ 0, 0, 0, 0, -1, 0 }; 37 37 const Cost Cost::reference = Cost{ 0, 0, 0, 0, 0, 1 }; 38 38 -
src/ResolvExpr/Cost.h
re99e43f rd97c3a4 21 21 class Cost { 22 22 private: 23 Cost( int unsafeCost, int polyCost, int varCost, int specCost, int safeCost,24 23 Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost, 24 int referenceCost ); 25 25 26 26 public: 27 27 Cost & incUnsafe( int inc = 1 ); 28 28 Cost & incPoly( int inc = 1 ); 29 Cost & incSafe( int inc = 1 ); 29 30 Cost & incVar( int inc = 1 ); 30 31 Cost & decSpec( int inc = 1 ); 31 Cost & incSafe( int inc = 1 );32 32 Cost & incReference( int inc = 1 ); 33 33 34 34 int get_unsafeCost() const { return unsafeCost; } 35 35 int get_polyCost() const { return polyCost; } 36 int get_safeCost() const { return safeCost; } 36 37 int get_varCost() const { return varCost; } 37 38 int get_specCost() const { return specCost; } 38 int get_safeCost() const { return safeCost; }39 39 int get_referenceCost() const { return referenceCost; } 40 40 … … 54 54 static const Cost unsafe; 55 55 static const Cost poly; 56 static const Cost safe; 56 57 static const Cost var; 57 58 static const Cost spec; 58 static const Cost safe;59 59 static const Cost reference; 60 60 … … 62 62 int unsafeCost; ///< Unsafe (narrowing) conversions 63 63 int polyCost; ///< Count of parameters and return values bound to some poly type 64 int safeCost; ///< Safe (widening) conversions 64 65 int varCost; ///< Count of polymorphic type variables 65 66 int specCost; ///< Polymorphic type specializations (type assertions), negative cost 66 int safeCost; ///< Safe (widening) conversions67 67 int referenceCost; ///< reference conversions 68 68 }; 69 69 70 inline Cost::Cost( int unsafeCost, int polyCost, int varCost, int specCost, int safeCost,70 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost, 71 71 int referenceCost ) 72 : unsafeCost( unsafeCost ), polyCost( polyCost ), varCost( varCost ), specCost( specCost ),73 s afeCost( safeCost ), referenceCost( referenceCost ) {}72 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), varCost( varCost ), 73 specCost( specCost ), referenceCost( referenceCost ) {} 74 74 75 75 inline Cost & Cost::incUnsafe( int inc ) { … … 85 85 } 86 86 87 inline Cost & Cost::incSafe( int inc ) { 88 if ( *this == infinity ) return *this; 89 safeCost += inc; 90 return *this; 91 } 92 87 93 inline Cost & Cost::incVar( int inc ) { 88 94 if ( *this == infinity ) return *this; … … 94 100 if ( *this == infinity ) return *this; 95 101 specCost -= dec; 96 return *this;97 }98 99 inline Cost & Cost::incSafe( int inc ) {100 if ( *this == infinity ) return *this;101 safeCost += inc;102 102 return *this; 103 103 } … … 112 112 if ( *this == infinity || other == infinity ) return infinity; 113 113 return Cost{ 114 unsafeCost + other.unsafeCost, polyCost + other.polyCost, 114 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 115 115 varCost + other.varCost, specCost + other.specCost, 116 safeCost + other.safeCost,referenceCost + other.referenceCost };116 referenceCost + other.referenceCost }; 117 117 } 118 118 … … 120 120 if ( *this == infinity || other == infinity ) return infinity; 121 121 return Cost{ 122 unsafeCost - other.unsafeCost, polyCost - other.polyCost, 122 unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, 123 123 varCost - other.varCost, specCost - other.specCost, 124 safeCost - other.safeCost,referenceCost - other.referenceCost };124 referenceCost - other.referenceCost }; 125 125 } 126 126 … … 133 133 unsafeCost += other.unsafeCost; 134 134 polyCost += other.polyCost; 135 safeCost += other.safeCost; 135 136 varCost += other.varCost; 136 137 specCost += other.specCost; 137 safeCost += other.safeCost;138 138 referenceCost += other.referenceCost; 139 139 return *this; … … 152 152 } else if ( polyCost < other.polyCost ) { 153 153 return true; 154 } else if ( safeCost > other.safeCost ) { 155 return false; 156 } else if ( safeCost < other.safeCost ) { 157 return true; 154 158 } else if ( varCost > other.varCost ) { 155 159 return false; … … 159 163 return false; 160 164 } else if ( specCost > other.specCost ) { 161 return true;162 } else if ( safeCost > other.safeCost ) {163 return false;164 } else if ( safeCost < other.safeCost ) {165 165 return true; 166 166 } else if ( referenceCost > other.referenceCost ) { … … 179 179 int c = unsafeCost - other.unsafeCost; if ( c ) return c; 180 180 c = polyCost - other.polyCost; if ( c ) return c; 181 c = safeCost - other.safeCost; if ( c ) return c; 181 182 c = varCost - other.varCost; if ( c ) return c; 182 183 c = specCost - other.specCost; if ( c ) return c; 183 c = safeCost - other.safeCost; if ( c ) return c;184 184 return referenceCost - other.referenceCost; 185 185 } … … 188 188 return unsafeCost == other.unsafeCost 189 189 && polyCost == other.polyCost 190 && safeCost == other.safeCost 190 191 && varCost == other.varCost 191 192 && specCost == other.specCost 192 && safeCost == other.safeCost193 193 && referenceCost == other.referenceCost; 194 194 } … … 200 200 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 201 201 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 202 << cost. varCost << ", " << cost.specCost << ", "203 << cost. safeCost << ", " << cost.referenceCost << " )";202 << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", " 203 << cost.referenceCost << " )"; 204 204 } 205 205 } // namespace ResolvExpr
Note: See TracChangeset
for help on using the changeset viewer.