Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/TypeSubstitution.h

    r6a9d4b4 r933f32f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:24 2017
    13 // Update Count     : 3
     12// Last Modified On : Tue Apr 30 22:52:47 2019
     13// Update Count     : 9
    1414//
    1515
     
    1919#include <iosfwd>                  // for ostream
    2020#include <list>                    // for list<>::iterator, _List_iterator
    21 #include <map>                     // for _Rb_tree_iterator, map, map<>::val...
    22 #include <set>                     // for set
     21#include <unordered_map>
     22#include <unordered_set>
    2323#include <string>                  // for string, operator!=
    2424#include <utility>                 // for pair
     
    3939        TypeSubstitution &operator=( const TypeSubstitution &other );
    4040
    41         template< typename SynTreeClass > int apply( SynTreeClass *&input );
    42         template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
     41        template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
     42        template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
    4343
    4444        void add( std::string formalType, Type *actualType );
     
    4848        bool empty() const;
    4949
     50        void addVar( std::string formalExpr, Expression *actualExpr );
     51
    5052        template< typename FormalIterator, typename ActualIterator >
    5153        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     
    5658
    5759        /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr
    58         static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env );
     60        static TypeSubstitution * newFromExpr( Expression * expr, const TypeSubstitution * env );
    5961
    6062        void normalize();
     
    7880        friend class PassVisitor;
    7981
    80         typedef std::map< std::string, Type* > TypeEnvType;
    81         typedef std::map< std::string, Expression* > VarEnvType;
     82        typedef std::unordered_map< std::string, Type * > TypeEnvType;
     83        typedef std::unordered_map< std::string, Expression * > VarEnvType;
    8284        TypeEnvType typeEnv;
    8385        VarEnvType varEnv;
     
    8991        auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    9092        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
     93
     94        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     95        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     96        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     97        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    9198};
    9299
     
    98105        ActualIterator actualIt = actualBegin;
    99106        for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) {
    100                 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) {
    101                         if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) {
     107                if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) {
     108                        if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) {
    102109                                if ( formal->get_name() != "" ) {
    103110                                        TypeEnvType::iterator i = typeEnv.find( formal->get_name() );
     
    130137// definitition must happen after PassVisitor is included so that WithGuards can be used
    131138struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132                 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
     139                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133140
    134141                Type * postmutate( TypeInstType * aggregateUseType );
     
    143150                void premutate( UnionInstType * aggregateUseType );
    144151
    145                 TypeSubstitution & sub;
     152                const TypeSubstitution & sub;
    146153                int subCount = 0;
    147154                bool freeOnly;
    148                 typedef std::set< std::string > BoundVarsType;
     155                typedef std::unordered_set< std::string > BoundVarsType;
    149156                BoundVarsType boundVars;
    150157};
    151158
    152159template< typename SynTreeClass >
    153 int TypeSubstitution::apply( SynTreeClass *&input ) {
     160int TypeSubstitution::apply( SynTreeClass *&input ) const {
    154161        assert( input );
    155162        PassVisitor<Substituter> sub( *this, false );
     
    163170
    164171template< typename SynTreeClass >
    165 int TypeSubstitution::applyFree( SynTreeClass *&input ) {
     172int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
    166173        assert( input );
    167174        PassVisitor<Substituter> sub( *this, true );
Note: See TracChangeset for help on using the changeset viewer.