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/GC.h" |
---|
23 | #include "Common/PassVisitor.h" |
---|
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 |
---|
28 | #include "SynTree/GcTracer.h" |
---|
29 | #include "SynTree/Type.h" // for Type |
---|
30 | |
---|
31 | namespace ResolvExpr { |
---|
32 | Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {} |
---|
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 ) {} |
---|
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 | } |
---|
51 | |
---|
52 | void Alternative::print( std::ostream &os, Indenter indent ) const { |
---|
53 | os << "Cost " << cost << ": "; |
---|
54 | if ( expr ) { |
---|
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; |
---|
60 | } else { |
---|
61 | os << "Null expression!" << std::endl; |
---|
62 | } // if |
---|
63 | os << indent << "Environment: "; |
---|
64 | env.print( os, indent+1 ); |
---|
65 | os << std::endl; |
---|
66 | } |
---|
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 | |
---|
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 | |
---|
88 | } // namespace ResolvExpr |
---|
89 | |
---|
90 | // Local Variables: // |
---|
91 | // tab-width: 4 // |
---|
92 | // mode: c++ // |
---|
93 | // compile-command: "make install" // |
---|
94 | // End: // |
---|