[99d4584] | 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 | // CandidateFinder.hpp -- |
---|
| 8 | // |
---|
| 9 | // Author : Aaron B. Moss |
---|
| 10 | // Created On : Wed Jun 5 14:30:00 2019 |
---|
[cf32116] | 11 | // Last Modified By : Andrew Beach |
---|
[39d8950] | 12 | // Last Modified On : Wed Mar 16 15:22:00 2022 |
---|
| 13 | // Update Count : 3 |
---|
[99d4584] | 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
| 18 | #include "Candidate.hpp" |
---|
[4a89b52] | 19 | #include "ResolveMode.hpp" |
---|
[99d4584] | 20 | #include "AST/Fwd.hpp" |
---|
[396037d] | 21 | #include "AST/Node.hpp" |
---|
[99d4584] | 22 | #include "AST/SymbolTable.hpp" |
---|
| 23 | #include "AST/TypeEnvironment.hpp" |
---|
| 24 | |
---|
| 25 | namespace ResolvExpr { |
---|
| 26 | |
---|
[39d8950] | 27 | struct ResolveContext; |
---|
| 28 | |
---|
[99d4584] | 29 | /// Data to perform expression resolution |
---|
| 30 | struct CandidateFinder { |
---|
[c8e4d2f8] | 31 | CandidateList candidates; ///< List of candidate resolutions |
---|
[7aa209e7] | 32 | const ResolveContext & context; ///< Information about where the canditates are being found. |
---|
[c8e4d2f8] | 33 | const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution |
---|
| 34 | ast::ptr< ast::Type > targetType; ///< Target type for resolution |
---|
[46da46b] | 35 | bool strictMode = false; ///< If set to true, requires targetType to be exact match (inside return cast) |
---|
| 36 | bool allowVoid = false; ///< If set to true, allow void-returning function calls (only top level, cast to void and first in comma) |
---|
[7aa209e7] | 37 | std::set< std::string > otypeKeys; ///< different type may map to same key |
---|
[c8e4d2f8] | 38 | |
---|
[cf32116] | 39 | CandidateFinder( |
---|
[39d8950] | 40 | const ResolveContext & context, const ast::TypeEnvironment & env, |
---|
[c8e4d2f8] | 41 | const ast::Type * tt = nullptr ) |
---|
[39d8950] | 42 | : candidates(), context( context ), env( env ), targetType( tt ) {} |
---|
[99d4584] | 43 | |
---|
| 44 | /// Fill candidates with feasible resolutions for `expr` |
---|
[4a89b52] | 45 | void find( const ast::Expr * expr, ResolveMode mode = {} ); |
---|
[1389810] | 46 | bool pruneCandidates( CandidateList & candidates, CandidateList & out, std::vector<std::string> & errors ); |
---|
[2773ab8] | 47 | |
---|
| 48 | /// Runs new candidate finder on each element in xs, returning the list of finders |
---|
| 49 | std::vector< CandidateFinder > findSubExprs( const std::vector< ast::ptr< ast::Expr > > & xs ); |
---|
| 50 | |
---|
| 51 | using value_type = CandidateList::value_type; |
---|
| 52 | using iterator = CandidateList::iterator; |
---|
| 53 | using const_iterator = CandidateList::const_iterator; |
---|
| 54 | |
---|
| 55 | iterator begin() { return candidates.begin(); } |
---|
| 56 | const_iterator begin() const { return candidates.begin(); } |
---|
[cf32116] | 57 | |
---|
[2773ab8] | 58 | iterator end() { return candidates.end(); } |
---|
| 59 | const_iterator end() const { return candidates.end(); } |
---|
[85855b0] | 60 | |
---|
| 61 | const ast::Expr * makeEnumOffsetCast( const ast::EnumInstType * src, |
---|
| 62 | const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ); |
---|
[99d4584] | 63 | }; |
---|
| 64 | |
---|
[b69233ac] | 65 | /// Computes conversion cost between two types |
---|
[cf32116] | 66 | Cost computeConversionCost( |
---|
| 67 | const ast::Type * argType, const ast::Type * paramType, bool argIsLvalue, |
---|
| 68 | const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ); |
---|
[b69233ac] | 69 | |
---|
[fed6a0f] | 70 | /// Create an expression that preforms reference to rvalue conversion on |
---|
| 71 | /// the given expression and update the cost of the expression. |
---|
| 72 | const ast::Expr * referenceToRvalueConversion( |
---|
| 73 | const ast::Expr * expr, Cost & cost ); |
---|
| 74 | |
---|
[ab780e6] | 75 | /// Wrap an expression to convert the result to a conditional result. |
---|
| 76 | const ast::Expr * createCondExpr( const ast::Expr * expr ); |
---|
[af746cc] | 77 | |
---|
[99d4584] | 78 | } // namespace ResolvExpr |
---|
| 79 | |
---|
| 80 | // Local Variables: // |
---|
| 81 | // tab-width: 4 // |
---|
| 82 | // mode: c++ // |
---|
| 83 | // compile-command: "make install" // |
---|
| 84 | // End: // |
---|