Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r62423350 rce8c12f  
    4242                virtual void visit(PointerType *pointerType);
    4343                virtual void visit(ArrayType *arrayType);
     44                virtual void visit(ReferenceType *refType);
    4445                virtual void visit(FunctionType *functionType);
    4546                virtual void visit(StructInstType *aggregateUseType);
     
    114115        }
    115116
    116         bool isFtype( Type *type ) {
     117        bool isFtype( Type *type, const SymTab::Indexer &indexer ) {
    117118                if ( dynamic_cast< FunctionType* >( type ) ) {
    118119                        return true;
     
    123124        }
    124125
    125         bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {
     126        bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) {
    126127                switch ( data.kind ) {
    127128                  case TypeDecl::Any:
     
    131132                        // type must also be complete
    132133                        // 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() );
    134135                  case TypeDecl::Ftype:
    135                         return isFtype( type );
     136                        return isFtype( type, indexer );
    136137                  case TypeDecl::Ttype:
    137138                        // ttype unifies with any tuple type
     
    144145                OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() );
    145146                assert( tyvar != openVars.end() );
    146                 if ( ! tyVarCompatible( tyvar->second, other ) ) {
     147                if ( ! tyVarCompatible( tyvar->second, other, indexer ) ) {
    147148                        return false;
    148149                } // if
     
    344345                std::cerr << "unifyInexact type 1 is ";
    345346                type1->print( std::cerr );
    346                 std::cerr << " type 2 is ";
     347                std::cerr << "type 2 is ";
    347348                type2->print( std::cerr );
    348349                std::cerr << std::endl;
     
    388389        }
    389390
    390         void Unify::visit( __attribute__((unused)) VoidType *voidType) {
     391        void Unify::visit(VoidType *voidType) {
    391392                result = dynamic_cast< VoidType* >( type2 );
    392393        }
     
    425426                        markAssertions( haveAssertions, needAssertions, pointerType );
    426427                        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 );
    427436                } // if
    428437        }
     
    606615                        } else if ( tupleParam ) {
    607616                                // bundle other parameters into tuple to match
    608                                 std::list< Type * > binderTypes;
     617                                TupleType* binder = new TupleType{ paramTy->get_qualifiers() };
    609618
    610619                                do {
    611                                         binderTypes.push_back( otherParam->get_type()->clone() );
     620                                        binder->get_types().push_back( otherParam->get_type()->clone() );
    612621                                        ++jt;
    613622
     
    618627                                } while (true);
    619628
    620                                 otherParamTy = new TupleType{ paramTy->get_qualifiers(), binderTypes };
     629                                otherParamTy = binder;
    621630                                ++it;  // skip ttype parameter for break
    622631                        } else if ( otherTupleParam ) {
    623632                                // bundle parameters into tuple to match other
    624                                 std::list< Type * > binderTypes;
     633                                TupleType* binder = new TupleType{ otherParamTy->get_qualifiers() };
    625634
    626635                                do {
    627                                         binderTypes.push_back( param->get_type()->clone() );
     636                                        binder->get_types().push_back( param->get_type()->clone() );
    628637                                        ++it;
    629638
     
    634643                                } while (true);
    635644
    636                                 paramTy = new TupleType{ otherParamTy->get_qualifiers(), binderTypes };
     645                                paramTy = binder;
    637646                                ++jt;  // skip ttype parameter for break
    638647                        }
     
    683692
    684693        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 ) {
    686695                auto get_type = [](Type * t) { return t; };
    687696                for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
     
    733742                        flatten( flat2.get(), back_inserter( types2 ) );
    734743
    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) {
    740749                result = dynamic_cast< VarArgsType* >( type2 );
    741750        }
    742751
    743         void Unify::visit( __attribute__((unused)) ZeroType *zeroType ) {
     752        void Unify::visit(ZeroType *zeroType) {
    744753                result = dynamic_cast< ZeroType* >( type2 );
    745754        }
    746755
    747         void Unify::visit( __attribute__((unused)) OneType *oneType ) {
     756        void Unify::visit(OneType *oneType) {
    748757                result = dynamic_cast< OneType* >( type2 );
    749758        }
     
    756765                        return function->get_returnVals().front()->get_type()->clone();
    757766                } else {
    758                         std::list< Type * > types;
     767                        TupleType * tupleType = new TupleType( Type::Qualifiers() );
    759768                        for ( DeclarationWithType * decl : function->get_returnVals() ) {
    760                                 types.push_back( decl->get_type()->clone() );
     769                                tupleType->get_types().push_back( decl->get_type()->clone() );
    761770                        } // for
    762                         return new TupleType( Type::Qualifiers(), types );
     771                        return tupleType;
    763772                }
    764773        }
Note: See TracChangeset for help on using the changeset viewer.