[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 | |
---|
[51b7345] | 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 |
---|
[51b7345] | 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 | |
---|
[50377a4] | 37 | void Alternative::print( std::ostream &os, Indenter indent ) const { |
---|
| 38 | os << "Cost " << cost << ": "; |
---|
[a32b204] | 39 | if ( expr ) { |
---|
[50377a4] | 40 | expr->print( os, indent+1 ); |
---|
| 41 | os << std::endl << indent << "(types:" << std::endl; |
---|
| 42 | os << indent+1; |
---|
| 43 | expr->result->print( os, indent+1 ); |
---|
| 44 | os << std::endl << indent << ")" << std::endl; |
---|
[a32b204] | 45 | } else { |
---|
| 46 | os << "Null expression!" << std::endl; |
---|
| 47 | } // if |
---|
[50377a4] | 48 | os << indent << "Environment: "; |
---|
| 49 | env.print( os, indent+1 ); |
---|
[a32b204] | 50 | os << std::endl; |
---|
[d9a0e76] | 51 | } |
---|
[bd4f2e9] | 52 | |
---|
| 53 | void splice( AltList& dst, AltList& src ) { |
---|
| 54 | dst.reserve( dst.size() + src.size() ); |
---|
| 55 | for ( Alternative& alt : src ) { |
---|
| 56 | dst.push_back( std::move(alt) ); |
---|
| 57 | } |
---|
| 58 | src.clear(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void spliceBegin( AltList& dst, AltList& src ) { |
---|
| 62 | splice( src, dst ); |
---|
| 63 | dst.swap( src ); |
---|
| 64 | } |
---|
| 65 | |
---|
[51b7345] | 66 | } // namespace ResolvExpr |
---|
[a32b204] | 67 | |
---|
| 68 | // Local Variables: // |
---|
| 69 | // tab-width: 4 // |
---|
| 70 | // mode: c++ // |
---|
| 71 | // compile-command: "make install" // |
---|
| 72 | // End: // |
---|