[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 |
|
---|
| 30 | Alternative::Alternative( const Alternative &other ) {
|
---|
| 31 | initialize( other, *this );
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | Alternative &Alternative::operator=( const Alternative &other ) {
|
---|
| 35 | if ( &other == this ) return *this;
|
---|
| 36 | initialize( other, *this );
|
---|
| 37 | return *this;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[aefcc3b] | 40 | Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
|
---|
| 41 | other.expr = nullptr;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | Alternative & Alternative::operator=( Alternative && other ) {
|
---|
| 45 | if ( &other == this ) return *this;
|
---|
| 46 | delete expr;
|
---|
| 47 | cost = other.cost;
|
---|
| 48 | cvtCost = other.cvtCost;
|
---|
| 49 | expr = other.expr;
|
---|
| 50 | env = other.env;
|
---|
| 51 | other.expr = nullptr;
|
---|
| 52 | return *this;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[a32b204] | 55 | void Alternative::initialize( const Alternative &src, Alternative &dest ) {
|
---|
| 56 | dest.cost = src.cost;
|
---|
| 57 | dest.cvtCost = src.cvtCost;
|
---|
| 58 | dest.expr = maybeClone( src.expr );
|
---|
| 59 | dest.env = src.env;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | Alternative::~Alternative() {
|
---|
| 63 | delete expr;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | void Alternative::print( std::ostream &os, int indent ) const {
|
---|
| 67 | os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
|
---|
| 68 | if ( expr ) {
|
---|
| 69 | expr->print( os, indent );
|
---|
| 70 | os << "(types:" << std::endl;
|
---|
[906e24d] | 71 | os << std::string( indent+4, ' ' );
|
---|
| 72 | expr->get_result()->print( os, indent + 4 );
|
---|
| 73 | os << std::endl << ")" << std::endl;
|
---|
[a32b204] | 74 | } else {
|
---|
| 75 | os << "Null expression!" << std::endl;
|
---|
| 76 | } // if
|
---|
| 77 | os << std::string( indent, ' ' ) << "Environment: ";
|
---|
| 78 | env.print( os, indent+2 );
|
---|
| 79 | os << std::endl;
|
---|
[d9a0e76] | 80 | }
|
---|
[51b73452] | 81 | } // namespace ResolvExpr
|
---|
[a32b204] | 82 |
|
---|
| 83 | // Local Variables: //
|
---|
| 84 | // tab-width: 4 //
|
---|
| 85 | // mode: c++ //
|
---|
| 86 | // compile-command: "make install" //
|
---|
| 87 | // End: //
|
---|