source: src/GenPoly/ScrubTyVars.h @ ea91c42

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ea91c42 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change #ifndef to #pragma once

  • 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 : Sat Jul 22 09:21:47 2017
13// Update Count     : 2
14//
15
16#pragma once
17
18#include <string>
19
20#include "GenPoly.h"
21
22#include "SynTree/SynTree.h"
23#include "SynTree/Mutator.h"
24
25namespace GenPoly {
26        class ScrubTyVars : public Mutator {
27                /// Whether to scrub all type variables from the provided map, dynamic type variables from the provided map, or all type variables
28                enum ScrubMode { FromMap, DynamicFromMap, All };
29
30                ScrubTyVars() : tyVars(nullptr), mode( All ) {}
31
32                ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {}
33
34        public:
35                /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
36                /// and sizeof/alignof expressions with the proper variable
37                template< typename SynTreeClass >
38                static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
39
40                /// For all dynamic-layout types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
41                /// and sizeof/alignof expressions with the proper variable
42                template< typename SynTreeClass >
43                static SynTreeClass *scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars );
44
45                /// For all polymorphic types, replaces generic types, dtypes, and ftypes with the appropriate void type,
46                /// and sizeof/alignof expressions with the proper variable
47                template< typename SynTreeClass >
48                static SynTreeClass *scrubAll( SynTreeClass *target );
49
50                virtual Type* mutate( TypeInstType *typeInst );
51                virtual Type* mutate( StructInstType *structInst );
52                virtual Type* mutate( UnionInstType *unionInst );
53                virtual Expression* mutate( SizeofExpr *szeof );
54                virtual Expression* mutate( AlignofExpr *algnof );
55                virtual Type* mutate( PointerType *pointer );
56
57          private:
58                /// Returns the type if it should be scrubbed, NULL otherwise.
59                Type* shouldScrub( Type *ty ) {
60                        switch ( mode ) {
61                        case FromMap: return isPolyType( ty, *tyVars );
62                        case DynamicFromMap: return isDynType( ty, *tyVars );
63                        case All: return isPolyType( ty );
64                        }
65                        assert(false); return nullptr; // unreachable
66                        // return dynamicOnly ? isDynType( ty, tyVars ) : isPolyType( ty, tyVars );
67                }
68               
69                /// Mutates (possibly generic) aggregate types appropriately
70                Type* mutateAggregateType( Type *ty );
71               
72                const TyVarMap *tyVars;  ///< Type variables to scrub
73                ScrubMode mode;          ///< which type variables to scrub? [FromMap]
74        };
75
76        template< typename SynTreeClass >
77        SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) {
78                ScrubTyVars scrubber( tyVars );
79                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
80        }
81
82        template< typename SynTreeClass >
83        SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) {
84                ScrubTyVars scrubber( tyVars, ScrubTyVars::DynamicFromMap );
85                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
86        }
87
88        template< typename SynTreeClass >
89        SynTreeClass * ScrubTyVars::scrubAll( SynTreeClass *target ) {
90                ScrubTyVars scrubber;
91                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
92        }
93
94} // namespace GenPoly
95
96// Local Variables: //
97// tab-width: 4 //
98// mode: c++ //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.