source: src/ResolvExpr/Alternative.h @ 6d6e829

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 6d6e829 was 6d6e829, checked in by Aaron Moss <a3moss@…>, 6 years ago

First compiling draft of deferred assertions (build failure)

  • Property mode set to 100644
File size: 3.1 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.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sat May 16 23:45:43 2015
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Thu Oct 11 10:55:00 2018
13// Update Count     : 4
14//
15
16#pragma once
17
18#include <iosfwd>             // for ostream
19#include <vector>             // for vector
20
21#include "Cost.h"             // for Cost
22#include "TypeEnvironment.h"  // for TypeEnvironment, AssertionSetValue
23
24class Expression;
25
26namespace ResolvExpr {
27        /// One assertion to resolve
28        struct AssertionItem {
29                DeclarationWithType* decl;
30                AssertionSetValue info;
31               
32                AssertionItem() = default;
33                AssertionItem( DeclarationWithType* decl, const AssertionSetValue& info ) 
34                : decl(decl), info(info) {}
35                AssertionItem( const AssertionSet::value_type& e ) : decl(e.first), info(e.second) {}
36                operator AssertionSet::value_type () const { return { decl, info }; }
37        };
38        /// A list of unresolved assertions
39        using AssertionList = std::vector<AssertionItem>;
40
41        /// One option for resolution of an expression
42        struct Alternative {
43                Alternative();
44                Alternative( Expression *expr, const TypeEnvironment &env );
45                Alternative( const Alternative &o, Expression *expr, const Cost &cost );
46                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet& openVars, 
47                        const AssertionList& need, const Cost &cost );
48                Alternative( Expression *expr, const TypeEnvironment &env, const OpenVarSet& openVars, 
49                        const AssertionList& need, const Cost &cost, const Cost &cvtCost );
50                Alternative( const Alternative &other );
51                Alternative &operator=( const Alternative &other );
52                Alternative( Alternative && other );
53                Alternative &operator=( Alternative && other );
54                ~Alternative();
55
56                void print( std::ostream &os, Indenter indent = {} ) const;
57
58                /// Returns the stored expression, but released from management of this Alternative
59                Expression* release_expr() {
60                        Expression* tmp = expr;
61                        expr = nullptr;
62                        return tmp;
63                }
64
65                /// Sorts by cost
66                bool operator< ( const Alternative& o ) const { return cost < o.cost; }
67
68                Cost cost;            ///< Cost of the whole expression
69                Cost cvtCost;         ///< Cost of conversions to the satisfying expression
70                Expression *expr;     ///< Satisfying expression
71                TypeEnvironment env;  ///< Containing type environment
72                OpenVarSet openVars;  ///< Open variables for environment
73                AssertionList need;   ///< Assertions which need to be resolved
74        };
75
76        typedef std::vector< Alternative > AltList;
77
78        /// Moves all elements from src to the end of dst
79        void splice( AltList& dst, AltList& src );
80
81        /// Moves all elements from src to the beginning of dst
82        void spliceBegin( AltList& dst, AltList& src );
83
84        static inline std::ostream & operator<<(std::ostream & os, const ResolvExpr::Alternative & alt) {
85                alt.print( os );
86                return os;
87        }
88} // namespace ResolvExpr
89
90// Local Variables: //
91// tab-width: 4 //
92// mode: c++ //
93// compile-command: "make install" //
94// End: //
Note: See TracBrowser for help on using the repository browser.