Changeset e76acbe
- Timestamp:
- Sep 7, 2016, 10:46:55 AM (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:
- 4e7f0f1
- Parents:
- 1ced874
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r1ced874 re76acbe 174 174 } 175 175 } 176 177 // flatten tuple type into list of types 178 template< typename OutputIterator > 179 void flatten( Type * type, OutputIterator out ) { 180 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) { 181 for ( Type * t : *tupleType ) { 182 flatten( t, out ); 183 } 184 } else { 185 *out++ = type; 186 } 187 } 176 188 } 177 189 … … 269 281 std::list< Expression* >& actuals = appExpr->get_args(); 270 282 283 std::list< Type * > formalTypes; 284 std::list< Type * >::iterator formalType = formalTypes.end(); 285 271 286 for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) { 287 272 288 PRINT( 273 289 std::cerr << "actual expression:" << std::endl; … … 279 295 Cost actualCost; 280 296 for ( std::list< Type* >::iterator actualType = (*actualExpr)->get_results().begin(); actualType != (*actualExpr)->get_results().end(); ++actualType ) { 281 // xxx - need tuple handling code here 282 if ( formal == formals.end() ) { 283 if ( function->get_isVarArgs() ) { 284 convCost += Cost( 1, 0, 0 ); 285 break; 286 } else { 287 return Cost::infinity; 297 298 // tuple handling code 299 if ( formalType == formalTypes.end() ) { 300 // the type of the formal parameter may be a tuple type. To make this easier to work with, 301 // flatten the tuple type and traverse the resulting list of types, incrementing the formal 302 // iterator once its types have been extracted. Once a particular formal parameter's type has 303 // been exhausted load the next formal parameter's type. 304 if ( formal == formals.end() ) { 305 if ( function->get_isVarArgs() ) { 306 convCost += Cost( 1, 0, 0 ); 307 break; 308 } else { 309 return Cost::infinity; 310 } 288 311 } 312 formalTypes.clear(); 313 flatten( (*formal)->get_type(), back_inserter( formalTypes ) ); 314 formalType = formalTypes.begin(); 315 ++formal; 289 316 } 317 290 318 PRINT( 291 319 std::cerr << std::endl << "converting "; … … 294 322 (*formal)->get_type()->print( std::cerr, 8 ); 295 323 ) 296 Cost newCost = conversionCost( *actualType, (*formal)->get_type(), indexer, alt.env );324 Cost newCost = conversionCost( *actualType, *formalType, indexer, alt.env ); 297 325 PRINT( 298 326 std::cerr << std::endl << "cost is" << newCost << std::endl; … … 305 333 actualCost += newCost; 306 334 307 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actualType, alt.env, indexer ), 0 );308 309 formal ++;335 convCost += Cost( 0, polyCost( *formalType, alt.env, indexer ) + polyCost( *actualType, alt.env, indexer ), 0 ); 336 337 formalType++; 310 338 } 311 339 if ( actualCost != Cost( 0, 0, 0 ) ) { … … 362 390 } 363 391 /// needAssertions.insert( needAssertions.end(), (*tyvar)->get_assertions().begin(), (*tyvar)->get_assertions().end() ); 364 }365 }366 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 392 } 376 393 }
Note: See TracChangeset
for help on using the changeset viewer.