Changeset 24d6572 for src/AST/Pass.impl.hpp
- Timestamp:
- Jun 12, 2023, 2:45:32 PM (2 years ago)
- Branches:
- ast-experimental, master
- Children:
- 62d62db
- Parents:
- 34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r34b4268 r24d6572 20 20 #include <unordered_map> 21 21 22 #include "AST/Copy.hpp" 22 23 #include "AST/TranslationUnit.hpp" 23 24 #include "AST/TypeSubstitution.hpp" … … 45 46 46 47 #ifdef PEDANTIC_PASS_ASSERT 47 #define __pedantic_pass_assert(...) assert 48 #define __pedantic_pass_assert(...) assert(__VA_ARGS__) 48 49 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__) 49 50 #else … … 124 125 return !new_val.empty(); 125 126 } 126 }127 128 template< typename node_t >129 template< typename object_t, typename super_t, typename field_t >130 void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {131 object->*field = value;132 127 } 133 128 … … 233 228 234 229 return {true, compound}; 235 }236 237 template< template <class...> class container_t >238 template< typename object_t, typename super_t, typename field_t >239 void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {240 auto & container = object->*field;241 __pedantic_pass_assert( container.size() <= values.size() );242 243 auto cit = enumerate(container).begin();244 245 container_t<ptr<Stmt>> nvals;246 for (delta & d : values) {247 if ( d.is_old ) {248 __pedantic_pass_assert( cit.idx <= d.old_idx );249 std::advance( cit, d.old_idx - cit.idx );250 nvals.push_back( std::move( (*cit).val) );251 } else {252 nvals.push_back( std::move(d.new_val) );253 }254 }255 256 container = std::move(nvals);257 }258 259 template< template <class...> class container_t >260 template< template <class...> class incontainer_t >261 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {262 if (!stmts || stmts->empty()) return;263 264 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),265 [](ast::ptr<ast::Stmt>& stmt) -> delta {266 return delta( stmt.release(), -1, false );267 });268 stmts->clear();269 differs = true;270 }271 272 template< template<class...> class container_t >273 template< template<class...> class incontainer_t >274 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {275 if (!decls || decls->empty()) return;276 277 std::transform(decls->begin(), decls->end(), std::back_inserter( values ),278 [](ast::ptr<ast::Decl>& decl) -> delta {279 auto loc = decl->location;280 auto stmt = new DeclStmt( loc, decl.release() );281 return delta( stmt, -1, false );282 });283 decls->clear();284 differs = true;285 230 } 286 231 … … 352 297 353 298 return new_kids; 354 }355 356 template< template <class...> class container_t, typename node_t >357 template< typename object_t, typename super_t, typename field_t >358 void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {359 auto & container = object->*field;360 __pedantic_pass_assert( container.size() == values.size() );361 362 for(size_t i = 0; i < container.size(); i++) {363 // Take all the elements that are different in 'values'364 // and swap them into 'container'365 if( values[i] != nullptr ) swap(container[i], values[i]);366 }367 368 // Now the original containers should still have the unchanged values369 // but also contain the new values370 299 } 371 300 … … 836 765 if ( enterScope ) { 837 766 __pass::symtab::enter(core, 0); 838 __pass::scope::enter(core, 0);839 767 } 840 768 }, [this, leaveScope = !this->atFunctionTop]() { 841 769 if ( leaveScope ) { 842 770 __pass::symtab::leave(core, 0); 843 __pass::scope::leave(core, 0);844 771 } 845 772 }); … … 1067 994 1068 995 //-------------------------------------------------------------------------- 996 // WhenClause 997 template< typename core_t > 998 const ast::WhenClause * ast::Pass< core_t >::visit( const ast::WhenClause * node ) { 999 VISIT_START( node ); 1000 1001 if ( __visit_children() ) { 1002 maybe_accept( node, &WhenClause::target ); 1003 maybe_accept( node, &WhenClause::stmt ); 1004 maybe_accept( node, &WhenClause::when_cond ); 1005 } 1006 1007 VISIT_END( WhenClause, node ); 1008 } 1009 1010 //-------------------------------------------------------------------------- 1069 1011 // WaitForStmt 1070 1012 template< typename core_t > … … 1091 1033 1092 1034 if ( __visit_children() ) { 1093 maybe_accept( node, &WaitForClause::target _func);1035 maybe_accept( node, &WaitForClause::target ); 1094 1036 maybe_accept( node, &WaitForClause::target_args ); 1095 1037 maybe_accept( node, &WaitForClause::stmt ); 1096 maybe_accept( node, &WaitForClause:: cond );1038 maybe_accept( node, &WaitForClause::when_cond ); 1097 1039 } 1098 1040 1099 1041 VISIT_END( WaitForClause, node ); 1042 } 1043 1044 //-------------------------------------------------------------------------- 1045 // WaitUntilStmt 1046 template< typename core_t > 1047 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitUntilStmt * node ) { 1048 VISIT_START( node ); 1049 1050 if ( __visit_children() ) { 1051 maybe_accept( node, &WaitUntilStmt::clauses ); 1052 maybe_accept( node, &WaitUntilStmt::timeout_time ); 1053 maybe_accept( node, &WaitUntilStmt::timeout_stmt ); 1054 maybe_accept( node, &WaitUntilStmt::timeout_cond ); 1055 maybe_accept( node, &WaitUntilStmt::else_stmt ); 1056 maybe_accept( node, &WaitUntilStmt::else_cond ); 1057 } 1058 1059 VISIT_END( Stmt, node ); 1100 1060 } 1101 1061 … … 2043 2003 if ( __visit_children() ) { 2044 2004 maybe_accept( node, &TupleType::types ); 2045 maybe_accept( node, &TupleType::members );2046 2005 } 2047 2006 … … 2205 2164 } 2206 2165 2166 #undef __pedantic_pass_assertf 2167 #undef __pedantic_pass_assert 2207 2168 #undef VISIT_START 2208 2169 #undef VISIT_END
Note:
See TracChangeset
for help on using the changeset viewer.