Changeset b6d6e97


Ignore:
Timestamp:
Sep 27, 2017, 3:54:21 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7bcb8eb
Parents:
a4477db
Message:

Add maybeFind to AlternativeFinder? to prevent excess exceptions when finding function operators

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    ra4477db rb6d6e97  
    174174        }
    175175
    176         void AlternativeFinder::find( Expression *expr, bool adjust, bool prune ) {
     176        void AlternativeFinder::find( Expression *expr, bool adjust, bool prune, bool failFast ) {
    177177                expr->accept( *this );
    178                 if ( alternatives.empty() ) {
     178                if ( failFast && alternatives.empty() ) {
    179179                        throw SemanticError( "No reasonable alternatives for expression ", expr );
    180180                }
     
    191191                        AltList::iterator oldBegin = alternatives.begin();
    192192                        pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ) );
    193                         if ( alternatives.begin() == oldBegin ) {
     193                        if ( failFast && alternatives.begin() == oldBegin ) {
    194194                                std::ostringstream stream;
    195195                                AltList winners;
     
    214214        }
    215215
    216         void AlternativeFinder::findWithAdjustment( Expression *expr, bool prune ) {
    217                 find( expr, true, prune );
     216        void AlternativeFinder::findWithAdjustment( Expression *expr ) {
     217                find( expr, true );
     218        }
     219
     220        void AlternativeFinder::findWithoutPrune( Expression * expr ) {
     221                find( expr, true, false );
     222        }
     223
     224        void AlternativeFinder::maybeFind( Expression * expr ) {
     225                find( expr, true, true, false );
    218226        }
    219227
     
    714722
    715723                // find function operators
     724                static NameExpr *opExpr = new NameExpr( "?()" );
    716725                AlternativeFinder funcOpFinder( indexer, env );
    717                 NameExpr *opExpr = new NameExpr( "?()" );
    718                 try {
    719                         funcOpFinder.findWithAdjustment( opExpr );
    720                 } catch( SemanticError &e ) {
    721                         // it's ok if there aren't any defined function ops
    722                 }
     726                // it's ok if there aren't any defined function ops
     727                funcOpFinder.maybeFind( opExpr);
    723728                PRINT(
    724729                        std::cerr << "known function ops:" << std::endl;
     
    928933                AlternativeFinder finder( indexer, env );
    929934                // don't prune here, since it's guaranteed all alternatives will have the same type
    930                 // (giving the alternatives different types is half of the point of ConstructorExpr nodes)
    931                 finder.findWithAdjustment( castExpr->get_arg(), false );
     935                finder.findWithoutPrune( castExpr->get_arg() );
    932936                for ( Alternative & alt : finder.alternatives ) {
    933937                        alternatives.push_back( Alternative(
     
    12261230                // don't prune here, since it's guaranteed all alternatives will have the same type
    12271231                // (giving the alternatives different types is half of the point of ConstructorExpr nodes)
    1228                 finder.findWithAdjustment( ctorExpr->get_callExpr(), false );
     1232                finder.findWithoutPrune( ctorExpr->get_callExpr() );
    12291233                for ( Alternative & alt : finder.alternatives ) {
    12301234                        alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
  • src/ResolvExpr/AlternativeFinder.h

    ra4477db rb6d6e97  
    3434          public:
    3535                AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env );
    36                 void find( Expression *expr, bool adjust = false, bool prune = true );
     36                void find( Expression *expr, bool adjust = false, bool prune = true, bool failFast = true );
    3737                /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types
    38                 void findWithAdjustment( Expression *expr, bool prune = true );
     38                void findWithAdjustment( Expression *expr );
     39                /// Calls find with the adjust flag set and prune flag unset; pruning ensures there is at most one alternative per result type
     40                void findWithoutPrune( Expression *expr );
     41                /// Calls find with the adjust and prune flags set, failFast flags unset; fail fast ensures that there is at least one resulting alternative
     42                void maybeFind( Expression *expr );
    3943                AltList &get_alternatives() { return alternatives; }
    4044
Note: See TracChangeset for help on using the changeset viewer.