source: src/GenPoly/ScrubTyVars.h @ 5a3ac84

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 5a3ac84 was 5a3ac84, checked in by Aaron Moss <a3moss@…>, 6 years ago

Fixed Box(T*) generic instantiation bug

  • Property mode set to 100644
File size: 3.6 KB
Line 
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
26namespace GenPoly {
27        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 };
30
31                ScrubTyVars() : tyVars(nullptr), mode( All ) {}
32
33                ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {}
34
35        public:
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
38                template< typename SynTreeClass >
39                static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
40
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
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
51                virtual Type* mutate( TypeInstType *typeInst );
52                virtual Type* mutate( StructInstType *structInst );
53                virtual Type* mutate( UnionInstType *unionInst );
54                virtual Expression* mutate( SizeofExpr *szeof );
55                virtual Expression* mutate( AlignofExpr *algnof );
56                virtual Type* mutate( PointerType *pointer );
57
58          private:
59                /// Returns the type if it should be scrubbed, NULL otherwise.
60                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 );
68                }
69               
70                /// Mutates (possibly generic) aggregate types appropriately
71                Type* mutateAggregateType( Type *ty );
72               
73                const TyVarMap *tyVars;  ///< Type variables to scrub
74                ScrubMode mode;          ///< which type variables to scrub? [FromMap]
75        };
76
77        template< typename SynTreeClass >
78        SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) {
79                ScrubTyVars scrubber( tyVars );
80                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
81        }
82
83        template< typename SynTreeClass >
84        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;
92                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
93        }
94
95} // namespace GenPoly
96
97#endif // _SCRUBTYVARS_H
98
99// Local Variables: //
100// tab-width: 4 //
101// mode: c++ //
102// compile-command: "make install" //
103// End: //
Note: See TracBrowser for help on using the repository browser.