source: src/ResolvExpr/Alternative.cc @ 6840e7c

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6840e7c was 50377a4, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Refactor tree print code to use Indenter

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[a32b204]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//
[906e24d]7// Alternative.cc --
[a32b204]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
[906e24d]14//
[a32b204]15
[51b7345]16#include "Alternative.h"
[ea6332d]17
18#include <ostream>                       // for operator<<, ostream, basic_o...
19#include <string>                        // for operator<<, char_traits, string
20
21#include "Common/utility.h"              // for maybeClone
22#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
23#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
24#include "SynTree/Expression.h"          // for Expression
25#include "SynTree/Type.h"                // for Type
[51b7345]26
27namespace ResolvExpr {
[3c13c03]28        Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
[a32b204]29
30        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
31                : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {}
32
33        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
34                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
35
[89be1c68]36        Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
[a32b204]37        }
38
39        Alternative &Alternative::operator=( const Alternative &other ) {
40                if ( &other == this ) return *this;
[89be1c68]41                delete expr;
42                cost = other.cost;
43                cvtCost = other.cvtCost;
44                expr = maybeClone( other.expr );
45                env = other.env;
[a32b204]46                return *this;
47        }
48
[aefcc3b]49        Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
50                other.expr = nullptr;
51        }
52
53        Alternative & Alternative::operator=( Alternative && other ) {
54                if ( &other == this )  return *this;
55                delete expr;
56                cost = other.cost;
57                cvtCost = other.cvtCost;
58                expr = other.expr;
59                env = other.env;
60                other.expr = nullptr;
61                return *this;
62        }
63
[a32b204]64        Alternative::~Alternative() {
65                delete expr;
66        }
67
[50377a4]68        void Alternative::print( std::ostream &os, Indenter indent ) const {
69                os << "Cost " << cost << ": ";
[a32b204]70                if ( expr ) {
[50377a4]71                        expr->print( os, indent+1 );
72                        os << std::endl << indent << "(types:" << std::endl;
73                        os << indent+1;
74                        expr->result->print( os, indent+1 );
75                        os << std::endl << indent << ")" << std::endl;
[a32b204]76                } else {
77                        os << "Null expression!" << std::endl;
78                } // if
[50377a4]79                os << indent << "Environment: ";
80                env.print( os, indent+1 );
[a32b204]81                os << std::endl;
[d9a0e76]82        }
[51b7345]83} // namespace ResolvExpr
[a32b204]84
85// Local Variables: //
86// tab-width: 4 //
87// mode: c++ //
88// compile-command: "make install" //
89// End: //
Note: See TracBrowser for help on using the repository browser.