| [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" | 
|---|
| [ea6332d] | 17 |  | 
|---|
|  | 18 | #include <ostream>                       // for operator<<, ostream, basic_o... | 
|---|
|  | 19 | #include <string>                        // for operator<<, char_traits, string | 
|---|
| [bd4f2e9] | 20 | #include <utility>                       // for move | 
|---|
| [ea6332d] | 21 |  | 
|---|
|  | 22 | #include "Common/utility.h"              // for maybeClone | 
|---|
|  | 23 | #include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<< | 
|---|
|  | 24 | #include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment | 
|---|
|  | 25 | #include "SynTree/Expression.h"          // for Expression | 
|---|
|  | 26 | #include "SynTree/Type.h"                // for Type | 
|---|
| [51b73452] | 27 |  | 
|---|
|  | 28 | namespace ResolvExpr { | 
|---|
| [3c13c03] | 29 | Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {} | 
|---|
| [a32b204] | 30 |  | 
|---|
|  | 31 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) | 
|---|
|  | 32 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {} | 
|---|
|  | 33 |  | 
|---|
|  | 34 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) | 
|---|
|  | 35 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {} | 
|---|
|  | 36 |  | 
|---|
| [89be1c68] | 37 | Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) { | 
|---|
| [a32b204] | 38 | } | 
|---|
|  | 39 |  | 
|---|
|  | 40 | Alternative &Alternative::operator=( const Alternative &other ) { | 
|---|
|  | 41 | if ( &other == this ) return *this; | 
|---|
| [89be1c68] | 42 | delete expr; | 
|---|
|  | 43 | cost = other.cost; | 
|---|
|  | 44 | cvtCost = other.cvtCost; | 
|---|
|  | 45 | expr = maybeClone( other.expr ); | 
|---|
|  | 46 | env = other.env; | 
|---|
| [a32b204] | 47 | return *this; | 
|---|
|  | 48 | } | 
|---|
|  | 49 |  | 
|---|
| [aefcc3b] | 50 | Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) { | 
|---|
|  | 51 | other.expr = nullptr; | 
|---|
|  | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | Alternative & Alternative::operator=( Alternative && other ) { | 
|---|
|  | 55 | if ( &other == this )  return *this; | 
|---|
|  | 56 | delete expr; | 
|---|
|  | 57 | cost = other.cost; | 
|---|
|  | 58 | cvtCost = other.cvtCost; | 
|---|
|  | 59 | expr = other.expr; | 
|---|
|  | 60 | env = other.env; | 
|---|
|  | 61 | other.expr = nullptr; | 
|---|
|  | 62 | return *this; | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
| [a32b204] | 65 | Alternative::~Alternative() { | 
|---|
|  | 66 | delete expr; | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
| [50377a4] | 69 | void Alternative::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 70 | os << "Cost " << cost << ": "; | 
|---|
| [a32b204] | 71 | if ( expr ) { | 
|---|
| [50377a4] | 72 | expr->print( os, indent+1 ); | 
|---|
|  | 73 | os << std::endl << indent << "(types:" << std::endl; | 
|---|
|  | 74 | os << indent+1; | 
|---|
|  | 75 | expr->result->print( os, indent+1 ); | 
|---|
|  | 76 | os << std::endl << indent << ")" << std::endl; | 
|---|
| [a32b204] | 77 | } else { | 
|---|
|  | 78 | os << "Null expression!" << std::endl; | 
|---|
|  | 79 | } // if | 
|---|
| [50377a4] | 80 | os << indent << "Environment: "; | 
|---|
|  | 81 | env.print( os, indent+1 ); | 
|---|
| [a32b204] | 82 | os << std::endl; | 
|---|
| [d9a0e76] | 83 | } | 
|---|
| [bd4f2e9] | 84 |  | 
|---|
|  | 85 | void splice( AltList& dst, AltList& src ) { | 
|---|
|  | 86 | dst.reserve( dst.size() + src.size() ); | 
|---|
|  | 87 | for ( Alternative& alt : src ) { | 
|---|
|  | 88 | dst.push_back( std::move(alt) ); | 
|---|
|  | 89 | } | 
|---|
|  | 90 | src.clear(); | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | void spliceBegin( AltList& dst, AltList& src ) { | 
|---|
|  | 94 | splice( src, dst ); | 
|---|
|  | 95 | dst.swap( src ); | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
| [51b73452] | 98 | } // namespace ResolvExpr | 
|---|
| [a32b204] | 99 |  | 
|---|
|  | 100 | // Local Variables: // | 
|---|
|  | 101 | // tab-width: 4 // | 
|---|
|  | 102 | // mode: c++ // | 
|---|
|  | 103 | // compile-command: "make install" // | 
|---|
|  | 104 | // End: // | 
|---|