source: src/ResolvExpr/Alternative.h @ 5b7fea7

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 5b7fea7 was fd642d2, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Added const in a few more places. This should be all the leaf areas need to make unify const.

  • Property mode set to 100644
File size: 4.4 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//
[3c13c03]7// Alternative.h --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sat May 16 23:45:43 2015
[6d6e829]11// Last Modified By : Aaron B. Moss
12// Last Modified On : Thu Oct 11 10:55:00 2018
13// Update Count     : 4
[3c13c03]14//
[a32b204]15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <iosfwd>             // for ostream
[bd4f2e9]19#include <vector>             // for vector
[ea6332d]20
21#include "Cost.h"             // for Cost
[6d6e829]22#include "TypeEnvironment.h"  // for TypeEnvironment, AssertionSetValue
[ea6332d]23
[2c187378]24#include "Common/utility.h"   // for maybeClone
25
[ea6332d]26class Expression;
[51b7345]27
28namespace ResolvExpr {
[6d6e829]29        /// One assertion to resolve
30        struct AssertionItem {
[fd642d2]31                const DeclarationWithType* decl;
[6d6e829]32                AssertionSetValue info;
[fd642d2]33
[6d6e829]34                AssertionItem() = default;
[fd642d2]35                AssertionItem( const DeclarationWithType* decl, const AssertionSetValue& info )
[6d6e829]36                : decl(decl), info(info) {}
37                AssertionItem( const AssertionSet::value_type& e ) : decl(e.first), info(e.second) {}
38                operator AssertionSet::value_type () const { return { decl, info }; }
[2c187378]39
40                // to support cloneAll
41                AssertionItem clone() const { return { maybeClone(decl), info }; }
[6d6e829]42        };
43        /// A list of unresolved assertions
44        using AssertionList = std::vector<AssertionItem>;
45
[2c187378]46        /// Clones an assertion list into an assertion set
47        static inline void cloneAll( const AssertionList& src, AssertionSet& dst ) {
48                for ( const AssertionItem& item : src ) {
49                        dst.emplace( maybeClone(item.decl), item.info );
50                }
51        }
52
53        /// Clones an assertion set into an assertion list
54        static inline void cloneAll( const AssertionSet& src, AssertionList& dst ) {
55                dst.reserve( dst.size() + src.size() );
56                for ( const auto& entry : src ) {
57                        dst.emplace_back( maybeClone(entry.first), entry.second );
58                }
59        }
60
61        /// Clones an assertion list into an assertion list
62        static inline void cloneAll( const AssertionList& src, AssertionList& dst ) {
63                dst.reserve( dst.size() + src.size() );
64                for ( const AssertionItem& item : src ) {
65                        dst.emplace_back( maybeClone(item.decl), item.info );
66                }
67        }
68
[6d6e829]69        /// One option for resolution of an expression
[a32b204]70        struct Alternative {
71                Alternative();
[6d6e829]72                Alternative( Expression *expr, const TypeEnvironment &env );
73                Alternative( const Alternative &o, Expression *expr, const Cost &cost );
74                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet& openVars, 
75                        const AssertionList& need, const Cost &cost );
76                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet& openVars, 
77                        const AssertionList& need, const Cost &cost, const Cost &cvtCost );
[2c187378]78                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet &openVars, 
79                        const AssertionSet &need, const Cost &cost);
80                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet &openVars, 
81                        const AssertionSet &need, const Cost &cost, const Cost& cvtCost );
82                Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars, 
83                        AssertionSet &&need, const Cost &cost );
84                Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars, 
85                        AssertionSet &&need, const Cost &cost, const Cost &cvtCost );
[a32b204]86                Alternative( const Alternative &other );
87                Alternative &operator=( const Alternative &other );
[aefcc3b]88                Alternative( Alternative && other );
89                Alternative &operator=( Alternative && other );
[a32b204]90                ~Alternative();
[3c13c03]91
[50377a4]92                void print( std::ostream &os, Indenter indent = {} ) const;
[3c13c03]93
[62194cb]94                /// Returns the stored expression, but released from management of this Alternative
95                Expression* release_expr() {
96                        Expression* tmp = expr;
97                        expr = nullptr;
98                        return tmp;
99                }
100
[6d6e829]101                /// Sorts by cost
102                bool operator< ( const Alternative& o ) const { return cost < o.cost; }
103
104                Cost cost;            ///< Cost of the whole expression
105                Cost cvtCost;         ///< Cost of conversions to the satisfying expression
106                Expression *expr;     ///< Satisfying expression
107                TypeEnvironment env;  ///< Containing type environment
108                OpenVarSet openVars;  ///< Open variables for environment
109                AssertionList need;   ///< Assertions which need to be resolved
[a32b204]110        };
[bd4f2e9]111
112        typedef std::vector< Alternative > AltList;
113
[4a161be]114        static inline std::ostream & operator<<(std::ostream & os, const ResolvExpr::Alternative & alt) {
115                alt.print( os );
116                return os;
117        }
[51b7345]118} // namespace ResolvExpr
119
[a32b204]120// Local Variables: //
121// tab-width: 4 //
122// mode: c++ //
123// compile-command: "make install" //
124// End: //
Note: See TracBrowser for help on using the repository browser.