Changes in src/AST/Pass.impl.hpp [9e23b446:1df492a]
- File:
-
- 1 edited
-
src/AST/Pass.impl.hpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r9e23b446 r1df492a 155 155 __pedantic_pass_assert( expr ); 156 156 157 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 ); 158 if ( typeSubs_ptr && expr->env ) { 159 *typeSubs_ptr = expr->env; 160 } 161 157 162 auto nval = expr->accept( *this ); 158 163 return { nval != expr, nval }; … … 169 174 170 175 template< typename core_t > 171 __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept_top( const ast::Expr * expr ) {172 __pedantic_pass_assert( __visit_children() );173 __pedantic_pass_assert( expr );174 175 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );176 if ( typeSubs_ptr && expr->env ) {177 *typeSubs_ptr = expr->env;178 }179 180 auto nval = expr->accept( *this );181 return { nval != expr, nval };182 }183 184 template< typename core_t >185 176 __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) { 186 177 __pedantic_pass_assert( __visit_children() ); … … 191 182 192 183 // get the stmts/decls that will need to be spliced in 193 auto stmts_before = __pass::stmtsToAddBefore( core, 0 );194 auto stmts_after = __pass::stmtsToAddAfter ( core, 0 );195 auto decls_before = __pass::declsToAddBefore( core, 0 );196 auto decls_after = __pass::declsToAddAfter ( core, 0 );184 auto stmts_before = __pass::stmtsToAddBefore( core, 0); 185 auto stmts_after = __pass::stmtsToAddAfter ( core, 0); 186 auto decls_before = __pass::declsToAddBefore( core, 0); 187 auto decls_after = __pass::declsToAddAfter ( core, 0); 197 188 198 189 // These may be modified by subnode but most be restored once we exit this statemnet. … … 296 287 297 288 // get the stmts/decls that will need to be spliced in 298 auto stmts_before = __pass::stmtsToAddBefore( core, 0 );299 auto stmts_after = __pass::stmtsToAddAfter ( core, 0 );300 auto decls_before = __pass::declsToAddBefore( core, 0 );301 auto decls_after = __pass::declsToAddAfter ( core, 0 );289 auto stmts_before = __pass::stmtsToAddBefore( core, 0); 290 auto stmts_after = __pass::stmtsToAddAfter ( core, 0); 291 auto decls_before = __pass::declsToAddBefore( core, 0); 292 auto decls_after = __pass::declsToAddAfter ( core, 0); 302 293 303 294 // These may be modified by subnode but most be restored once we exit this statemnet. … … 326 317 assert(( empty( stmts_before ) && empty( stmts_after )) 327 318 || ( empty( decls_before ) && empty( decls_after )) ); 319 320 328 321 329 322 // Take all the statements which should have gone after, N/A for first iteration … … 419 412 420 413 auto new_val = call_accept( old_val ); 421 422 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");423 424 if( new_val.differs ) {425 auto new_parent = __pass::mutate<core_t>(parent);426 new_val.apply(new_parent, field);427 parent = new_parent;428 }429 }430 431 template< typename core_t >432 template<typename node_t, typename super_t, typename field_t>433 void ast::Pass< core_t >::maybe_accept_top(434 const node_t * & parent,435 field_t super_t::*field436 ) {437 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );438 439 if(__pass::skip(parent->*field)) return;440 const auto & old_val = __pass::get(parent->*field, 0);441 442 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");443 444 auto new_val = call_accept_top( old_val );445 414 446 415 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR"); … … 681 650 if ( __visit_children() ) { 682 651 // unlike structs, traits, and unions, enums inject their members into the global scope 652 maybe_accept( node, &EnumDecl::base ); 683 653 maybe_accept( node, &EnumDecl::params ); 684 654 maybe_accept( node, &EnumDecl::members ); … … 788 758 789 759 if ( __visit_children() ) { 790 maybe_accept _top( node, &StaticAssertDecl::cond );760 maybe_accept( node, &StaticAssertDecl::cond ); 791 761 maybe_accept( node, &StaticAssertDecl::msg ); 792 762 } … … 830 800 831 801 if ( __visit_children() ) { 832 maybe_accept _top( node, &ExprStmt::expr );802 maybe_accept( node, &ExprStmt::expr ); 833 803 } 834 804 … … 871 841 guard_symtab guard { *this }; 872 842 maybe_accept( node, &IfStmt::inits ); 873 maybe_accept _top( node, &IfStmt::cond );843 maybe_accept( node, &IfStmt::cond ); 874 844 maybe_accept_as_compound( node, &IfStmt::then ); 875 845 maybe_accept_as_compound( node, &IfStmt::else_ ); … … 889 859 guard_symtab guard { *this }; 890 860 maybe_accept( node, &WhileDoStmt::inits ); 891 maybe_accept _top( node, &WhileDoStmt::cond );861 maybe_accept( node, &WhileDoStmt::cond ); 892 862 maybe_accept_as_compound( node, &WhileDoStmt::body ); 893 863 } … … 907 877 // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later. 908 878 maybe_accept( node, &ForStmt::inits ); 909 maybe_accept _top( node, &ForStmt::cond );910 maybe_accept _top( node, &ForStmt::inc );879 maybe_accept( node, &ForStmt::cond ); 880 maybe_accept( node, &ForStmt::inc ); 911 881 maybe_accept_as_compound( node, &ForStmt::body ); 912 882 } … … 922 892 923 893 if ( __visit_children() ) { 924 maybe_accept _top( node, &SwitchStmt::cond );894 maybe_accept( node, &SwitchStmt::cond ); 925 895 maybe_accept( node, &SwitchStmt::cases ); 926 896 } … … 936 906 937 907 if ( __visit_children() ) { 938 maybe_accept _top( node, &CaseClause::cond );908 maybe_accept( node, &CaseClause::cond ); 939 909 maybe_accept( node, &CaseClause::stmts ); 940 910 } … … 958 928 959 929 if ( __visit_children() ) { 960 maybe_accept _top( node, &ReturnStmt::expr );930 maybe_accept( node, &ReturnStmt::expr ); 961 931 } 962 932 … … 1003 973 guard_symtab guard { *this }; 1004 974 maybe_accept( node, &CatchClause::decl ); 1005 maybe_accept _top( node, &CatchClause::cond );975 maybe_accept( node, &CatchClause::cond ); 1006 976 maybe_accept_as_compound( node, &CatchClause::body ); 1007 977 } … … 2090 2060 2091 2061 if ( __visit_children() ) { 2092 maybe_accept _top( node, &SingleInit::value );2062 maybe_accept( node, &SingleInit::value ); 2093 2063 } 2094 2064 … … 2146 2116 if ( __visit_children() ) { 2147 2117 bool mutated = false; 2148 ast::TypeSubstitution::TypeMapnew_map;2149 for ( const auto & p : node->type Map) {2118 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map; 2119 for ( const auto & p : node->typeEnv ) { 2150 2120 guard_symtab guard { *this }; 2151 2121 auto new_node = p.second->accept( *this ); … … 2155 2125 if (mutated) { 2156 2126 auto new_node = __pass::mutate<core_t>( node ); 2157 new_node->type Map.swap( new_map );2127 new_node->typeEnv.swap( new_map ); 2158 2128 node = new_node; 2159 2129 }
Note:
See TracChangeset
for help on using the changeset viewer.