Ignore:
Timestamp:
Sep 10, 2016, 12:53:36 PM (8 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:
908cc83
Parents:
add7117
Message:

major refactoring of Rodolfo's tuple assignment code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleAssignment.h

    radd7117 r5af62f1  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleAssignment.h -- 
     7// TupleAssignment.h --
    88//
    99// Author           : Rodolfo G. Esteves
     
    2626
    2727namespace Tuples {
    28         class TupleAssignSpotter {
    29           public:
    30                 // dispatcher for Tuple (multiple and mass) assignment operations
    31                 TupleAssignSpotter( ResolvExpr::AlternativeFinder * );
    32                 ~TupleAssignSpotter() { delete matcher; matcher = 0; }
    33 
    34                 bool pointsToTuple( Expression * );
    35                 static bool isTupleVar( DeclarationWithType * );
    36                 bool isTuple( Expression *, bool isRight = false );
    37                 bool isMVR( Expression * );
    38                 bool isTupleAssignment( UntypedExpr *, std::list<ResolvExpr::AltList> & );
    39                 bool match();
    40           private:
    41                 // records for assignment generation
    42                 class Options {
    43                   public:
    44                         void add_option( ResolvExpr::AltList &opt );
    45                         std::list< ResolvExpr::AltList > get_best();
    46                         void print( std::ostream & );
    47                         int size() const { return options.size(); }
    48                         ResolvExpr::AltList get_option( std::list< ResolvExpr::AltList >::size_type index );
    49 
    50                         // should really use the one in ResolvExpr/AlternativeFinder, but it's too coupled with the object
    51                         template< typename InputIterator, typename OutputIterator >
    52                         void findMinCost( InputIterator begin, InputIterator end, OutputIterator out );
    53 
    54                         template< typename InputIterator, typename OutputIterator >
    55                         void lift_intersection( InputIterator begin, InputIterator end, OutputIterator out );
    56                   private:
    57                         std::list< ResolvExpr::AltList > options;
    58                         std::vector< std::vector< ResolvExpr::Cost > > costMatrix;
    59                 };
    60 
    61                 class Matcher {
    62                   public:
    63                         Matcher( /*TupleAssignSpotter &spot, */Expression *_lhs, Expression *_rhs );
    64                         virtual ~Matcher() {}
    65                         virtual bool match( std::list< Expression * > &out ) = 0;
    66                         virtual bool solve( std::list< Expression * > &assigns ) = 0;
    67                         static UntypedExpr *createAssgn( Expression *left, Expression *right );
    68                   protected:
    69                         Matcher() /*: own_spotter( TupleAssignSpotter(0) ) */{}
    70                         void init(/* TupleAssignSpotter &, */Expression *_lhs, Expression *_rhs );
    71                         std::list< Expression * > lhs, rhs;
    72                         //TupleAssignSpotter &own_spotter;
    73                 };
    74 
    75                 class MassAssignMatcher : public Matcher {
    76                   public:
    77                         MassAssignMatcher( Expression *_lhs, Expression *_rhs ) : Matcher( _lhs, _rhs ) {
    78                                 rhs.push_back( _rhs );
    79                         }
    80                         virtual bool match( std::list< Expression * > &out );
    81                         virtual bool solve( std::list< Expression * > &assigns );
    82                   private:
    83                         //std::vector< ResolvExpr::AltList > optMass;
    84                 };
    85 
    86                 class MultipleAssignMatcher : public Matcher {
    87                   public:
    88                         MultipleAssignMatcher( Expression *_lhs, Expression *_rhs );
    89                         virtual bool match( std::list< Expression * > &out );
    90                         virtual bool solve( std::list< Expression * > &assigns );
    91                   private:
    92                         //Options options;
    93                 };
    94 
    95                 friend class Matcher;
    96 
    97                 ResolvExpr::AlternativeFinder *currentFinder;
    98                 //std::list<Expression *> rhs, lhs;
    99                 Expression *rhs, *lhs;
    100                 Matcher *matcher;
    101                 bool hasMatched;
    102                 Options options;
    103                 std::vector< ResolvExpr::AltList > optMass;
    104         };
    105 
    106         ResolvExpr::Cost extract_cost( ResolvExpr::Alternative & );
    107 
    108         template< typename InputIterator, typename OutputIterator >
    109         void findMinCostAlt( InputIterator begin, InputIterator end, OutputIterator out ) {
    110                 using namespace ResolvExpr;
    111                 AltList alternatives;
    112 
    113                 // select the alternatives that have the minimum parameter cost
    114                 Cost minCost = Cost::infinity;
    115                 for ( AltList::iterator i = begin; i != end; ++i ) {
    116                         if ( i->cost < minCost ) {
    117                                 minCost = i->cost;
    118                                 i->cost = i->cvtCost;
    119                                 alternatives.clear();
    120                                 alternatives.push_back( *i );
    121                         } else if ( i->cost == minCost ) {
    122                                 i->cost = i->cvtCost;
    123                                 alternatives.push_back( *i );
    124                         }
    125                 }
    126                 std::copy( alternatives.begin(), alternatives.end(), out );
    127         }
     28        void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * assign, std::list<ResolvExpr::AltList> & possibilities );
    12829} // namespace Tuples
    12930
Note: See TracChangeset for help on using the changeset viewer.