source: translator/GenPoly/FindFunction.cc @ b8508a2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since b8508a2 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: FindFunction.cc,v 1.5 2005/08/29 20:14:13 rcbilson Exp $
5 *
6 */
7
8#include "FindFunction.h"
9#include "SynTree/Type.h"
10#include "SynTree/Declaration.h"
11#include "SynTree/Visitor.h"
12
13namespace GenPoly {
14
15class FindFunction : public Mutator
16{
17public:
18  FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );
19 
20  virtual Type *mutate( FunctionType *functionType );
21  virtual Type *mutate( PointerType *pointerType );
22 
23private:
24  void handleForall( const std::list< TypeDecl* > &forall );
25
26  std::list< FunctionType* > &functions;
27  TyVarMap tyVars;
28  bool replaceMode;
29  FindFunctionPredicate predicate;
30};
31
32void
33findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate )
34{
35  FindFunction finder( functions, tyVars, false, predicate );
36  type->acceptMutator( finder );
37}
38
39void
40findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate )
41{
42  FindFunction finder( functions, tyVars, true, predicate );
43  type = type->acceptMutator( finder );
44}
45
46FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )
47  : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate )
48{
49}
50
51void
52FindFunction::handleForall( const std::list< TypeDecl* > &forall )
53{
54  for( std::list< TypeDecl* >::const_iterator i = forall.begin(); i != forall.end(); ++i ) {
55    TyVarMap::iterator var = tyVars.find( (*i)->get_name() );
56    if( var != tyVars.end() ) {
57      tyVars.erase( var );
58    }
59  }
60}
61
62Type* 
63FindFunction::mutate( FunctionType *functionType )
64{
65  TyVarMap oldTyVars = tyVars;
66  handleForall( functionType->get_forall() );
67  mutateAll( functionType->get_returnVals(), *this );
68  Type *ret = functionType;
69  if( predicate( functionType, tyVars ) ) {
70    functions.push_back( functionType );
71    if( replaceMode ) {
72      ret = new FunctionType( Type::Qualifiers(), true );
73    }
74  }
75  tyVars = oldTyVars;
76  return ret;
77}
78
79Type *
80FindFunction::mutate( PointerType *pointerType )
81{
82  TyVarMap oldTyVars = tyVars;
83  handleForall( pointerType->get_forall() );
84  Type *ret = Mutator::mutate( pointerType );
85  tyVars = oldTyVars;
86  return ret;
87}
88
89} // namespace GenPoly
Note: See TracBrowser for help on using the repository browser.