Changes in src/ResolvExpr/Unify.cc [62423350:ce8c12f]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r62423350 rce8c12f 42 42 virtual void visit(PointerType *pointerType); 43 43 virtual void visit(ArrayType *arrayType); 44 virtual void visit(ReferenceType *refType); 44 45 virtual void visit(FunctionType *functionType); 45 46 virtual void visit(StructInstType *aggregateUseType); … … 114 115 } 115 116 116 bool isFtype( Type *type ) {117 bool isFtype( Type *type, const SymTab::Indexer &indexer ) { 117 118 if ( dynamic_cast< FunctionType* >( type ) ) { 118 119 return true; … … 123 124 } 124 125 125 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {126 bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) { 126 127 switch ( data.kind ) { 127 128 case TypeDecl::Any: … … 131 132 // type must also be complete 132 133 // xxx - should this also check that type is not a tuple type and that it's not a ttype? 133 return ! isFtype( type ) && (! data.isComplete || type->isComplete() );134 return ! isFtype( type, indexer ) && (! data.isComplete || type->isComplete() ); 134 135 case TypeDecl::Ftype: 135 return isFtype( type );136 return isFtype( type, indexer ); 136 137 case TypeDecl::Ttype: 137 138 // ttype unifies with any tuple type … … 144 145 OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() ); 145 146 assert( tyvar != openVars.end() ); 146 if ( ! tyVarCompatible( tyvar->second, other ) ) {147 if ( ! tyVarCompatible( tyvar->second, other, indexer ) ) { 147 148 return false; 148 149 } // if … … 344 345 std::cerr << "unifyInexact type 1 is "; 345 346 type1->print( std::cerr ); 346 std::cerr << " type 2 is ";347 std::cerr << "type 2 is "; 347 348 type2->print( std::cerr ); 348 349 std::cerr << std::endl; … … 388 389 } 389 390 390 void Unify::visit( __attribute__((unused))VoidType *voidType) {391 void Unify::visit(VoidType *voidType) { 391 392 result = dynamic_cast< VoidType* >( type2 ); 392 393 } … … 425 426 markAssertions( haveAssertions, needAssertions, pointerType ); 426 427 markAssertions( haveAssertions, needAssertions, otherPointer ); 428 } // if 429 } 430 431 void Unify::visit(ReferenceType *refType) { 432 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) { 433 result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 434 markAssertions( haveAssertions, needAssertions, refType ); 435 markAssertions( haveAssertions, needAssertions, otherRef ); 427 436 } // if 428 437 } … … 606 615 } else if ( tupleParam ) { 607 616 // bundle other parameters into tuple to match 608 std::list< Type * > binderTypes;617 TupleType* binder = new TupleType{ paramTy->get_qualifiers() }; 609 618 610 619 do { 611 binder Types.push_back( otherParam->get_type()->clone() );620 binder->get_types().push_back( otherParam->get_type()->clone() ); 612 621 ++jt; 613 622 … … 618 627 } while (true); 619 628 620 otherParamTy = new TupleType{ paramTy->get_qualifiers(), binderTypes };629 otherParamTy = binder; 621 630 ++it; // skip ttype parameter for break 622 631 } else if ( otherTupleParam ) { 623 632 // bundle parameters into tuple to match other 624 std::list< Type * > binderTypes;633 TupleType* binder = new TupleType{ otherParamTy->get_qualifiers() }; 625 634 626 635 do { 627 binder Types.push_back( param->get_type()->clone() );636 binder->get_types().push_back( param->get_type()->clone() ); 628 637 ++it; 629 638 … … 634 643 } while (true); 635 644 636 paramTy = new TupleType{ otherParamTy->get_qualifiers(), binderTypes };645 paramTy = binder; 637 646 ++jt; // skip ttype parameter for break 638 647 } … … 683 692 684 693 template< typename Iterator1, typename Iterator2 > 685 bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) {694 bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 686 695 auto get_type = [](Type * t) { return t; }; 687 696 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { … … 733 742 flatten( flat2.get(), back_inserter( types2 ) ); 734 743 735 result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, indexer );736 } // if 737 } 738 739 void Unify::visit( __attribute__((unused)) VarArgsType *varArgsType) {744 result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, widenMode, indexer ); 745 } // if 746 } 747 748 void Unify::visit(VarArgsType *varArgsType) { 740 749 result = dynamic_cast< VarArgsType* >( type2 ); 741 750 } 742 751 743 void Unify::visit( __attribute__((unused)) ZeroType *zeroType) {752 void Unify::visit(ZeroType *zeroType) { 744 753 result = dynamic_cast< ZeroType* >( type2 ); 745 754 } 746 755 747 void Unify::visit( __attribute__((unused)) OneType *oneType) {756 void Unify::visit(OneType *oneType) { 748 757 result = dynamic_cast< OneType* >( type2 ); 749 758 } … … 756 765 return function->get_returnVals().front()->get_type()->clone(); 757 766 } else { 758 std::list< Type * > types;767 TupleType * tupleType = new TupleType( Type::Qualifiers() ); 759 768 for ( DeclarationWithType * decl : function->get_returnVals() ) { 760 t ypes.push_back( decl->get_type()->clone() );769 tupleType->get_types().push_back( decl->get_type()->clone() ); 761 770 } // for 762 return new TupleType( Type::Qualifiers(), types );771 return tupleType; 763 772 } 764 773 }
Note:
See TracChangeset
for help on using the changeset viewer.