source: translator/GenPoly/FindFunction.cc @ 51587aa

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 2.9 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// XXX.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count     : 0
14//
15/*
16 * This file is part of the Cforall project
17 *
18 * $Id: FindFunction.cc,v 1.5 2005/08/29 20:14:13 rcbilson Exp $
19 *
20 */
21
22#include "FindFunction.h"
23#include "SynTree/Type.h"
24#include "SynTree/Declaration.h"
25#include "SynTree/Visitor.h"
26
27namespace GenPoly {
28
29class FindFunction : public Mutator
30{
31public:
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 
37private:
38  void handleForall( const std::list< TypeDecl* > &forall );
39
40  std::list< FunctionType* > &functions;
41  TyVarMap tyVars;
42  bool replaceMode;
43  FindFunctionPredicate predicate;
44};
45
46void
47findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate )
48{
49  FindFunction finder( functions, tyVars, false, predicate );
50  type->acceptMutator( finder );
51}
52
53void
54findAndReplaceFunction( 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}
59
60FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )
61  : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate )
62{
63}
64
65void
66FindFunction::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}
75
76Type* 
77FindFunction::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}
92
93Type *
94FindFunction::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 GenPoly
104// Local Variables: //
105// tab-width: 4 //
106// mode: c++ //
107// compile-command: "make install" //
108// End: //
Note: See TracBrowser for help on using the repository browser.