Changeset b73bd70


Ignore:
Timestamp:
Jun 22, 2017, 1:13:26 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
186b398
Parents:
65dc863
Message:

PassVisitor? now properly copes skip-children

Location:
src/Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r65dc863 rb73bd70  
    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;
     
    240246        std::list< Declaration* > *     get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
    241247        std::list< Declaration* > *     get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
    242         bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
    243         void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }
     248
     249        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
    244250
    245251        guard_value_impl init_guard() {
     
    280286        std::list< Statement* > stmtsToAddAfter;
    281287};
    282 
    283288class WithShortCircuiting {
    284289protected:
     
    287292
    288293public:
    289         bool skip_children;
     294        bool_ref visit_children;
    290295};
    291296
     
    306311};
    307312
     313template<typename pass_type>
     314class WithVisitorRef {
     315protected:
     316        WithVisitorRef() = default;
     317        ~WithVisitorRef() = default;
     318
     319public:
     320        PassVisitor<pass_type> * const visitor;
     321};
    308322
    309323#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    r65dc863 rb73bd70  
    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
  • src/Common/PassVisitor.proto.h

    r65dc863 rb73bd70  
    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//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    114135FIELD_PTR( std::list< Declaration* >, declsToAddBefore )
    115136FIELD_PTR( std::list< Declaration* >, declsToAddAfter  )
    116 FIELD_PTR( bool, skip_children )
     137FIELD_PTR( bool_ref, visit_children )
    117138FIELD_PTR( at_cleanup_t, at_cleanup )
     139FIELD_PTR( PassVisitor<pass_type> * const, visitor )
Note: See TracChangeset for help on using the changeset viewer.