Changes in src/Common/PassVisitor.h [62423350:6ca154b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r62423350 r6ca154b 12 12 #include "SynTree/Expression.h" 13 13 #include "SynTree/Constant.h" 14 #include "SynTree/TypeSubstitution.h"15 14 16 15 #include "PassVisitor.proto.h" … … 27 26 // stmtsToAddBefore or stmtsToAddAfter respectively. 28 27 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children 29 // | With Guards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable28 // | WithScopes - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable 30 29 // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. 31 30 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 33 32 class PassVisitor final : public Visitor, public Mutator { 34 33 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 } 259 270 }; 260 271 … … 272 283 273 284 public: 274 TypeSubstitution * env = nullptr;285 TypeSubstitution * env; 275 286 }; 276 287 … … 284 295 std::list< Statement* > stmtsToAddAfter; 285 296 }; 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 Guards {307 protected: 308 With Guards() = default;309 ~With Guards() = default;306 class WithScopes { 307 protected: 308 WithScopes() = default; 309 ~WithScopes() = 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 }333 320 }; 334 321 … … 336 323 class WithVisitorRef { 337 324 protected: 338 WithVisitorRef() {}339 ~WithVisitorRef() {}340 341 public: 342 PassVisitor<pass_type> * const visitor = nullptr;325 WithVisitorRef() = default; 326 ~WithVisitorRef() = default; 327 328 public: 329 PassVisitor<pass_type> * const visitor; 343 330 }; 344 331
Note:
See TracChangeset
for help on using the changeset viewer.