Changes in src/GenPoly/FindFunction.cc [c6b4432:c97b448]
- File:
-
- 1 edited
-
src/GenPoly/FindFunction.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/FindFunction.cc
rc6b4432 rc97b448 20 20 #include "AST/Pass.hpp" // for Pass 21 21 #include "AST/Type.hpp" 22 #include "Common/PassVisitor.h" // for PassVisitor 22 23 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::iterator 23 24 #include "GenPoly/GenPoly.h" // for TyVarMap 24 25 #include "ScrubTyVars.h" // for ScrubTyVars 26 #include "SynTree/Declaration.h" // for DeclarationWithType, TypeDecl 27 #include "SynTree/Mutator.h" // for Mutator, mutateAll 28 #include "SynTree/Type.h" // for FunctionType, Type, Type::For... 25 29 26 30 namespace GenPoly { 31 class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting { 32 public: 33 FindFunction( std::list< FunctionType const* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 34 35 void premutate( FunctionType * functionType ); 36 Type * postmutate( FunctionType * functionType ); 37 void premutate( PointerType * pointerType ); 38 private: 39 void handleForall( const Type::ForallList &forall ); 40 41 std::list< FunctionType const * > & functions; 42 TyVarMap tyVars; 43 bool replaceMode; 44 FindFunctionPredicate predicate; 45 }; 46 47 void findFunction( Type *type, std::list< FunctionType const * > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 48 PassVisitor<FindFunction> finder( functions, tyVars, false, predicate ); 49 type->acceptMutator( finder ); 50 } 51 52 void findAndReplaceFunction( Type *&type, std::list< FunctionType const * > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 53 PassVisitor<FindFunction> finder( functions, tyVars, true, predicate ); 54 type = type->acceptMutator( finder ); 55 } 56 57 FindFunction::FindFunction( std::list< FunctionType const * > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ) 58 : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) { 59 } 60 61 void FindFunction::handleForall( const Type::ForallList &forall ) { 62 for ( const Declaration * td : forall ) { 63 TyVarMap::iterator var = tyVars.find( td->name ); 64 if ( var != tyVars.end() ) { 65 tyVars.erase( var->first ); 66 } // if 67 } // for 68 } 69 70 void FindFunction::premutate( FunctionType * functionType ) { 71 visit_children = false; 72 GuardScope( tyVars ); 73 handleForall( functionType->get_forall() ); 74 mutateAll( functionType->get_returnVals(), *visitor ); 75 } 76 77 Type * FindFunction::postmutate( FunctionType * functionType ) { 78 Type *ret = functionType; 79 if ( predicate( functionType, tyVars ) ) { 80 functions.push_back( functionType ); 81 if ( replaceMode ) { 82 // replace type parameters in function type with void* 83 ret = ScrubTyVars::scrub( functionType->clone(), tyVars ); 84 } // if 85 } // if 86 return ret; 87 } 88 89 void FindFunction::premutate( PointerType * pointerType ) { 90 GuardScope( tyVars ); 91 handleForall( pointerType->get_forall() ); 92 } 27 93 28 94 namespace { … … 88 154 void FindFunctionCore::previsit( ast::PointerType const * /*type*/ ) { 89 155 GuardScope( typeVars ); 156 //handleForall( type->forall ); 90 157 } 91 158 … … 97 164 ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, false ); 98 165 type->accept( pass ); 166 //(void)type; 167 //(void)functions; 168 //(void)typeVars; 169 //(void)predicate; 99 170 } 100 171 … … 104 175 ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, true ); 105 176 return type->accept( pass ); 177 //(void)functions; 178 //(void)typeVars; 179 //(void)predicate; 180 //return type; 106 181 } 107 182
Note:
See TracChangeset
for help on using the changeset viewer.