source: src/ResolvExpr/AlternativeFinder.h @ d67cdb7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d67cdb7 was d67cdb7, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

merge

  • Property mode set to 100644
File size: 6.6 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//
[dc2e7e0]7// AlternativeFinder.h --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sat May 16 23:56:12 2015
[a5f0529]11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Jul 26 11:24:00 2017
13// Update Count     : 4
[dc2e7e0]14//
[a32b204]15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <algorithm>                     // for copy
19#include <list>                          // for list
20#include <string>                        // for string
[51b7345]21
[ea6332d]22#include "Alternative.h"                 // for AltList, Alternative
23#include "ResolvExpr/Cost.h"             // for Cost, Cost::infinity
24#include "ResolvExpr/TypeEnvironment.h"  // for AssertionSet, OpenVarSet
25#include "SynTree/Visitor.h"             // for Visitor
26#include "SynTree/SynTree.h"             // for Visitor Nodes
27
28namespace SymTab {
29class Indexer;
30}  // namespace SymTab
[51b7345]31
32namespace ResolvExpr {
[a32b204]33        class AlternativeFinder : public Visitor {
34          public:
35                AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env );
[b6fe7e6]36                void find( Expression *expr, bool adjust = false, bool prune = true );
[0f19d763]37                /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types
[b6fe7e6]38                void findWithAdjustment( Expression *expr, bool prune = true );
[a32b204]39                AltList &get_alternatives() { return alternatives; }
40
41                // make this look like an STL container so that we can apply generic algorithms
42                typedef Alternative value_type;
43                typedef AltList::iterator iterator;
44                typedef AltList::const_iterator const_iterator;
45                AltList::iterator begin() { return alternatives.begin(); }
46                AltList::iterator end() { return alternatives.end(); }
47                AltList::const_iterator begin() const { return alternatives.begin(); }
48                AltList::const_iterator end() const { return alternatives.end(); }
[51b7345]49
[a32b204]50                const SymTab::Indexer &get_indexer() const { return indexer; }
51                const TypeEnvironment &get_environ() const { return env; }
[d67cdb7]52
53                /// Runs a new alternative finder on each element in [begin, end)
54                /// and writes each alternative finder to out.
55                template< typename InputIterator, typename OutputIterator >
56                void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out );
[a32b204]57          private:
58                virtual void visit( ApplicationExpr *applicationExpr );
59                virtual void visit( UntypedExpr *untypedExpr );
60                virtual void visit( AddressExpr *addressExpr );
[5809461]61                virtual void visit( LabelAddressExpr *labelExpr );
[a32b204]62                virtual void visit( CastExpr *castExpr );
[a5f0529]63                virtual void visit( VirtualCastExpr *castExpr );
[a32b204]64                virtual void visit( UntypedMemberExpr *memberExpr );
65                virtual void visit( MemberExpr *memberExpr );
66                virtual void visit( NameExpr *variableExpr );
67                virtual void visit( VariableExpr *variableExpr );
[dc2e7e0]68                virtual void visit( ConstantExpr *constantExpr );
[a32b204]69                virtual void visit( SizeofExpr *sizeofExpr );
[25a054f]70                virtual void visit( AlignofExpr *alignofExpr );
[2a4b088]71                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
[25a054f]72                virtual void visit( OffsetofExpr *offsetofExpr );
[afc1045]73                virtual void visit( OffsetPackExpr *offsetPackExpr );
[a32b204]74                virtual void visit( AttrExpr *attrExpr );
75                virtual void visit( LogicalExpr *logicalExpr );
76                virtual void visit( ConditionalExpr *conditionalExpr );
77                virtual void visit( CommaExpr *commaExpr );
[dc2e7e0]78                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
[b6fe7e6]79                virtual void visit( ConstructorExpr * ctorExpr );
[8a5cad8]80                virtual void visit( RangeExpr * rangeExpr );
[907eccb]81                virtual void visit( UntypedTupleExpr *tupleExpr );
82                virtual void visit( TupleExpr *tupleExpr );
[8f7cea1]83                virtual void visit( TupleIndexExpr *tupleExpr );
[aa8f9df]84                virtual void visit( TupleAssignExpr *tupleExpr );
[bf32bb8]85                virtual void visit( UniqueExpr *unqExpr );
[722617d]86                virtual void visit( StmtExpr *stmtExpr );
[e4d829b]87                virtual void visit( UntypedInitExpr *initExpr );
[51b7345]88
[4b0f997]89                /// Adds alternatives for anonymous members
90                void addAnonConversions( const Alternative & alt );
[2a4b088]91                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
[add7117]92                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
[848ce71]93                /// Adds alternatives for member expressions where the left side has tuple type
94                void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
[2a4b088]95                /// Adds alternatives for offsetof expressions, given the base type and name of the member
96                template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
[aefcc3b]97                bool instantiateFunction( std::list< DeclarationWithType* >& formals, const AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave, AltList & out );
[a32b204]98                template< typename OutputIterator >
[aefcc3b]99                void makeFunctionAlternatives( const Alternative &func, FunctionType *funcType, const AltList &actualAlt, OutputIterator out );
[a32b204]100                template< typename OutputIterator >
101                void inferParameters( const AssertionSet &need, AssertionSet &have, const Alternative &newAlt, OpenVarSet &openVars, OutputIterator out );
102                void resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env );
[51b7345]103
[a32b204]104                const SymTab::Indexer &indexer;
105                AltList alternatives;
106                const TypeEnvironment &env;
[7933351]107                Type * targetType = nullptr;
[a32b204]108        }; // AlternativeFinder
109
110        Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env );
[d67cdb7]111        void referenceToRvalueConversion( Expression *& expr );
[5af62f1]112
113        template< typename InputIterator, typename OutputIterator >
114        void findMinCost( InputIterator begin, InputIterator end, OutputIterator out ) {
115                AltList alternatives;
116
117                // select the alternatives that have the minimum parameter cost
118                Cost minCost = Cost::infinity;
119                for ( InputIterator i = begin; i != end; ++i ) {
120                        if ( i->cost < minCost ) {
121                                minCost = i->cost;
122                                i->cost = i->cvtCost;
123                                alternatives.clear();
124                                alternatives.push_back( *i );
125                        } else if ( i->cost == minCost ) {
126                                i->cost = i->cvtCost;
127                                alternatives.push_back( *i );
128                        }
129                }
130                std::copy( alternatives.begin(), alternatives.end(), out );
131        }
[908cc83]132
133        Cost sumCost( const AltList &in );
[ac9ca96]134
135        template< typename InputIterator >
136        void simpleCombineEnvironments( InputIterator begin, InputIterator end, TypeEnvironment &result ) {
137                while ( begin != end ) {
138                        result.simpleCombine( (*begin++).env );
139                }
140        }
[51b7345]141} // namespace ResolvExpr
142
[a32b204]143// Local Variables: //
144// tab-width: 4 //
145// mode: c++ //
146// compile-command: "make install" //
147// End: //
Note: See TracBrowser for help on using the repository browser.