Changes in / [69dd8e6:ac16a55]


Ignore:
Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    r69dd8e6 rac16a55  
    233233private:
    234234
    235         bool __visit_children() { bool * ptr = __pass::visit_children(core, 0); return ptr ? *ptr : true; }
     235        bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(core, 0); return ptr ? *ptr : true; }
    236236
    237237private:
     
    342342/// set visit_children false of all child nodes should be ignored
    343343struct WithShortCircuiting {
    344         bool visit_children;
     344        __pass::bool_ref visit_children;
    345345};
    346346
  • src/AST/Pass.proto.hpp

    r69dd8e6 rac16a55  
    4040typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
    4141
    42 /// Implementation of the guard value
    43 /// Created inside the visit scope
     42// boolean reference that may be null
     43// either refers to a boolean value or is null and returns true
     44class bool_ref {
     45public:
     46        bool_ref() = default;
     47        ~bool_ref() = default;
     48
     49        operator bool() { return m_ref ? *m_ref : true; }
     50        bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
     51
     52private:
     53
     54        friend class visit_children_guard;
     55
     56        bool * set( bool * val ) {
     57                bool * prev = m_ref;
     58                m_ref = val;
     59                return prev;
     60        }
     61
     62        bool * m_ref = nullptr;
     63};
     64
     65// Implementation of the guard value
     66// Created inside the visit scope
    4467class guard_value {
    4568public:
     
    80103public:
    81104
    82         visit_children_guard( bool * ref ) :
    83                 m_ref( ref ), m_val( true )
    84         {
    85                 if ( m_ref ) { m_val = *m_ref; *m_ref = true; }
    86         }
     105        visit_children_guard( bool_ref * ref )
     106                : m_val ( true )
     107                , m_prev( ref ? ref->set( &m_val ) : nullptr )
     108                , m_ref ( ref )
     109        {}
    87110
    88111        ~visit_children_guard() {
    89                 if ( m_ref ) { *m_ref = m_val; }
    90         }
     112                if( m_ref ) {
     113                        m_ref->set( m_prev );
     114                }
     115        }
     116
     117        operator bool() { return m_val; }
    91118
    92119private:
    93         bool * m_ref;
    94         bool   m_val;
     120        bool       m_val;
     121        bool     * m_prev;
     122        bool_ref * m_ref;
     123};
     124
     125/// "Short hand" to check if this is a valid previsit function
     126/// Mostly used to make the static_assert look (and print) prettier
     127template<typename core_t, typename node_t>
     128struct is_valid_previsit {
     129        using ret_t = decltype( std::declval<core_t*>()->previsit( std::declval<const node_t *>() ) );
     130
     131        static constexpr bool value = std::is_void< ret_t >::value ||
     132                std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
    95133};
    96134
     
    189227                // but also contain the new values.
    190228        }
    191 };
    192 
    193 /// "Short hand" to check if this is a valid previsit function
    194 /// Mostly used to make the static_assert look (and print) prettier
    195 template<typename core_t, typename node_t>
    196 struct is_valid_previsit {
    197         using ret_t = decltype( std::declval<core_t*>()->previsit( std::declval<const node_t *>() ) );
    198 
    199         static constexpr bool value = std::is_void< ret_t >::value ||
    200                 std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
    201229};
    202230
     
    279307FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
    280308FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
    281 FIELD_PTR( visit_children, bool )
     309FIELD_PTR( visit_children, __pass::bool_ref )
    282310FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
    283311FIELD_PTR( visitor, ast::Pass<core_t> * const )
Note: See TracChangeset for help on using the changeset viewer.