source: src/ResolvExpr/Alternative.cc @ b6d6e97

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

Merge branch 'master' into references

  • 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
68        void Alternative::print( std::ostream &os, int indent ) const {
69                os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
70                if ( expr ) {
71                        expr->print( os, indent );
72                        os << "(types:" << std::endl;
[906e24d]73                        os << std::string( indent+4, ' ' );
74                        expr->get_result()->print( os, indent + 4 );
75                        os << std::endl << ")" << std::endl;
[a32b204]76                } else {
77                        os << "Null expression!" << std::endl;
78                } // if
79                os << std::string( indent, ' ' ) << "Environment: ";
80                env.print( os, indent+2 );
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.