Changes in / [1ced874:f04a8b81]


Ignore:
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r1ced874 rf04a8b81  
    268268                std::list< DeclarationWithType* >::iterator formal = formals.begin();
    269269                std::list< Expression* >& actuals = appExpr->get_args();
    270 
    271270                for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) {
    272271                        PRINT(
     
    278277                        std::list< DeclarationWithType* >::iterator startFormal = formal;
    279278                        Cost actualCost;
    280                         for ( std::list< Type* >::iterator actualType = (*actualExpr)->get_results().begin(); actualType != (*actualExpr)->get_results().end(); ++actualType ) {
    281                                 // xxx - need tuple handling code here
     279                        for ( std::list< Type* >::iterator actual = (*actualExpr)->get_results().begin(); actual != (*actualExpr)->get_results().end(); ++actual ) {
    282280                                if ( formal == formals.end() ) {
    283281                                        if ( function->get_isVarArgs() ) {
     
    290288                                PRINT(
    291289                                        std::cerr << std::endl << "converting ";
    292                                         (*actualType)->print( std::cerr, 8 );
     290                                        (*actual)->print( std::cerr, 8 );
    293291                                        std::cerr << std::endl << " to ";
    294292                                        (*formal)->get_type()->print( std::cerr, 8 );
    295293                                )
    296                                 Cost newCost = conversionCost( *actualType, (*formal)->get_type(), indexer, alt.env );
     294                                Cost newCost = conversionCost( *actual, (*formal)->get_type(), indexer, alt.env );
    297295                                PRINT(
    298296                                        std::cerr << std::endl << "cost is" << newCost << std::endl;
     
    305303                                actualCost += newCost;
    306304
    307                                 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actualType, alt.env, indexer ), 0 );
     305                                convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actual, alt.env, indexer ), 0 );
    308306
    309307                                formal++;
     
    365363        }
    366364
    367         template< typename OutputIterator >
    368         void flatten( Type * type, OutputIterator out ) {
    369                 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
    370                         for ( Type * t : *tupleType ) {
    371                                 flatten( t, out );
    372                         }
    373                 } else {
    374                         *out++ = type;
    375                 }
    376         }
    377 
    378365        bool AlternativeFinder::instantiateFunction( std::list< DeclarationWithType* >& formals, /*const*/ AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave ) {
    379366                simpleCombineEnvironments( actuals.begin(), actuals.end(), resultEnv );
     
    393380                */
    394381                std::list< DeclarationWithType* >::iterator formal = formals.begin();
    395 
    396                 std::list< Type * > formalTypes;
    397                 std::list< Type * >::iterator formalType = formalTypes.end();
    398 
    399382                for ( AltList::const_iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) {
    400                         std::list< Type* > & actualTypes = actualExpr->expr->get_results();
    401                         for ( std::list< Type* >::iterator actualType = actualTypes.begin(); actualType != actualTypes.end(); ++actualType ) {
    402                                 if ( formalType == formalTypes.end() ) {
    403                                         // the type of the formal parameter may be a tuple type. To make this easier to work with,
    404                                         // flatten the tuple type and traverse the resulting list of types, incrementing the formal
    405                                         // iterator once its types have been extracted. Once a particular formal parameter's type has
    406                                         // been exhausted load the next formal parameter's type.
    407                                         if ( formal == formals.end() ) {
    408                                                 return isVarArgs;
    409                                         }
    410                                         formalTypes.clear();
    411                                         flatten( (*formal)->get_type(), back_inserter( formalTypes ) );
    412                                         formalType = formalTypes.begin();
    413                                         ++formal;
     383                        for ( std::list< Type* >::iterator actual = actualExpr->expr->get_results().begin(); actual != actualExpr->expr->get_results().end(); ++actual ) {
     384                                if ( formal == formals.end() ) {
     385                                        return isVarArgs;
    414386                                }
    415387                                PRINT(
     
    417389                                        (*formal)->get_type()->print( std::cerr );
    418390                                        std::cerr << std::endl << "actual type is ";
    419                                         (*actualType)->print( std::cerr );
     391                                        (*actual)->print( std::cerr );
    420392                                        std::cerr << std::endl;
    421393                                )
    422                                 if ( ! unify( *formalType, *actualType, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {
     394                                if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {
    423395                                        return false;
    424396                                }
    425                                 ++formalType;
    426                         }
    427                 }
    428 
    429                 // xxx - a tuple type was not completely matched
    430                 // partially handle the tuple with default arguments??
    431                 if ( formalType != formalTypes.end() ) return false;
    432 
     397                                formal++;
     398                        }
     399                }
    433400                // Handling of default values
    434401                while ( formal != formals.end() ) {
  • src/ResolvExpr/AlternativeFinder.h

    r1ced874 rf04a8b81  
    6767                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
    6868          public:  // xxx - temporary hack - should make Tuples::TupleAssignment a friend
    69           /// Runs a new alternative finder on each element in [begin, end)
    70           /// and writes each alternative finder to out.
    7169                template< typename InputIterator, typename OutputIterator >
    7270                void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out );
  • src/SynTree/Type.h

    r1ced874 rf04a8b81  
    352352        virtual ~TupleType();
    353353
    354         typedef std::list<Type*> value_type;
    355         typedef value_type::iterator iterator;
    356 
    357354        std::list<Type*>& get_types() { return types; }
    358 
    359         iterator begin() { return types.begin(); }
    360         iterator end() { return types.end(); }
    361355
    362356        virtual TupleType *clone() const { return new TupleType( *this ); }
Note: See TracChangeset for help on using the changeset viewer.