[a32b204] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
[3c13c03] | 7 | // Alternative.h --
|
---|
[a32b204] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Sat May 16 23:45:43 2015
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Sat May 16 23:54:39 2015
|
---|
| 13 | // Update Count : 2
|
---|
[3c13c03] | 14 | //
|
---|
[a32b204] | 15 |
|
---|
| 16 | #ifndef ALTERNATIVE_H
|
---|
| 17 | #define ALTERNATIVE_H
|
---|
[51b73452] | 18 |
|
---|
| 19 | #include <list>
|
---|
| 20 | #include "SynTree/SynTree.h"
|
---|
| 21 | #include "Cost.h"
|
---|
| 22 | #include "TypeEnvironment.h"
|
---|
| 23 |
|
---|
| 24 | namespace ResolvExpr {
|
---|
[a32b204] | 25 | struct Alternative;
|
---|
| 26 | typedef std::list< Alternative > AltList;
|
---|
[d9a0e76] | 27 |
|
---|
[a32b204] | 28 | struct Alternative {
|
---|
| 29 | Alternative();
|
---|
| 30 | Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost );
|
---|
| 31 | Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost );
|
---|
| 32 | Alternative( const Alternative &other );
|
---|
| 33 | Alternative &operator=( const Alternative &other );
|
---|
| 34 | ~Alternative();
|
---|
[3c13c03] | 35 |
|
---|
[a32b204] | 36 | void initialize( const Alternative &src, Alternative &dest );
|
---|
[3c13c03] | 37 |
|
---|
[a32b204] | 38 | void print( std::ostream &os, int indent = 0 ) const;
|
---|
[3c13c03] | 39 |
|
---|
[a32b204] | 40 | Cost cost;
|
---|
| 41 | Cost cvtCost;
|
---|
| 42 | Expression *expr;
|
---|
| 43 | TypeEnvironment env;
|
---|
| 44 | };
|
---|
[3c13c03] | 45 |
|
---|
| 46 | /// helper function used by explode
|
---|
| 47 | template< typename OutputIterator >
|
---|
| 48 | void explodeUnique( Expression * expr, const Alternative & alt, OutputIterator out ) {
|
---|
| 49 | Type * res = expr->get_result();
|
---|
| 50 | if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
|
---|
| 51 | if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( alt.expr ) ) {
|
---|
| 52 | for ( Expression * expr : tupleExpr->get_exprs() ) {
|
---|
| 53 | explodeUnique( expr, alt, out );
|
---|
| 54 | }
|
---|
| 55 | } else {
|
---|
| 56 | UniqueExpr * unq = new UniqueExpr( expr->clone() );
|
---|
| 57 | for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
|
---|
| 58 | TupleIndexExpr * idx = new TupleIndexExpr( unq->clone(), i );
|
---|
| 59 | explodeUnique( idx, alt, out );
|
---|
| 60 | delete idx;
|
---|
| 61 | }
|
---|
| 62 | delete unq;
|
---|
| 63 | }
|
---|
| 64 | } else {
|
---|
| 65 | *out++ = Alternative( expr->clone(), alt.env, alt.cost, alt.cvtCost );
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type
|
---|
| 70 | template< typename OutputIterator >
|
---|
| 71 | void explode( Alternative &alt, OutputIterator out ) {
|
---|
| 72 | explodeUnique( alt.expr, alt, out );
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | // explode list of alternatives
|
---|
| 76 | template< typename OutputIterator >
|
---|
| 77 | void explode( AltList & alts, OutputIterator out ) {
|
---|
| 78 | for ( Alternative & alt : alts ) {
|
---|
| 79 | explode( alt, out );
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[51b73452] | 82 | } // namespace ResolvExpr
|
---|
| 83 |
|
---|
[a32b204] | 84 | #endif // ALTERNATIVE_H
|
---|
| 85 |
|
---|
| 86 | // Local Variables: //
|
---|
| 87 | // tab-width: 4 //
|
---|
| 88 | // mode: c++ //
|
---|
| 89 | // compile-command: "make install" //
|
---|
| 90 | // End: //
|
---|