Changeset 5a3ac84 for src/GenPoly/ScrubTyVars.h
- Timestamp:
- Mar 15, 2017, 5:01:18 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9b443c7f
- Parents:
- 17df48e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScrubTyVars.h
r17df48e r5a3ac84 26 26 namespace GenPoly { 27 27 class ScrubTyVars : public Mutator { 28 public:29 ScrubTyVars( const TyVarMap &tyVars, bool dynamicOnly = false ): tyVars( tyVars ), dynamicOnly( dynamicOnly ) {}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 }; 30 30 31 ScrubTyVars() : tyVars(nullptr), mode( All ) {} 32 33 ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {} 34 35 public: 31 36 /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type, 32 37 /// and sizeof/alignof expressions with the proper variable … … 38 43 template< typename SynTreeClass > 39 44 static SynTreeClass *scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ); 45 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 ); 40 50 41 51 virtual Type* mutate( TypeInstType *typeInst ); … … 49 59 /// Returns the type if it should be scrubbed, NULL otherwise. 50 60 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 ); 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 ); 59 68 } 60 69 … … 62 71 Type* mutateAggregateType( Type *ty ); 63 72 64 const TyVarMap &tyVars; ///< Type variables to scrub65 bool dynamicOnly; ///< only scrub the types with dynamic layout? [false]73 const TyVarMap *tyVars; ///< Type variables to scrub 74 ScrubMode mode; ///< which type variables to scrub? [FromMap] 66 75 }; 67 76 … … 74 83 template< typename SynTreeClass > 75 84 SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) { 76 ScrubTyVars scrubber( tyVars, true ); 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; 77 92 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 78 93 }
Note: See TracChangeset
for help on using the changeset viewer.