Changeset 96c04e4
- Timestamp:
- May 28, 2024, 11:38:25 AM (6 months ago)
- Branches:
- master
- Children:
- 91b9e10
- Parents:
- 66286aa
- Location:
- src/AST
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.hpp
r66286aa r96c04e4 351 351 }; 352 352 353 template< typename core_t >354 friend auto __pass:: at_cleanup( core_t & core, int ) -> decltype( &core.at_cleanup);353 template< typename core_t > 354 friend auto __pass::make_value_guard( core_t & core, int ) -> decltype( value_guard( core.at_cleanup ) ); 355 355 public: 356 356 -
src/AST/Pass.impl.hpp
r66286aa r96c04e4 27 27 using namespace ast; \ 28 28 /* back-up the last known code location */ \ 29 __attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node, 0 ); \29 __attribute__((unused)) auto guard0 = __pass::make_location_guard( core, node, 0 ); \ 30 30 /* back-up the visit children */ \ 31 __attribute__((unused)) a st::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0)); \31 __attribute__((unused)) auto guard1 = __pass::make_visit_children_guard( core, 0 ); \ 32 32 /* setup the scope for passes that want to run code at exit */ \ 33 __attribute__((unused)) a st::__pass::guard_value guard2( ast::__pass::at_cleanup (core, 0)); \33 __attribute__((unused)) auto guard2 = __pass::make_value_guard( core, 0 ); \ 34 34 /* begin tracing memory allocation if requested by this pass */ \ 35 35 __pass::beginTrace( core, 0 ); \ -
src/AST/Pass.proto.hpp
r66286aa r96c04e4 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 44 class guard_value { 42 /// Replaces guards we don't want to use. 43 struct empty_guard { 44 }; 45 46 /// Implementation of the value guard. Created inside the visit scope. 47 class value_guard { 45 48 public: 46 49 /// Push onto the cleanup 47 guard_value( at_cleanup_t * at_cleanup ) { 48 if( at_cleanup ) { 49 *at_cleanup = [this]( cleanup_func_t && func, void* val ) { 50 push( std::move( func ), val ); 51 }; 52 } 53 } 54 55 ~guard_value() { 50 value_guard( at_cleanup_t & at_cleanup ) { 51 at_cleanup = [this]( cleanup_func_t && func, void* val ) { 52 push( std::move( func ), val ); 53 }; 54 } 55 56 ~value_guard() { 56 57 while( !cleanups.empty() ) { 57 58 auto& cleanup = cleanups.top(); … … 74 75 75 76 std::stack< cleanup_t, std::vector<cleanup_t> > cleanups; 76 };77 78 // Guard structure implementation for whether or not children should be visited79 class visit_children_guard {80 public:81 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 }87 88 ~visit_children_guard() {89 if ( m_ref ) { *m_ref = m_val; }90 }91 92 private:93 bool * m_ref;94 bool m_val;95 77 }; 96 78 … … 280 262 FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > ) 281 263 FIELD_PTR( visit_children, bool ) 282 FIELD_PTR( at_cleanup, __pass::at_cleanup_t )283 264 FIELD_PTR( visitor, ast::Pass<core_t> * const ) 284 265 FIELD_PTR( translationUnit, const TranslationUnit * ) … … 314 295 } 315 296 297 // These are the guards declared at the beginning of a visit. 298 // They are replaced with empty objects when not used. 299 316 300 template< typename core_t, typename node_t > 317 static auto make_location_guard( core_t & core, node_t * node, int )301 static inline auto make_location_guard( core_t & core, node_t * node, int ) 318 302 -> decltype( node->location, ValueGuardPtr<const CodeLocation *>( &core.location ) ) { 319 303 ValueGuardPtr<const CodeLocation *> guard( &core.location ); … … 323 307 324 308 template< typename core_t, typename node_t > 325 static auto make_location_guard( core_t &, node_t *, long ) -> int { 326 return 0; 309 static inline empty_guard make_location_guard( core_t &, node_t *, long ) { 310 return empty_guard(); 311 } 312 313 template< typename core_t > 314 static inline auto make_visit_children_guard( core_t & core, int ) 315 -> decltype( ValueGuardPtr<bool>( &core.visit_children ) ) { 316 ValueGuardPtr<bool> guard( &core.visit_children ); 317 core.visit_children = true; 318 return guard; 319 } 320 321 template< typename core_t > 322 static inline empty_guard make_visit_children_guard( core_t &, long ) { 323 return empty_guard(); 324 } 325 326 template< typename core_t > 327 static inline auto make_value_guard( core_t & core, int ) 328 -> decltype( value_guard( core.at_cleanup ) ) { 329 // Requires guaranteed copy elision: 330 return value_guard( core.at_cleanup ); 331 } 332 333 template< typename core_t > 334 static inline empty_guard make_value_guard( core_t &, long ) { 335 return empty_guard(); 327 336 } 328 337
Note: See TracChangeset
for help on using the changeset viewer.