Ignore:
Timestamp:
Mar 15, 2017, 5:01:18 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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
Message:

Fixed Box(T*) generic instantiation bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScrubTyVars.h

    r17df48e r5a3ac84  
    2626namespace GenPoly {
    2727        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 };
    3030
     31                ScrubTyVars() : tyVars(nullptr), mode( All ) {}
     32
     33                ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {}
     34
     35        public:
    3136                /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
    3237                /// and sizeof/alignof expressions with the proper variable
     
    3843                template< typename SynTreeClass >
    3944                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 );
    4050
    4151                virtual Type* mutate( TypeInstType *typeInst );
     
    4959                /// Returns the type if it should be scrubbed, NULL otherwise.
    5060                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 );
    5968                }
    6069               
     
    6271                Type* mutateAggregateType( Type *ty );
    6372               
    64                 const TyVarMap &tyVars;  ///< Type variables to scrub
    65                 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]
    6675        };
    6776
     
    7483        template< typename SynTreeClass >
    7584        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;
    7792                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
    7893        }
Note: See TracChangeset for help on using the changeset viewer.