Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rb6fe7e6 r02cea2d  
    197197        }
    198198
    199         void AlternativeFinder::find( Expression *expr, bool adjust, bool prune ) {
     199        void AlternativeFinder::find( Expression *expr, bool adjust ) {
    200200                expr->accept( *this );
    201201                if ( alternatives.empty() ) {
     
    207207                        }
    208208                }
    209                 if ( prune ) {
    210                         PRINT(
    211                                 std::cerr << "alternatives before prune:" << std::endl;
    212                                 printAlts( alternatives, std::cerr );
    213                         )
    214                         AltList::iterator oldBegin = alternatives.begin();
    215                         pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer );
    216                         if ( alternatives.begin() == oldBegin ) {
    217                                 std::ostringstream stream;
    218                                 stream << "Can't choose between alternatives for expression ";
    219                                 expr->print( stream );
    220                                 stream << "Alternatives are:";
    221                                 AltList winners;
    222                                 findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) );
    223                                 printAlts( winners, stream, 8 );
    224                                 throw SemanticError( stream.str() );
    225                         }
    226                         alternatives.erase( oldBegin, alternatives.end() );
    227                         PRINT(
    228                                 std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    229                         )
    230                 }
     209                PRINT(
     210                        std::cerr << "alternatives before prune:" << std::endl;
     211                        printAlts( alternatives, std::cerr );
     212                )
     213                AltList::iterator oldBegin = alternatives.begin();
     214                pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer );
     215                if ( alternatives.begin() == oldBegin ) {
     216                        std::ostringstream stream;
     217                        stream << "Can't choose between alternatives for expression ";
     218                        expr->print( stream );
     219                        stream << "Alternatives are:";
     220                        AltList winners;
     221                        findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) );
     222                        printAlts( winners, stream, 8 );
     223                        throw SemanticError( stream.str() );
     224                }
     225                alternatives.erase( oldBegin, alternatives.end() );
     226                PRINT(
     227                        std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
     228                )
    231229
    232230                // Central location to handle gcc extension keyword for all expression types.
     
    236234        }
    237235
    238         void AlternativeFinder::findWithAdjustment( Expression *expr, bool prune ) {
    239                 find( expr, true, prune );
     236        void AlternativeFinder::findWithAdjustment( Expression *expr ) {
     237                find( expr, true );
    240238        }
    241239
    242240        template< typename StructOrUnionType >
    243         void AlternativeFinder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string &name ) {
     241        void AlternativeFinder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const std::string &name ) {
    244242                std::list< Declaration* > members;
    245243                aggInst->lookup( name, members );
     
    762760                        if ( agg->expr->get_results().size() == 1 ) {
    763761                                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( agg->expr->get_results().front() ) ) {
    764                                         addAggMembers( structInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
     762                                        addAggMembers( structInst, agg->expr, agg->cost, memberExpr->get_member() );
    765763                                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( agg->expr->get_results().front() ) ) {
    766                                         addAggMembers( unionInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
     764                                        addAggMembers( unionInst, agg->expr, agg->cost, memberExpr->get_member() );
    767765                                } // if
    768766                        } // if
     
    791789                        renameTypes( alternatives.back().expr );
    792790                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) {
    793                                 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), env, "" );
     791                                addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), "" );
    794792                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) {
    795                                 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), env, "" );
     793                                addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), "" );
    796794                        } // if
    797795                } // for
     
    10141012                alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) );
    10151013        }
    1016 
    1017         void AlternativeFinder::visit( ConstructorExpr * ctorExpr ) {
    1018                 AlternativeFinder finder( indexer, env );
    1019                 // don't prune here, since it's guaranteed all alternatives will have the same type
    1020                 // (giving the alternatives different types is half of the point of ConstructorExpr nodes)
    1021                 finder.findWithAdjustment( ctorExpr->get_callExpr(), false );
    1022                 for ( Alternative & alt : finder.alternatives ) {
    1023                         alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
    1024                 }
    1025         }
    10261014} // namespace ResolvExpr
    10271015
Note: See TracChangeset for help on using the changeset viewer.