Changes in src/AST/Pass.impl.hpp [293dc1c:954c954]
- File:
-
- 1 edited
-
src/AST/Pass.impl.hpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r293dc1c r954c954 20 20 #include <unordered_map> 21 21 22 #include "AST/TranslationUnit.hpp"23 22 #include "AST/TypeSubstitution.hpp" 24 23 … … 168 167 __pedantic_pass_assert( stmt ); 169 168 170 return stmt->accept( *this );171 }172 173 template< typename core_t >174 const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {175 __pedantic_pass_assert( __visit_children() );176 __pedantic_pass_assert( stmt );177 178 169 // add a few useful symbols to the scope 179 170 using __pass::empty; … … 343 334 } 344 335 345 template< typename core_t >346 template<typename node_t, typename parent_t, typename child_t>347 void ast::Pass< core_t >::maybe_accept_as_compound(348 const node_t * & parent,349 child_t parent_t::*child350 ) {351 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );352 353 if(__pass::skip(parent->*child)) return;354 const auto & old_val = __pass::get(parent->*child, 0);355 356 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");357 358 auto new_val = call_accept_as_compound( old_val );359 360 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");361 362 if( __pass::differs(old_val, new_val) ) {363 auto new_parent = __pass::mutate<core_t>(parent);364 new_parent->*child = new_val;365 parent = new_parent;366 }367 }368 369 336 370 337 template< typename core_t > … … 431 398 pass_visitor_stats.depth--; 432 399 if ( !errors.isEmpty() ) { throw errors; } 433 }434 435 template< typename core_t >436 inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) {437 return ast::accept_all( unit.decls, visitor );438 400 } 439 401 … … 508 470 // foralls are still in function type 509 471 maybe_accept( node, &FunctionDecl::type ); 510 // First remember that we are now within a function. 472 // function body needs to have the same scope as parameters - CompoundStmt will not enter 473 // a new scope if inFunction is true 511 474 ValueGuard< bool > oldInFunction( inFunction ); 512 475 inFunction = true; 513 // The function body needs to have the same scope as parameters.514 // A CompoundStmt will not enter a new scope if atFunctionTop is true.515 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );516 atFunctionTop = true;517 476 maybe_accept( node, &FunctionDecl::stmts ); 518 477 maybe_accept( node, &FunctionDecl::attributes ); … … 680 639 const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) { 681 640 VISIT_START( node ); 682 VISIT( 683 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.684 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {685 if ( enterScope) __pass::symtab::enter(core, 0);686 }, [this, leaveScope = !this->atFunctionTop]() {687 if ( leaveScope) __pass::symtab::leave(core, 0);641 VISIT({ 642 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 643 auto guard1 = makeFuncGuard( [this, inFunctionCpy = this->inFunction]() { 644 if ( ! inFunctionCpy ) __pass::symtab::enter(core, 0); 645 }, [this, inFunctionCpy = this->inFunction]() { 646 if ( ! inFunctionCpy ) __pass::symtab::leave(core, 0); 688 647 }); 689 ValueGuard< bool > guard2( atFunctionTop ); 690 atFunctionTop = false; 648 ValueGuard< bool > guard2( inFunction ); 691 649 guard_scope guard3 { *this }; 650 inFunction = false; 692 651 maybe_accept( node, &CompoundStmt::kids ); 693 )652 }) 694 653 VISIT_END( CompoundStmt, node ); 695 654 } … … 744 703 maybe_accept( node, &IfStmt::inits ); 745 704 maybe_accept( node, &IfStmt::cond ); 746 maybe_accept _as_compound( node, &IfStmt::thenPart );747 maybe_accept _as_compound( node, &IfStmt::elsePart );705 maybe_accept( node, &IfStmt::thenPart ); 706 maybe_accept( node, &IfStmt::elsePart ); 748 707 }) 749 708 … … 762 721 maybe_accept( node, &WhileStmt::inits ); 763 722 maybe_accept( node, &WhileStmt::cond ); 764 maybe_accept _as_compound( node, &WhileStmt::body );723 maybe_accept( node, &WhileStmt::body ); 765 724 }) 766 725 … … 777 736 // for statements introduce a level of scope (for the initialization) 778 737 guard_symtab guard { *this }; 779 // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.780 738 maybe_accept( node, &ForStmt::inits ); 781 739 maybe_accept( node, &ForStmt::cond ); 782 740 maybe_accept( node, &ForStmt::inc ); 783 maybe_accept _as_compound( node, &ForStmt::body );741 maybe_accept( node, &ForStmt::body ); 784 742 }) 785 743 … … 876 834 maybe_accept( node, &CatchStmt::decl ); 877 835 maybe_accept( node, &CatchStmt::cond ); 878 maybe_accept _as_compound( node, &CatchStmt::body );836 maybe_accept( node, &CatchStmt::body ); 879 837 }) 880 838
Note:
See TracChangeset
for help on using the changeset viewer.