[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: Alternative.cc,v 1.6 2005/08/29 20:14:15 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "Alternative.h" |
---|
| 9 | #include "SynTree/Type.h" |
---|
| 10 | #include "SynTree/Expression.h" |
---|
| 11 | #include "utility.h" |
---|
| 12 | |
---|
| 13 | namespace ResolvExpr { |
---|
| 14 | |
---|
| 15 | Alternative::Alternative() |
---|
| 16 | : expr( 0 ) |
---|
| 17 | { |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) |
---|
| 21 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) |
---|
| 22 | { |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) |
---|
| 26 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) |
---|
| 27 | { |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | Alternative::Alternative( const Alternative &other ) |
---|
| 31 | { |
---|
| 32 | initialize( other, *this ); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | Alternative & |
---|
| 36 | Alternative::operator=( const Alternative &other ) |
---|
| 37 | { |
---|
| 38 | if( &other == this ) return *this; |
---|
| 39 | initialize( other, *this ); |
---|
| 40 | return *this; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | void |
---|
| 44 | Alternative::initialize( const Alternative &src, Alternative &dest ) |
---|
| 45 | { |
---|
| 46 | dest.cost = src.cost; |
---|
| 47 | dest.cvtCost = src.cvtCost; |
---|
| 48 | dest.expr = maybeClone( src.expr ); |
---|
| 49 | dest.env = src.env; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | Alternative::~Alternative() |
---|
| 53 | { |
---|
| 54 | delete expr; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void |
---|
| 58 | Alternative::print( std::ostream &os, int indent ) const |
---|
| 59 | { |
---|
| 60 | os << std::string( indent, ' ' ) << "Cost " << cost << ": "; |
---|
| 61 | if( expr ) { |
---|
| 62 | expr->print( os, indent ); |
---|
| 63 | os << "(types:" << std::endl; |
---|
| 64 | printAll( expr->get_results(), os, indent + 4 ); |
---|
| 65 | os << ")" << std::endl; |
---|
| 66 | } else { |
---|
| 67 | os << "Null expression!" << std::endl; |
---|
| 68 | } |
---|
| 69 | os << std::string( indent, ' ' ) << "Environment: "; |
---|
| 70 | env.print( os, indent+2 ); |
---|
| 71 | os << std::endl; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | } // namespace ResolvExpr |
---|