source: src/GenPoly/ScrubTyVars.h @ 201aeb9

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 201aeb9 was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[51587aa]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//
[ea6332d]7// ScrubTyVars.h --
[51587aa]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[01aeade]11// Last Modified By : Peter A. Buhr
[6b0b624]12// Last Modified On : Sat Jul 22 09:21:47 2017
13// Update Count     : 2
[51587aa]14//
[01aeade]15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <cassert>            // for assert
[78dd0da]19
[08fc48f]20#include "GenPoly.h"          // for TyVarMap, isPolyType, isDynType
21#include "SynTree/Mutator.h"  // for Mutator
22#include "SynTree/Type.h"     // for Type (ptr only), PointerType (ptr only)
[51b7345]23
[08fc48f]24class AlignofExpr;
25class Expression;
26class SizeofExpr;
[51b7345]27
28namespace GenPoly {
[01aeade]29        class ScrubTyVars : public Mutator {
[5a3ac84]30                /// Whether to scrub all type variables from the provided map, dynamic type variables from the provided map, or all type variables
31                enum ScrubMode { FromMap, DynamicFromMap, All };
[f8b961b]32
[5a3ac84]33                ScrubTyVars() : tyVars(nullptr), mode( All ) {}
34
35                ScrubTyVars( const TyVarMap &tyVars, ScrubMode mode = FromMap ): tyVars( &tyVars ), mode( mode ) {}
36
37        public:
[ebe9b3a]38                /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
39                /// and sizeof/alignof expressions with the proper variable
[01aeade]40                template< typename SynTreeClass >
41                static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
[b18b0b5]42
[3bb195cb]43                /// For all dynamic-layout types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
44                /// and sizeof/alignof expressions with the proper variable
45                template< typename SynTreeClass >
46                static SynTreeClass *scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars );
47
[5a3ac84]48                /// For all polymorphic types, replaces generic types, dtypes, and ftypes with the appropriate void type,
49                /// and sizeof/alignof expressions with the proper variable
50                template< typename SynTreeClass >
51                static SynTreeClass *scrubAll( SynTreeClass *target );
52
[01aeade]53                virtual Type* mutate( TypeInstType *typeInst );
[b18b0b5]54                virtual Type* mutate( StructInstType *structInst );
55                virtual Type* mutate( UnionInstType *unionInst );
56                virtual Expression* mutate( SizeofExpr *szeof );
57                virtual Expression* mutate( AlignofExpr *algnof );
[01aeade]58                virtual Type* mutate( PointerType *pointer );
[b18b0b5]59
[01aeade]60          private:
[3bb195cb]61                /// Returns the type if it should be scrubbed, NULL otherwise.
62                Type* shouldScrub( Type *ty ) {
[5a3ac84]63                        switch ( mode ) {
64                        case FromMap: return isPolyType( ty, *tyVars );
65                        case DynamicFromMap: return isDynType( ty, *tyVars );
66                        case All: return isPolyType( ty );
67                        }
68                        assert(false); return nullptr; // unreachable
69                        // return dynamicOnly ? isDynType( ty, tyVars ) : isPolyType( ty, tyVars );
[3bb195cb]70                }
[ea6332d]71
[b18b0b5]72                /// Mutates (possibly generic) aggregate types appropriately
73                Type* mutateAggregateType( Type *ty );
[ea6332d]74
[5a3ac84]75                const TyVarMap *tyVars;  ///< Type variables to scrub
76                ScrubMode mode;          ///< which type variables to scrub? [FromMap]
[01aeade]77        };
78
[bdd516a]79        template< typename SynTreeClass >
[01aeade]80        SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) {
[ebe9b3a]81                ScrubTyVars scrubber( tyVars );
[01aeade]82                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
83        }
84
[3bb195cb]85        template< typename SynTreeClass >
86        SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) {
[5a3ac84]87                ScrubTyVars scrubber( tyVars, ScrubTyVars::DynamicFromMap );
88                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
89        }
90
91        template< typename SynTreeClass >
92        SynTreeClass * ScrubTyVars::scrubAll( SynTreeClass *target ) {
93                ScrubTyVars scrubber;
[3bb195cb]94                return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
95        }
96
[51b7345]97} // namespace GenPoly
98
[51587aa]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.