Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r62423350 r6ca154b  
    1212#include "SynTree/Expression.h"
    1313#include "SynTree/Constant.h"
    14 #include "SynTree/TypeSubstitution.h"
    1514
    1615#include "PassVisitor.proto.h"
     
    2726//                          stmtsToAddBefore or stmtsToAddAfter respectively.
    2827// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
    29 // | WithGuards           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
     28// | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    3029//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
    3130//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    3332class PassVisitor final : public Visitor, public Mutator {
    3433public:
     34        PassVisitor() = default;
    3535
    3636        template< typename... Args >
     
    257257
    258258        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        }
    259270};
    260271
     
    272283
    273284public:
    274         TypeSubstitution * env = nullptr;
     285        TypeSubstitution * env;
    275286};
    276287
     
    284295        std::list< Statement* > stmtsToAddAfter;
    285296};
    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 
    297297class WithShortCircuiting {
    298298protected:
     
    304304};
    305305
    306 class WithGuards {
    307 protected:
    308         WithGuards() = default;
    309         ~WithGuards() = default;
     306class WithScopes {
     307protected:
     308        WithScopes() = default;
     309        ~WithScopes() = default;
    310310
    311311public:
     
    318318                }, static_cast< void * >( & val ) );
    319319        }
    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         }
    333320};
    334321
     
    336323class WithVisitorRef {
    337324protected:
    338         WithVisitorRef() {}
    339         ~WithVisitorRef() {}
    340 
    341 public:
    342         PassVisitor<pass_type> * const visitor = nullptr;
     325        WithVisitorRef() = default;
     326        ~WithVisitorRef() = default;
     327
     328public:
     329        PassVisitor<pass_type> * const visitor;
    343330};
    344331
Note: See TracChangeset for help on using the changeset viewer.