| 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 | #include <utility> // for move
|
|---|
| 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
|
|---|
| 27 |
|
|---|
| 28 | namespace ResolvExpr {
|
|---|
| 29 | Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
|
|---|
| 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 |
|
|---|
| 37 | Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | Alternative &Alternative::operator=( const Alternative &other ) {
|
|---|
| 41 | if ( &other == this ) return *this;
|
|---|
| 42 | delete expr;
|
|---|
| 43 | cost = other.cost;
|
|---|
| 44 | cvtCost = other.cvtCost;
|
|---|
| 45 | expr = maybeClone( other.expr );
|
|---|
| 46 | env = other.env;
|
|---|
| 47 | return *this;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 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 |
|
|---|
| 65 | Alternative::~Alternative() {
|
|---|
| 66 | delete expr;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | void Alternative::print( std::ostream &os, Indenter indent ) const {
|
|---|
| 70 | os << "Cost " << cost << ": ";
|
|---|
| 71 | if ( expr ) {
|
|---|
| 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;
|
|---|
| 77 | } else {
|
|---|
| 78 | os << "Null expression!" << std::endl;
|
|---|
| 79 | } // if
|
|---|
| 80 | os << indent << "Environment: ";
|
|---|
| 81 | env.print( os, indent+1 );
|
|---|
| 82 | os << std::endl;
|
|---|
| 83 | }
|
|---|
| 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 |
|
|---|
| 98 | } // namespace ResolvExpr
|
|---|
| 99 |
|
|---|
| 100 | // Local Variables: //
|
|---|
| 101 | // tab-width: 4 //
|
|---|
| 102 | // mode: c++ //
|
|---|
| 103 | // compile-command: "make install" //
|
|---|
| 104 | // End: //
|
|---|