Ignore:
Timestamp:
May 19, 2015, 7:57:09 AM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

licencing: fifth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/GenPoly/FindFunction.cc

    r51587aa r01aeade  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// FindFunction.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 07:35:48 2015
     13// Update Count     : 1
    1414//
    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  */
    2115
    2216#include "FindFunction.h"
     
    2620
    2721namespace 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 );
    2830
    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        };
    3936
    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        }
    4541
    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        }
    5246
    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        }
    5950
    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        }
    6459
    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        }
    7574
    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
    9283
    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 GenPoly
    10484// Local Variables: //
    10585// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.