Changes in / [9c90718:186b398]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r9c90718 r186b398  
    3737        PassVisitor(Args &&... args)
    3838                : pass( std::forward<Args>( args )... )
    39         {}
     39        {
     40                typedef PassVisitor<pass_type> this_t;
     41                this_t * const * visitor = visitor_impl(pass, 0);
     42                if(visitor) {
     43                        *const_cast<this_t **>( visitor ) = this;
     44                }
     45        }
    4046
    4147        virtual ~PassVisitor() = default;
     
    238244        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    239245        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
    240         bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
    241         void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }
     246        std::list< Declaration* > *     get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
     247        std::list< Declaration* > *     get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
     248
     249        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
    242250
    243251        guard_value_impl init_guard() {
     
    278286        std::list< Statement* > stmtsToAddAfter;
    279287};
    280 
    281288class WithShortCircuiting {
    282289protected:
     
    285292
    286293public:
    287         bool skip_children;
     294        bool_ref visit_children;
    288295};
    289296
     
    304311};
    305312
     313template<typename pass_type>
     314class WithVisitorRef {
     315protected:
     316        WithVisitorRef() = default;
     317        ~WithVisitorRef() = default;
     318
     319public:
     320        PassVisitor<pass_type> * const visitor;
     321};
    306322
    307323#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    r9c90718 r186b398  
    44        __attribute__((unused))                   \
    55        const auto & guard = init_guard();        \
     6        bool visit_children = true;               \
     7        set_visit_children( visit_children );   \
    68        call_previsit( node );                    \
    7         if( visit_children() ) {                  \
     9        if( visit_children ) {                    \
    810
    911#define VISIT_END( node )                       \
    1012        }                                         \
    11         reset_visit();                            \
    1213        call_postvisit( node );                   \
    1314
     
    1516        __attribute__((unused))                   \
    1617        const auto & guard = init_guard();        \
     18        bool visit_children = true;               \
     19        set_visit_children( visit_children );   \
    1720        call_premutate( node );                   \
    18         if( visit_children() ) {                  \
     21        if( visit_children ) {                    \
    1922
    2023#define MUTATE_END( type, node )                \
    2124        }                                         \
    22         reset_visit();                            \
    2325        return call_postmutate< type * >( node ); \
    2426
     
    348350
    349351//--------------------------------------------------------------------------
    350 // SwitchStmt
     352// CaseStmt
    351353template< typename pass_type >
    352354void PassVisitor< pass_type >::visit( CaseStmt * node ) {
  • src/Common/PassVisitor.proto.h

    r9c90718 r186b398  
    11#pragma once
     2
     3template<typename pass_type>
     4class PassVisitor;
    25
    36typedef std::function<void( void * )> cleanup_func_t;
     
    3134
    3235typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
     36
     37class bool_ref {
     38public:
     39        bool_ref() = default;
     40        ~bool_ref() = default;
     41
     42        operator bool() { return *m_ref; }
     43        bool operator=( bool val ) { return *m_ref = val; }
     44
     45private:
     46
     47        template<typename pass>
     48        friend class PassVisitor;
     49
     50        void set( bool & val ) { m_ref = &val; };
     51
     52        bool * m_ref;
     53};
    3354
    3455//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    112133FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
    113134FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
    114 FIELD_PTR( bool, skip_children )
     135FIELD_PTR( std::list< Declaration* >, declsToAddBefore )
     136FIELD_PTR( std::list< Declaration* >, declsToAddAfter  )
     137FIELD_PTR( bool_ref, visit_children )
    115138FIELD_PTR( at_cleanup_t, at_cleanup )
     139FIELD_PTR( PassVisitor<pass_type> * const, visitor )
  • src/InitTweak/InitTweak.cc

    r9c90718 r186b398  
    474474        public:
    475475                ConstExprChecker() : isConstExpr( true ) {}
     476
     477                using Visitor::visit;
    476478
    477479                virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; }
Note: See TracChangeset for help on using the changeset viewer.