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