Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r0f79853 r00ac42e  
    176176                                                selected[ mangleName ] = current;
    177177                                        } else if ( candidate->cost == mapPlace->second.candidate->cost ) {
    178                                                 // if one of the candidates contains a deleted identifier, can pick the other, since
    179                                                 // deleted expressions should not be ambiguous if there is another option that is at least as good
    180                                                 if ( findDeletedExpr( candidate->expr ) ) {
    181                                                         // do nothing
    182                                                         PRINT( std::cerr << "candidate is deleted" << std::endl; )
    183                                                 } else if ( findDeletedExpr( mapPlace->second.candidate->expr ) ) {
    184                                                         PRINT( std::cerr << "current is deleted" << std::endl; )
    185                                                         selected[ mangleName ] = current;
    186                                                 } else {
    187                                                         PRINT(
    188                                                                 std::cerr << "marking ambiguous" << std::endl;
    189                                                         )
    190                                                         mapPlace->second.isAmbiguous = true;
    191                                                 }
     178                                                PRINT(
     179                                                        std::cerr << "marking ambiguous" << std::endl;
     180                                                )
     181                                                mapPlace->second.isAmbiguous = true;
    192182                                        } else {
    193183                                                PRINT(
     
    345335                if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) {
    346336                        // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning
    347                         auto val = constantExpr->intValue();
     337                        // xxx - this should be improved by memoizing the value of constant exprs
     338                        // during parsing and reusing that information here.
     339                        std::stringstream ss( constantExpr->get_constant()->get_value() );
     340                        int val = 0;
    348341                        std::string tmp;
    349                         if ( val >= 0 && (unsigned long long)val < tupleType->size() ) {
     342                        if ( ss >> val && ! (ss >> tmp) ) {
     343                                if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
     344                                        alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     345                                } // if
     346                        } // if
     347                } else if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ) ) {
     348                        // xxx - temporary hack until 0/1 are int constants
     349                        if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
     350                                std::stringstream ss( nameExpr->get_name() );
     351                                int val;
     352                                ss >> val;
    350353                                alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
    351                         } // if
     354                        }
    352355                } // if
    353356        }
     
    436439                                        return Cost::infinity;
    437440                                }
    438                         }
    439                         if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) {
    440                                 // default arguments should be free - don't include conversion cost.
    441                                 // Unwrap them here because they are not relevant to the rest of the system.
    442                                 *actualExpr = def->expr;
    443                                 ++formal;
    444                                 continue;
    445441                        }
    446442                        Type * formalType = (*formal)->get_type();
     
    615611        ConstantExpr* getDefaultValue( Initializer* init ) {
    616612                if ( SingleInit* si = dynamic_cast<SingleInit*>( init ) ) {
    617                         if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->value ) ) {
    618                                 return dynamic_cast<ConstantExpr*>( ce->arg );
    619                         } else {
    620                                 return dynamic_cast<ConstantExpr*>( si->value );
     613                        if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->get_value() ) ) {
     614                                return dynamic_cast<ConstantExpr*>( ce->get_arg() );
    621615                        }
    622616                }
     
    879873                                                                indexer ) ) {
    880874                                                        results.emplace_back(
    881                                                                 i, new DefaultArgExpr( cnstExpr ), move(env), move(need), move(have),
     875                                                                i, cnstExpr, move(env), move(need), move(have),
    882876                                                                move(openVars), nextArg, nTuples );
    883877                                                }
     
    10711065                funcFinder.findWithAdjustment( untypedExpr->function );
    10721066                // if there are no function alternatives, then proceeding is a waste of time.
    1073                 // xxx - findWithAdjustment throws, so this check and others like it shouldn't be necessary.
    10741067                if ( funcFinder.alternatives.empty() ) return;
    10751068
Note: See TracChangeset for help on using the changeset viewer.