Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScrubTyVars.h

    r5a3ac84 r3bb195cb  
    2626namespace GenPoly {
    2727        class ScrubTyVars : public Mutator {
    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 };
     28          public:
     29                ScrubTyVars( const TyVarMap &tyVars, bool dynamicOnly = false ): tyVars( tyVars ), dynamicOnly( dynamicOnly ) {}
    3030
    31                 ScrubTyVars() : tyVars(nullptr), mode( All ) {}
    32 
    33                 ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {}
    34 
    35         public:
    3631                /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
    3732                /// and sizeof/alignof expressions with the proper variable
     
    4338                template< typename SynTreeClass >
    4439                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 );
    5040
    5141                virtual Type* mutate( TypeInstType *typeInst );
     
    5949                /// Returns the type if it should be scrubbed, NULL otherwise.
    6050                Type* shouldScrub( Type *ty ) {
    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 );
     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 );
    6859                }
    6960               
     
    7162                Type* mutateAggregateType( Type *ty );
    7263               
    73                 const TyVarMap *tyVars;  ///< Type variables to scrub
    74                 ScrubMode mode;          ///< which type variables to scrub? [FromMap]
     64                const TyVarMap &tyVars;  ///< Type variables to scrub
     65                bool dynamicOnly;        ///< only scrub the types with dynamic layout? [false]
    7566        };
    7667
     
    8374        template< typename SynTreeClass >
    8475        SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) {
    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;
     76                ScrubTyVars scrubber( tyVars, true );
    9277                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
    9378        }
Note: See TracChangeset for help on using the changeset viewer.