source: translator/ResolvExpr/Alternative.cc @ f7f6785

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since f7f6785 was d9a0e76, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[51b7345]1#include "Alternative.h"
2#include "SynTree/Type.h"
3#include "SynTree/Expression.h"
4#include "utility.h"
5
6namespace ResolvExpr {
[d9a0e76]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    }
[51b7345]50} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.