Changeset 4c8621ac for src/GenPoly


Ignore:
Timestamp:
Dec 22, 2016, 4:07:58 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1e3d5b6
Parents:
907eccb
Message:

allow construction, destruction, and assignment for empty tuples, allow matching a ttype parameter with an empty tuple, fix specialization to work with empty tuples and void functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r907eccb r4c8621ac  
    3232#include "Common/utility.h"
    3333#include "InitTweak/InitTweak.h"
     34#include "Tuples/Tuples.h"
    3435
    3536namespace GenPoly {
     
    211212        // [begin, end) are the formal parameters.
    212213        // args is the list of arguments currently given to the actual function, the last of which needs to be restructured.
    213         template< typename Iterator >
    214         void fixLastArg( std::list< Expression * > & args, Iterator begin, Iterator end ) {
    215                 assertf( ! args.empty(), "Somehow args to tuple function are empty" ); // xxx - it's quite possible this will trigger for the nullary case...
    216                 Expression * last = args.back();
     214        template< typename Iterator, typename OutIterator >
     215        void fixLastArg( Expression * last, Iterator begin, Iterator end, OutIterator out ) {
    217216                // safe_dynamic_cast for the assertion
    218217                safe_dynamic_cast< TupleType * >( last->get_result() ); // xxx - it's quite possible this will trigger for the unary case...
    219                 args.pop_back(); // replace last argument in the call with
    220218                unsigned idx = 0;
    221219                for ( ; begin != end; ++begin ) {
    222220                        DeclarationWithType * formal = *begin;
    223221                        Type * formalType = formal->get_type();
    224                         matchOneFormal( last, idx, formalType, back_inserter( args ) );
     222                        matchOneFormal( last, idx, formalType, out );
    225223                }
    226224                delete last;
     
    251249
    252250                FunctionType * actualType = getFunctionType( actual->get_result() );
    253                 std::list< DeclarationWithType * >::iterator begin = actualType->get_parameters().begin();
    254                 std::list< DeclarationWithType * >::iterator end = actualType->get_parameters().end();
    255 
     251                std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();
     252                std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();
     253                std::list< DeclarationWithType * >::iterator formalBegin = funType->get_parameters().begin();
     254                std::list< DeclarationWithType * >::iterator formalEnd = funType->get_parameters().end();
     255
     256                Expression * last = nullptr;
    256257                for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) {
    257258                        // walk the parameters to the actual function alongside the parameters to the thunk to find the location where the ttype parameter begins to satisfy parameters in the actual function.
    258                         assert( begin != end );
    259                         ++begin;
    260 
    261                         // std::cerr << "thunk param: " << param << std::endl;
    262                         // last param will always be a tuple type... expand it into the actual type(?)
    263259                        param->set_name( paramNamer.newName() );
     260                        assertf( formalBegin != formalEnd, "Reached end of formal parameters before finding ttype parameter" );
     261                        if ( Tuples::isTtype((*formalBegin)->get_type()) ) {
     262                                last = new VariableExpr( param );
     263                                break;
     264                        }
     265                        assertf( actualBegin != actualEnd, "reached end of actual function's arguments before finding ttype parameter" );
     266                        ++actualBegin;
     267                        ++formalBegin;
     268
    264269                        appExpr->get_args().push_back( new VariableExpr( param ) );
    265270                } // for
    266                 fixLastArg( appExpr->get_args(), --begin, end );
     271                assert( last );
     272                fixLastArg( last, actualBegin, actualEnd, back_inserter( appExpr->get_args() ) );
    267273                appExpr->set_env( maybeClone( env ) );
    268274                if ( inferParams ) {
Note: See TracChangeset for help on using the changeset viewer.