Ignore:
Timestamp:
Mar 12, 2019, 3:00:54 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
30e32b2, a2545593
Parents:
9d9a451 (diff), 91d6584 (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 second draft of Aaron's thesis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Cost.h

    r9d9a451 r53bb8f1  
    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 : Thu Feb  7 20:54:29 2019
     13// Update Count     : 8
    1414//
    1515
     
    2121        class Cost {
    2222          private:
    23                 Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost,
    24                         int referenceCost );
    25 
     23                Cost( int unsafeCost, int polyCost, int safeCost, int signCost,
     24                        int varCost, int specCost, int referenceCost );
    2625          public:
    2726                Cost & incUnsafe( int inc = 1 );
    2827                Cost & incPoly( int inc = 1 );
    2928                Cost & incSafe( int inc = 1 );
     29                Cost & incSign( int inc = 1 );
    3030                Cost & incVar( int inc = 1 );
    3131                Cost & decSpec( int inc = 1 );
     
    3535                int get_polyCost() const { return polyCost; }
    3636                int get_safeCost() const { return safeCost; }
     37                int get_signCost() const { return signCost; }
    3738                int get_varCost() const { return varCost; }
    3839                int get_specCost() const { return specCost; }
     
    4041
    4142                Cost operator+( const Cost &other ) const;
    42                 Cost operator-( const Cost &other ) const;
    4343                Cost &operator+=( const Cost &other );
    4444                bool operator<( const Cost &other ) const;
     
    5555                static const Cost poly;
    5656                static const Cost safe;
     57                static const Cost sign;
    5758                static const Cost var;
    5859                static const Cost spec;
     
    6364                int polyCost;       ///< Count of parameters and return values bound to some poly type
    6465                int safeCost;       ///< Safe (widening) conversions
     66                int signCost;       ///< Count of safe sign conversions
    6567                int varCost;        ///< Count of polymorphic type variables
    6668                int specCost;       ///< Polymorphic type specializations (type assertions), negative cost
     
    6870        };
    6971
    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 ) {}
     72        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int signCost,
     73                        int varCost, int specCost, int referenceCost )
     74                : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), signCost( signCost ),
     75                  varCost( varCost ), specCost( specCost ), referenceCost( referenceCost ) {}
    7476
    7577        inline Cost & Cost::incUnsafe( int inc ) {
     
    8890                if ( *this == infinity ) return *this;
    8991                safeCost += inc;
     92                return *this;
     93        }
     94
     95        inline Cost & Cost::incSign( int inc ) {
     96                if ( *this == infinity ) return *this;
     97                signCost += inc;
    9098                return *this;
    9199        }
     
    111119        inline Cost Cost::operator+( const Cost &other ) const {
    112120                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,
     121                return Cost{
     122                        unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost,
     123                        signCost + other.signCost, varCost + other.varCost, specCost + other.specCost,
    116124                        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 };
    125125        }
    126126
     
    134134                polyCost += other.polyCost;
    135135                safeCost += other.safeCost;
     136                signCost += other.signCost;
    136137                varCost += other.varCost;
    137138                specCost += other.specCost;
     
    156157                } else if ( safeCost < other.safeCost ) {
    157158                        return true;
     159                } else if ( signCost > other.signCost ) {
     160                        return false;
     161                } else if ( signCost < other.signCost ) {
     162                        return true;
    158163                } else if ( varCost > other.varCost ) {
    159164                        return false;
     
    180185                c = polyCost - other.polyCost; if ( c ) return c;
    181186                c = safeCost - other.safeCost; if ( c ) return c;
     187                c = signCost - other.signCost; if ( c ) return c;
    182188                c = varCost - other.varCost; if ( c ) return c;
    183189                c = specCost - other.specCost; if ( c ) return c;
     
    189195                        && polyCost == other.polyCost
    190196                        && safeCost == other.safeCost
     197                        && signCost == other.signCost
    191198                        && varCost == other.varCost
    192199                        && specCost == other.specCost
     
    199206
    200207        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
    201                 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", "
    202                           << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", "
     208                return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", "
     209                          << cost.safeCost << ", " << cost.signCost << ", "
     210                                  << cost.varCost << ", " << cost.specCost << ", "
    203211                          << cost.referenceCost << " )";
    204212        }
Note: See TracChangeset for help on using the changeset viewer.