Changeset 64eae56 for src/GenPoly


Ignore:
Timestamp:
Dec 21, 2016, 5:15:27 PM (7 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:
0c286cf
Parents:
53e3b4a
Message:

match formal parameter type of actual function when specializing ttype parameter, flatten types when unifying ttype parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r53e3b4a r64eae56  
    194194        }
    195195
     196        /// restructures arg to match the structure of a single formal parameter. Assumes that atomic types are compatible (as the Resolver should have ensured this)
     197        template< typename OutIterator >
     198        void matchOneFormal( Expression * arg, unsigned & idx, Type * formal, OutIterator out ) {
     199                if ( TupleType * tupleType = dynamic_cast< TupleType * >( formal ) ) {
     200                        std::list< Expression * > exprs;
     201                        for ( Type * t : *tupleType ) {
     202                                matchOneFormal( arg, idx, t, back_inserter( exprs ) );
     203                        }
     204                        *out++ = new TupleExpr( exprs );
     205                } else {
     206                        *out++ = new TupleIndexExpr( arg->clone(), idx++ );
     207                }
     208        }
     209
     210        /// restructures the ttype argument to match the structure of the formal parameters of the actual function.
     211        // [begin, end) are the formal parameters.
     212        // args is the list of arguments currently given to the actual function, the last of which needs to be restructured.
    196213        template< typename Iterator >
    197214        void fixLastArg( std::list< Expression * > & args, Iterator begin, Iterator end ) {
     
    203220                unsigned idx = 0;
    204221                for ( ; begin != end; ++begin ) {
    205                         // DeclarationWithType * formal = *begin;
    206                         // Type * formalType = formal->get_type();
    207                         args.push_back( new TupleIndexExpr( last->clone(), idx++ ) );
     222                        DeclarationWithType * formal = *begin;
     223                        Type * formalType = formal->get_type();
     224                        matchOneFormal( last, idx, formalType, back_inserter( args ) );
    208225                }
    209226                delete last;
     
    238255
    239256                for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) {
     257                        // 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 );
    240259                        ++begin;
    241                         assert( begin != end );
    242260
    243261                        // std::cerr << "thunk param: " << param << std::endl;
Note: See TracChangeset for help on using the changeset viewer.