Changeset 4c8621ac for src/GenPoly
- Timestamp:
- Dec 22, 2016, 4:07:58 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Specialize.cc
r907eccb r4c8621ac 32 32 #include "Common/utility.h" 33 33 #include "InitTweak/InitTweak.h" 34 #include "Tuples/Tuples.h" 34 35 35 36 namespace GenPoly { … … 211 212 // [begin, end) are the formal parameters. 212 213 // 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 ) { 217 216 // safe_dynamic_cast for the assertion 218 217 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 with220 218 unsigned idx = 0; 221 219 for ( ; begin != end; ++begin ) { 222 220 DeclarationWithType * formal = *begin; 223 221 Type * formalType = formal->get_type(); 224 matchOneFormal( last, idx, formalType, back_inserter( args ));222 matchOneFormal( last, idx, formalType, out ); 225 223 } 226 224 delete last; … … 251 249 252 250 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; 256 257 for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) { 257 258 // 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(?)263 259 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 264 269 appExpr->get_args().push_back( new VariableExpr( param ) ); 265 270 } // for 266 fixLastArg( appExpr->get_args(), --begin, end ); 271 assert( last ); 272 fixLastArg( last, actualBegin, actualEnd, back_inserter( appExpr->get_args() ) ); 267 273 appExpr->set_env( maybeClone( env ) ); 268 274 if ( inferParams ) {
Note: See TracChangeset
for help on using the changeset viewer.