source: src/ResolvExpr/Alternative.cc@ e50e9ff

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since e50e9ff was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 2.8 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
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
26
27namespace ResolvExpr {
28 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
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
36 Alternative::Alternative( const Alternative &other ) {
37 initialize( other, *this );
38 }
39
40 Alternative &Alternative::operator=( const Alternative &other ) {
41 if ( &other == this ) return *this;
42 initialize( other, *this );
43 return *this;
44 }
45
46 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
47 other.expr = nullptr;
48 }
49
50 Alternative & Alternative::operator=( Alternative && other ) {
51 if ( &other == this ) return *this;
52 delete expr;
53 cost = other.cost;
54 cvtCost = other.cvtCost;
55 expr = other.expr;
56 env = other.env;
57 other.expr = nullptr;
58 return *this;
59 }
60
61 void Alternative::initialize( const Alternative &src, Alternative &dest ) {
62 dest.cost = src.cost;
63 dest.cvtCost = src.cvtCost;
64 dest.expr = maybeClone( src.expr );
65 dest.env = src.env;
66 }
67
68 Alternative::~Alternative() {
69 delete expr;
70 }
71
72 void Alternative::print( std::ostream &os, int indent ) const {
73 os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
74 if ( expr ) {
75 expr->print( os, indent );
76 os << "(types:" << std::endl;
77 os << std::string( indent+4, ' ' );
78 expr->get_result()->print( os, indent + 4 );
79 os << std::endl << ")" << std::endl;
80 } else {
81 os << "Null expression!" << std::endl;
82 } // if
83 os << std::string( indent, ' ' ) << "Environment: ";
84 env.print( os, indent+2 );
85 os << std::endl;
86 }
87} // namespace ResolvExpr
88
89// Local Variables: //
90// tab-width: 4 //
91// mode: c++ //
92// compile-command: "make install" //
93// End: //
Note: See TracBrowser for help on using the repository browser.