1 | #include "Alternative.h"
|
---|
2 | #include "SynTree/Type.h"
|
---|
3 | #include "SynTree/Expression.h"
|
---|
4 | #include "utility.h"
|
---|
5 |
|
---|
6 | namespace ResolvExpr {
|
---|
7 | Alternative::Alternative() : expr( 0 ) {}
|
---|
8 |
|
---|
9 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
|
---|
10 | : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {}
|
---|
11 |
|
---|
12 | Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
|
---|
13 | : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
|
---|
14 |
|
---|
15 | Alternative::Alternative( const Alternative &other ) {
|
---|
16 | initialize( other, *this );
|
---|
17 | }
|
---|
18 |
|
---|
19 | Alternative &Alternative::operator=( const Alternative &other ) {
|
---|
20 | if ( &other == this ) return *this;
|
---|
21 | initialize( other, *this );
|
---|
22 | return *this;
|
---|
23 | }
|
---|
24 |
|
---|
25 | void Alternative::initialize( const Alternative &src, Alternative &dest ) {
|
---|
26 | dest.cost = src.cost;
|
---|
27 | dest.cvtCost = src.cvtCost;
|
---|
28 | dest.expr = maybeClone( src.expr );
|
---|
29 | dest.env = src.env;
|
---|
30 | }
|
---|
31 |
|
---|
32 | Alternative::~Alternative() {
|
---|
33 | delete expr;
|
---|
34 | }
|
---|
35 |
|
---|
36 | void Alternative::print( std::ostream &os, int indent ) const {
|
---|
37 | os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
|
---|
38 | if ( expr ) {
|
---|
39 | expr->print( os, indent );
|
---|
40 | os << "(types:" << std::endl;
|
---|
41 | printAll( expr->get_results(), os, indent + 4 );
|
---|
42 | os << ")" << std::endl;
|
---|
43 | } else {
|
---|
44 | os << "Null expression!" << std::endl;
|
---|
45 | }
|
---|
46 | os << std::string( indent, ' ' ) << "Environment: ";
|
---|
47 | env.print( os, indent+2 );
|
---|
48 | os << std::endl;
|
---|
49 | }
|
---|
50 | } // namespace ResolvExpr
|
---|