source: src/ResolvExpr/Alternative.cc@ 10dc6908

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 10dc6908 was 50377a4, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Refactor tree print code to use Indenter

  • 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 ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
37 }
38
39 Alternative &Alternative::operator=( const Alternative &other ) {
40 if ( &other == this ) return *this;
41 delete expr;
42 cost = other.cost;
43 cvtCost = other.cvtCost;
44 expr = maybeClone( other.expr );
45 env = other.env;
46 return *this;
47 }
48
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
64 Alternative::~Alternative() {
65 delete expr;
66 }
67
68 void Alternative::print( std::ostream &os, Indenter indent ) const {
69 os << "Cost " << cost << ": ";
70 if ( expr ) {
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;
76 } else {
77 os << "Null expression!" << std::endl;
78 } // if
79 os << indent << "Environment: ";
80 env.print( os, indent+1 );
81 os << std::endl;
82 }
83} // namespace ResolvExpr
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.