Ignore:
File:
1 edited

Legend:

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

    r665f432 rc570806  
    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
     
    429444                        guard_symtab guard { *this };
    430445                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    431                         static ast::ObjectDecl func(
    432                                 node->location, "__func__",
    433                                 new ast::ArrayType(
    434                                         new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ),
     446                        static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
     447                                CodeLocation{}, "__func__",
     448                                new ast::ArrayType{
     449                                        new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
    435450                                        nullptr, VariableLen, DynamicDim
    436                                 )
    437                         );
    438                         __pass::symtab::addId( pass, 0, &func );
     451                                }
     452                        } };
     453                        __pass::symtab::addId( pass, 0, func );
    439454                        VISIT(
    440455                                maybe_accept( node, &FunctionDecl::type );
     
    610625        VISIT({
    611626                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    612                 auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() {
    613                         if ( ! inFunction ) __pass::symtab::enter(pass, 0);
    614                 }, [this, inFunction = this->inFunction]() {
    615                         if ( ! inFunction ) __pass::symtab::leave(pass, 0);
     627                auto guard1 = makeFuncGuard( [this, inFunctionCpy = this->inFunction]() {
     628                        if ( ! inFunctionCpy ) __pass::symtab::enter(pass, 0);
     629                }, [this, inFunctionCpy = this->inFunction]() {
     630                        if ( ! inFunctionCpy ) __pass::symtab::leave(pass, 0);
    616631                });
    617632                ValueGuard< bool > guard2( inFunction );
     
    938953        // For now this isn't visited, it is unclear if this causes problem
    939954        // if all tests are known to pass, remove this code
    940         // VISIT(
    941         //      maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
    942         // )
     955        VISIT(
     956                maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
     957        )
    943958
    944959        VISIT_END( Stmt, node );
     
    13001315                        maybe_accept( node, &AsmExpr::result );
    13011316                }
     1317                maybe_accept( node, &AsmExpr::inout      );
    13021318                maybe_accept( node, &AsmExpr::constraint );
    13031319                maybe_accept( node, &AsmExpr::operand    );
     
    16661682        VISIT_START( node );
    16671683
    1668         VISIT(
    1669                 maybe_accept( node, &FunctionType::forall  );
     1684        VISIT({
     1685                guard_forall_subs forall_guard { *this, node };
     1686                mutate_forall( node );
    16701687                maybe_accept( node, &FunctionType::returns );
    16711688                maybe_accept( node, &FunctionType::params  );
    1672         )
     1689        })
    16731690
    16741691        VISIT_END( Type, node );
     
    16851702        VISIT({
    16861703                guard_symtab guard { *this };
    1687                 maybe_accept( node, &StructInstType::forall );
     1704                guard_forall_subs forall_guard { *this, node };
     1705                mutate_forall( node );
    16881706                maybe_accept( node, &StructInstType::params );
    16891707        })
     
    16981716        VISIT_START( node );
    16991717
    1700         __pass::symtab::addStruct( pass, 0, node->name );
    1701 
    1702         {
     1718        __pass::symtab::addUnion( pass, 0, node->name );
     1719
     1720        VISIT({
    17031721                guard_symtab guard { *this };
    1704                 maybe_accept( node, &UnionInstType::forall );
     1722                guard_forall_subs forall_guard { *this, node };
     1723                mutate_forall( node );
    17051724                maybe_accept( node, &UnionInstType::params );
    1706         }
     1725        })
    17071726
    17081727        VISIT_END( Type, node );
     
    17151734        VISIT_START( node );
    17161735
    1717         VISIT(
    1718                 maybe_accept( node, &EnumInstType::forall );
     1736        VISIT({
     1737                guard_forall_subs forall_guard { *this, node };
     1738                mutate_forall( node );
    17191739                maybe_accept( node, &EnumInstType::params );
    1720         )
     1740        })
    17211741
    17221742        VISIT_END( Type, node );
     
    17291749        VISIT_START( node );
    17301750
    1731         VISIT(
    1732                 maybe_accept( node, &TraitInstType::forall );
     1751        VISIT({
     1752                guard_forall_subs forall_guard { *this, node };
     1753                mutate_forall( node );
    17331754                maybe_accept( node, &TraitInstType::params );
    1734         )
     1755        })
    17351756
    17361757        VISIT_END( Type, node );
     
    17441765
    17451766        VISIT(
    1746                 maybe_accept( node, &TypeInstType::forall );
    1747                 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 );
    17481774        )
    17491775
     
    18941920                                guard_symtab guard { *this };
    18951921                                auto new_node = p.second->accept( *this );
    1896                                 if (new_node != p.second) mutated = false;
     1922                                if (new_node != p.second) mutated = true;
    18971923                                new_map.insert({ p.first, new_node });
    18981924                        }
     
    19101936                                guard_symtab guard { *this };
    19111937                                auto new_node = p.second->accept( *this );
    1912                                 if (new_node != p.second) mutated = false;
     1938                                if (new_node != p.second) mutated = true;
    19131939                                new_map.insert({ p.first, new_node });
    19141940                        }
Note: See TracChangeset for help on using the changeset viewer.