[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 | //
|
---|
[906e24d] | 7 | // Alternative.cc --
|
---|
[a32b204] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Sat May 16 23:44:23 2015
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Sat May 16 23:54:23 2015
|
---|
| 13 | // Update Count : 2
|
---|
[906e24d] | 14 | //
|
---|
[a32b204] | 15 |
|
---|
[51b73452] | 16 | #include "Alternative.h"
|
---|
| 17 | #include "SynTree/Type.h"
|
---|
| 18 | #include "SynTree/Expression.h"
|
---|
[d3b7937] | 19 | #include "Common/utility.h"
|
---|
[51b73452] | 20 |
|
---|
| 21 | namespace ResolvExpr {
|
---|
[3c13c03] | 22 | Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
|
---|
[a32b204] | 23 |
|
---|
| 24 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
|
---|
| 25 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {}
|
---|
| 26 |
|
---|
| 27 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
|
---|
| 28 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
|
---|
| 29 |
|
---|
[89be1c68] | 30 | Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
|
---|
[a32b204] | 31 | }
|
---|
| 32 |
|
---|
| 33 | Alternative &Alternative::operator=( const Alternative &other ) {
|
---|
| 34 | if ( &other == this ) return *this;
|
---|
[89be1c68] | 35 | delete expr;
|
---|
| 36 | cost = other.cost;
|
---|
| 37 | cvtCost = other.cvtCost;
|
---|
| 38 | expr = maybeClone( other.expr );
|
---|
| 39 | env = other.env;
|
---|
[a32b204] | 40 | return *this;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[aefcc3b] | 43 | Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
|
---|
| 44 | other.expr = nullptr;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | Alternative & Alternative::operator=( Alternative && other ) {
|
---|
| 48 | if ( &other == this ) return *this;
|
---|
| 49 | delete expr;
|
---|
| 50 | cost = other.cost;
|
---|
| 51 | cvtCost = other.cvtCost;
|
---|
| 52 | expr = other.expr;
|
---|
| 53 | env = other.env;
|
---|
| 54 | other.expr = nullptr;
|
---|
| 55 | return *this;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[a32b204] | 58 | Alternative::~Alternative() {
|
---|
| 59 | delete expr;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void Alternative::print( std::ostream &os, int indent ) const {
|
---|
| 63 | os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
|
---|
| 64 | if ( expr ) {
|
---|
| 65 | expr->print( os, indent );
|
---|
| 66 | os << "(types:" << std::endl;
|
---|
[906e24d] | 67 | os << std::string( indent+4, ' ' );
|
---|
| 68 | expr->get_result()->print( os, indent + 4 );
|
---|
| 69 | os << std::endl << ")" << std::endl;
|
---|
[a32b204] | 70 | } else {
|
---|
| 71 | os << "Null expression!" << std::endl;
|
---|
| 72 | } // if
|
---|
| 73 | os << std::string( indent, ' ' ) << "Environment: ";
|
---|
| 74 | env.print( os, indent+2 );
|
---|
| 75 | os << std::endl;
|
---|
[d9a0e76] | 76 | }
|
---|
[51b73452] | 77 | } // namespace ResolvExpr
|
---|
[a32b204] | 78 |
|
---|
| 79 | // Local Variables: //
|
---|
| 80 | // tab-width: 4 //
|
---|
| 81 | // mode: c++ //
|
---|
| 82 | // compile-command: "make install" //
|
---|
| 83 | // End: //
|
---|