Changeset 69dd8e6


Ignore:
Timestamp:
May 6, 2024, 1:18:30 PM (13 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
b2ea0cd, f5cb7c2
Parents:
ac16a55 (diff), 164a6b6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    rac16a55 r69dd8e6  
    233233private:
    234234
    235         bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(core, 0); return ptr ? *ptr : true; }
     235        bool __visit_children() { bool * 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         __pass::bool_ref visit_children;
     344        bool visit_children;
    345345};
    346346
  • src/AST/Pass.proto.hpp

    rac16a55 r69dd8e6  
    4040typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
    4141
    42 // boolean reference that may be null
    43 // either refers to a boolean value or is null and returns true
    44 class bool_ref {
    45 public:
    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 
    52 private:
    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
     42/// Implementation of the guard value
     43/// Created inside the visit scope
    6744class guard_value {
    6845public:
     
    10380public:
    10481
    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         {}
     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        }
    11087
    11188        ~visit_children_guard() {
    112                 if( m_ref ) {
    113                         m_ref->set( m_prev );
    114                 }
    115         }
    116 
    117         operator bool() { return m_val; }
     89                if ( m_ref ) { *m_ref = m_val; }
     90        }
    11891
    11992private:
    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
    127 template<typename core_t, typename node_t>
    128 struct 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;
     93        bool * m_ref;
     94        bool   m_val;
    13395};
    13496
     
    227189                // but also contain the new values.
    228190        }
     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
     195template<typename core_t, typename node_t>
     196struct 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;
    229201};
    230202
     
    307279FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
    308280FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
    309 FIELD_PTR( visit_children, __pass::bool_ref )
     281FIELD_PTR( visit_children, bool )
    310282FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
    311283FIELD_PTR( visitor, ast::Pass<core_t> * const )
Note: See TracChangeset for help on using the changeset viewer.