Ignore:
Timestamp:
Jun 23, 2017, 10:12:09 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
2ac095d
Parents:
1c273d0 (diff), 653f2c7 (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.h

    r1c273d0 rd43cd01  
    2525// | WithStmtsToAdd       - provides the ability to insert statements before or after the current statement by adding new statements into
    2626//                          stmtsToAddBefore or stmtsToAddAfter respectively.
    27 // | WithShortCircuiting  - provides the ability to skip visiting child nodes; set skip_children to true if pre{visit,mutate} to skip visiting children
     27// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
    2828// | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    2929//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
     
    3737        PassVisitor(Args &&... args)
    3838                : 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        }
    4046
    4147        virtual ~PassVisitor() = default;
     
    214220
    215221private:
     222        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     223        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     224
    216225        template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
    217226        template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
     
    225234        void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); }
    226235
    227         void visitStatementList( std::list< Statement* > &statements );
     236        template< typename func_t >
     237        void handleStatementList( std::list< Statement * > & statements, func_t func );
     238        void visitStatementList ( std::list< Statement* > &statements );
    228239        void mutateStatementList( std::list< Statement* > &statements );
    229240
    230         Statement * visitStatement( Statement * stmt );
     241        template< typename func_t >
     242        Statement * handleStatement( Statement * stmt, func_t func );
     243        Statement * visitStatement ( Statement * stmt );
    231244        Statement * mutateStatement( Statement * stmt );
    232245
    233         void visitExpression( Expression * expr );
     246        template< typename func_t >
     247        Expression * handleExpression( Expression * expr, func_t func );
     248        Expression * visitExpression ( Expression * expr );
    234249        Expression * mutateExpression( Expression * expr );
    235250
     
    238253        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    239254        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
    240         bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
    241         void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }
     255        std::list< Declaration* > *     get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
     256        std::list< Declaration* > *     get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
     257
     258        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
    242259
    243260        guard_value_impl init_guard() {
     
    278295        std::list< Statement* > stmtsToAddAfter;
    279296};
    280 
    281297class WithShortCircuiting {
    282298protected:
     
    285301
    286302public:
    287         bool skip_children;
     303        bool_ref visit_children;
    288304};
    289305
     
    304320};
    305321
     322template<typename pass_type>
     323class WithVisitorRef {
     324protected:
     325        WithVisitorRef() = default;
     326        ~WithVisitorRef() = default;
     327
     328public:
     329        PassVisitor<pass_type> * const visitor;
     330};
    306331
    307332#include "PassVisitor.impl.h"
Note: See TracChangeset for help on using the changeset viewer.