Changes in src/AST/Pass.proto.hpp [164a6b6:7a36848]
- File:
-
- 1 edited
-
src/AST/Pass.proto.hpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.proto.hpp
r164a6b6 r7a36848 40 40 typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t; 41 41 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 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 44 67 class guard_value { 45 68 public: … … 80 103 public: 81 104 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 {} 87 110 88 111 ~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; } 91 118 92 119 private: 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 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; 95 133 }; 96 134 … … 189 227 // but also contain the new values. 190 228 } 191 };192 193 /// "Short hand" to check if this is a valid previsit function194 /// Mostly used to make the static_assert look (and print) prettier195 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;201 229 }; 202 230 … … 279 307 FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > ) 280 308 FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > ) 281 FIELD_PTR( visit_children, bool)309 FIELD_PTR( visit_children, __pass::bool_ref ) 282 310 FIELD_PTR( at_cleanup, __pass::at_cleanup_t ) 283 311 FIELD_PTR( visitor, ast::Pass<core_t> * const )
Note:
See TracChangeset
for help on using the changeset viewer.