Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r6ca154b r62423350  
    1212#include "SynTree/Expression.h"
    1313#include "SynTree/Constant.h"
     14#include "SynTree/TypeSubstitution.h"
    1415
    1516#include "PassVisitor.proto.h"
     
    2627//                          stmtsToAddBefore or stmtsToAddAfter respectively.
    2728// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
    28 // | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
     29// | WithGuards           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    2930//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
    3031//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    3233class PassVisitor final : public Visitor, public Mutator {
    3334public:
    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         }
    270259};
    271260
     
    283272
    284273public:
    285         TypeSubstitution * env;
     274        TypeSubstitution * env = nullptr;
    286275};
    287276
     
    295284        std::list< Statement* > stmtsToAddAfter;
    296285};
     286
     287class WithDeclsToAdd {
     288protected:
     289        WithDeclsToAdd() = default;
     290        ~WithDeclsToAdd() = default;
     291
     292public:
     293        std::list< Declaration* > declsToAddBefore;
     294        std::list< Declaration* > declsToAddAfter;
     295};
     296
    297297class WithShortCircuiting {
    298298protected:
     
    304304};
    305305
    306 class WithScopes {
    307 protected:
    308         WithScopes() = default;
    309         ~WithScopes() = default;
     306class WithGuards {
     307protected:
     308        WithGuards() = default;
     309        ~WithGuards() = 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        }
    320333};
    321334
     
    323336class WithVisitorRef {
    324337protected:
    325         WithVisitorRef() = default;
    326         ~WithVisitorRef() = default;
    327 
    328 public:
    329         PassVisitor<pass_type> * const visitor;
     338        WithVisitorRef() {}
     339        ~WithVisitorRef() {}
     340
     341public:
     342        PassVisitor<pass_type> * const visitor = nullptr;
    330343};
    331344
Note: See TracChangeset for help on using the changeset viewer.