Changeset 2f42718 for src/ResolvExpr


Ignore:
Timestamp:
Feb 22, 2019, 10:43:29 AM (7 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
no_list
Parents:
43e0949
Message:

Parameters and return value of functions are now vectors (and some related clean-up)

Location:
src/ResolvExpr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r43e0949 r2f42718  
    434434
    435435                Cost convCost = Cost::zero;
    436                 std::list< DeclarationWithType* >& formals = function->parameters;
    437                 std::list< DeclarationWithType* >::iterator formal = formals.begin();
    438                 std::list< Expression* >& actuals = appExpr->args;
     436                auto & formals = function->parameters;
     437                auto   formal = formals.begin();
     438                auto & actuals = appExpr->args;
    439439
    440440                for ( Expression*& actualExpr : actuals ) {
     
    493493        /// Adds type variables to the open variable set and marks their assertions
    494494        void makeUnifiableVars( Type *type, OpenVarSet &unifiableVars, AssertionSet &needAssertions ) {
    495                 for ( Type::ForallList::const_iterator tyvar = type->forall.begin(); tyvar != type->forall.end(); ++tyvar ) {
    496                         unifiableVars[ (*tyvar)->get_name() ] = TypeDecl::Data{ *tyvar };
    497                         for ( std::list< DeclarationWithType* >::iterator assert = (*tyvar)->assertions.begin(); assert != (*tyvar)->assertions.end(); ++assert ) {
    498                                 needAssertions[ *assert ].isUsed = true;
     495                for ( auto tyvar : type->forall ) {
     496                        unifiableVars[ tyvar->get_name() ] = TypeDecl::Data{ tyvar };
     497                        for ( auto assert : tyvar->assertions ) {
     498                                needAssertions[ assert ].isUsed = true;
    499499                        }
    500500                }
     
    14071407                        // assume no polymorphism
    14081408                        // assume no implicit conversions
    1409                         assert( function->get_parameters().size() == 1 );
     1409                        assert( function->parameters.size() == 1 );
    14101410                        PRINT(
    14111411                                std::cerr << "resolvAttr: funcDecl is ";
     
    14171417                        const SymTab::Indexer & indexer = finder.get_indexer();
    14181418                        AltList & alternatives = finder.get_alternatives();
    1419                         if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {
     1419                        if ( typesCompatibleIgnoreQualifiers( argType, function->parameters.front()->get_type(), indexer, env ) ) {
    14201420                                Cost cost = Cost::zero;
    14211421                                Expression * newExpr = data.combine( cost );
     
    14421442                                if ( FunctionType *function = dynamic_cast< FunctionType* >( id->get_type() ) ) {
    14431443                                        // assume exactly one parameter
    1444                                         if ( function->get_parameters().size() == 1 ) {
     1444                                        if ( function->parameters.size() == 1 ) {
    14451445                                                if ( attrExpr->get_isType() ) {
    14461446                                                        resolveAttr( data, function, attrExpr->get_type(), env, altFinder);
  • src/ResolvExpr/ConversionCost.cc

    r43e0949 r2f42718  
    388388                Cost c = Cost::zero;
    389389                if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) {
    390                         std::list< Type * >::const_iterator srcIt = tupleType->types.begin();
    391                         std::list< Type * >::const_iterator destIt = destAsTuple->types.begin();
     390                        std::vector< Type * >::const_iterator srcIt = tupleType->types.begin();
     391                        std::vector< Type * >::const_iterator destIt = destAsTuple->types.begin();
    392392                        while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) {
    393393                                Cost newCost = costFunc( *srcIt++, *destIt++, indexer, env );
  • src/ResolvExpr/FindOpenVars.cc

    r43e0949 r2f42718  
    5050        void FindOpenVars::common_action( Type *type ) {
    5151                if ( nextIsOpen ) {
    52                         for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    53                                 openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    54                                 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
    55                                         needAssertions[ *assert ].isUsed = false;
     52                        for ( const auto i : type->get_forall() ) {
     53                                openVars[ i->get_name() ] = TypeDecl::Data{ i };
     54                                for ( const auto assert : i->assertions ) {
     55                                        needAssertions[ assert ].isUsed = false;
    5656                                }
    57 ///       cloneAll( (*i)->get_assertions(), needAssertions );
    58 ///       needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
    5957                        }
    6058                } else {
    61                         for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    62                                 closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    63                                 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
    64                                         haveAssertions[ *assert ].isUsed = false;
     59                        for ( const auto i : type->get_forall() ) {
     60                                closedVars[ i->get_name() ] = TypeDecl::Data{ i };
     61                                for ( const auto assert : i->assertions ) {
     62                                        haveAssertions[ assert ].isUsed = false;
    6563                                }
    66 ///       cloneAll( (*i)->get_assertions(), haveAssertions );
    67 ///       haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
    6864                        } // for
    6965                } // if
    70 ///   std::cerr << "type is ";
    71 ///   type->print( std::cerr );
    72 ///   std::cerr << std::endl << "need is" << std::endl;
    73 ///   printAssertionSet( needAssertions, std::cerr );
    74 ///   std::cerr << std::endl << "have is" << std::endl;
    75 ///   printAssertionSet( haveAssertions, std::cerr );
    7666        }
    7767
  • src/ResolvExpr/SpecCost.cc

    r43e0949 r2f42718  
    4242        private:
    4343                // takes minimum non-negative count over parameter/return list
    44                 void takeminover( int& mincount, std::list<DeclarationWithType*>& dwts ) {
     44                void takeminover( int& mincount, std::vector<DeclarationWithType*> & dwts ) {
    4545                        for ( DeclarationWithType* dwt : dwts ) {
    4646                                count = -1;
     
    6161                        visit_children = false;
    6262                }
    63        
     63
    6464        private:
    6565                // returns minimum non-negative count + 1 over type parameters (-1 if none such)
     
    8080                        visit_children = false;
    8181                }
    82                
     82
    8383                // look for polymorphic parameters
    8484                void previsit(UnionInstType* uty) {
  • src/ResolvExpr/Unify.cc

    r43e0949 r2f42718  
    283283        void markAssertions( AssertionSet &assertion1, AssertionSet &assertion2, Type *type ) {
    284284                for ( auto tyvar : type->get_forall() ) {
    285                         for ( auto assert : tyvar->get_assertions() ) {
     285                        for ( auto assert : tyvar->assertions ) {
    286286                                markAssertionSet( assertion1, assert );
    287287                                markAssertionSet( assertion2, assert );
     
    336336        template< typename Iterator, typename Func >
    337337        std::unique_ptr<Type> combineTypes( Iterator begin, Iterator end, Func & toType ) {
    338                 std::list< Type * > types;
     338                std::vector< Type * > types;
    339339                for ( ; begin != end; ++begin ) {
    340340                        // it's guaranteed that a ttype variable will be bound to a flat tuple, so ensure that this results in a flat tuple
     
    404404        /// flattens a list of declarations, so that each tuple type has a single declaration.
    405405        /// makes use of TtypeExpander to ensure ttypes are flat as well.
    406         void flattenList( std::list< DeclarationWithType * > src, std::list< DeclarationWithType * > & dst, TypeEnvironment & env ) {
     406        void flattenList( std::vector< DeclarationWithType * > src, std::vector< DeclarationWithType * > & dst, TypeEnvironment & env ) {
    407407                dst.clear();
    408408                for ( DeclarationWithType * dcl : src ) {
     
    429429                        std::unique_ptr<FunctionType> flatFunc( functionType->clone() );
    430430                        std::unique_ptr<FunctionType> flatOther( otherFunction->clone() );
    431                         flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env );
    432                         flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env );
     431                        flattenList( flatFunc ->parameters, flatFunc ->parameters, env );
     432                        flattenList( flatOther->parameters, flatOther->parameters, env );
    433433
    434434                        // sizes don't have to match if ttypes are involved; need to be more precise wrt where the ttype is to prevent errors
     
    481481                        } else if ( tupleParam ) {
    482482                                // bundle other parameters into tuple to match
    483                                 std::list< Type * > binderTypes;
     483                                std::vector< Type * > binderTypes;
    484484
    485485                                do {
     
    497497                        } else if ( otherTupleParam ) {
    498498                                // bundle parameters into tuple to match other
    499                                 std::list< Type * > binderTypes;
     499                                std::vector< Type * > binderTypes;
    500500
    501501                                do {
     
    626626        // xxx - compute once and store in the FunctionType?
    627627        Type * extractResultType( FunctionType * function ) {
    628                 if ( function->get_returnVals().size() == 0 ) {
     628                if ( function->returnVals.size() == 0 ) {
    629629                        return new VoidType( Type::Qualifiers() );
    630                 } else if ( function->get_returnVals().size() == 1 ) {
    631                         return function->get_returnVals().front()->get_type()->clone();
     630                } else if ( function->returnVals.size() == 1 ) {
     631                        return function->returnVals.front()->get_type()->clone();
    632632                } else {
    633                         std::list< Type * > types;
    634                         for ( DeclarationWithType * decl : function->get_returnVals() ) {
     633                        std::vector< Type * > types;
     634                        for ( DeclarationWithType * decl : function->returnVals ) {
    635635                                types.push_back( decl->get_type()->clone() );
    636636                        } // for
  • src/ResolvExpr/typeops.h

    r43e0949 r2f42718  
    7373
    7474        // in AlternativeFinder.cc
    75         Cost computeConversionCost( Type *actualType, Type *formalType, 
     75        Cost computeConversionCost( Type *actualType, Type *formalType,
    7676                const SymTab::Indexer &indexer, const TypeEnvironment &env );
    7777
     
    112112        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
    113113
    114         template<typename Iter> 
     114        template<typename Iter>
    115115        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
    116116                while ( begin != end ) {
     
    128128        void flatten( Type * type, OutputIterator out ) {
    129129                if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
    130                         for ( Type * t : tupleType->get_types() ) {
     130                        for ( Type * t : tupleType->types ) {
    131131                                flatten( t, out );
    132132                        }
Note: See TracChangeset for help on using the changeset viewer.