Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r6ccfb7f rddf8a29  
    698698
    699699        void AlternativeFinder::visit( UntypedExpr *untypedExpr ) {
     700                bool doneInit = false;
     701                AlternativeFinder funcOpFinder( indexer, env );
     702
     703                AlternativeFinder funcFinder( indexer, env );
     704
    700705                {
    701706                        std::string fname = InitTweak::getFunctionName( untypedExpr );
     
    710715                }
    711716
    712                 AlternativeFinder funcFinder( indexer, env );
    713717                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 
    717718                std::list< AlternativeFinder > argAlternatives;
    718719                findSubExprs( untypedExpr->begin_args(), untypedExpr->end_args(), back_inserter( argAlternatives ) );
     
    724725                // if not tuple assignment, assignment is taken care of as a normal function call
    725726                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                 )
    739727
    740728                AltList candidates;
     
    766754                                                } // if
    767755                                        } // 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
     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
    782784                                                } // if
    783                                         } // if
    784                                 } // for
     785                                        } // for
     786                                } // if
    785787                        } catch ( SemanticError &e ) {
    786788                                errors.append( e );
Note: See TracChangeset for help on using the changeset viewer.