| 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 | // | 
|---|
| 7 | // Alternative.cc -- | 
|---|
| 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 | 
|---|
| 14 | // | 
|---|
| 15 |  | 
|---|
| 16 | #include "Alternative.h" | 
|---|
| 17 |  | 
|---|
| 18 | #include <ostream>                       // for operator<<, ostream, basic_o... | 
|---|
| 19 | #include <string>                        // for operator<<, char_traits, string | 
|---|
| 20 |  | 
|---|
| 21 | #include "Common/utility.h"              // for maybeClone | 
|---|
| 22 | #include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<< | 
|---|
| 23 | #include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment | 
|---|
| 24 | #include "SynTree/Expression.h"          // for Expression | 
|---|
| 25 | #include "SynTree/Type.h"                // for Type | 
|---|
| 26 |  | 
|---|
| 27 | namespace ResolvExpr { | 
|---|
| 28 | Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {} | 
|---|
| 29 |  | 
|---|
| 30 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) | 
|---|
| 31 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {} | 
|---|
| 32 |  | 
|---|
| 33 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) | 
|---|
| 34 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {} | 
|---|
| 35 |  | 
|---|
| 36 | Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) { | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | Alternative &Alternative::operator=( const Alternative &other ) { | 
|---|
| 40 | if ( &other == this ) return *this; | 
|---|
| 41 | delete expr; | 
|---|
| 42 | cost = other.cost; | 
|---|
| 43 | cvtCost = other.cvtCost; | 
|---|
| 44 | expr = maybeClone( other.expr ); | 
|---|
| 45 | env = other.env; | 
|---|
| 46 | return *this; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) { | 
|---|
| 50 | other.expr = nullptr; | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | Alternative & Alternative::operator=( Alternative && other ) { | 
|---|
| 54 | if ( &other == this )  return *this; | 
|---|
| 55 | delete expr; | 
|---|
| 56 | cost = other.cost; | 
|---|
| 57 | cvtCost = other.cvtCost; | 
|---|
| 58 | expr = other.expr; | 
|---|
| 59 | env = other.env; | 
|---|
| 60 | other.expr = nullptr; | 
|---|
| 61 | return *this; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | Alternative::~Alternative() { | 
|---|
| 65 | delete expr; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | void Alternative::print( std::ostream &os, int indent ) const { | 
|---|
| 69 | os << std::string( indent, ' ' ) << "Cost " << cost << ": "; | 
|---|
| 70 | if ( expr ) { | 
|---|
| 71 | expr->print( os, indent ); | 
|---|
| 72 | os << "(types:" << std::endl; | 
|---|
| 73 | os << std::string( indent+4, ' ' ); | 
|---|
| 74 | expr->get_result()->print( os, indent + 4 ); | 
|---|
| 75 | os << std::endl << ")" << std::endl; | 
|---|
| 76 | } else { | 
|---|
| 77 | os << "Null expression!" << std::endl; | 
|---|
| 78 | } // if | 
|---|
| 79 | os << std::string( indent, ' ' ) << "Environment: "; | 
|---|
| 80 | env.print( os, indent+2 ); | 
|---|
| 81 | os << std::endl; | 
|---|
| 82 | } | 
|---|
| 83 | } // namespace ResolvExpr | 
|---|
| 84 |  | 
|---|
| 85 | // Local Variables: // | 
|---|
| 86 | // tab-width: 4 // | 
|---|
| 87 | // mode: c++ // | 
|---|
| 88 | // compile-command: "make install" // | 
|---|
| 89 | // End: // | 
|---|