Changeset 53e3b4a for src/ResolvExpr/Unify.cc
- Timestamp:
- Dec 21, 2016, 5:13:15 PM (7 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:
- 64eae56
- Parents:
- b940dc71
- git-author:
- Rob Schluntz <rschlunt@…> (12/21/16 16:32:57)
- git-committer:
- Rob Schluntz <rschlunt@…> (12/21/16 17:13:15)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
rb940dc71 r53e3b4a 26 26 #include "SymTab/Indexer.h" 27 27 #include "Common/utility.h" 28 28 #include "Tuples/Tuples.h" 29 29 30 30 // #define DEBUG … … 160 160 case TypeDecl::Ftype: 161 161 return isFtype( type, indexer ); 162 case TypeDecl::Ttype: 163 // ttype eats up any remaining parameters, no matter the type 164 return true; 162 165 } // switch 163 assert( false );164 166 return false; 165 167 } … … 485 487 } 486 488 489 template< typename Iterator > 490 Type * combineTypes( Iterator begin, Iterator end ) { 491 std::list< Type * > types; 492 for ( ; begin != end; ++begin ) { 493 // might need to break apart these types too? 494 // yes, looks like we should flatten begin and push back each types individually 495 types.push_back( (*begin)->get_type()->clone() ); 496 } 497 return new TupleType( Type::Qualifiers(), types ); 498 } 499 487 500 template< typename Iterator1, typename Iterator2 > 488 501 bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 489 502 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { 490 // Type * commonType; 491 // if ( ! unifyInexact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) { 492 if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 503 Type * t1 = (*list1Begin)->get_type(); 504 Type * t2 = (*list2Begin)->get_type(); 505 bool isTtype1 = Tuples::isTtype( t1 ); 506 bool isTtype2 = Tuples::isTtype( t2 ); 507 // xxx - assumes ttype must be last parameter; needs cleanup; use unique_ptr for combinedType 508 if ( isTtype1 && ! isTtype2 ) { 509 // combine all of the things in list2, then unify 510 Type * combinedType = combineTypes( list2Begin, list2End ); 511 return unifyExact( t1, combinedType, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 512 } else if ( isTtype2 && ! isTtype1 ) { 513 // combine all of the things in list1, then unify 514 Type * combinedType = combineTypes( list1Begin, list1End ); 515 return unifyExact( combinedType, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 516 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 493 517 return false; 494 518 } // if … … 504 528 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 505 529 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { 506 if ( functionType->get_parameters().size() == otherFunction->get_parameters().size() && functionType->get_returnVals().size() == otherFunction->get_returnVals().size() ) { 530 // sizes don't have to match if ttypes are involved; need to be more precise wrt where the ttype is to prevent errors 531 if ( (functionType->get_parameters().size() == otherFunction->get_parameters().size() && functionType->get_returnVals().size() == otherFunction->get_returnVals().size()) || functionType->isTtype() || otherFunction->isTtype() ) { 507 532 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 508 533 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
Note: See TracChangeset
for help on using the changeset viewer.