Ignore:
Timestamp:
Oct 23, 2020, 9:06:16 PM (4 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
37b7d95
Parents:
41b8ea4
Message:

move FixInit? to new ast

File:
1 edited

Legend:

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

    r41b8ea4 r490fb92e  
    167167                __pedantic_pass_assert( stmt );
    168168
     169                return stmt->accept( *this );
     170        }
     171
     172        template< typename core_t >
     173        const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
     174                __pedantic_pass_assert( __visit_children() );
     175                __pedantic_pass_assert( stmt );
     176
    169177                // add a few useful symbols to the scope
    170178                using __pass::empty;
     
    324332
    325333                auto new_val = call_accept( old_val );
     334
     335                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
     336
     337                if( __pass::differs(old_val, new_val) ) {
     338                        auto new_parent = __pass::mutate<core_t>(parent);
     339                        new_parent->*child = new_val;
     340                        parent = new_parent;
     341                }
     342        }
     343
     344        template< typename core_t >
     345        template<typename node_t, typename parent_t, typename child_t>
     346        void ast::Pass< core_t >::maybe_accept_as_compound(
     347                const node_t * & parent,
     348                child_t parent_t::*child
     349        ) {
     350                static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );
     351
     352                if(__pass::skip(parent->*child)) return;
     353                const auto & old_val = __pass::get(parent->*child, 0);
     354
     355                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
     356
     357                auto new_val = call_accept_as_compound( old_val );
    326358
    327359                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
     
    703735                maybe_accept( node, &IfStmt::inits    );
    704736                maybe_accept( node, &IfStmt::cond     );
    705                 maybe_accept( node, &IfStmt::thenPart );
    706                 maybe_accept( node, &IfStmt::elsePart );
     737                maybe_accept_as_compound( node, &IfStmt::thenPart );
     738                maybe_accept_as_compound( node, &IfStmt::elsePart );
    707739        })
    708740
     
    721753                maybe_accept( node, &WhileStmt::inits );
    722754                maybe_accept( node, &WhileStmt::cond  );
    723                 maybe_accept( node, &WhileStmt::body  );
     755                maybe_accept_as_compound( node, &WhileStmt::body  );
    724756        })
    725757
     
    736768                // for statements introduce a level of scope (for the initialization)
    737769                guard_symtab guard { *this };
     770                // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.
    738771                maybe_accept( node, &ForStmt::inits );
    739772                maybe_accept( node, &ForStmt::cond  );
    740773                maybe_accept( node, &ForStmt::inc   );
    741                 maybe_accept( node, &ForStmt::body  );
     774                maybe_accept_as_compound( node, &ForStmt::body  );
    742775        })
    743776
     
    834867                maybe_accept( node, &CatchStmt::decl );
    835868                maybe_accept( node, &CatchStmt::cond );
    836                 maybe_accept( node, &CatchStmt::body );
     869                maybe_accept_as_compound( node, &CatchStmt::body );
    837870        })
    838871
Note: See TracChangeset for help on using the changeset viewer.