Ignore:
Timestamp:
Jan 14, 2019, 3:38:28 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
fd73248
Parents:
07ec1a2 (diff), 52ffa30 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Cost.h

    r07ec1a2 r276a55b2  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 09:39:50 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:35:55 2017
    13 // Update Count     : 5
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Fri Oct 05 14:32:00 2018
     13// Update Count     : 7
    1414//
    1515
     
    2121        class Cost {
    2222          private:
    23                 Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );
     23                Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost,
     24                        int referenceCost );
    2425
    2526          public:
     
    2728                Cost & incPoly( int inc = 1 );
    2829                Cost & incSafe( int inc = 1 );
     30                Cost & incVar( int inc = 1 );
     31                Cost & decSpec( int inc = 1 );
    2932                Cost & incReference( int inc = 1 );
    3033
     
    3235                int get_polyCost() const { return polyCost; }
    3336                int get_safeCost() const { return safeCost; }
     37                int get_varCost() const { return varCost; }
     38                int get_specCost() const { return specCost; }
    3439                int get_referenceCost() const { return referenceCost; }
    3540
     
    4146                bool operator!=( const Cost &other ) const;
    4247                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;
    4350
    4451                static const Cost zero;
     
    4855                static const Cost poly;
    4956                static const Cost safe;
     57                static const Cost var;
     58                static const Cost spec;
    5059                static const Cost reference;
     60
    5161          private:
    52                 int compare( const Cost &other ) const;
    53 
    54                 int unsafeCost;
    55                 int polyCost;
    56                 int safeCost;
    57                 int referenceCost;
     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
    5868        };
    5969
    60         inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {}
     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 ) {}
    6174
    6275        inline Cost & Cost::incUnsafe( int inc ) {
     
    7588                if ( *this == infinity ) return *this;
    7689                safeCost += inc;
     90                return *this;
     91        }
     92
     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;
    77102                return *this;
    78103        }
     
    86111        inline Cost Cost::operator+( const Cost &other ) const {
    87112                if ( *this == infinity || other == infinity ) return infinity;
    88                 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost );
     113                return Cost{
     114                        unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost,
     115                        varCost + other.varCost, specCost + other.specCost,
     116                        referenceCost + other.referenceCost };
    89117        }
    90118
    91119        inline Cost Cost::operator-( const Cost &other ) const {
    92120                if ( *this == infinity || other == infinity ) return infinity;
    93                 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost );
     121                return Cost{
     122                        unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost,
     123                        varCost - other.varCost, specCost - other.specCost,
     124                        referenceCost - other.referenceCost };
    94125        }
    95126
     
    103134                polyCost += other.polyCost;
    104135                safeCost += other.safeCost;
     136                varCost += other.varCost;
     137                specCost += other.specCost;
    105138                referenceCost += other.referenceCost;
    106139                return *this;
     
    123156                } else if ( safeCost < other.safeCost ) {
    124157                        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;
    125166                } else if ( referenceCost > other.referenceCost ) {
    126167                        return false;
     
    130171                        return false;
    131172                } // if
     173        }
     174
     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;
    132185        }
    133186
     
    136189                        && polyCost == other.polyCost
    137190                        && safeCost == other.safeCost
     191                        && varCost == other.varCost
     192                        && specCost == other.specCost
    138193                        && referenceCost == other.referenceCost;
    139194        }
     
    144199
    145200        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
    146                 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )";
    147                 return os;
     201                return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", "
     202                          << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", "
     203                          << cost.referenceCost << " )";
    148204        }
    149205} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.