Changes in src/ResolvExpr/Unify.cc [1cbca6e:02ec390]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r1cbca6e 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 { … … 61 61 62 62 template< typename RefType > void handleRefType( RefType *inst, Type *other ); 63 template< typename RefType > void handleGenericRefType( RefType *inst, Type *other ); 63 64 64 65 bool result; … … 80 81 bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 81 82 TypeEnvironment newEnv; 82 OpenVarSet openVars , closedVars; // added closedVars83 OpenVarSet openVars; 83 84 AssertionSet needAssertions, haveAssertions; 84 85 Type *newFirst = first->clone(), *newSecond = second->clone(); 85 86 env.apply( newFirst ); 86 87 env.apply( newSecond ); 87 88 // do we need to do this? Seems like we do, types should be able to be compatible if they89 // have free variables that can unify90 findOpenVars( newFirst, openVars, closedVars, needAssertions, haveAssertions, false );91 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );92 93 88 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 94 89 delete newFirst; … … 431 426 432 427 void Unify::visit(ArrayType *arrayType) { 428 // XXX -- compare array dimension 433 429 ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 ); 434 // to unify, array types must both be VLA or both not VLA 435 // and must both have a dimension expression or not have a dimension 436 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() 437 && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0) 438 || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) { 439 440 // not positive this is correct in all cases, but it's needed for typedefs 441 if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) { 442 return; 443 } 444 445 if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() && 446 arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0 ) { 447 ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() ); 448 ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() ); 449 assert(ce1 && ce2); 450 451 Constant * c1 = ce1->get_constant(); 452 Constant * c2 = ce2->get_constant(); 453 454 if ( c1->get_value() != c2->get_value() ) { 455 // does not unify if the dimension is different 456 return; 457 } 458 } 459 430 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) { 460 431 result = unifyExact( arrayType->get_base(), otherArray->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 461 432 } // if … … 465 436 bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 466 437 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { 467 // Type * commonType;468 // if ( ! unifyInexact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) {469 438 if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 470 439 return false; … … 481 450 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 482 451 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { 483 452 484 453 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 485 454 … … 496 465 497 466 template< typename RefType > 498 void Unify::handleRefType( RefType *inst, Type *other ) { 467 void Unify::handleRefType( RefType *inst, Type *other ) { 468 // check that other type is compatible and named the same 499 469 RefType *otherStruct = dynamic_cast< RefType* >( other ); 500 470 result = otherStruct && inst->get_name() == otherStruct->get_name(); 501 } 471 } 472 473 template< typename RefType > 474 void Unify::handleGenericRefType( RefType *inst, Type *other ) { 475 // Check that other type is compatible and named the same 476 handleRefType( inst, other ); 477 if ( ! result ) return; 478 // Check that parameters of type unify, if any 479 std::list< Expression* > params = inst->get_parameters(); 480 if ( ! params.empty() ) { 481 std::list< TypeDecl* > *baseParams = inst->get_baseParameters(); 482 if ( ! baseParams ) { 483 result = false; 484 return; 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 } 503 } 504 } 502 505 503 506 void Unify::visit(StructInstType *structInst) { 504 handle RefType( structInst, type2 );507 handleGenericRefType( structInst, type2 ); 505 508 } 506 509 507 510 void Unify::visit(UnionInstType *unionInst) { 508 handle RefType( unionInst, type2 );511 handleGenericRefType( unionInst, type2 ); 509 512 } 510 513
Note:
See TracChangeset
for help on using the changeset viewer.