Ignore:
Timestamp:
Jun 27, 2019, 5:16:54 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7d0881c
Parents:
6be3b7d6
Message:

Somewhat deeper clone for types with forall qualifiers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r6be3b7d6 re0e9a0b  
    127127                        , decltype( node->accept(*this) )
    128128                >::type
    129 
    130129        {
    131130                __pedantic_pass_assert( __visit_children() );
    132                 __pedantic_pass_assert( expr );
     131                __pedantic_pass_assert( node );
    133132
    134133                static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR");
     
    323322        }
    324323
     324
     325        template< typename pass_t >
     326        template< typename node_t >
     327        void ast::Pass< pass_t >::mutate_forall( const node_t *& node ) {
     328                if ( auto subs = __pass::forall::subs( pass, 0 ) ) {
     329                        // tracking TypeDecl substitution, full clone
     330                        if ( node->forall.empty() ) return;
     331
     332                        node_t * mut = mutate( node );
     333                        mut->forall = subs->clone( node->forall, *this );
     334                        node = mut;
     335                } else {
     336                        // not tracking TypeDecl substitution, just mutate
     337                        maybe_accept( node, &node_t::forall );
     338                }
     339        }
    325340}
    326341
     
    16671682        VISIT_START( node );
    16681683
    1669         VISIT(
    1670                 maybe_accept( node, &FunctionType::forall  );
     1684        VISIT({
     1685                guard_forall_subs forall_guard { *this, node };
     1686                mutate_forall( node );
    16711687                maybe_accept( node, &FunctionType::returns );
    16721688                maybe_accept( node, &FunctionType::params  );
    1673         )
     1689        })
    16741690
    16751691        VISIT_END( Type, node );
     
    16861702        VISIT({
    16871703                guard_symtab guard { *this };
    1688                 maybe_accept( node, &StructInstType::forall );
     1704                guard_forall_subs forall_guard { *this, node };
     1705                mutate_forall( node );
    16891706                maybe_accept( node, &StructInstType::params );
    16901707        })
     
    16991716        VISIT_START( node );
    17001717
    1701         __pass::symtab::addStruct( pass, 0, node->name );
    1702 
    1703         {
     1718        __pass::symtab::addUnion( pass, 0, node->name );
     1719
     1720        VISIT({
    17041721                guard_symtab guard { *this };
    1705                 maybe_accept( node, &UnionInstType::forall );
     1722                guard_forall_subs forall_guard { *this, node };
     1723                mutate_forall( node );
    17061724                maybe_accept( node, &UnionInstType::params );
    1707         }
     1725        })
    17081726
    17091727        VISIT_END( Type, node );
     
    17161734        VISIT_START( node );
    17171735
    1718         VISIT(
    1719                 maybe_accept( node, &EnumInstType::forall );
     1736        VISIT({
     1737                guard_forall_subs forall_guard { *this, node };
     1738                mutate_forall( node );
    17201739                maybe_accept( node, &EnumInstType::params );
    1721         )
     1740        })
    17221741
    17231742        VISIT_END( Type, node );
     
    17301749        VISIT_START( node );
    17311750
    1732         VISIT(
    1733                 maybe_accept( node, &TraitInstType::forall );
     1751        VISIT({
     1752                guard_forall_subs forall_guard { *this, node };
     1753                mutate_forall( node );
    17341754                maybe_accept( node, &TraitInstType::params );
    1735         )
     1755        })
    17361756
    17371757        VISIT_END( Type, node );
     
    17451765
    17461766        VISIT(
    1747                 maybe_accept( node, &TypeInstType::forall );
    1748                 maybe_accept( node, &TypeInstType::params );
     1767                {
     1768                        guard_forall_subs forall_guard { *this, node };
     1769                        mutate_forall( node );
     1770                        maybe_accept( node, &TypeInstType::params );
     1771                }
     1772                // ensure that base re-bound if doing substitution
     1773                __pass::forall::replace( pass, 0, node );
    17491774        )
    17501775
Note: See TracChangeset for help on using the changeset viewer.