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