Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Cost.h

    rd97c3a4 rddf8a29  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 09:39:50 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Fri Oct 05 14:32:00 2018
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:35:55 2017
     13// Update Count     : 5
    1414//
    1515
     
    2121        class Cost {
    2222          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 );
    2524
    2625          public:
     
    2827                Cost & incPoly( int inc = 1 );
    2928                Cost & incSafe( int inc = 1 );
    30                 Cost & incVar( int inc = 1 );
    31                 Cost & decSpec( int inc = 1 );
    3229                Cost & incReference( int inc = 1 );
    3330
     
    3532                int get_polyCost() const { return polyCost; }
    3633                int get_safeCost() const { return safeCost; }
    37                 int get_varCost() const { return varCost; }
    38                 int get_specCost() const { return specCost; }
    3934                int get_referenceCost() const { return referenceCost; }
    4035
     
    4641                bool operator!=( const Cost &other ) const;
    4742                friend std::ostream &operator<<( std::ostream &os, const Cost &cost );
    48                 // returns negative for *this < other, 0 for *this == other, positive for *this > other
    49                 int compare( const Cost &other ) const;
    5043
    5144                static const Cost zero;
     
    5548                static const Cost poly;
    5649                static const Cost safe;
    57                 static const Cost var;
    58                 static const Cost spec;
    5950                static const Cost reference;
     51          private:
     52                int compare( const Cost &other ) const;
    6053
    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;
    6858        };
    6959
    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 ) {}
    7461
    7562        inline Cost & Cost::incUnsafe( int inc ) {
     
    9178        }
    9279
    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 
    10580        inline Cost & Cost::incReference( int inc ) {
    10681                if ( *this == infinity ) return *this;
     
    11186        inline Cost Cost::operator+( const Cost &other ) const {
    11287                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 );
    11789        }
    11890
    11991        inline Cost Cost::operator-( const Cost &other ) const {
    12092                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 );
    12594        }
    12695
     
    134103                polyCost += other.polyCost;
    135104                safeCost += other.safeCost;
    136                 varCost += other.varCost;
    137                 specCost += other.specCost;
    138105                referenceCost += other.referenceCost;
    139106                return *this;
     
    156123                } else if ( safeCost < other.safeCost ) {
    157124                        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;
    166125                } else if ( referenceCost > other.referenceCost ) {
    167126                        return false;
     
    173132        }
    174133
    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 
    187134        inline bool Cost::operator==( const Cost &other ) const {
    188135                return unsafeCost == other.unsafeCost
    189136                        && polyCost == other.polyCost
    190137                        && safeCost == other.safeCost
    191                         && varCost == other.varCost
    192                         && specCost == other.specCost
    193138                        && referenceCost == other.referenceCost;
    194139        }
     
    199144
    200145        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;
    204148        }
    205149} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.