Changeset 8fd1b7c
- Timestamp:
- May 10, 2023, 4:53:01 PM (20 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- c34a1a4, f977509
- Parents:
- fece3d9 (diff), 2d0f918 (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. - Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
rfece3d9 r8fd1b7c 22 22 #include "AST/TranslationUnit.hpp" 23 23 #include "AST/TypeSubstitution.hpp" 24 #include "Common/Iterate.hpp"25 24 26 25 #define VISIT_START( node ) \ … … 127 126 } 128 127 129 template< typename node_t >130 template< typename object_t, typename super_t, typename field_t >131 void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {132 object->*field = value;133 }134 135 128 template< typename core_t > 136 129 template< typename node_t > … … 234 227 235 228 return {true, compound}; 236 }237 238 template< template <class...> class container_t >239 template< typename object_t, typename super_t, typename field_t >240 void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {241 auto & container = object->*field;242 __pedantic_pass_assert( container.size() <= values.size() );243 244 auto cit = enumerate(container).begin();245 246 container_t<ptr<Stmt>> nvals;247 for (delta & d : values) {248 if ( d.is_old ) {249 __pedantic_pass_assert( cit.idx <= d.old_idx );250 std::advance( cit, d.old_idx - cit.idx );251 nvals.push_back( std::move( (*cit).val) );252 } else {253 nvals.push_back( std::move(d.new_val) );254 }255 }256 257 container = std::move(nvals);258 }259 260 template< template <class...> class container_t >261 template< template <class...> class incontainer_t >262 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {263 if (!stmts || stmts->empty()) return;264 265 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),266 [](ast::ptr<ast::Stmt>& stmt) -> delta {267 return delta( stmt.release(), -1, false );268 });269 stmts->clear();270 differs = true;271 }272 273 template< template<class...> class container_t >274 template< template<class...> class incontainer_t >275 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {276 if (!decls || decls->empty()) return;277 278 std::transform(decls->begin(), decls->end(), std::back_inserter( values ),279 [](ast::ptr<ast::Decl>& decl) -> delta {280 auto loc = decl->location;281 auto stmt = new DeclStmt( loc, decl.release() );282 return delta( stmt, -1, false );283 });284 decls->clear();285 differs = true;286 229 } 287 230 … … 353 296 354 297 return new_kids; 355 }356 357 template< template <class...> class container_t, typename node_t >358 template< typename object_t, typename super_t, typename field_t >359 void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {360 auto & container = object->*field;361 __pedantic_pass_assert( container.size() == values.size() );362 363 for(size_t i = 0; i < container.size(); i++) {364 // Take all the elements that are different in 'values'365 // and swap them into 'container'366 if( values[i] != nullptr ) swap(container[i], values[i]);367 }368 369 // Now the original containers should still have the unchanged values370 // but also contain the new values371 298 } 372 299 … … 2236 2163 } 2237 2164 2165 #undef __pedantic_pass_assertf 2166 #undef __pedantic_pass_assert 2238 2167 #undef VISIT_START 2239 2168 #undef VISIT_END -
src/AST/Pass.proto.hpp
rfece3d9 r8fd1b7c 17 17 // IWYU pragma: private, include "Pass.hpp" 18 18 19 #include "Common/Iterate.hpp" 19 20 #include "Common/Stats/Heap.h" 20 21 namespace ast { … … 24 25 template<typename node_t> node_t * deepCopy( const node_t * ); 25 26 } 27 28 #ifdef PEDANTIC_PASS_ASSERT 29 #define __pedantic_pass_assert(...) assert (__VA_ARGS__) 30 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__) 31 #else 32 #define __pedantic_pass_assert(...) 33 #define __pedantic_pass_assertf(...) 34 #endif 26 35 27 36 namespace ast::__pass { … … 130 139 131 140 template< typename object_t, typename super_t, typename field_t > 132 void apply( object_t *, field_t super_t::* field ); 141 void apply( object_t * object, field_t super_t::* field ) { 142 object->*field = value; 143 } 133 144 }; 134 145 … … 150 161 151 162 template< typename object_t, typename super_t, typename field_t > 152 void apply( object_t *, field_t super_t::* field ); 163 void apply( object_t * object, field_t super_t::* field ) { 164 field_t & container = object->*field; 165 __pedantic_pass_assert( container.size() <= values.size() ); 166 167 auto cit = enumerate(container).begin(); 168 169 container_t<ptr<Stmt>> nvals; 170 for ( delta & d : values ) { 171 if ( d.is_old ) { 172 __pedantic_pass_assert( cit.idx <= d.old_idx ); 173 std::advance( cit, d.old_idx - cit.idx ); 174 nvals.push_back( std::move( (*cit).val ) ); 175 } else { 176 nvals.push_back( std::move( d.new_val ) ); 177 } 178 } 179 180 container = std::move(nvals); 181 } 153 182 154 183 template< template<class...> class incontainer_t > 155 void take_all( incontainer_t<ptr<Stmt>> * stmts ); 184 void take_all( incontainer_t<ptr<Stmt>> * stmts ) { 185 if ( !stmts || stmts->empty() ) return; 186 187 std::transform( stmts->begin(), stmts->end(), std::back_inserter( values ), 188 [](ast::ptr<ast::Stmt>& stmt) -> delta { 189 return delta( stmt.release(), -1, false ); 190 }); 191 stmts->clear(); 192 differs = true; 193 } 156 194 157 195 template< template<class...> class incontainer_t > 158 void take_all( incontainer_t<ptr<Decl>> * decls ); 196 void take_all( incontainer_t<ptr<Decl>> * decls ) { 197 if ( !decls || decls->empty() ) return; 198 199 std::transform( decls->begin(), decls->end(), std::back_inserter( values ), 200 [](ast::ptr<ast::Decl>& decl) -> delta { 201 ast::Decl const * d = decl.release(); 202 return delta( new DeclStmt( d->location, d ), -1, false ); 203 }); 204 decls->clear(); 205 differs = true; 206 } 159 207 }; 160 208 … … 166 214 167 215 template< typename object_t, typename super_t, typename field_t > 168 void apply( object_t *, field_t super_t::* field ); 216 void apply( object_t * object, field_t super_t::* field ) { 217 field_t & container = object->*field; 218 __pedantic_pass_assert( container.size() == values.size() ); 219 220 for ( size_t i = 0; i < container.size(); ++i ) { 221 // Take all the elements that are different in 'values' 222 // and swap them into 'container' 223 if ( values[i] != nullptr ) swap(container[i], values[i]); 224 } 225 // Now the original containers should still have the unchanged values 226 // but also contain the new values. 227 } 169 228 }; 170 229 … … 517 576 518 577 } // namespace ast::__pass 578 579 #undef __pedantic_pass_assertf 580 #undef __pedantic_pass_assert
Note: See TracChangeset
for help on using the changeset viewer.