Changes in src/AST/Pass.impl.hpp [665f432:3e5dd913]
- File:
-
- 1 edited
-
src/AST/Pass.impl.hpp (modified) (124 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r665f432 r3e5dd913 20 20 #include <unordered_map> 21 21 22 #include "AST/TranslationUnit.hpp" 22 23 #include "AST/TypeSubstitution.hpp" 23 24 … … 25 26 using namespace ast; \ 26 27 /* back-up the visit children */ \ 27 __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children( pass, 0) ); \28 __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \ 28 29 /* setup the scope for passes that want to run code at exit */ \ 29 __attribute__((unused)) ast::__pass::guard_value guard2( ast::__pass::at_cleanup (pass, 0) ); \ 30 __attribute__((unused)) ast::__pass::guard_value guard2( ast::__pass::at_cleanup (core, 0) ); \ 31 /* begin tracing memory allocation if requested by this pass */ \ 32 __pass::beginTrace( core, 0 ); \ 30 33 /* call the implementation of the previsit of this pass */ \ 31 __pass::previsit( pass, node, 0 );34 __pass::previsit( core, node, 0 ); 32 35 33 36 #define VISIT( code... ) \ … … 40 43 #define VISIT_END( type, node ) \ 41 44 /* call the implementation of the postvisit of this pass */ \ 42 auto __return = __pass::postvisit( pass, node, 0 ); \45 auto __return = __pass::postvisit( core, node, 0 ); \ 43 46 assertf(__return, "post visit should never return null"); \ 47 /* end tracing memory allocation if requested by this pass */ \ 48 __pass::endTrace( core, 0 ); \ 44 49 return __return; 45 50 … … 53 58 54 59 namespace ast { 60 template<typename node_t> 61 node_t * shallowCopy( const node_t * node ); 62 55 63 namespace __pass { 56 64 // Check if this is either a null pointer or a pointer to an empty container … … 60 68 } 61 69 70 template< typename core_t, typename node_t > 71 static inline node_t* mutate(const node_t *node) { 72 return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node); 73 } 74 62 75 //------------------------------ 63 76 template<typename it_t, template <class...> class container_t> … … 119 132 } 120 133 121 template< typename pass_t >134 template< typename core_t > 122 135 template< typename node_t > 123 auto ast::Pass< pass_t >::call_accept( const node_t * node )136 auto ast::Pass< core_t >::call_accept( const node_t * node ) 124 137 -> typename std::enable_if< 125 138 !std::is_base_of<ast::Expr, node_t>::value && … … 127 140 , decltype( node->accept(*this) ) 128 141 >::type 129 130 142 { 131 143 __pedantic_pass_assert( __visit_children() ); 132 __pedantic_pass_assert( expr);144 __pedantic_pass_assert( node ); 133 145 134 146 static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR"); … … 138 150 } 139 151 140 template< typename pass_t >141 const ast::Expr * ast::Pass< pass_t >::call_accept( const ast::Expr * expr ) {152 template< typename core_t > 153 const ast::Expr * ast::Pass< core_t >::call_accept( const ast::Expr * expr ) { 142 154 __pedantic_pass_assert( __visit_children() ); 143 155 __pedantic_pass_assert( expr ); 144 156 145 const ast::TypeSubstitution ** env_ptr = __pass::env( pass, 0);146 if ( env_ptr && expr->env ) {147 * env_ptr = expr->env;157 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 ); 158 if ( typeSubs_ptr && expr->env ) { 159 *typeSubs_ptr = expr->env; 148 160 } 149 161 … … 151 163 } 152 164 153 template< typename pass_t >154 const ast::Stmt * ast::Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {165 template< typename core_t > 166 const ast::Stmt * ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) { 155 167 __pedantic_pass_assert( __visit_children() ); 156 168 __pedantic_pass_assert( stmt ); 157 169 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 158 178 // add a few useful symbols to the scope 159 179 using __pass::empty; 160 180 161 181 // get the stmts/decls that will need to be spliced in 162 auto stmts_before = __pass::stmtsToAddBefore( pass, 0);163 auto stmts_after = __pass::stmtsToAddAfter ( pass, 0);164 auto decls_before = __pass::declsToAddBefore( pass, 0);165 auto decls_after = __pass::declsToAddAfter ( pass, 0);182 auto stmts_before = __pass::stmtsToAddBefore( core, 0); 183 auto stmts_after = __pass::stmtsToAddAfter ( core, 0); 184 auto decls_before = __pass::declsToAddBefore( core, 0); 185 auto decls_after = __pass::declsToAddAfter ( core, 0); 166 186 167 187 // These may be modified by subnode but most be restored once we exit this statemnet. 168 ValueGuardPtr< const ast::TypeSubstitution * > __old_env ( __pass:: env( pass, 0) );188 ValueGuardPtr< const ast::TypeSubstitution * > __old_env ( __pass::typeSubs( core, 0 ) ); 169 189 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); 170 190 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); … … 202 222 } 203 223 204 template< typename pass_t >224 template< typename core_t > 205 225 template< template <class...> class container_t > 206 container_t< ptr<Stmt> > ast::Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {226 container_t< ptr<Stmt> > ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 207 227 __pedantic_pass_assert( __visit_children() ); 208 228 if( statements.empty() ) return {}; … … 215 235 216 236 // get the stmts/decls that will need to be spliced in 217 auto stmts_before = __pass::stmtsToAddBefore( pass, 0);218 auto stmts_after = __pass::stmtsToAddAfter ( pass, 0);219 auto decls_before = __pass::declsToAddBefore( pass, 0);220 auto decls_after = __pass::declsToAddAfter ( pass, 0);237 auto stmts_before = __pass::stmtsToAddBefore( core, 0); 238 auto stmts_after = __pass::stmtsToAddAfter ( core, 0); 239 auto decls_before = __pass::declsToAddBefore( core, 0); 240 auto decls_after = __pass::declsToAddAfter ( core, 0); 221 241 222 242 // These may be modified by subnode but most be restored once we exit this statemnet. … … 268 288 } 269 289 270 template< typename pass_t >290 template< typename core_t > 271 291 template< template <class...> class container_t, typename node_t > 272 container_t< ast::ptr<node_t> > ast::Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {292 container_t< ast::ptr<node_t> > ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 273 293 __pedantic_pass_assert( __visit_children() ); 274 294 if( container.empty() ) return {}; … … 299 319 } 300 320 301 template< typename pass_t >321 template< typename core_t > 302 322 template<typename node_t, typename parent_t, typename child_t> 303 void ast::Pass< pass_t >::maybe_accept(323 void ast::Pass< core_t >::maybe_accept( 304 324 const node_t * & parent, 305 325 child_t parent_t::*child … … 317 337 318 338 if( __pass::differs(old_val, new_val) ) { 319 auto new_parent = mutate(parent); 339 auto new_parent = __pass::mutate<core_t>(parent); 340 new_parent->*child = new_val; 341 parent = new_parent; 342 } 343 } 344 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::*child 350 ) { 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); 320 364 new_parent->*child = new_val; 321 365 parent = new_parent; … … 333 377 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 334 378 335 template< typename pass_t >336 inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {379 template< typename core_t > 380 inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< core_t > & visitor ) { 337 381 // We are going to aggregate errors for all these statements 338 382 SemanticErrorException errors; … … 342 386 343 387 // get the stmts/decls that will need to be spliced in 344 auto decls_before = __pass::declsToAddBefore( visitor. pass, 0);345 auto decls_after = __pass::declsToAddAfter ( visitor. pass, 0);388 auto decls_before = __pass::declsToAddBefore( visitor.core, 0); 389 auto decls_after = __pass::declsToAddAfter ( visitor.core, 0); 346 390 347 391 // update pass statitistics … … 363 407 } 364 408 catch( SemanticErrorException &e ) { 365 errors.append( e ); 409 if (__pass::on_error (visitor.core, *i, 0)) 410 errors.append( e ); 366 411 } 367 412 … … 371 416 pass_visitor_stats.depth--; 372 417 if ( !errors.isEmpty() ) { throw errors; } 418 } 419 420 template< typename core_t > 421 inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) { 422 return ast::accept_all( unit.decls, visitor ); 373 423 } 374 424 … … 392 442 //-------------------------------------------------------------------------- 393 443 // ObjectDecl 394 template< typename pass_t >395 const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {444 template< typename core_t > 445 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::ObjectDecl * node ) { 396 446 VISIT_START( node ); 397 447 … … 406 456 ) 407 457 408 __pass::symtab::addId( pass, 0, node );458 __pass::symtab::addId( core, 0, node ); 409 459 410 460 VISIT_END( DeclWithType, node ); … … 413 463 //-------------------------------------------------------------------------- 414 464 // FunctionDecl 415 template< typename pass_t >416 const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::FunctionDecl * node ) {417 VISIT_START( node ); 418 419 __pass::symtab::addId( pass, 0, node );465 template< typename core_t > 466 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::FunctionDecl * node ) { 467 VISIT_START( node ); 468 469 __pass::symtab::addId( core, 0, node ); 420 470 421 471 VISIT(maybe_accept( node, &FunctionDecl::withExprs );) … … 425 475 // shadow with exprs and not the other way around. 426 476 guard_symtab guard { *this }; 427 __pass::symtab::addWith( pass, 0, node->withExprs, node );477 __pass::symtab::addWith( core, 0, node->withExprs, node ); 428 478 { 429 479 guard_symtab guard { *this }; 430 480 // 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 ) ),481 static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{ 482 CodeLocation{}, "__func__", 483 new ast::ArrayType{ 484 new ast::BasicType{ ast::BasicType::Char, ast::CV::Const }, 435 485 nullptr, VariableLen, DynamicDim 436 )437 );438 __pass::symtab::addId( pass, 0, &func );486 } 487 } }; 488 __pass::symtab::addId( core, 0, func ); 439 489 VISIT( 440 maybe_accept( node, &FunctionDecl::type ); 441 // function body needs to have the same scope as parameters - CompoundStmt will not enter 442 // a new scope if inFunction is true 490 // parameter declarations 491 maybe_accept( node, &FunctionDecl::params ); 492 maybe_accept( node, &FunctionDecl::returns ); 493 // type params and assertions 494 maybe_accept( node, &FunctionDecl::type_params ); 495 maybe_accept( node, &FunctionDecl::assertions ); 496 // First remember that we are now within a function. 443 497 ValueGuard< bool > oldInFunction( inFunction ); 444 498 inFunction = true; 499 // The function body needs to have the same scope as parameters. 500 // A CompoundStmt will not enter a new scope if atFunctionTop is true. 501 ValueGuard< bool > oldAtFunctionTop( atFunctionTop ); 502 atFunctionTop = true; 445 503 maybe_accept( node, &FunctionDecl::stmts ); 446 504 maybe_accept( node, &FunctionDecl::attributes ); … … 454 512 //-------------------------------------------------------------------------- 455 513 // StructDecl 456 template< typename pass_t >457 const ast::Decl * ast::Pass< pass_t >::visit( const ast::StructDecl * node ) {514 template< typename core_t > 515 const ast::Decl * ast::Pass< core_t >::visit( const ast::StructDecl * node ) { 458 516 VISIT_START( node ); 459 517 460 518 // make up a forward declaration and add it before processing the members 461 519 // needs to be on the heap because addStruct saves the pointer 462 __pass::symtab::addStructFwd( pass, 0, node );520 __pass::symtab::addStructFwd( core, 0, node ); 463 521 464 522 VISIT({ … … 469 527 470 528 // this addition replaces the forward declaration 471 __pass::symtab::addStruct( pass, 0, node );529 __pass::symtab::addStruct( core, 0, node ); 472 530 473 531 VISIT_END( Decl, node ); … … 476 534 //-------------------------------------------------------------------------- 477 535 // UnionDecl 478 template< typename pass_t >479 const ast::Decl * ast::Pass< pass_t >::visit( const ast::UnionDecl * node ) {536 template< typename core_t > 537 const ast::Decl * ast::Pass< core_t >::visit( const ast::UnionDecl * node ) { 480 538 VISIT_START( node ); 481 539 482 540 // make up a forward declaration and add it before processing the members 483 __pass::symtab::addUnionFwd( pass, 0, node );541 __pass::symtab::addUnionFwd( core, 0, node ); 484 542 485 543 VISIT({ … … 489 547 }) 490 548 491 __pass::symtab::addUnion( pass, 0, node );549 __pass::symtab::addUnion( core, 0, node ); 492 550 493 551 VISIT_END( Decl, node ); … … 496 554 //-------------------------------------------------------------------------- 497 555 // EnumDecl 498 template< typename pass_t >499 const ast::Decl * ast::Pass< pass_t >::visit( const ast::EnumDecl * node ) {500 VISIT_START( node ); 501 502 __pass::symtab::addEnum( pass, 0, node );556 template< typename core_t > 557 const ast::Decl * ast::Pass< core_t >::visit( const ast::EnumDecl * node ) { 558 VISIT_START( node ); 559 560 __pass::symtab::addEnum( core, 0, node ); 503 561 504 562 VISIT( … … 513 571 //-------------------------------------------------------------------------- 514 572 // TraitDecl 515 template< typename pass_t >516 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TraitDecl * node ) {573 template< typename core_t > 574 const ast::Decl * ast::Pass< core_t >::visit( const ast::TraitDecl * node ) { 517 575 VISIT_START( node ); 518 576 … … 523 581 }) 524 582 525 __pass::symtab::addTrait( pass, 0, node );583 __pass::symtab::addTrait( core, 0, node ); 526 584 527 585 VISIT_END( Decl, node ); … … 530 588 //-------------------------------------------------------------------------- 531 589 // TypeDecl 532 template< typename pass_t >533 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypeDecl * node ) {590 template< typename core_t > 591 const ast::Decl * ast::Pass< core_t >::visit( const ast::TypeDecl * node ) { 534 592 VISIT_START( node ); 535 593 536 594 VISIT({ 537 595 guard_symtab guard { *this }; 538 maybe_accept( node, &TypeDecl::params );539 596 maybe_accept( node, &TypeDecl::base ); 540 597 }) … … 543 600 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 544 601 // and may depend on the type itself 545 __pass::symtab::addType( pass, 0, node );602 __pass::symtab::addType( core, 0, node ); 546 603 547 604 VISIT( … … 559 616 //-------------------------------------------------------------------------- 560 617 // TypedefDecl 561 template< typename pass_t >562 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypedefDecl * node ) {618 template< typename core_t > 619 const ast::Decl * ast::Pass< core_t >::visit( const ast::TypedefDecl * node ) { 563 620 VISIT_START( node ); 564 621 565 622 VISIT({ 566 623 guard_symtab guard { *this }; 567 maybe_accept( node, &TypedefDecl::params );568 624 maybe_accept( node, &TypedefDecl::base ); 569 625 }) 570 626 571 __pass::symtab::addType( pass, 0, node );627 __pass::symtab::addType( core, 0, node ); 572 628 573 629 VISIT( maybe_accept( node, &TypedefDecl::assertions ); ) … … 578 634 //-------------------------------------------------------------------------- 579 635 // AsmDecl 580 template< typename pass_t >581 const ast::AsmDecl * ast::Pass< pass_t >::visit( const ast::AsmDecl * node ) {636 template< typename core_t > 637 const ast::AsmDecl * ast::Pass< core_t >::visit( const ast::AsmDecl * node ) { 582 638 VISIT_START( node ); 583 639 … … 591 647 //-------------------------------------------------------------------------- 592 648 // StaticAssertDecl 593 template< typename pass_t >594 const ast::StaticAssertDecl * ast::Pass< pass_t >::visit( const ast::StaticAssertDecl * node ) {649 template< typename core_t > 650 const ast::StaticAssertDecl * ast::Pass< core_t >::visit( const ast::StaticAssertDecl * node ) { 595 651 VISIT_START( node ); 596 652 … … 605 661 //-------------------------------------------------------------------------- 606 662 // CompoundStmt 607 template< typename pass_t > 608 const ast::CompoundStmt * ast::Pass< pass_t >::visit( const ast::CompoundStmt * node ) { 609 VISIT_START( node ); 610 VISIT({ 611 // 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); 663 template< typename core_t > 664 const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) { 665 VISIT_START( node ); 666 VISIT( 667 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result. 668 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() { 669 if ( enterScope ) { 670 __pass::symtab::enter(core, 0); 671 __pass::scope::enter(core, 0); 672 } 673 }, [this, leaveScope = !this->atFunctionTop]() { 674 if ( leaveScope ) { 675 __pass::symtab::leave(core, 0); 676 __pass::scope::leave(core, 0); 677 } 616 678 }); 617 ValueGuard< bool > guard2( inFunction ); 679 ValueGuard< bool > guard2( atFunctionTop ); 680 atFunctionTop = false; 618 681 guard_scope guard3 { *this }; 619 inFunction = false;620 682 maybe_accept( node, &CompoundStmt::kids ); 621 })683 ) 622 684 VISIT_END( CompoundStmt, node ); 623 685 } … … 625 687 //-------------------------------------------------------------------------- 626 688 // ExprStmt 627 template< typename pass_t >628 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ExprStmt * node ) {689 template< typename core_t > 690 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ExprStmt * node ) { 629 691 VISIT_START( node ); 630 692 … … 638 700 //-------------------------------------------------------------------------- 639 701 // AsmStmt 640 template< typename pass_t >641 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::AsmStmt * node ) {702 template< typename core_t > 703 const ast::Stmt * ast::Pass< core_t >::visit( const ast::AsmStmt * node ) { 642 704 VISIT_START( node ) 643 705 … … 654 716 //-------------------------------------------------------------------------- 655 717 // DirectiveStmt 656 template< typename pass_t >657 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DirectiveStmt * node ) {718 template< typename core_t > 719 const ast::Stmt * ast::Pass< core_t >::visit( const ast::DirectiveStmt * node ) { 658 720 VISIT_START( node ) 659 721 … … 663 725 //-------------------------------------------------------------------------- 664 726 // IfStmt 665 template< typename pass_t >666 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::IfStmt * node ) {727 template< typename core_t > 728 const ast::Stmt * ast::Pass< core_t >::visit( const ast::IfStmt * node ) { 667 729 VISIT_START( node ); 668 730 … … 672 734 maybe_accept( node, &IfStmt::inits ); 673 735 maybe_accept( node, &IfStmt::cond ); 674 maybe_accept ( node, &IfStmt::thenPart );675 maybe_accept ( node, &IfStmt::elsePart );736 maybe_accept_as_compound( node, &IfStmt::thenPart ); 737 maybe_accept_as_compound( node, &IfStmt::elsePart ); 676 738 }) 677 739 … … 681 743 //-------------------------------------------------------------------------- 682 744 // WhileStmt 683 template< typename pass_t >684 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WhileStmt * node ) {745 template< typename core_t > 746 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) { 685 747 VISIT_START( node ); 686 748 … … 690 752 maybe_accept( node, &WhileStmt::inits ); 691 753 maybe_accept( node, &WhileStmt::cond ); 692 maybe_accept ( node, &WhileStmt::body );754 maybe_accept_as_compound( node, &WhileStmt::body ); 693 755 }) 694 756 … … 698 760 //-------------------------------------------------------------------------- 699 761 // ForStmt 700 template< typename pass_t >701 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ForStmt * node ) {762 template< typename core_t > 763 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ForStmt * node ) { 702 764 VISIT_START( node ); 703 765 … … 705 767 // for statements introduce a level of scope (for the initialization) 706 768 guard_symtab guard { *this }; 769 // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later. 707 770 maybe_accept( node, &ForStmt::inits ); 708 771 maybe_accept( node, &ForStmt::cond ); 709 772 maybe_accept( node, &ForStmt::inc ); 710 maybe_accept ( node, &ForStmt::body );773 maybe_accept_as_compound( node, &ForStmt::body ); 711 774 }) 712 775 … … 716 779 //-------------------------------------------------------------------------- 717 780 // SwitchStmt 718 template< typename pass_t >719 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SwitchStmt * node ) {781 template< typename core_t > 782 const ast::Stmt * ast::Pass< core_t >::visit( const ast::SwitchStmt * node ) { 720 783 VISIT_START( node ); 721 784 … … 730 793 //-------------------------------------------------------------------------- 731 794 // CaseStmt 732 template< typename pass_t >733 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CaseStmt * node ) {795 template< typename core_t > 796 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt * node ) { 734 797 VISIT_START( node ); 735 798 … … 744 807 //-------------------------------------------------------------------------- 745 808 // BranchStmt 746 template< typename pass_t >747 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::BranchStmt * node ) {809 template< typename core_t > 810 const ast::Stmt * ast::Pass< core_t >::visit( const ast::BranchStmt * node ) { 748 811 VISIT_START( node ); 749 812 VISIT_END( Stmt, node ); … … 752 815 //-------------------------------------------------------------------------- 753 816 // ReturnStmt 754 template< typename pass_t >755 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ReturnStmt * node ) {817 template< typename core_t > 818 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ReturnStmt * node ) { 756 819 VISIT_START( node ); 757 820 … … 765 828 //-------------------------------------------------------------------------- 766 829 // ThrowStmt 767 template< typename pass_t >768 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ThrowStmt * node ) {830 template< typename core_t > 831 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ThrowStmt * node ) { 769 832 VISIT_START( node ); 770 833 … … 779 842 //-------------------------------------------------------------------------- 780 843 // TryStmt 781 template< typename pass_t >782 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::TryStmt * node ) {844 template< typename core_t > 845 const ast::Stmt * ast::Pass< core_t >::visit( const ast::TryStmt * node ) { 783 846 VISIT_START( node ); 784 847 … … 794 857 //-------------------------------------------------------------------------- 795 858 // CatchStmt 796 template< typename pass_t >797 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CatchStmt * node ) {859 template< typename core_t > 860 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt * node ) { 798 861 VISIT_START( node ); 799 862 … … 803 866 maybe_accept( node, &CatchStmt::decl ); 804 867 maybe_accept( node, &CatchStmt::cond ); 805 maybe_accept ( node, &CatchStmt::body );868 maybe_accept_as_compound( node, &CatchStmt::body ); 806 869 }) 807 870 … … 811 874 //-------------------------------------------------------------------------- 812 875 // FinallyStmt 813 template< typename pass_t >814 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::FinallyStmt * node ) {876 template< typename core_t > 877 const ast::Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt * node ) { 815 878 VISIT_START( node ); 816 879 … … 823 886 824 887 //-------------------------------------------------------------------------- 888 // FinallyStmt 889 template< typename core_t > 890 const ast::Stmt * ast::Pass< core_t >::visit( const ast::SuspendStmt * node ) { 891 VISIT_START( node ); 892 893 VISIT( 894 maybe_accept( node, &SuspendStmt::then ); 895 ) 896 897 VISIT_END( Stmt, node ); 898 } 899 900 //-------------------------------------------------------------------------- 825 901 // WaitForStmt 826 template< typename pass_t >827 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WaitForStmt * node ) {902 template< typename core_t > 903 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitForStmt * node ) { 828 904 VISIT_START( node ); 829 905 // for( auto & clause : node->clauses ) { … … 862 938 863 939 if(mutated) { 864 auto n = mutate(node);940 auto n = __pass::mutate<core_t>(node); 865 941 n->clauses = std::move( new_clauses ); 866 942 node = n; … … 872 948 auto nval = call_accept( node->field ); \ 873 949 if(nval != node->field ) { \ 874 auto nparent = mutate(node); \950 auto nparent = __pass::mutate<core_t>(node); \ 875 951 nparent->field = nval; \ 876 952 node = nparent; \ … … 893 969 //-------------------------------------------------------------------------- 894 970 // WithStmt 895 template< typename pass_t >896 const ast::Decl * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {971 template< typename core_t > 972 const ast::Decl * ast::Pass< core_t >::visit( const ast::WithStmt * node ) { 897 973 VISIT_START( node ); 898 974 … … 902 978 // catch statements introduce a level of scope (for the caught exception) 903 979 guard_symtab guard { *this }; 904 __pass::symtab::addWith( pass, 0, node->exprs, node );980 __pass::symtab::addWith( core, 0, node->exprs, node ); 905 981 maybe_accept( node, &WithStmt::stmt ); 906 982 } … … 911 987 //-------------------------------------------------------------------------- 912 988 // NullStmt 913 template< typename pass_t >914 const ast::NullStmt * ast::Pass< pass_t >::visit( const ast::NullStmt * node ) {989 template< typename core_t > 990 const ast::NullStmt * ast::Pass< core_t >::visit( const ast::NullStmt * node ) { 915 991 VISIT_START( node ); 916 992 VISIT_END( NullStmt, node ); … … 919 995 //-------------------------------------------------------------------------- 920 996 // DeclStmt 921 template< typename pass_t >922 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DeclStmt * node ) {997 template< typename core_t > 998 const ast::Stmt * ast::Pass< core_t >::visit( const ast::DeclStmt * node ) { 923 999 VISIT_START( node ); 924 1000 … … 932 1008 //-------------------------------------------------------------------------- 933 1009 // ImplicitCtorDtorStmt 934 template< typename pass_t >935 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ImplicitCtorDtorStmt * node ) {1010 template< typename core_t > 1011 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ImplicitCtorDtorStmt * node ) { 936 1012 VISIT_START( node ); 937 1013 938 1014 // For now this isn't visited, it is unclear if this causes problem 939 1015 // if all tests are known to pass, remove this code 940 //VISIT(941 //maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );942 //)1016 VISIT( 1017 maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); 1018 ) 943 1019 944 1020 VISIT_END( Stmt, node ); … … 947 1023 //-------------------------------------------------------------------------- 948 1024 // ApplicationExpr 949 template< typename pass_t >950 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ApplicationExpr * node ) {1025 template< typename core_t > 1026 const ast::Expr * ast::Pass< core_t >::visit( const ast::ApplicationExpr * node ) { 951 1027 VISIT_START( node ); 952 1028 … … 965 1041 //-------------------------------------------------------------------------- 966 1042 // UntypedExpr 967 template< typename pass_t >968 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedExpr * node ) {1043 template< typename core_t > 1044 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedExpr * node ) { 969 1045 VISIT_START( node ); 970 1046 … … 983 1059 //-------------------------------------------------------------------------- 984 1060 // NameExpr 985 template< typename pass_t >986 const ast::Expr * ast::Pass< pass_t >::visit( const ast::NameExpr * node ) {1061 template< typename core_t > 1062 const ast::Expr * ast::Pass< core_t >::visit( const ast::NameExpr * node ) { 987 1063 VISIT_START( node ); 988 1064 … … 997 1073 //-------------------------------------------------------------------------- 998 1074 // CastExpr 999 template< typename pass_t >1000 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CastExpr * node ) {1075 template< typename core_t > 1076 const ast::Expr * ast::Pass< core_t >::visit( const ast::CastExpr * node ) { 1001 1077 VISIT_START( node ); 1002 1078 … … 1013 1089 //-------------------------------------------------------------------------- 1014 1090 // KeywordCastExpr 1015 template< typename pass_t >1016 const ast::Expr * ast::Pass< pass_t >::visit( const ast::KeywordCastExpr * node ) {1091 template< typename core_t > 1092 const ast::Expr * ast::Pass< core_t >::visit( const ast::KeywordCastExpr * node ) { 1017 1093 VISIT_START( node ); 1018 1094 … … 1029 1105 //-------------------------------------------------------------------------- 1030 1106 // VirtualCastExpr 1031 template< typename pass_t >1032 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VirtualCastExpr * node ) {1107 template< typename core_t > 1108 const ast::Expr * ast::Pass< core_t >::visit( const ast::VirtualCastExpr * node ) { 1033 1109 VISIT_START( node ); 1034 1110 … … 1045 1121 //-------------------------------------------------------------------------- 1046 1122 // AddressExpr 1047 template< typename pass_t >1048 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AddressExpr * node ) {1123 template< typename core_t > 1124 const ast::Expr * ast::Pass< core_t >::visit( const ast::AddressExpr * node ) { 1049 1125 VISIT_START( node ); 1050 1126 … … 1061 1137 //-------------------------------------------------------------------------- 1062 1138 // LabelAddressExpr 1063 template< typename pass_t >1064 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LabelAddressExpr * node ) {1139 template< typename core_t > 1140 const ast::Expr * ast::Pass< core_t >::visit( const ast::LabelAddressExpr * node ) { 1065 1141 VISIT_START( node ); 1066 1142 … … 1075 1151 //-------------------------------------------------------------------------- 1076 1152 // UntypedMemberExpr 1077 template< typename pass_t >1078 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedMemberExpr * node ) {1153 template< typename core_t > 1154 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedMemberExpr * node ) { 1079 1155 VISIT_START( node ); 1080 1156 … … 1092 1168 //-------------------------------------------------------------------------- 1093 1169 // MemberExpr 1094 template< typename pass_t >1095 const ast::Expr * ast::Pass< pass_t >::visit( const ast::MemberExpr * node ) {1170 template< typename core_t > 1171 const ast::Expr * ast::Pass< core_t >::visit( const ast::MemberExpr * node ) { 1096 1172 VISIT_START( node ); 1097 1173 … … 1108 1184 //-------------------------------------------------------------------------- 1109 1185 // VariableExpr 1110 template< typename pass_t >1111 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VariableExpr * node ) {1186 template< typename core_t > 1187 const ast::Expr * ast::Pass< core_t >::visit( const ast::VariableExpr * node ) { 1112 1188 VISIT_START( node ); 1113 1189 … … 1122 1198 //-------------------------------------------------------------------------- 1123 1199 // ConstantExpr 1124 template< typename pass_t >1125 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstantExpr * node ) {1200 template< typename core_t > 1201 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstantExpr * node ) { 1126 1202 VISIT_START( node ); 1127 1203 … … 1136 1212 //-------------------------------------------------------------------------- 1137 1213 // SizeofExpr 1138 template< typename pass_t >1139 const ast::Expr * ast::Pass< pass_t >::visit( const ast::SizeofExpr * node ) {1214 template< typename core_t > 1215 const ast::Expr * ast::Pass< core_t >::visit( const ast::SizeofExpr * node ) { 1140 1216 VISIT_START( node ); 1141 1217 … … 1156 1232 //-------------------------------------------------------------------------- 1157 1233 // AlignofExpr 1158 template< typename pass_t >1159 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AlignofExpr * node ) {1234 template< typename core_t > 1235 const ast::Expr * ast::Pass< core_t >::visit( const ast::AlignofExpr * node ) { 1160 1236 VISIT_START( node ); 1161 1237 … … 1176 1252 //-------------------------------------------------------------------------- 1177 1253 // UntypedOffsetofExpr 1178 template< typename pass_t >1179 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedOffsetofExpr * node ) {1254 template< typename core_t > 1255 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedOffsetofExpr * node ) { 1180 1256 VISIT_START( node ); 1181 1257 … … 1192 1268 //-------------------------------------------------------------------------- 1193 1269 // OffsetofExpr 1194 template< typename pass_t >1195 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetofExpr * node ) {1270 template< typename core_t > 1271 const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetofExpr * node ) { 1196 1272 VISIT_START( node ); 1197 1273 … … 1208 1284 //-------------------------------------------------------------------------- 1209 1285 // OffsetPackExpr 1210 template< typename pass_t >1211 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetPackExpr * node ) {1286 template< typename core_t > 1287 const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetPackExpr * node ) { 1212 1288 VISIT_START( node ); 1213 1289 … … 1224 1300 //-------------------------------------------------------------------------- 1225 1301 // LogicalExpr 1226 template< typename pass_t >1227 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LogicalExpr * node ) {1302 template< typename core_t > 1303 const ast::Expr * ast::Pass< core_t >::visit( const ast::LogicalExpr * node ) { 1228 1304 VISIT_START( node ); 1229 1305 … … 1241 1317 //-------------------------------------------------------------------------- 1242 1318 // ConditionalExpr 1243 template< typename pass_t >1244 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConditionalExpr * node ) {1319 template< typename core_t > 1320 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConditionalExpr * node ) { 1245 1321 VISIT_START( node ); 1246 1322 … … 1259 1335 //-------------------------------------------------------------------------- 1260 1336 // CommaExpr 1261 template< typename pass_t >1262 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CommaExpr * node ) {1337 template< typename core_t > 1338 const ast::Expr * ast::Pass< core_t >::visit( const ast::CommaExpr * node ) { 1263 1339 VISIT_START( node ); 1264 1340 … … 1276 1352 //-------------------------------------------------------------------------- 1277 1353 // TypeExpr 1278 template< typename pass_t >1279 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TypeExpr * node ) {1354 template< typename core_t > 1355 const ast::Expr * ast::Pass< core_t >::visit( const ast::TypeExpr * node ) { 1280 1356 VISIT_START( node ); 1281 1357 … … 1292 1368 //-------------------------------------------------------------------------- 1293 1369 // AsmExpr 1294 template< typename pass_t >1295 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AsmExpr * node ) {1370 template< typename core_t > 1371 const ast::Expr * ast::Pass< core_t >::visit( const ast::AsmExpr * node ) { 1296 1372 VISIT_START( node ); 1297 1373 … … 1309 1385 //-------------------------------------------------------------------------- 1310 1386 // ImplicitCopyCtorExpr 1311 template< typename pass_t >1312 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {1387 template< typename core_t > 1388 const ast::Expr * ast::Pass< core_t >::visit( const ast::ImplicitCopyCtorExpr * node ) { 1313 1389 VISIT_START( node ); 1314 1390 … … 1325 1401 //-------------------------------------------------------------------------- 1326 1402 // ConstructorExpr 1327 template< typename pass_t >1328 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstructorExpr * node ) {1403 template< typename core_t > 1404 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstructorExpr * node ) { 1329 1405 VISIT_START( node ); 1330 1406 … … 1341 1417 //-------------------------------------------------------------------------- 1342 1418 // CompoundLiteralExpr 1343 template< typename pass_t >1344 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CompoundLiteralExpr * node ) {1419 template< typename core_t > 1420 const ast::Expr * ast::Pass< core_t >::visit( const ast::CompoundLiteralExpr * node ) { 1345 1421 VISIT_START( node ); 1346 1422 … … 1357 1433 //-------------------------------------------------------------------------- 1358 1434 // RangeExpr 1359 template< typename pass_t >1360 const ast::Expr * ast::Pass< pass_t >::visit( const ast::RangeExpr * node ) {1435 template< typename core_t > 1436 const ast::Expr * ast::Pass< core_t >::visit( const ast::RangeExpr * node ) { 1361 1437 VISIT_START( node ); 1362 1438 … … 1374 1450 //-------------------------------------------------------------------------- 1375 1451 // UntypedTupleExpr 1376 template< typename pass_t >1377 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedTupleExpr * node ) {1452 template< typename core_t > 1453 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedTupleExpr * node ) { 1378 1454 VISIT_START( node ); 1379 1455 … … 1390 1466 //-------------------------------------------------------------------------- 1391 1467 // TupleExpr 1392 template< typename pass_t >1393 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleExpr * node ) {1468 template< typename core_t > 1469 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleExpr * node ) { 1394 1470 VISIT_START( node ); 1395 1471 … … 1406 1482 //-------------------------------------------------------------------------- 1407 1483 // TupleIndexExpr 1408 template< typename pass_t >1409 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleIndexExpr * node ) {1484 template< typename core_t > 1485 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleIndexExpr * node ) { 1410 1486 VISIT_START( node ); 1411 1487 … … 1422 1498 //-------------------------------------------------------------------------- 1423 1499 // TupleAssignExpr 1424 template< typename pass_t >1425 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleAssignExpr * node ) {1500 template< typename core_t > 1501 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleAssignExpr * node ) { 1426 1502 VISIT_START( node ); 1427 1503 … … 1438 1514 //-------------------------------------------------------------------------- 1439 1515 // StmtExpr 1440 template< typename pass_t >1441 const ast::Expr * ast::Pass< pass_t >::visit( const ast::StmtExpr * node ) {1516 template< typename core_t > 1517 const ast::Expr * ast::Pass< core_t >::visit( const ast::StmtExpr * node ) { 1442 1518 VISIT_START( node ); 1443 1519 1444 1520 VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr 1445 1521 // get the stmts that will need to be spliced in 1446 auto stmts_before = __pass::stmtsToAddBefore( pass, 0);1447 auto stmts_after = __pass::stmtsToAddAfter ( pass, 0);1522 auto stmts_before = __pass::stmtsToAddBefore( core, 0); 1523 auto stmts_after = __pass::stmtsToAddAfter ( core, 0); 1448 1524 1449 1525 // These may be modified by subnode but most be restored once we exit this statemnet. 1450 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass:: env( pass, 0) );1526 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::typeSubs( core, 0 ) ); 1451 1527 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); 1452 1528 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); … … 1466 1542 //-------------------------------------------------------------------------- 1467 1543 // UniqueExpr 1468 template< typename pass_t >1469 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UniqueExpr * node ) {1544 template< typename core_t > 1545 const ast::Expr * ast::Pass< core_t >::visit( const ast::UniqueExpr * node ) { 1470 1546 VISIT_START( node ); 1471 1547 … … 1482 1558 //-------------------------------------------------------------------------- 1483 1559 // UntypedInitExpr 1484 template< typename pass_t >1485 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedInitExpr * node ) {1560 template< typename core_t > 1561 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedInitExpr * node ) { 1486 1562 VISIT_START( node ); 1487 1563 … … 1499 1575 //-------------------------------------------------------------------------- 1500 1576 // InitExpr 1501 template< typename pass_t >1502 const ast::Expr * ast::Pass< pass_t >::visit( const ast::InitExpr * node ) {1577 template< typename core_t > 1578 const ast::Expr * ast::Pass< core_t >::visit( const ast::InitExpr * node ) { 1503 1579 VISIT_START( node ); 1504 1580 … … 1516 1592 //-------------------------------------------------------------------------- 1517 1593 // DeletedExpr 1518 template< typename pass_t >1519 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DeletedExpr * node ) {1594 template< typename core_t > 1595 const ast::Expr * ast::Pass< core_t >::visit( const ast::DeletedExpr * node ) { 1520 1596 VISIT_START( node ); 1521 1597 … … 1533 1609 //-------------------------------------------------------------------------- 1534 1610 // DefaultArgExpr 1535 template< typename pass_t >1536 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DefaultArgExpr * node ) {1611 template< typename core_t > 1612 const ast::Expr * ast::Pass< core_t >::visit( const ast::DefaultArgExpr * node ) { 1537 1613 VISIT_START( node ); 1538 1614 … … 1549 1625 //-------------------------------------------------------------------------- 1550 1626 // GenericExpr 1551 template< typename pass_t >1552 const ast::Expr * ast::Pass< pass_t >::visit( const ast::GenericExpr * node ) {1627 template< typename core_t > 1628 const ast::Expr * ast::Pass< core_t >::visit( const ast::GenericExpr * node ) { 1553 1629 VISIT_START( node ); 1554 1630 … … 1578 1654 1579 1655 if(mutated) { 1580 auto n = mutate(node);1656 auto n = __pass::mutate<core_t>(node); 1581 1657 n->associations = std::move( new_kids ); 1582 1658 node = n; … … 1589 1665 //-------------------------------------------------------------------------- 1590 1666 // VoidType 1591 template< typename pass_t >1592 const ast::Type * ast::Pass< pass_t >::visit( const ast::VoidType * node ) {1667 template< typename core_t > 1668 const ast::Type * ast::Pass< core_t >::visit( const ast::VoidType * node ) { 1593 1669 VISIT_START( node ); 1594 1670 … … 1598 1674 //-------------------------------------------------------------------------- 1599 1675 // BasicType 1600 template< typename pass_t >1601 const ast::Type * ast::Pass< pass_t >::visit( const ast::BasicType * node ) {1676 template< typename core_t > 1677 const ast::Type * ast::Pass< core_t >::visit( const ast::BasicType * node ) { 1602 1678 VISIT_START( node ); 1603 1679 … … 1607 1683 //-------------------------------------------------------------------------- 1608 1684 // PointerType 1609 template< typename pass_t >1610 const ast::Type * ast::Pass< pass_t >::visit( const ast::PointerType * node ) {1685 template< typename core_t > 1686 const ast::Type * ast::Pass< core_t >::visit( const ast::PointerType * node ) { 1611 1687 VISIT_START( node ); 1612 1688 … … 1621 1697 //-------------------------------------------------------------------------- 1622 1698 // ArrayType 1623 template< typename pass_t >1624 const ast::Type * ast::Pass< pass_t >::visit( const ast::ArrayType * node ) {1699 template< typename core_t > 1700 const ast::Type * ast::Pass< core_t >::visit( const ast::ArrayType * node ) { 1625 1701 VISIT_START( node ); 1626 1702 … … 1635 1711 //-------------------------------------------------------------------------- 1636 1712 // ReferenceType 1637 template< typename pass_t >1638 const ast::Type * ast::Pass< pass_t >::visit( const ast::ReferenceType * node ) {1713 template< typename core_t > 1714 const ast::Type * ast::Pass< core_t >::visit( const ast::ReferenceType * node ) { 1639 1715 VISIT_START( node ); 1640 1716 … … 1648 1724 //-------------------------------------------------------------------------- 1649 1725 // QualifiedType 1650 template< typename pass_t >1651 const ast::Type * ast::Pass< pass_t >::visit( const ast::QualifiedType * node ) {1726 template< typename core_t > 1727 const ast::Type * ast::Pass< core_t >::visit( const ast::QualifiedType * node ) { 1652 1728 VISIT_START( node ); 1653 1729 … … 1662 1738 //-------------------------------------------------------------------------- 1663 1739 // FunctionType 1664 template< typename pass_t > 1665 const ast::Type * ast::Pass< pass_t >::visit( const ast::FunctionType * node ) { 1666 VISIT_START( node ); 1667 1668 VISIT( 1669 maybe_accept( node, &FunctionType::forall ); 1740 template< typename core_t > 1741 const ast::Type * ast::Pass< core_t >::visit( const ast::FunctionType * node ) { 1742 VISIT_START( node ); 1743 1744 VISIT({ 1745 // guard_forall_subs forall_guard { *this, node }; 1746 // mutate_forall( node ); 1747 maybe_accept( node, &FunctionType::assertions ); 1670 1748 maybe_accept( node, &FunctionType::returns ); 1671 1749 maybe_accept( node, &FunctionType::params ); 1672 )1750 }) 1673 1751 1674 1752 VISIT_END( Type, node ); … … 1677 1755 //-------------------------------------------------------------------------- 1678 1756 // StructInstType 1679 template< typename pass_t >1680 const ast::Type * ast::Pass< pass_t >::visit( const ast::StructInstType * node ) {1681 VISIT_START( node ); 1682 1683 __pass::symtab::addStruct( pass, 0, node->name );1757 template< typename core_t > 1758 const ast::Type * ast::Pass< core_t >::visit( const ast::StructInstType * node ) { 1759 VISIT_START( node ); 1760 1761 __pass::symtab::addStruct( core, 0, node->name ); 1684 1762 1685 1763 VISIT({ 1686 1764 guard_symtab guard { *this }; 1687 maybe_accept( node, &StructInstType::forall );1688 1765 maybe_accept( node, &StructInstType::params ); 1689 1766 }) … … 1694 1771 //-------------------------------------------------------------------------- 1695 1772 // UnionInstType 1696 template< typename pass_t >1697 const ast::Type * ast::Pass< pass_t >::visit( const ast::UnionInstType * node ) {1698 VISIT_START( node ); 1699 1700 __pass::symtab::add Struct( pass, 0, node->name );1701 1702 {1773 template< typename core_t > 1774 const ast::Type * ast::Pass< core_t >::visit( const ast::UnionInstType * node ) { 1775 VISIT_START( node ); 1776 1777 __pass::symtab::addUnion( core, 0, node->name ); 1778 1779 VISIT({ 1703 1780 guard_symtab guard { *this }; 1704 maybe_accept( node, &UnionInstType::forall );1705 1781 maybe_accept( node, &UnionInstType::params ); 1706 } 1782 }) 1707 1783 1708 1784 VISIT_END( Type, node ); … … 1711 1787 //-------------------------------------------------------------------------- 1712 1788 // EnumInstType 1713 template< typename pass_t > 1714 const ast::Type * ast::Pass< pass_t >::visit( const ast::EnumInstType * node ) { 1715 VISIT_START( node ); 1716 1717 VISIT( 1718 maybe_accept( node, &EnumInstType::forall ); 1789 template< typename core_t > 1790 const ast::Type * ast::Pass< core_t >::visit( const ast::EnumInstType * node ) { 1791 VISIT_START( node ); 1792 1793 VISIT({ 1719 1794 maybe_accept( node, &EnumInstType::params ); 1720 )1795 }) 1721 1796 1722 1797 VISIT_END( Type, node ); … … 1725 1800 //-------------------------------------------------------------------------- 1726 1801 // TraitInstType 1727 template< typename pass_t > 1728 const ast::Type * ast::Pass< pass_t >::visit( const ast::TraitInstType * node ) { 1729 VISIT_START( node ); 1730 1731 VISIT( 1732 maybe_accept( node, &TraitInstType::forall ); 1802 template< typename core_t > 1803 const ast::Type * ast::Pass< core_t >::visit( const ast::TraitInstType * node ) { 1804 VISIT_START( node ); 1805 1806 VISIT({ 1733 1807 maybe_accept( node, &TraitInstType::params ); 1734 )1808 }) 1735 1809 1736 1810 VISIT_END( Type, node ); … … 1739 1813 //-------------------------------------------------------------------------- 1740 1814 // TypeInstType 1741 template< typename pass_t > 1742 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeInstType * node ) { 1743 VISIT_START( node ); 1744 1745 VISIT( 1746 maybe_accept( node, &TypeInstType::forall ); 1747 maybe_accept( node, &TypeInstType::params ); 1815 template< typename core_t > 1816 const ast::Type * ast::Pass< core_t >::visit( const ast::TypeInstType * node ) { 1817 VISIT_START( node ); 1818 1819 VISIT( 1820 { 1821 maybe_accept( node, &TypeInstType::params ); 1822 } 1823 // ensure that base re-bound if doing substitution 1824 __pass::forall::replace( core, 0, node ); 1748 1825 ) 1749 1826 … … 1753 1830 //-------------------------------------------------------------------------- 1754 1831 // TupleType 1755 template< typename pass_t >1756 const ast::Type * ast::Pass< pass_t >::visit( const ast::TupleType * node ) {1832 template< typename core_t > 1833 const ast::Type * ast::Pass< core_t >::visit( const ast::TupleType * node ) { 1757 1834 VISIT_START( node ); 1758 1835 … … 1767 1844 //-------------------------------------------------------------------------- 1768 1845 // TypeofType 1769 template< typename pass_t >1770 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeofType * node ) {1846 template< typename core_t > 1847 const ast::Type * ast::Pass< core_t >::visit( const ast::TypeofType * node ) { 1771 1848 VISIT_START( node ); 1772 1849 … … 1780 1857 //-------------------------------------------------------------------------- 1781 1858 // VarArgsType 1782 template< typename pass_t >1783 const ast::Type * ast::Pass< pass_t >::visit( const ast::VarArgsType * node ) {1859 template< typename core_t > 1860 const ast::Type * ast::Pass< core_t >::visit( const ast::VarArgsType * node ) { 1784 1861 VISIT_START( node ); 1785 1862 … … 1789 1866 //-------------------------------------------------------------------------- 1790 1867 // ZeroType 1791 template< typename pass_t >1792 const ast::Type * ast::Pass< pass_t >::visit( const ast::ZeroType * node ) {1868 template< typename core_t > 1869 const ast::Type * ast::Pass< core_t >::visit( const ast::ZeroType * node ) { 1793 1870 VISIT_START( node ); 1794 1871 … … 1798 1875 //-------------------------------------------------------------------------- 1799 1876 // OneType 1800 template< typename pass_t >1801 const ast::Type * ast::Pass< pass_t >::visit( const ast::OneType * node ) {1877 template< typename core_t > 1878 const ast::Type * ast::Pass< core_t >::visit( const ast::OneType * node ) { 1802 1879 VISIT_START( node ); 1803 1880 … … 1807 1884 //-------------------------------------------------------------------------- 1808 1885 // GlobalScopeType 1809 template< typename pass_t >1810 const ast::Type * ast::Pass< pass_t >::visit( const ast::GlobalScopeType * node ) {1886 template< typename core_t > 1887 const ast::Type * ast::Pass< core_t >::visit( const ast::GlobalScopeType * node ) { 1811 1888 VISIT_START( node ); 1812 1889 … … 1817 1894 //-------------------------------------------------------------------------- 1818 1895 // Designation 1819 template< typename pass_t >1820 const ast::Designation * ast::Pass< pass_t >::visit( const ast::Designation * node ) {1896 template< typename core_t > 1897 const ast::Designation * ast::Pass< core_t >::visit( const ast::Designation * node ) { 1821 1898 VISIT_START( node ); 1822 1899 … … 1828 1905 //-------------------------------------------------------------------------- 1829 1906 // SingleInit 1830 template< typename pass_t >1831 const ast::Init * ast::Pass< pass_t >::visit( const ast::SingleInit * node ) {1907 template< typename core_t > 1908 const ast::Init * ast::Pass< core_t >::visit( const ast::SingleInit * node ) { 1832 1909 VISIT_START( node ); 1833 1910 … … 1841 1918 //-------------------------------------------------------------------------- 1842 1919 // ListInit 1843 template< typename pass_t >1844 const ast::Init * ast::Pass< pass_t >::visit( const ast::ListInit * node ) {1920 template< typename core_t > 1921 const ast::Init * ast::Pass< core_t >::visit( const ast::ListInit * node ) { 1845 1922 VISIT_START( node ); 1846 1923 … … 1855 1932 //-------------------------------------------------------------------------- 1856 1933 // ConstructorInit 1857 template< typename pass_t >1858 const ast::Init * ast::Pass< pass_t >::visit( const ast::ConstructorInit * node ) {1934 template< typename core_t > 1935 const ast::Init * ast::Pass< core_t >::visit( const ast::ConstructorInit * node ) { 1859 1936 VISIT_START( node ); 1860 1937 … … 1870 1947 //-------------------------------------------------------------------------- 1871 1948 // Attribute 1872 template< typename pass_t >1873 const ast::Attribute * ast::Pass< pass_t >::visit( const ast::Attribute * node ) {1949 template< typename core_t > 1950 const ast::Attribute * ast::Pass< core_t >::visit( const ast::Attribute * node ) { 1874 1951 VISIT_START( node ); 1875 1952 … … 1883 1960 //-------------------------------------------------------------------------- 1884 1961 // TypeSubstitution 1885 template< typename pass_t >1886 const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {1962 template< typename core_t > 1963 const ast::TypeSubstitution * ast::Pass< core_t >::visit( const ast::TypeSubstitution * node ) { 1887 1964 VISIT_START( node ); 1888 1965 … … 1890 1967 { 1891 1968 bool mutated = false; 1892 std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;1969 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map; 1893 1970 for ( const auto & p : node->typeEnv ) { 1894 1971 guard_symtab guard { *this }; 1895 1972 auto new_node = p.second->accept( *this ); 1896 if (new_node != p.second) mutated = false;1973 if (new_node != p.second) mutated = true; 1897 1974 new_map.insert({ p.first, new_node }); 1898 1975 } 1899 1976 if (mutated) { 1900 auto new_node = mutate( node );1977 auto new_node = __pass::mutate<core_t>( node ); 1901 1978 new_node->typeEnv.swap( new_map ); 1902 1979 node = new_node; 1903 1980 } 1904 1981 } 1905 1906 {1907 bool mutated = false;1908 std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;1909 for ( const auto & p : node->varEnv ) {1910 guard_symtab guard { *this };1911 auto new_node = p.second->accept( *this );1912 if (new_node != p.second) mutated = false;1913 new_map.insert({ p.first, new_node });1914 }1915 if (mutated) {1916 auto new_node = mutate( node );1917 new_node->varEnv.swap( new_map );1918 node = new_node;1919 }1920 }1921 1982 ) 1922 1983
Note:
See TracChangeset
for help on using the changeset viewer.