Ignore:
Timestamp:
Aug 14, 2020, 11:40:04 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5715d43, fa5e0112
Parents:
309d814 (diff), badd22f (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/TypeSubstitution.hpp

    r309d814 r4c925cd  
    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                // const SynTreeClass * node;
     49                ast::ptr<SynTreeClass> node;
     50                int count;
     51        };
     52
     53        template< typename SynTreeClass > ApplyResult<SynTreeClass> apply( const SynTreeClass * input ) const;
     54        template< typename SynTreeClass > ApplyResult<SynTreeClass> applyFree( const SynTreeClass * input ) const;
    4855
    4956        template< typename node_t, enum Node::ref_type ref_t >
    5057        int apply( ptr_base< node_t, ref_t > & input ) const {
    5158                const node_t * p = input.get();
    52                 int ret = apply(p);
    53                 input = p;
    54                 return ret;
     59                auto ret = apply(p);
     60                input = ret.node;
     61                return ret.count;
    5562        }
    5663
     
    5865        int applyFree( ptr_base< node_t, ref_t > & input ) const {
    5966                const node_t * p = input.get();
    60                 int ret = applyFree(p);
    61                 input = p;
    62                 return ret;
     67                auto ret = applyFree(p);
     68                input = ret.node;
     69                return ret.count;
    6370        }
    6471
     
    9299        void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
    93100
    94         template<typename pass_type>
     101        template<typename core_t>
    95102        friend class Pass;
    96103
     
    147154// PassVisitor are defined before PassVisitor implementation accesses TypeSubstitution internals.
    148155#include "Pass.hpp"
     156#include "Copy.hpp"
    149157
    150158namespace ast {
     
    152160// definitition must happen after PassVisitor is included so that WithGuards can be used
    153161struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
     162                static size_t traceId;
    154163
    155164                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    156165
    157 #if TIME_TO_CONVERT_PASSES
    158 
    159                 Type * postmutate( TypeInstType * aggregateUseType );
    160                 Expression * postmutate( NameExpr * nameExpr );
     166                const Type * postvisit( const TypeInstType * aggregateUseType );
     167                const Expr * postvisit( const NameExpr * nameExpr );
    161168
    162169                /// Records type variable bindings from forall-statements
    163                 void premutate( Type * type );
     170                void previsit( const ParameterizedType * type );
    164171                /// Records type variable bindings from forall-statements and instantiations of generic types
    165                 template< typename TypeClass > void handleAggregateType( TypeClass * type );
    166 
    167                 void premutate( StructInstType * aggregateUseType );
    168                 void premutate( UnionInstType * aggregateUseType );
    169 
    170 #endif
     172                void handleAggregateType( const ReferenceToType * type );
     173
     174                void previsit( const StructInstType * aggregateUseType );
     175                void previsit( const UnionInstType * aggregateUseType );
    171176
    172177                const TypeSubstitution & sub;
     
    179184
    180185template< typename SynTreeClass >
    181 int TypeSubstitution::apply( const SynTreeClass *& input ) const {
     186TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::apply( const SynTreeClass * input ) const {
    182187        assert( input );
    183188        Pass<Substituter> sub( *this, false );
    184         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;
     189        input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) );
     190        return { input, sub.core.subCount };
    189191}
    190192
    191193template< typename SynTreeClass >
    192 int TypeSubstitution::applyFree( const SynTreeClass *& input ) const {
     194TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::applyFree( const SynTreeClass * input ) const {
    193195        assert( input );
    194196        Pass<Substituter> sub( *this, true );
    195197        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;
     198        return { input, sub.core.subCount };
    200199}
    201200
Note: See TracChangeset for help on using the changeset viewer.