source: src/ResolvExpr/Alternative.cc @ 396037d

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 396037d was e99e43f, checked in by Aaron Moss <a3moss@…>, 5 years ago

Merge remote-tracking branch 'plg/master' into deferred_resn

  • Property mode set to 100644
File size: 5.3 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 : Aaron B. Moss
12// Last Modified On : Thu Oct 11 10:55:00 2018
13// Update Count     : 3
14//
15
16#include "Alternative.h"
17
18#include <ostream>                       // for operator<<, ostream, basic_o...
19#include <string>                        // for operator<<, char_traits, string
20#include <utility>                       // for move
21
22#include "Common/utility.h"              // for cloneAll
23#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
24#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
25#include "SynTree/Expression.h"          // for Expression
26#include "SynTree/Type.h"                // for Type
27
28namespace ResolvExpr {
29        Alternative::Alternative() 
30        : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ), env(), openVars(), need() {}
31
32        Alternative::Alternative( Expression *expr, const TypeEnvironment &env )
33        : cost( Cost::zero ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars(), need() {}
34       
35        Alternative::Alternative( const Alternative &o, Expression *expr, const Cost &cost ) 
36        : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( o.env ), openVars( o.openVars ), 
37          need() { cloneAll( o.need, need ); }
38
39        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, 
40                const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost )
41        : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ), 
42          need() { cloneAll( oneed, need ); }
43
44        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, 
45                const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost, 
46                const Cost &cvtCost )
47        : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ), 
48          need() { cloneAll( oneed, need ); }
49       
50        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, 
51                const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost)
52        : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ), 
53          need() { cloneAll( oneed, need ); }
54       
55        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, 
56                const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost, 
57                const Cost& cvtCost )
58        : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ), 
59          need() { cloneAll( oneed, need ); }
60       
61        Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars, 
62                AssertionSet &&needSet, const Cost &cost )
63        : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( std::move(env) ), 
64          openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
65       
66        Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars, 
67                AssertionSet &&needSet, const Cost &cost, const Cost &cvtCost )
68        : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( std::move(env) ), 
69          openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
70
71        Alternative::Alternative( const Alternative &other ) 
72        : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), 
73          env( other.env ), openVars( other.openVars ), need() { cloneAll( other.need, need ); }
74
75        Alternative &Alternative::operator=( const Alternative &other ) {
76                if ( &other == this ) return *this;
77                delete expr;
78                cost = other.cost;
79                cvtCost = other.cvtCost;
80                expr = maybeClone( other.expr );
81                env = other.env;
82                openVars = other.openVars;
83                need.clear();
84                cloneAll( other.need, need );
85                return *this;
86        }
87
88        Alternative::Alternative( Alternative && other ) 
89        : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), 
90          env( std::move( other.env ) ), openVars( std::move( other.openVars ) ), 
91          need( std::move( other.need ) ) { other.expr = nullptr; }
92
93        Alternative & Alternative::operator=( Alternative && other ) {
94                if ( &other == this )  return *this;
95                delete expr;
96                cost = other.cost;
97                cvtCost = other.cvtCost;
98                expr = other.expr;
99                env = std::move( other.env );
100                openVars = std::move( other.openVars );
101                need = std::move( other.need );
102                other.expr = nullptr;
103                return *this;
104        }
105
106        Alternative::~Alternative() {
107                for ( AssertionItem& n : need ) { delete n.decl; }
108                delete expr;
109        }
110
111        void Alternative::print( std::ostream &os, Indenter indent ) const {
112                os << "Cost " << cost << ": ";
113                if ( expr ) {
114                        expr->print( os, indent+1 );
115                        os << std::endl << indent << "(types:" << std::endl;
116                        os << indent+1;
117                        expr->result->print( os, indent+1 );
118                        os << std::endl << indent << ")" << std::endl;
119                } else {
120                        os << "Null expression!" << std::endl;
121                } // if
122                os << indent << "Environment:";
123                env.print( os, indent+1 );
124                os << std::endl;
125        }
126
127        void splice( AltList& dst, AltList& src ) {
128                dst.reserve( dst.size() + src.size() );
129                for ( Alternative& alt : src ) {
130                        dst.push_back( std::move(alt) );
131                }
132                src.clear();
133        }
134
135        void spliceBegin( AltList& dst, AltList& src ) {
136                splice( src, dst );
137                dst.swap( src );
138        }
139
140} // namespace ResolvExpr
141
142// Local Variables: //
143// tab-width: 4 //
144// mode: c++ //
145// compile-command: "make install" //
146// End: //
Note: See TracBrowser for help on using the repository browser.