Ignore:
Timestamp:
Jul 17, 2017, 3:05:57 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e6cee92
Parents:
89be1c68
git-author:
Rob Schluntz <rschlunt@…> (07/17/17 14:58:13)
git-committer:
Rob Schluntz <rschlunt@…> (07/17/17 15:05:57)
Message:

Add reference cost field to cost tuple

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Cost.h

    r89be1c68 r7ebaa56  
    2222        class Cost {
    2323          private:
    24                 Cost( int unsafeCost, int polyCost, int safeCost );
     24                Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );
    2525
    2626          public:
     
    2828                Cost & incPoly( int inc = 1 );
    2929                Cost & incSafe( int inc = 1 );
     30                Cost & incReference( int inc = 1 );
    3031
    3132                Cost operator+( const Cost &other ) const;
     
    3940                static const Cost zero;
    4041                static const Cost infinity;
     42
    4143                static const Cost unsafe;
    4244                static const Cost poly;
    4345                static const Cost safe;
     46                static const Cost reference;
    4447          private:
    4548                int compare( const Cost &other ) const;
     
    4851                int polyCost;
    4952                int safeCost;
     53                int referenceCost;
    5054        };
    5155
    52         inline Cost::Cost( int unsafeCost, int polyCost, int safeCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ) {}
     56        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {}
    5357
    5458        inline Cost & Cost::incUnsafe( int inc ) {
     
    6771        }
    6872
     73        inline Cost & Cost::incReference( int inc ) {
     74                referenceCost += inc;
     75                return *this;
     76        }
     77
    6978        inline Cost Cost::operator+( const Cost &other ) const {
    70                 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost );
     79                return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost );
    7180        }
    7281
    7382        inline Cost Cost::operator-( const Cost &other ) const {
    74                 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost );
     83                return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost );
    7584        }
    7685
     
    7988                polyCost += other.polyCost;
    8089                safeCost += other.safeCost;
     90                referenceCost += other.referenceCost;
    8191                return *this;
    8292        }
     
    98108                } else if ( safeCost < other.safeCost ) {
    99109                        return true;
     110                } else if ( referenceCost > other.referenceCost ) {
     111                        return false;
     112                } else if ( referenceCost < other.referenceCost ) {
     113                        return true;
    100114                } else {
    101115                        return false;
     
    106120                return unsafeCost == other.unsafeCost
    107121                        && polyCost == other.polyCost
    108                         && safeCost == other.safeCost;
     122                        && safeCost == other.safeCost
     123                        && referenceCost == other.referenceCost;
    109124        }
    110125
     
    114129
    115130        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
    116                 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << " )";
     131                os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )";
    117132                return os;
    118133        }
Note: See TracChangeset for help on using the changeset viewer.