Changes in src/ResolvExpr/Unify.cc [f5234f3:02ec390]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
rf5234f3 r02ec390 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Sep 02 14:43:22201513 // Update Count : 3611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 26 14:57:05 2015 13 // Update Count : 7 14 14 // 15 15 … … 28 28 29 29 30 // #define DEBUG30 //#define DEBUG 31 31 32 32 namespace ResolvExpr { … … 81 81 bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 82 82 TypeEnvironment newEnv; 83 OpenVarSet openVars , closedVars; // added closedVars83 OpenVarSet openVars; 84 84 AssertionSet needAssertions, haveAssertions; 85 85 Type *newFirst = first->clone(), *newSecond = second->clone(); 86 86 env.apply( newFirst ); 87 87 env.apply( newSecond ); 88 89 // do we need to do this? Seems like we do, types should be able to be compatible if they90 // have free variables that can unify91 findOpenVars( newFirst, openVars, closedVars, needAssertions, haveAssertions, false );92 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );93 94 88 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 95 89 delete newFirst; … … 432 426 433 427 void Unify::visit(ArrayType *arrayType) { 428 // XXX -- compare array dimension 434 429 ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 ); 435 // to unify, array types must both be VLA or both not VLA 436 // and must both have a dimension expression or not have a dimension 437 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() 438 && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0) 439 || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) { 440 441 // not positive this is correct in all cases, but it's needed for typedefs 442 if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) { 443 return; 444 } 445 446 if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() && 447 arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0 ) { 448 ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() ); 449 ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() ); 450 assert(ce1 && ce2); 451 452 Constant * c1 = ce1->get_constant(); 453 Constant * c2 = ce2->get_constant(); 454 455 if ( c1->get_value() != c2->get_value() ) { 456 // does not unify if the dimension is different 457 return; 458 } 459 } 460 430 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) { 461 431 result = unifyExact( arrayType->get_base(), otherArray->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 462 432 } // if … … 466 436 bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 467 437 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { 468 // Type * commonType;469 // if ( ! unifyInexact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) {470 438 if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 471 439 return false; … … 482 450 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 483 451 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { 484 452 485 453 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 486 454 … … 508 476 handleRefType( inst, other ); 509 477 if ( ! result ) return; 510 // Check that parameters of type sunify, if any478 // Check that parameters of type unify, if any 511 479 std::list< Expression* > params = inst->get_parameters(); 512 std::list< Expression* > otherParams = ((RefType*)other)->get_parameters(); 513 514 std::list< Expression* >::const_iterator it = params.begin(), jt = otherParams.begin(); 515 for ( ; it != params.end() && jt != otherParams.end(); ++it, ++jt ) { 516 TypeExpr *param = dynamic_cast< TypeExpr* >(*it); 517 assert(param && "Aggregate parameters should be type expressions"); 518 TypeExpr *otherParam = dynamic_cast< TypeExpr* >(*jt); 519 assert(otherParam && "Aggregate parameters should be type expressions"); 520 521 if ( ! unifyExact( param->get_type(), otherParam->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) { 480 if ( ! params.empty() ) { 481 std::list< TypeDecl* > *baseParams = inst->get_baseParameters(); 482 if ( ! baseParams ) { 522 483 result = false; 523 484 return; 524 485 } 486 std::list< Expression* >::const_iterator it = params.begin(); 487 std::list< TypeDecl* >::const_iterator baseIt = baseParams->begin(); 488 while ( it != params.end() && baseIt != baseParams->end()) { 489 TypeExpr *param = dynamic_cast< TypeExpr* >(*it); 490 assert(param && "Aggregate parameters should be type expressions"); 491 TypeInstType baseType(Type::Qualifiers(), (*baseIt)->get_name(), *baseIt); 492 if ( ! unifyExact( param->get_type(), &baseType, env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) { 493 result = false; 494 return; 495 } 496 497 ++it; 498 ++baseIt; 499 } 500 if ( it != params.end() || baseIt != baseParams->end() ) { 501 result = false; 502 } 525 503 } 526 result = ( it == params.end() && jt == otherParams.end() );527 504 } 528 505
Note:
See TracChangeset
for help on using the changeset viewer.