source: src/GenPoly/FindFunction.cc @ 7e17503

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 7e17503 was 8c49c0e, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

decouple code that uses Type's forall list from std::list in preparation for trying to replace with a managed list

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[51587aa]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//
[b4cd03b7]7// FindFunction.cc --
[51587aa]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[b4cd03b7]11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri Feb 05 12:22:20 2016
13// Update Count     : 6
[51587aa]14//
[51b7345]15
16#include "FindFunction.h"
17#include "SynTree/Type.h"
18#include "SynTree/Declaration.h"
19#include "SynTree/Visitor.h"
20
[b4cd03b7]21#include "ScrubTyVars.h"
22
[51b7345]23namespace GenPoly {
[01aeade]24        class FindFunction : public Mutator {
25          public:
26                FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );
[b4cd03b7]27
[01aeade]28                virtual Type *mutate( FunctionType *functionType );
29                virtual Type *mutate( PointerType *pointerType );
30          private:
[8c49c0e]31                void handleForall( const Type::ForallList &forall );
[51b7345]32
[01aeade]33                std::list< FunctionType* > &functions;
34                TyVarMap tyVars;
35                bool replaceMode;
36                FindFunctionPredicate predicate;
37        };
[51b7345]38
[01aeade]39        void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
40                FindFunction finder( functions, tyVars, false, predicate );
41                type->acceptMutator( finder );
42        }
[51b7345]43
[01aeade]44        void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
45                FindFunction finder( functions, tyVars, true, predicate );
46                type = type->acceptMutator( finder );
47        }
[51b7345]48
[01aeade]49        FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )
50                : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) {
51        }
[51b7345]52
[8c49c0e]53        void FindFunction::handleForall( const Type::ForallList &forall ) {
54                for ( Type::ForallList::const_iterator i = forall.begin(); i != forall.end(); ++i ) {
[01aeade]55                        TyVarMap::iterator var = tyVars.find( (*i)->get_name() );
56                        if ( var != tyVars.end() ) {
[bfae637]57                                tyVars.erase( var->first );
[01aeade]58                        } // if
59                } // for
60        }
[51b7345]61
[01aeade]62        Type * FindFunction::mutate( FunctionType *functionType ) {
[6f49cdf]63                tyVars.beginScope();
[01aeade]64                handleForall( functionType->get_forall() );
65                mutateAll( functionType->get_returnVals(), *this );
66                Type *ret = functionType;
67                if ( predicate( functionType, tyVars ) ) {
68                        functions.push_back( functionType );
69                        if ( replaceMode ) {
[b4cd03b7]70                                // replace type parameters in function type with void*
71                                ret = ScrubTyVars::scrub( functionType->clone(), tyVars );
[01aeade]72                        } // if
73                } // if
[6f49cdf]74                tyVars.endScope();
[01aeade]75                return ret;
76        }
[51b7345]77
[01aeade]78        Type * FindFunction::mutate( PointerType *pointerType ) {
[6f49cdf]79                tyVars.beginScope();
[01aeade]80                handleForall( pointerType->get_forall() );
81                Type *ret = Mutator::mutate( pointerType );
[6f49cdf]82                tyVars.endScope();
[01aeade]83                return ret;
84        }
[51b7345]85} // namespace GenPoly
[01aeade]86
[51587aa]87// Local Variables: //
88// tab-width: 4 //
89// mode: c++ //
90// compile-command: "make install" //
91// End: //
Note: See TracBrowser for help on using the repository browser.