Changeset 0362d42
- Timestamp:
- Sep 1, 2016, 3:27:57 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:
- 1ced874
- Parents:
- fba44f8
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rfba44f8 r0362d42 267 267 std::list< DeclarationWithType* >::iterator formal = formals.begin(); 268 268 std::list< Expression* >& actuals = appExpr->get_args(); 269 269 270 for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) { 270 271 PRINT( … … 276 277 std::list< DeclarationWithType* >::iterator startFormal = formal; 277 278 Cost actualCost; 278 for ( std::list< Type* >::iterator actual = (*actualExpr)->get_results().begin(); actual != (*actualExpr)->get_results().end(); ++actual ) { 279 for ( std::list< Type* >::iterator actualType = (*actualExpr)->get_results().begin(); actualType != (*actualExpr)->get_results().end(); ++actualType ) { 280 // xxx - need tuple handling code here 279 281 if ( formal == formals.end() ) { 280 282 if ( function->get_isVarArgs() ) { … … 287 289 PRINT( 288 290 std::cerr << std::endl << "converting "; 289 (*actual )->print( std::cerr, 8 );291 (*actualType)->print( std::cerr, 8 ); 290 292 std::cerr << std::endl << " to "; 291 293 (*formal)->get_type()->print( std::cerr, 8 ); 292 294 ) 293 Cost newCost = conversionCost( *actual , (*formal)->get_type(), indexer, alt.env );295 Cost newCost = conversionCost( *actualType, (*formal)->get_type(), indexer, alt.env ); 294 296 PRINT( 295 297 std::cerr << std::endl << "cost is" << newCost << std::endl; … … 302 304 actualCost += newCost; 303 305 304 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actual , alt.env, indexer ), 0 );306 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actualType, alt.env, indexer ), 0 ); 305 307 306 308 formal++; … … 362 364 } 363 365 366 template< typename OutputIterator > 367 void flatten( Type * type, OutputIterator out ) { 368 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) { 369 for ( Type * t : *tupleType ) { 370 flatten( t, out ); 371 } 372 } else { 373 *out++ = type; 374 } 375 } 376 364 377 bool AlternativeFinder::instantiateFunction( std::list< DeclarationWithType* >& formals, /*const*/ AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave ) { 365 378 simpleCombineEnvironments( actuals.begin(), actuals.end(), resultEnv ); … … 379 392 */ 380 393 std::list< DeclarationWithType* >::iterator formal = formals.begin(); 394 395 std::list< Type * > formalTypes; 396 std::list< Type * >::iterator formalType = formalTypes.end(); 397 381 398 for ( AltList::const_iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) { 382 for ( std::list< Type* >::iterator actual = actualExpr->expr->get_results().begin(); actual != actualExpr->expr->get_results().end(); ++actual ) { 383 if ( formal == formals.end() ) { 384 return isVarArgs; 399 std::list< Type* > & actualTypes = actualExpr->expr->get_results(); 400 for ( std::list< Type* >::iterator actualType = actualTypes.begin(); actualType != actualTypes.end(); ++actualType ) { 401 if ( formalType == formalTypes.end() ) { 402 // the type of the formal parameter may be a tuple type. To make this easier to work with, 403 // flatten the tuple type and traverse the resulting list of types, incrementing the formal 404 // iterator once its types have been extracted. Once a particular formal parameter's type has 405 // been exhausted load the next formal parameter's type. 406 if ( formal == formals.end() ) { 407 return isVarArgs; 408 } 409 formalTypes.clear(); 410 flatten( (*formal)->get_type(), back_inserter( formalTypes ) ); 411 formalType = formalTypes.begin(); 412 ++formal; 385 413 } 386 414 PRINT( … … 388 416 (*formal)->get_type()->print( std::cerr ); 389 417 std::cerr << std::endl << "actual type is "; 390 (*actual )->print( std::cerr );418 (*actualType)->print( std::cerr ); 391 419 std::cerr << std::endl; 392 420 ) 393 if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {421 if ( ! unify( *formalType, *actualType, resultEnv, resultNeed, resultHave, openVars, indexer ) ) { 394 422 return false; 395 423 } 396 formal++; 397 } 398 } 424 ++formalType; 425 } 426 } 427 428 // xxx - a tuple type was not completely matched 429 // partially handle the tuple with default arguments?? 430 if ( formalType != formalTypes.end() ) return false; 431 399 432 // Handling of default values 400 433 while ( formal != formals.end() ) { -
src/ResolvExpr/AlternativeFinder.h
rfba44f8 r0362d42 67 67 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ); 68 68 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. 69 71 template< typename InputIterator, typename OutputIterator > 70 72 void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out ); -
src/SynTree/Type.h
rfba44f8 r0362d42 352 352 virtual ~TupleType(); 353 353 354 typedef std::list<Type*> value_type; 355 typedef value_type::iterator iterator; 356 354 357 std::list<Type*>& get_types() { return types; } 358 359 iterator begin() { return types.begin(); } 360 iterator end() { return types.end(); } 355 361 356 362 virtual TupleType *clone() const { return new TupleType( *this ); }
Note: See TracChangeset
for help on using the changeset viewer.