Changeset 1d7b0a8


Ignore:
Timestamp:
Jun 11, 2018, 2:50:06 PM (3 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env
Children:
6d53e779, 982f95d
Parents:
8e18b8e
Message:

Move AlternativeFinder? find flags to ResolvMode? struct

Location:
src/ResolvExpr
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r8e18b8e r1d7b0a8  
    233233        }
    234234
    235         void AlternativeFinder::find( Expression *expr, bool adjust, bool prune, bool failFast ) {
     235        void AlternativeFinder::find( Expression *expr, ResolvMode mode ) {
    236236                PassVisitor<Finder> finder( *this );
    237237                expr->accept( finder );
    238                 if ( failFast && alternatives.empty() ) {
     238                if ( mode.failFast && alternatives.empty() ) {
    239239                        PRINT(
    240240                                std::cerr << "No reasonable alternatives for expression " << expr << std::endl;
     
    242242                        SemanticError( expr, "No reasonable alternatives for expression " );
    243243                }
    244                 if ( prune ) {
     244                if ( mode.prune ) {
    245245                        auto oldsize = alternatives.size();
    246246                        PRINT(
     
    250250                        AltList pruned;
    251251                        pruneAlternatives( alternatives.begin(), alternatives.end(), back_inserter( pruned ) );
    252                         if ( failFast && pruned.empty() ) {
     252                        if ( mode.failFast && pruned.empty() ) {
    253253                                std::ostringstream stream;
    254254                                AltList winners;
     
    269269                }
    270270                // adjust types after pruning so that types substituted by pruneAlternatives are correctly adjusted
    271                 for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
    272                         if ( adjust ) {
    273                                 adjustExprType( i->expr->get_result(), i->env, indexer );
     271                if ( mode.adjust ) {
     272                        for ( Alternative& i : alternatives ) {
     273                                adjustExprType( i.expr->result, i.env, indexer );
    274274                        }
    275275                }
     
    283283
    284284        void AlternativeFinder::findWithAdjustment( Expression *expr ) {
    285                 find( expr, true );
     285                find( expr, ResolvMode::withAdjustment() );
    286286        }
    287287
    288288        void AlternativeFinder::findWithoutPrune( Expression * expr ) {
    289                 find( expr, true, false );
     289                find( expr, ResolvMode::withoutPrune() );
    290290        }
    291291
    292292        void AlternativeFinder::maybeFind( Expression * expr ) {
    293                 find( expr, true, true, false );
     293                find( expr, ResolvMode::withoutFailFast() );
    294294        }
    295295
  • src/ResolvExpr/AlternativeFinder.h

    r8e18b8e r1d7b0a8  
    2222#include "Alternative.h"                 // for AltList, Alternative
    2323#include "ExplodedActual.h"              // for ExplodedActual
     24#include "ResolvMode.h"                  // for ResolvMode
    2425#include "ResolvExpr/Cost.h"             // for Cost, Cost::infinity
    2526#include "ResolvExpr/TypeEnvironment.h"  // for AssertionSet, OpenVarSet
     
    6869                }
    6970
    70                 void find( Expression *expr, bool adjust = false, bool prune = true, bool failFast = true );
     71                void find( Expression *expr, ResolvMode mode = ResolvMode{} );
    7172                /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types
    7273                void findWithAdjustment( Expression *expr );
  • src/ResolvExpr/Resolver.cc

    r8e18b8e r1d7b0a8  
    3333#include "ResolveTypeof.h"               // for resolveTypeof
    3434#include "Resolver.h"
     35#include "ResolvMode.h"                  // for ResolvMode
    3536#include "SymTab/Autogen.h"              // for SizeType
    3637#include "SymTab/Indexer.h"              // for Indexer
     
    165166
    166167        namespace {
    167                 void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {
     168                void findUnfinishedKindExpression( Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{} ) {
    168169                        assertf( untyped, "expected a non-null expression." );
    169170
     
    172173                        TypeEnvironment env;
    173174                        AlternativeFinder finder( indexer, env );
    174                         finder.find( untyped, adjust, prune, failFast );
     175                        finder.find( untyped, mode );
    175176
    176177                        #if 0
     
    218219
    219220                /// resolve `untyped` to the expression whose alternative satisfies `pred` with the lowest cost; kindStr is used for providing better error messages
    220                 void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {
     221                void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{}) {
    221222                        if ( ! untyped ) return;
    222223                        Alternative choice;
    223                         findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast );
     224                        findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, mode );
    224225                        finishExpr( choice.expr, choice.env, untyped->env );
    225226                        untyped = choice.expr;
     
    249250                // set up and resolve expression cast to void
    250251                Alternative choice;
    251                 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true );
     252                findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() );
    252253                CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr );
    253254                env = std::move( choice.env );
Note: See TracChangeset for help on using the changeset viewer.