[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
|
---|
[6d6e829] | 11 | // Last Modified By : Aaron B. Moss
|
---|
| 12 | // Last Modified On : Thu Oct 11 10:55:00 2018
|
---|
| 13 | // Update Count : 3
|
---|
[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 |
|
---|
[2c187378] | 22 | #include "Common/utility.h" // for cloneAll
|
---|
[ea6332d] | 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 {
|
---|
[6d6e829] | 29 | Alternative::Alternative()
|
---|
| 30 | : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ), env(), openVars(), need() {}
|
---|
| 31 |
|
---|
| 32 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env )
|
---|
| 33 | : cost( Cost::zero ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars(), need() {}
|
---|
| 34 |
|
---|
| 35 | Alternative::Alternative( const Alternative &o, Expression *expr, const Cost &cost )
|
---|
| 36 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( o.env ), openVars( o.openVars ),
|
---|
[2c187378] | 37 | need() { cloneAll( o.need, need ); }
|
---|
[6d6e829] | 38 |
|
---|
| 39 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
|
---|
[2c187378] | 40 | const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost )
|
---|
[6d6e829] | 41 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ),
|
---|
[2c187378] | 42 | need() { cloneAll( oneed, need ); }
|
---|
[6d6e829] | 43 |
|
---|
| 44 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
|
---|
[2c187378] | 45 | const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost,
|
---|
[6d6e829] | 46 | const Cost &cvtCost )
|
---|
| 47 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ),
|
---|
[2c187378] | 48 | need() { cloneAll( oneed, need ); }
|
---|
| 49 |
|
---|
| 50 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
|
---|
| 51 | const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost)
|
---|
| 52 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ),
|
---|
| 53 | need() { cloneAll( oneed, need ); }
|
---|
| 54 |
|
---|
| 55 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
|
---|
| 56 | const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost,
|
---|
| 57 | const Cost& cvtCost )
|
---|
| 58 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ),
|
---|
| 59 | need() { cloneAll( oneed, need ); }
|
---|
| 60 |
|
---|
| 61 | Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars,
|
---|
| 62 | AssertionSet &&needSet, const Cost &cost )
|
---|
| 63 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( std::move(env) ),
|
---|
| 64 | openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
|
---|
| 65 |
|
---|
| 66 | Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars,
|
---|
| 67 | AssertionSet &&needSet, const Cost &cost, const Cost &cvtCost )
|
---|
| 68 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( std::move(env) ),
|
---|
| 69 | openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
|
---|
[6d6e829] | 70 |
|
---|
| 71 | Alternative::Alternative( const Alternative &other )
|
---|
| 72 | : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ),
|
---|
[2c187378] | 73 | env( other.env ), openVars( other.openVars ), need() { cloneAll( other.need, need ); }
|
---|
[a32b204] | 74 |
|
---|
| 75 | Alternative &Alternative::operator=( const Alternative &other ) {
|
---|
| 76 | if ( &other == this ) return *this;
|
---|
[89be1c68] | 77 | delete expr;
|
---|
| 78 | cost = other.cost;
|
---|
| 79 | cvtCost = other.cvtCost;
|
---|
| 80 | expr = maybeClone( other.expr );
|
---|
| 81 | env = other.env;
|
---|
[6d6e829] | 82 | openVars = other.openVars;
|
---|
[2c187378] | 83 | need.clear();
|
---|
| 84 | cloneAll( other.need, need );
|
---|
[a32b204] | 85 | return *this;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[6d6e829] | 88 | Alternative::Alternative( Alternative && other )
|
---|
| 89 | : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ),
|
---|
| 90 | env( std::move( other.env ) ), openVars( std::move( other.openVars ) ),
|
---|
[2c187378] | 91 | need( std::move( other.need ) ) { other.expr = nullptr; }
|
---|
[aefcc3b] | 92 |
|
---|
| 93 | Alternative & Alternative::operator=( Alternative && other ) {
|
---|
| 94 | if ( &other == this ) return *this;
|
---|
| 95 | delete expr;
|
---|
| 96 | cost = other.cost;
|
---|
| 97 | cvtCost = other.cvtCost;
|
---|
| 98 | expr = other.expr;
|
---|
[4e7cc5ce] | 99 | env = std::move( other.env );
|
---|
[6d6e829] | 100 | openVars = std::move( other.openVars );
|
---|
| 101 | need = std::move( other.need );
|
---|
[aefcc3b] | 102 | other.expr = nullptr;
|
---|
| 103 | return *this;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[a32b204] | 106 | Alternative::~Alternative() {
|
---|
[aeb8f70] | 107 | for ( AssertionItem& n : need ) { delete n.decl; }
|
---|
[a32b204] | 108 | delete expr;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[50377a4] | 111 | void Alternative::print( std::ostream &os, Indenter indent ) const {
|
---|
| 112 | os << "Cost " << cost << ": ";
|
---|
[a32b204] | 113 | if ( expr ) {
|
---|
[50377a4] | 114 | expr->print( os, indent+1 );
|
---|
| 115 | os << std::endl << indent << "(types:" << std::endl;
|
---|
| 116 | os << indent+1;
|
---|
| 117 | expr->result->print( os, indent+1 );
|
---|
| 118 | os << std::endl << indent << ")" << std::endl;
|
---|
[a32b204] | 119 | } else {
|
---|
| 120 | os << "Null expression!" << std::endl;
|
---|
| 121 | } // if
|
---|
[08222c7] | 122 | os << indent << "Environment:";
|
---|
[50377a4] | 123 | env.print( os, indent+1 );
|
---|
[a32b204] | 124 | os << std::endl;
|
---|
[d9a0e76] | 125 | }
|
---|
[bd4f2e9] | 126 |
|
---|
[51b73452] | 127 | } // namespace ResolvExpr
|
---|
[a32b204] | 128 |
|
---|
| 129 | // Local Variables: //
|
---|
| 130 | // tab-width: 4 //
|
---|
| 131 | // mode: c++ //
|
---|
| 132 | // compile-command: "make install" //
|
---|
| 133 | // End: //
|
---|