Changeset b73bd70
- Timestamp:
- Jun 22, 2017, 1:13:26 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 186b398
- Parents:
- 65dc863
- Location:
- src/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r65dc863 rb73bd70 37 37 PassVisitor(Args &&... args) 38 38 : pass( std::forward<Args>( args )... ) 39 {} 39 { 40 typedef PassVisitor<pass_type> this_t; 41 this_t * const * visitor = visitor_impl(pass, 0); 42 if(visitor) { 43 *const_cast<this_t **>( visitor ) = this; 44 } 45 } 40 46 41 47 virtual ~PassVisitor() = default; … … 240 246 std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); } 241 247 std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } 242 bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); } 243 void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }248 249 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 244 250 245 251 guard_value_impl init_guard() { … … 280 286 std::list< Statement* > stmtsToAddAfter; 281 287 }; 282 283 288 class WithShortCircuiting { 284 289 protected: … … 287 292 288 293 public: 289 bool skip_children;294 bool_ref visit_children; 290 295 }; 291 296 … … 306 311 }; 307 312 313 template<typename pass_type> 314 class WithVisitorRef { 315 protected: 316 WithVisitorRef() = default; 317 ~WithVisitorRef() = default; 318 319 public: 320 PassVisitor<pass_type> * const visitor; 321 }; 308 322 309 323 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
r65dc863 rb73bd70 4 4 __attribute__((unused)) \ 5 5 const auto & guard = init_guard(); \ 6 bool visit_children = true; \ 7 set_visit_children( visit_children ); \ 6 8 call_previsit( node ); \ 7 if( visit_children () ) {\9 if( visit_children ) { \ 8 10 9 11 #define VISIT_END( node ) \ 10 12 } \ 11 reset_visit(); \12 13 call_postvisit( node ); \ 13 14 … … 15 16 __attribute__((unused)) \ 16 17 const auto & guard = init_guard(); \ 18 bool visit_children = true; \ 19 set_visit_children( visit_children ); \ 17 20 call_premutate( node ); \ 18 if( visit_children () ) {\21 if( visit_children ) { \ 19 22 20 23 #define MUTATE_END( type, node ) \ 21 24 } \ 22 reset_visit(); \23 25 return call_postmutate< type * >( node ); \ 24 26 -
src/Common/PassVisitor.proto.h
r65dc863 rb73bd70 1 1 #pragma once 2 3 template<typename pass_type> 4 class PassVisitor; 2 5 3 6 typedef std::function<void( void * )> cleanup_func_t; … … 31 34 32 35 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t; 36 37 class bool_ref { 38 public: 39 bool_ref() = default; 40 ~bool_ref() = default; 41 42 operator bool() { return *m_ref; } 43 bool operator=( bool val ) { return *m_ref = val; } 44 45 private: 46 47 template<typename pass> 48 friend class PassVisitor; 49 50 void set( bool & val ) { m_ref = &val; }; 51 52 bool * m_ref; 53 }; 33 54 34 55 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 114 135 FIELD_PTR( std::list< Declaration* >, declsToAddBefore ) 115 136 FIELD_PTR( std::list< Declaration* >, declsToAddAfter ) 116 FIELD_PTR( bool , skip_children )137 FIELD_PTR( bool_ref, visit_children ) 117 138 FIELD_PTR( at_cleanup_t, at_cleanup ) 139 FIELD_PTR( PassVisitor<pass_type> * const, visitor )
Note: See TracChangeset
for help on using the changeset viewer.