Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rddf8a29 r6ccfb7f  
    698698
    699699        void AlternativeFinder::visit( UntypedExpr *untypedExpr ) {
    700                 bool doneInit = false;
    701                 AlternativeFinder funcOpFinder( indexer, env );
    702 
    703                 AlternativeFinder funcFinder( indexer, env );
    704 
    705700                {
    706701                        std::string fname = InitTweak::getFunctionName( untypedExpr );
     
    715710                }
    716711
     712                AlternativeFinder funcFinder( indexer, env );
    717713                funcFinder.findWithAdjustment( untypedExpr->get_function() );
     714                // if there are no function alternatives, then proceeding is a waste of time.
     715                if ( funcFinder.alternatives.empty() ) return;
     716
    718717                std::list< AlternativeFinder > argAlternatives;
    719718                findSubExprs( untypedExpr->begin_args(), untypedExpr->end_args(), back_inserter( argAlternatives ) );
     
    725724                // if not tuple assignment, assignment is taken care of as a normal function call
    726725                Tuples::handleTupleAssignment( *this, untypedExpr, possibilities );
     726
     727                // find function operators
     728                AlternativeFinder funcOpFinder( indexer, env );
     729                NameExpr *opExpr = new NameExpr( "?()" );
     730                try {
     731                        funcOpFinder.findWithAdjustment( opExpr );
     732                } catch( SemanticError &e ) {
     733                        // it's ok if there aren't any defined function ops
     734                }
     735                PRINT(
     736                        std::cerr << "known function ops:" << std::endl;
     737                        printAlts( funcOpFinder.alternatives, std::cerr, 8 );
     738                )
    727739
    728740                AltList candidates;
     
    754766                                                } // if
    755767                                        } // if
    756                                 } else {
    757                                         // seek a function operator that's compatible
    758                                         if ( ! doneInit ) {
    759                                                 doneInit = true;
    760                                                 NameExpr *opExpr = new NameExpr( "?()" );
    761                                                 try {
    762                                                         funcOpFinder.findWithAdjustment( opExpr );
    763                                                 } catch( SemanticError &e ) {
    764                                                         // it's ok if there aren't any defined function ops
    765                                                 }
    766                                                 PRINT(
    767                                                         std::cerr << "known function ops:" << std::endl;
    768                                                         printAlts( funcOpFinder.alternatives, std::cerr, 8 );
    769                                                 )
    770                                         }
    771 
    772                                         for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
    773                                                 // check if the type is pointer to function
    774                                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) {
    775                                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    776                                                                 referenceToRvalueConversion( funcOp->expr );
    777                                                                 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
    778                                                                         AltList currentAlt;
    779                                                                         currentAlt.push_back( *func );
    780                                                                         currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
    781                                                                         makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
    782                                                                 } // for
    783                                                         } // if
     768                                }
     769
     770                                // try each function operator ?() with the current function alternative and each of the argument combinations
     771                                for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
     772                                        // check if the type is pointer to function
     773                                        if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) {
     774                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     775                                                        referenceToRvalueConversion( funcOp->expr );
     776                                                        for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     777                                                                AltList currentAlt;
     778                                                                currentAlt.push_back( *func );
     779                                                                currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() );
     780                                                                makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );
     781                                                        } // for
    784782                                                } // if
    785                                         } // for
    786                                 } // if
     783                                        } // if
     784                                } // for
    787785                        } catch ( SemanticError &e ) {
    788786                                errors.append( e );
Note: See TracChangeset for help on using the changeset viewer.