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( 0 ) {} |
---|
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 | void Alternative::print( std::ostream &os, Indenter indent ) const { |
---|
41 | os << "Cost " << cost << ": "; |
---|
42 | if ( expr ) { |
---|
43 | expr->print( os, indent+1 ); |
---|
44 | os << std::endl << indent << "(types:" << std::endl; |
---|
45 | os << indent+1; |
---|
46 | expr->result->print( os, indent+1 ); |
---|
47 | os << std::endl << indent << ")" << std::endl; |
---|
48 | } else { |
---|
49 | os << "Null expression!" << std::endl; |
---|
50 | } // if |
---|
51 | os << indent << "Environment: "; |
---|
52 | env.print( os, indent+1 ); |
---|
53 | os << std::endl; |
---|
54 | } |
---|
55 | |
---|
56 | void splice( AltList& dst, AltList& src ) { |
---|
57 | dst.reserve( dst.size() + src.size() ); |
---|
58 | for ( Alternative& alt : src ) { |
---|
59 | dst.push_back( std::move(alt) ); |
---|
60 | } |
---|
61 | src.clear(); |
---|
62 | } |
---|
63 | |
---|
64 | void spliceBegin( AltList& dst, AltList& src ) { |
---|
65 | splice( src, dst ); |
---|
66 | dst.swap( src ); |
---|
67 | } |
---|
68 | |
---|
69 | const GC& operator<< ( const GC& gc, const Alternative& alt ) { |
---|
70 | PassVisitor<GcTracer> tracer{ gc }; |
---|
71 | maybeAccept( alt.expr, tracer ); |
---|
72 | tracer << alt.env; |
---|
73 | return gc; |
---|
74 | } |
---|
75 | |
---|
76 | } // namespace ResolvExpr |
---|
77 | |
---|
78 | // Local Variables: // |
---|
79 | // tab-width: 4 // |
---|
80 | // mode: c++ // |
---|
81 | // compile-command: "make install" // |
---|
82 | // End: // |
---|