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