Changeset 164a6b6
- Timestamp:
- May 6, 2024, 9:09:07 AM (7 months ago)
- Branches:
- master
- Children:
- 69dd8e6, c333ed2
- Parents:
- d69f7114
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.hpp
rd69f7114 r164a6b6 233 233 private: 234 234 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; } 236 236 237 237 private: … … 342 342 /// set visit_children false of all child nodes should be ignored 343 343 struct WithShortCircuiting { 344 __pass::bool_refvisit_children;344 bool visit_children; 345 345 }; 346 346 -
src/AST/Pass.proto.hpp
rd69f7114 r164a6b6 40 40 typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t; 41 41 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 67 44 class guard_value { 68 45 public: … … 103 80 public: 104 81 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 } 110 87 111 88 ~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 } 118 91 119 92 private: 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; 133 95 }; 134 96 … … 227 189 // but also contain the new values. 228 190 } 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; 229 201 }; 230 202 … … 307 279 FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > ) 308 280 FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > ) 309 FIELD_PTR( visit_children, __pass::bool_ref)281 FIELD_PTR( visit_children, bool ) 310 282 FIELD_PTR( at_cleanup, __pass::at_cleanup_t ) 311 283 FIELD_PTR( visitor, ast::Pass<core_t> * const )
Note: See TracChangeset
for help on using the changeset viewer.