/* * This file is part of the Cforall project * * $Id: Alternative.cc,v 1.6 2005/08/29 20:14:15 rcbilson Exp $ * */ #include "Alternative.h" #include "SynTree/Type.h" #include "SynTree/Expression.h" #include "utility.h" namespace ResolvExpr { Alternative::Alternative() : expr( 0 ) { } Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) { } Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) { } Alternative::Alternative( const Alternative &other ) { initialize( other, *this ); } Alternative & Alternative::operator=( const Alternative &other ) { if( &other == this ) return *this; initialize( other, *this ); return *this; } void Alternative::initialize( const Alternative &src, Alternative &dest ) { dest.cost = src.cost; dest.cvtCost = src.cvtCost; dest.expr = maybeClone( src.expr ); dest.env = src.env; } Alternative::~Alternative() { delete expr; } void Alternative::print( std::ostream &os, int indent ) const { os << std::string( indent, ' ' ) << "Cost " << cost << ": "; if( expr ) { expr->print( os, indent ); os << "(types:" << std::endl; printAll( expr->get_results(), os, indent + 4 ); os << ")" << std::endl; } else { os << "Null expression!" << std::endl; } os << std::string( indent, ' ' ) << "Environment: "; env.print( os, indent+2 ); os << std::endl; } } // namespace ResolvExpr