Ignore:
Timestamp:
Jan 7, 2021, 3:27:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b4daf2, 64aeca0
Parents:
3c64c668 (diff), eef8dfb (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 park_unpark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/TypeSubstitution.hpp

    r3c64c668 r58fe85a  
    4444        TypeSubstitution &operator=( const TypeSubstitution &other );
    4545
    46         template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const;
    47         template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const;
     46        template< typename SynTreeClass >
     47        struct ApplyResult {
     48                ast::ptr<SynTreeClass> node;
     49                int count;
     50        };
     51
     52        template< typename SynTreeClass > ApplyResult<SynTreeClass> apply( const SynTreeClass * input ) const;
     53        template< typename SynTreeClass > ApplyResult<SynTreeClass> applyFree( const SynTreeClass * input ) const;
    4854
    4955        template< typename node_t, enum Node::ref_type ref_t >
    5056        int apply( ptr_base< node_t, ref_t > & input ) const {
    5157                const node_t * p = input.get();
    52                 int ret = apply(p);
    53                 input = p;
    54                 return ret;
     58                auto ret = apply(p);
     59                input = ret.node;
     60                return ret.count;
    5561        }
    5662
     
    5864        int applyFree( ptr_base< node_t, ref_t > & input ) const {
    5965                const node_t * p = input.get();
    60                 int ret = applyFree(p);
    61                 input = p;
    62                 return ret;
     66                auto ret = applyFree(p);
     67                input = ret.node;
     68                return ret.count;
    6369        }
    6470
    65         void add( std::string formalType, const Type *actualType );
     71        void add( const TypeInstType * formalType, const Type *actualType );
     72        void add( const TypeInstType::TypeEnvKey & key, const Type *actualType );
    6673        void add( const TypeSubstitution &other );
    67         void remove( std::string formalType );
    68         const Type *lookup( std::string formalType ) const;
     74        void remove( const TypeInstType * formalType );
     75        const Type *lookup( const TypeInstType * formalType ) const;
    6976        bool empty() const;
    70 
    71         void addVar( std::string formalExpr, const Expr *actualExpr );
    7277
    7378        template< typename FormalIterator, typename ActualIterator >
     
    9297        void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
    9398
    94         template<typename pass_type>
     99        template<typename core_t>
    95100        friend class Pass;
    96101
    97         typedef std::unordered_map< std::string, ptr<Type> > TypeEnvType;
    98         typedef std::unordered_map< std::string, ptr<Expr> > VarEnvType;
     102        typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeEnvType;
    99103        TypeEnvType typeEnv;
    100         VarEnvType varEnv;
    101104
    102105  public:
     
    107110        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
    108111
    109         auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
    110         auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    111         auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
    112         auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    113112};
    114113
     114// this is the only place where type parameters outside a function formal may be substituted.
    115115template< typename FormalIterator, typename ActualIterator >
    116116void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {
     
    123123                        if ( const TypeExpr *actual = actualIt->template as<TypeExpr>() ) {
    124124                                if ( formal->name != "" ) {
    125                                         typeEnv[ formal->name ] = actual->type;
     125                                        typeEnv[ formal ] = actual->type;
    126126                                } // if
    127127                        } else {
     
    129129                        } // if
    130130                } else {
    131                         // TODO: type check the formal and actual parameters
    132                         if ( (*formalIt)->name != "" ) {
    133                                 varEnv[ (*formalIt)->name ] = *actualIt;
    134                         } // if
     131                       
    135132                } // if
    136133        } // for
    137134}
     135
     136
    138137
    139138template< typename FormalIterator, typename ActualIterator >
     
    142141}
    143142
     143
    144144} // namespace ast
    145145
     
    147147// PassVisitor are defined before PassVisitor implementation accesses TypeSubstitution internals.
    148148#include "Pass.hpp"
     149#include "Copy.hpp"
    149150
    150151namespace ast {
    151152
    152153// definitition must happen after PassVisitor is included so that WithGuards can be used
    153 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
     154struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter>, public PureVisitor {
     155                static size_t traceId;
    154156
    155157                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    156158
    157 #if TIME_TO_CONVERT_PASSES
    158 
    159                 Type * postmutate( TypeInstType * aggregateUseType );
    160                 Expression * postmutate( NameExpr * nameExpr );
     159                const Type * postvisit( const TypeInstType * aggregateUseType );
    161160
    162161                /// Records type variable bindings from forall-statements
    163                 void premutate( Type * type );
     162                void previsit( const FunctionType * type );
    164163                /// Records type variable bindings from forall-statements and instantiations of generic types
    165                 template< typename TypeClass > void handleAggregateType( TypeClass * type );
     164                // void handleAggregateType( const BaseInstType * type );
    166165
    167                 void premutate( StructInstType * aggregateUseType );
    168                 void premutate( UnionInstType * aggregateUseType );
    169 
    170 #endif
     166                // void previsit( const StructInstType * aggregateUseType );
     167                // void previsit( const UnionInstType * aggregateUseType );
    171168
    172169                const TypeSubstitution & sub;
    173170                int subCount = 0;
    174171                bool freeOnly;
    175                 typedef std::unordered_set< std::string > BoundVarsType;
     172                typedef std::unordered_set< TypeInstType::TypeEnvKey > BoundVarsType;
    176173                BoundVarsType boundVars;
    177174
     
    179176
    180177template< typename SynTreeClass >
    181 int TypeSubstitution::apply( const SynTreeClass *& input ) const {
     178TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::apply( const SynTreeClass * input ) const {
    182179        assert( input );
    183180        Pass<Substituter> sub( *this, false );
    184181        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    185 ///     std::cerr << "substitution result is: ";
    186 ///     newType->print( std::cerr );
    187 ///     std::cerr << std::endl;
    188         return sub.pass.subCount;
     182        return { input, sub.core.subCount };
    189183}
    190184
    191185template< typename SynTreeClass >
    192 int TypeSubstitution::applyFree( const SynTreeClass *& input ) const {
     186TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::applyFree( const SynTreeClass * input ) const {
    193187        assert( input );
    194188        Pass<Substituter> sub( *this, true );
    195189        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    196 ///     std::cerr << "substitution result is: ";
    197 ///     newType->print( std::cerr );
    198 ///     std::cerr << std::endl;
    199         return sub.pass.subCount;
     190        return { input, sub.core.subCount };
    200191}
    201192
Note: See TracChangeset for help on using the changeset viewer.