Changeset 3c398b6 for src/Common/PassVisitor.proto.h
- Timestamp:
- Oct 3, 2017, 2:27:21 PM (5 years ago)
- Branches:
- aaron-thesis, arm-eh, 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:
- e1ff775
- Parents:
- 617b4b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.proto.h
r617b4b2 r3c398b6 46 46 ~bool_ref() = default; 47 47 48 operator bool() { return *m_ref; }48 operator bool() { return m_ref ? *m_ref : true; } 49 49 bool operator=( bool val ) { return *m_ref = val; } 50 50 51 51 private: 52 52 53 template<typename pass> 54 friend class PassVisitor; 55 56 void set( bool & val ) { m_ref = &val; }; 57 58 bool * m_ref; 53 friend class ChildrenGuard; 54 55 bool * set( bool & val ) { 56 bool * prev = m_ref; 57 m_ref = &val; 58 return prev; 59 } 60 61 bool * m_ref = nullptr; 59 62 }; 60 63 61 template< typename TreeType, typename VisitorType > 62 inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) { 63 auto guard = makeFuncGuard( 64 [&visitor]() { visitor.indexerScopeEnter(); },65 [&visitor]() { visitor.indexerScopeLeave(); }66 );67 maybeAccept( tree, visitor );68 }69 70 template< typename TreeType, typename MutatorType > 71 inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator) {72 auto guard = makeFuncGuard(73 [&mutator]() { mutator.indexerScopeEnter(); },74 [&mutator]() { mutator.indexerScopeLeave();}75 ); 76 tree = maybeMutate( tree, mutator );77 } 78 79 template< typename TreeType, typename MutatorType > 80 inline void maybeMutateRef( TreeType *& tree, MutatorType & mutator ) { 81 tree = maybeMutate( tree, mutator );82 } 64 class ChildrenGuard { 65 public: 66 67 ChildrenGuard( bool_ref * ref ) 68 : m_val ( true ) 69 , m_prev( ref ? ref->set( m_val ) : nullptr ) 70 , m_ref ( ref ) 71 {} 72 73 ~ChildrenGuard() { 74 if( m_ref ) { 75 m_ref->set( *m_prev ); 76 } 77 } 78 79 operator bool() { return m_val; } 80 81 private: 82 bool m_val; 83 bool * m_prev; 84 bool_ref * m_ref; 85 }; 83 86 84 87 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.