Changes in src/Common/PassVisitor.h [6ca154b:62423350]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r6ca154b r62423350 12 12 #include "SynTree/Expression.h" 13 13 #include "SynTree/Constant.h" 14 #include "SynTree/TypeSubstitution.h" 14 15 15 16 #include "PassVisitor.proto.h" … … 26 27 // stmtsToAddBefore or stmtsToAddAfter respectively. 27 28 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children 28 // | With Scopes - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable29 // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable 29 30 // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. 30 31 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 32 33 class PassVisitor final : public Visitor, public Mutator { 33 34 public: 34 PassVisitor() = default;35 35 36 36 template< typename... Args > … … 257 257 258 258 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 259 260 guard_value_impl init_guard() {261 guard_value_impl guard;262 auto at_cleanup = at_cleanup_impl(pass, 0);263 if( at_cleanup ) {264 *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) {265 guard.push( std::move( func ), val );266 };267 }268 return guard;269 }270 259 }; 271 260 … … 283 272 284 273 public: 285 TypeSubstitution * env ;274 TypeSubstitution * env = nullptr; 286 275 }; 287 276 … … 295 284 std::list< Statement* > stmtsToAddAfter; 296 285 }; 286 287 class WithDeclsToAdd { 288 protected: 289 WithDeclsToAdd() = default; 290 ~WithDeclsToAdd() = default; 291 292 public: 293 std::list< Declaration* > declsToAddBefore; 294 std::list< Declaration* > declsToAddAfter; 295 }; 296 297 297 class WithShortCircuiting { 298 298 protected: … … 304 304 }; 305 305 306 class With Scopes {307 protected: 308 With Scopes() = default;309 ~With Scopes() = default;306 class WithGuards { 307 protected: 308 WithGuards() = default; 309 ~WithGuards() = default; 310 310 311 311 public: … … 318 318 }, static_cast< void * >( & val ) ); 319 319 } 320 321 template< typename T > 322 void GuardScope( T& val ) { 323 val.beginScope(); 324 at_cleanup( []( void * val ) { 325 static_cast< T * >( val )->endScope(); 326 }, static_cast< void * >( & val ) ); 327 } 328 329 template< typename Func > 330 void GuardAction( Func func ) { 331 at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr ); 332 } 320 333 }; 321 334 … … 323 336 class WithVisitorRef { 324 337 protected: 325 WithVisitorRef() = default;326 ~WithVisitorRef() = default;327 328 public: 329 PassVisitor<pass_type> * const visitor ;338 WithVisitorRef() {} 339 ~WithVisitorRef() {} 340 341 public: 342 PassVisitor<pass_type> * const visitor = nullptr; 330 343 }; 331 344
Note:
See TracChangeset
for help on using the changeset viewer.