| 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 | // ScrubTyVars.h -- 
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Tue May 19 07:48:14 2015
 | 
|---|
| 13 | // Update Count     : 1
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #ifndef _SCRUBTYVARS_H
 | 
|---|
| 17 | #define _SCRUBTYVARS_H
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <string>
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "GenPoly.h"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "SynTree/SynTree.h"
 | 
|---|
| 24 | #include "SynTree/Mutator.h"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | namespace GenPoly {
 | 
|---|
| 27 |         class ScrubTyVars : public Mutator {
 | 
|---|
| 28 |           public:
 | 
|---|
| 29 |                 ScrubTyVars( const TyVarMap &tyVars, bool dynamicOnly = false ): tyVars( tyVars ), dynamicOnly( dynamicOnly ) {}
 | 
|---|
| 30 | 
 | 
|---|
| 31 |                 /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
 | 
|---|
| 32 |                 /// and sizeof/alignof expressions with the proper variable
 | 
|---|
| 33 |                 template< typename SynTreeClass >
 | 
|---|
| 34 |                 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
 | 
|---|
| 35 | 
 | 
|---|
| 36 |                 /// For all dynamic-layout types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
 | 
|---|
| 37 |                 /// and sizeof/alignof expressions with the proper variable
 | 
|---|
| 38 |                 template< typename SynTreeClass >
 | 
|---|
| 39 |                 static SynTreeClass *scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars );
 | 
|---|
| 40 | 
 | 
|---|
| 41 |                 virtual Type* mutate( TypeInstType *typeInst );
 | 
|---|
| 42 |                 virtual Type* mutate( StructInstType *structInst );
 | 
|---|
| 43 |                 virtual Type* mutate( UnionInstType *unionInst );
 | 
|---|
| 44 |                 virtual Expression* mutate( SizeofExpr *szeof );
 | 
|---|
| 45 |                 virtual Expression* mutate( AlignofExpr *algnof );
 | 
|---|
| 46 |                 virtual Type* mutate( PointerType *pointer );
 | 
|---|
| 47 | 
 | 
|---|
| 48 |           private:
 | 
|---|
| 49 |                 /// Returns the type if it should be scrubbed, NULL otherwise.
 | 
|---|
| 50 |                 Type* shouldScrub( Type *ty ) {
 | 
|---|
| 51 |                         return dynamicOnly ? isDynType( ty, tyVars ) : isPolyType( ty, tyVars );
 | 
|---|
| 52 | //                      if ( ! dynamicOnly ) return isPolyType( ty, tyVars );
 | 
|---|
| 53 | // 
 | 
|---|
| 54 | //                      if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) {
 | 
|---|
| 55 | //                              return tyVars.find( typeInst->get_name() ) != tyVars.end() ? ty : 0;
 | 
|---|
| 56 | //                      }
 | 
|---|
| 57 | // 
 | 
|---|
| 58 | //                      return isDynType( ty, tyVars );
 | 
|---|
| 59 |                 }
 | 
|---|
| 60 |                 
 | 
|---|
| 61 |                 /// Mutates (possibly generic) aggregate types appropriately
 | 
|---|
| 62 |                 Type* mutateAggregateType( Type *ty );
 | 
|---|
| 63 |                 
 | 
|---|
| 64 |                 const TyVarMap &tyVars;  ///< Type variables to scrub
 | 
|---|
| 65 |                 bool dynamicOnly;        ///< only scrub the types with dynamic layout? [false]
 | 
|---|
| 66 |         };
 | 
|---|
| 67 | 
 | 
|---|
| 68 |         template< typename SynTreeClass >
 | 
|---|
| 69 |         SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) {
 | 
|---|
| 70 |                 ScrubTyVars scrubber( tyVars );
 | 
|---|
| 71 |                 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
 | 
|---|
| 72 |         }
 | 
|---|
| 73 | 
 | 
|---|
| 74 |         template< typename SynTreeClass >
 | 
|---|
| 75 |         SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) {
 | 
|---|
| 76 |                 ScrubTyVars scrubber( tyVars, true );
 | 
|---|
| 77 |                 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
 | 
|---|
| 78 |         }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | } // namespace GenPoly
 | 
|---|
| 81 | 
 | 
|---|
| 82 | #endif // _SCRUBTYVARS_H
 | 
|---|
| 83 | 
 | 
|---|
| 84 | // Local Variables: //
 | 
|---|
| 85 | // tab-width: 4 //
 | 
|---|
| 86 | // mode: c++ //
 | 
|---|
| 87 | // compile-command: "make install" //
 | 
|---|
| 88 | // End: //
 | 
|---|