- File:
-
- 1 edited
-
src/ResolvExpr/AlternativeFinder.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r0362d42 r85517ddb 42 42 #include "Common/utility.h" 43 43 #include "InitTweak/InitTweak.h" 44 #include "ResolveTypeof.h" 44 45 45 46 extern bool resolvep; … … 267 268 std::list< DeclarationWithType* >::iterator formal = formals.begin(); 268 269 std::list< Expression* >& actuals = appExpr->get_args(); 269 270 270 for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) { 271 271 PRINT( … … 277 277 std::list< DeclarationWithType* >::iterator startFormal = formal; 278 278 Cost actualCost; 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 for ( std::list< Type* >::iterator actual = (*actualExpr)->get_results().begin(); actual != (*actualExpr)->get_results().end(); ++actual ) { 281 280 if ( formal == formals.end() ) { 282 281 if ( function->get_isVarArgs() ) { … … 289 288 PRINT( 290 289 std::cerr << std::endl << "converting "; 291 (*actual Type)->print( std::cerr, 8 );290 (*actual)->print( std::cerr, 8 ); 292 291 std::cerr << std::endl << " to "; 293 292 (*formal)->get_type()->print( std::cerr, 8 ); 294 293 ) 295 Cost newCost = conversionCost( *actual Type, (*formal)->get_type(), indexer, alt.env );294 Cost newCost = conversionCost( *actual, (*formal)->get_type(), indexer, alt.env ); 296 295 PRINT( 297 296 std::cerr << std::endl << "cost is" << newCost << std::endl; … … 304 303 actualCost += newCost; 305 304 306 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actual Type, alt.env, indexer ), 0 );305 convCost += Cost( 0, polyCost( (*formal)->get_type(), alt.env, indexer ) + polyCost( *actual, alt.env, indexer ), 0 ); 307 306 308 307 formal++; … … 364 363 } 365 364 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 377 365 bool AlternativeFinder::instantiateFunction( std::list< DeclarationWithType* >& formals, /*const*/ AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave ) { 378 366 simpleCombineEnvironments( actuals.begin(), actuals.end(), resultEnv ); … … 392 380 */ 393 381 std::list< DeclarationWithType* >::iterator formal = formals.begin(); 394 395 std::list< Type * > formalTypes;396 std::list< Type * >::iterator formalType = formalTypes.end();397 398 382 for ( AltList::const_iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) { 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; 383 for ( std::list< Type* >::iterator actual = actualExpr->expr->get_results().begin(); actual != actualExpr->expr->get_results().end(); ++actual ) { 384 if ( formal == formals.end() ) { 385 return isVarArgs; 413 386 } 414 387 PRINT( … … 416 389 (*formal)->get_type()->print( std::cerr ); 417 390 std::cerr << std::endl << "actual type is "; 418 (*actual Type)->print( std::cerr );391 (*actual)->print( std::cerr ); 419 392 std::cerr << std::endl; 420 393 ) 421 if ( ! unify( *formalType, *actualType, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {394 if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) { 422 395 return false; 423 396 } 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 397 formal++; 398 } 399 } 432 400 // Handling of default values 433 401 while ( formal != formals.end() ) { … … 740 708 void AlternativeFinder::visit( CastExpr *castExpr ) { 741 709 for ( std::list< Type* >::iterator i = castExpr->get_results().begin(); i != castExpr->get_results().end(); ++i ) { 710 *i = resolveTypeof( *i, indexer ); 742 711 SymTab::validateType( *i, &indexer ); 743 712 adjustExprType( *i, env, indexer ); … … 828 797 829 798 void AlternativeFinder::visit( VariableExpr *variableExpr ) { 830 alternatives.push_back( Alternative( variableExpr->clone(), env, Cost::zero ) ); 799 // not sufficient to clone here, because variable's type may have changed 800 // since the VariableExpr was originally created. 801 alternatives.push_back( Alternative( new VariableExpr( variableExpr->get_var() ), env, Cost::zero ) ); 831 802 } 832 803 … … 837 808 void AlternativeFinder::visit( SizeofExpr *sizeofExpr ) { 838 809 if ( sizeofExpr->get_isType() ) { 810 // xxx - resolveTypeof? 839 811 alternatives.push_back( Alternative( sizeofExpr->clone(), env, Cost::zero ) ); 840 812 } else { … … 856 828 void AlternativeFinder::visit( AlignofExpr *alignofExpr ) { 857 829 if ( alignofExpr->get_isType() ) { 830 // xxx - resolveTypeof? 858 831 alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) ); 859 832 } else { … … 889 862 void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) { 890 863 AlternativeFinder funcFinder( indexer, env ); 864 // xxx - resolveTypeof? 891 865 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( offsetofExpr->get_type() ) ) { 892 866 addOffsetof( structInst, offsetofExpr->get_member() );
Note:
See TracChangeset
for help on using the changeset viewer.