Changeset effdde0


Ignore:
Timestamp:
Oct 2, 2017, 5:11:51 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
93fe7141
Parents:
d29fa5f
Message:

Convert FindFunction? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/FindFunction.cc

    rd29fa5f reffdde0  
    1818#include <utility>                      // for pair
    1919
     20#include "Common/PassVisitor.h"         // for PassVisitor
    2021#include "Common/SemanticError.h"       // for SemanticError
    2122#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::iterator
     
    2728
    2829namespace GenPoly {
    29         class FindFunction : public Mutator {
     30        class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting {
    3031          public:
    3132                FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );
    3233
    33                 virtual Type *mutate( FunctionType *functionType );
    34                 virtual Type *mutate( PointerType *pointerType );
     34                void premutate( FunctionType * functionType );
     35                Type * postmutate( FunctionType * functionType );
     36                void premutate( PointerType * pointerType );
    3537          private:
    3638                void handleForall( const Type::ForallList &forall );
     
    4345
    4446        void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
    45                 FindFunction finder( functions, tyVars, false, predicate );
     47                PassVisitor<FindFunction> finder( functions, tyVars, false, predicate );
    4648                type->acceptMutator( finder );
    4749        }
    4850
    4951        void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
    50                 FindFunction finder( functions, tyVars, true, predicate );
     52                PassVisitor<FindFunction> finder( functions, tyVars, true, predicate );
    5153                type = type->acceptMutator( finder );
    5254        }
     
    5759
    5860        void FindFunction::handleForall( const Type::ForallList &forall ) {
    59                 for ( Type::ForallList::const_iterator i = forall.begin(); i != forall.end(); ++i ) {
    60                         TyVarMap::iterator var = tyVars.find( (*i)->get_name() );
     61                for ( const Declaration * td : forall ) {
     62                        TyVarMap::iterator var = tyVars.find( td->name );
    6163                        if ( var != tyVars.end() ) {
    6264                                tyVars.erase( var->first );
     
    6567        }
    6668
    67         Type * FindFunction::mutate( FunctionType *functionType ) {
    68                 tyVars.beginScope();
     69        void FindFunction::premutate( FunctionType * functionType ) {
     70                visit_children = false;
     71                GuardScope( tyVars );
    6972                handleForall( functionType->get_forall() );
    70                 mutateAll( functionType->get_returnVals(), *this );
     73                mutateAll( functionType->get_returnVals(), *visitor );
     74        }
     75
     76        Type * FindFunction::postmutate( FunctionType * functionType ) {
    7177                Type *ret = functionType;
    7278                if ( predicate( functionType, tyVars ) ) {
     
    7783                        } // if
    7884                } // if
    79                 tyVars.endScope();
    8085                return ret;
    8186        }
    8287
    83         Type * FindFunction::mutate( PointerType *pointerType ) {
    84                 tyVars.beginScope();
     88        void FindFunction::premutate( PointerType * pointerType ) {
     89                GuardScope( tyVars );
    8590                handleForall( pointerType->get_forall() );
    86                 Type *ret = Mutator::mutate( pointerType );
    87                 tyVars.endScope();
    88                 return ret;
    8991        }
    9092} // namespace GenPoly
Note: See TracChangeset for help on using the changeset viewer.