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 : Aaron B. Moss |
---|
12 | // Last Modified On : Thu Oct 11 10:55:00 2018 |
---|
13 | // Update Count : 3 |
---|
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() |
---|
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 ), |
---|
37 | need( o.need ) {} |
---|
38 | |
---|
39 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, |
---|
40 | const OpenVarSet& openVars, const AssertionList& need, const Cost& cost ) |
---|
41 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ), |
---|
42 | need( need ) {} |
---|
43 | |
---|
44 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, |
---|
45 | const OpenVarSet& openVars, const AssertionList& need, const Cost& cost, |
---|
46 | const Cost &cvtCost ) |
---|
47 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ), |
---|
48 | need( need ) {} |
---|
49 | |
---|
50 | Alternative::Alternative( const Alternative &other ) |
---|
51 | : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), |
---|
52 | env( other.env ), openVars( other.openVars ), need( other.need ) {} |
---|
53 | |
---|
54 | Alternative &Alternative::operator=( const Alternative &other ) { |
---|
55 | if ( &other == this ) return *this; |
---|
56 | delete expr; |
---|
57 | cost = other.cost; |
---|
58 | cvtCost = other.cvtCost; |
---|
59 | expr = maybeClone( other.expr ); |
---|
60 | env = other.env; |
---|
61 | openVars = other.openVars; |
---|
62 | need = other.need; |
---|
63 | return *this; |
---|
64 | } |
---|
65 | |
---|
66 | Alternative::Alternative( Alternative && other ) |
---|
67 | : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), |
---|
68 | env( std::move( other.env ) ), openVars( std::move( other.openVars ) ), |
---|
69 | need( std::move( other.need ) ) { |
---|
70 | other.expr = nullptr; |
---|
71 | } |
---|
72 | |
---|
73 | Alternative & Alternative::operator=( Alternative && other ) { |
---|
74 | if ( &other == this ) return *this; |
---|
75 | delete expr; |
---|
76 | cost = other.cost; |
---|
77 | cvtCost = other.cvtCost; |
---|
78 | expr = other.expr; |
---|
79 | env = std::move( other.env ); |
---|
80 | openVars = std::move( other.openVars ); |
---|
81 | need = std::move( other.need ); |
---|
82 | other.expr = nullptr; |
---|
83 | return *this; |
---|
84 | } |
---|
85 | |
---|
86 | Alternative::~Alternative() { |
---|
87 | delete expr; |
---|
88 | } |
---|
89 | |
---|
90 | void Alternative::print( std::ostream &os, Indenter indent ) const { |
---|
91 | os << "Cost " << cost << ": "; |
---|
92 | if ( expr ) { |
---|
93 | expr->print( os, indent+1 ); |
---|
94 | os << std::endl << indent << "(types:" << std::endl; |
---|
95 | os << indent+1; |
---|
96 | expr->result->print( os, indent+1 ); |
---|
97 | os << std::endl << indent << ")" << std::endl; |
---|
98 | } else { |
---|
99 | os << "Null expression!" << std::endl; |
---|
100 | } // if |
---|
101 | os << indent << "Environment: "; |
---|
102 | env.print( os, indent+1 ); |
---|
103 | os << std::endl; |
---|
104 | } |
---|
105 | |
---|
106 | void splice( AltList& dst, AltList& src ) { |
---|
107 | dst.reserve( dst.size() + src.size() ); |
---|
108 | for ( Alternative& alt : src ) { |
---|
109 | dst.push_back( std::move(alt) ); |
---|
110 | } |
---|
111 | src.clear(); |
---|
112 | } |
---|
113 | |
---|
114 | void spliceBegin( AltList& dst, AltList& src ) { |
---|
115 | splice( src, dst ); |
---|
116 | dst.swap( src ); |
---|
117 | } |
---|
118 | |
---|
119 | } // namespace ResolvExpr |
---|
120 | |
---|
121 | // Local Variables: // |
---|
122 | // tab-width: 4 // |
---|
123 | // mode: c++ // |
---|
124 | // compile-command: "make install" // |
---|
125 | // End: // |
---|