Ignore:
Timestamp:
Nov 8, 2017, 5:43:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
954908d
Parents:
78315272 (diff), e35f30a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.proto.h

    r78315272 r3f7e12cb  
    4646        ~bool_ref() = default;
    4747
    48         operator bool() { return *m_ref; }
     48        operator bool() { return m_ref ? *m_ref : true; }
    4949        bool operator=( bool val ) { return *m_ref = val; }
    5050
    5151private:
    5252
    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;
    5962};
    6063
    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 }
     64class ChildrenGuard {
     65public:
     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
     81private:
     82        bool       m_val;
     83        bool     * m_prev;
     84        bool_ref * m_ref;
     85};
    8386
    8487//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.