Changeset 01aeade for translator/GenPoly/FindFunction.cc
- Timestamp:
- May 19, 2015, 7:57:09 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- a08ba92
- Parents:
- 51587aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/GenPoly/FindFunction.cc
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // FindFunction.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:35:48 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: FindFunction.cc,v 1.5 2005/08/29 20:14:13 rcbilson Exp $19 *20 */21 15 22 16 #include "FindFunction.h" … … 26 20 27 21 namespace GenPoly { 22 class FindFunction : public Mutator { 23 public: 24 FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 25 26 virtual Type *mutate( FunctionType *functionType ); 27 virtual Type *mutate( PointerType *pointerType ); 28 private: 29 void handleForall( const std::list< TypeDecl* > &forall ); 28 30 29 class FindFunction : public Mutator 30 { 31 public: 32 FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 33 34 virtual Type *mutate( FunctionType *functionType ); 35 virtual Type *mutate( PointerType *pointerType ); 36 37 private: 38 void handleForall( const std::list< TypeDecl* > &forall ); 31 std::list< FunctionType* > &functions; 32 TyVarMap tyVars; 33 bool replaceMode; 34 FindFunctionPredicate predicate; 35 }; 39 36 40 std::list< FunctionType* > &functions; 41 TyVarMap tyVars; 42 bool replaceMode; 43 FindFunctionPredicate predicate; 44 }; 37 void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 38 FindFunction finder( functions, tyVars, false, predicate ); 39 type->acceptMutator( finder ); 40 } 45 41 46 void 47 findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) 48 { 49 FindFunction finder( functions, tyVars, false, predicate ); 50 type->acceptMutator( finder ); 51 } 42 void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 43 FindFunction finder( functions, tyVars, true, predicate ); 44 type = type->acceptMutator( finder ); 45 } 52 46 53 void 54 findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) 55 { 56 FindFunction finder( functions, tyVars, true, predicate ); 57 type = type->acceptMutator( finder ); 58 } 47 FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ) 48 : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) { 49 } 59 50 60 FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ) 61 : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) 62 { 63 } 51 void FindFunction::handleForall( const std::list< TypeDecl* > &forall ) { 52 for ( std::list< TypeDecl* >::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 53 TyVarMap::iterator var = tyVars.find( (*i)->get_name() ); 54 if ( var != tyVars.end() ) { 55 tyVars.erase( var ); 56 } // if 57 } // for 58 } 64 59 65 void 66 FindFunction::handleForall( const std::list< TypeDecl* > &forall ) 67 { 68 for ( std::list< TypeDecl* >::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 69 TyVarMap::iterator var = tyVars.find( (*i)->get_name() ); 70 if ( var != tyVars.end() ) { 71 tyVars.erase( var ); 72 } 73 } 74 } 60 Type * FindFunction::mutate( FunctionType *functionType ) { 61 TyVarMap oldTyVars = tyVars; 62 handleForall( functionType->get_forall() ); 63 mutateAll( functionType->get_returnVals(), *this ); 64 Type *ret = functionType; 65 if ( predicate( functionType, tyVars ) ) { 66 functions.push_back( functionType ); 67 if ( replaceMode ) { 68 ret = new FunctionType( Type::Qualifiers(), true ); 69 } // if 70 } // if 71 tyVars = oldTyVars; 72 return ret; 73 } 75 74 76 Type* 77 FindFunction::mutate( FunctionType *functionType ) 78 { 79 TyVarMap oldTyVars = tyVars; 80 handleForall( functionType->get_forall() ); 81 mutateAll( functionType->get_returnVals(), *this ); 82 Type *ret = functionType; 83 if ( predicate( functionType, tyVars ) ) { 84 functions.push_back( functionType ); 85 if ( replaceMode ) { 86 ret = new FunctionType( Type::Qualifiers(), true ); 87 } 88 } 89 tyVars = oldTyVars; 90 return ret; 91 } 75 Type * FindFunction::mutate( PointerType *pointerType ) { 76 TyVarMap oldTyVars = tyVars; 77 handleForall( pointerType->get_forall() ); 78 Type *ret = Mutator::mutate( pointerType ); 79 tyVars = oldTyVars; 80 return ret; 81 } 82 } // namespace GenPoly 92 83 93 Type *94 FindFunction::mutate( PointerType *pointerType )95 {96 TyVarMap oldTyVars = tyVars;97 handleForall( pointerType->get_forall() );98 Type *ret = Mutator::mutate( pointerType );99 tyVars = oldTyVars;100 return ret;101 }102 103 } // namespace GenPoly104 84 // Local Variables: // 105 85 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.