Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    rce8c12f r62423350  
    4242                virtual void visit(PointerType *pointerType);
    4343                virtual void visit(ArrayType *arrayType);
    44                 virtual void visit(ReferenceType *refType);
    4544                virtual void visit(FunctionType *functionType);
    4645                virtual void visit(StructInstType *aggregateUseType);
     
    115114        }
    116115
    117         bool isFtype( Type *type, const SymTab::Indexer &indexer ) {
     116        bool isFtype( Type *type ) {
    118117                if ( dynamic_cast< FunctionType* >( type ) ) {
    119118                        return true;
     
    124123        }
    125124
    126         bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) {
     125        bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {
    127126                switch ( data.kind ) {
    128127                  case TypeDecl::Any:
     
    132131                        // type must also be complete
    133132                        // 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() );
    135134                  case TypeDecl::Ftype:
    136                         return isFtype( type, indexer );
     135                        return isFtype( type );
    137136                  case TypeDecl::Ttype:
    138137                        // ttype unifies with any tuple type
     
    145144                OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() );
    146145                assert( tyvar != openVars.end() );
    147                 if ( ! tyVarCompatible( tyvar->second, other, indexer ) ) {
     146                if ( ! tyVarCompatible( tyvar->second, other ) ) {
    148147                        return false;
    149148                } // if
     
    345344                std::cerr << "unifyInexact type 1 is ";
    346345                type1->print( std::cerr );
    347                 std::cerr << "type 2 is ";
     346                std::cerr << " type 2 is ";
    348347                type2->print( std::cerr );
    349348                std::cerr << std::endl;
     
    389388        }
    390389
    391         void Unify::visit(VoidType *voidType) {
     390        void Unify::visit( __attribute__((unused)) VoidType *voidType) {
    392391                result = dynamic_cast< VoidType* >( type2 );
    393392        }
     
    426425                        markAssertions( haveAssertions, needAssertions, pointerType );
    427426                        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 );
    436427                } // if
    437428        }
     
    615606                        } else if ( tupleParam ) {
    616607                                // bundle other parameters into tuple to match
    617                                 TupleType* binder = new TupleType{ paramTy->get_qualifiers() };
     608                                std::list< Type * > binderTypes;
    618609
    619610                                do {
    620                                         binder->get_types().push_back( otherParam->get_type()->clone() );
     611                                        binderTypes.push_back( otherParam->get_type()->clone() );
    621612                                        ++jt;
    622613
     
    627618                                } while (true);
    628619
    629                                 otherParamTy = binder;
     620                                otherParamTy = new TupleType{ paramTy->get_qualifiers(), binderTypes };
    630621                                ++it;  // skip ttype parameter for break
    631622                        } else if ( otherTupleParam ) {
    632623                                // bundle parameters into tuple to match other
    633                                 TupleType* binder = new TupleType{ otherParamTy->get_qualifiers() };
     624                                std::list< Type * > binderTypes;
    634625
    635626                                do {
    636                                         binder->get_types().push_back( param->get_type()->clone() );
     627                                        binderTypes.push_back( param->get_type()->clone() );
    637628                                        ++it;
    638629
     
    643634                                } while (true);
    644635
    645                                 paramTy = binder;
     636                                paramTy = new TupleType{ otherParamTy->get_qualifiers(), binderTypes };
    646637                                ++jt;  // skip ttype parameter for break
    647638                        }
     
    692683
    693684        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 ) {
    695686                auto get_type = [](Type * t) { return t; };
    696687                for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
     
    742733                        flatten( flat2.get(), back_inserter( types2 ) );
    743734
    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 ) {
    749740                result = dynamic_cast< VarArgsType* >( type2 );
    750741        }
    751742
    752         void Unify::visit(ZeroType *zeroType) {
     743        void Unify::visit( __attribute__((unused)) ZeroType *zeroType ) {
    753744                result = dynamic_cast< ZeroType* >( type2 );
    754745        }
    755746
    756         void Unify::visit(OneType *oneType) {
     747        void Unify::visit( __attribute__((unused)) OneType *oneType ) {
    757748                result = dynamic_cast< OneType* >( type2 );
    758749        }
     
    765756                        return function->get_returnVals().front()->get_type()->clone();
    766757                } else {
    767                         TupleType * tupleType = new TupleType( Type::Qualifiers() );
     758                        std::list< Type * > types;
    768759                        for ( DeclarationWithType * decl : function->get_returnVals() ) {
    769                                 tupleType->get_types().push_back( decl->get_type()->clone() );
     760                                types.push_back( decl->get_type()->clone() );
    770761                        } // for
    771                         return tupleType;
     762                        return new TupleType( Type::Qualifiers(), types );
    772763                }
    773764        }
Note: See TracChangeset for help on using the changeset viewer.