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