source: src/ResolvExpr/Alternative.cc @ fd344aa

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since fd344aa was 89be1c68, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Remove Cost constructors, use only named members

This change makes it easier to read code involving costs, since in almost every case, only a single part of the cost tuple is relevant. Furthermore, this change makes it much simpler to add another dimension to the cost tuple, since only Cost.h needs to be updated, rather than every location using the cost constructor.

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