source: src/GenPoly/ScrubTyVars.h@ c84e80a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since c84e80a was 3bb195cb, checked in by Aaron Moss <a3moss@…>, 9 years ago

Dtypes now erased on dtype-only generic types, tests pass, build produces many warnings

  • Property mode set to 100644
File size: 3.0 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//
[01aeade]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
12// Last Modified On : Tue May 19 07:48:14 2015
13// Update Count : 1
[51587aa]14//
[01aeade]15
16#ifndef _SCRUBTYVARS_H
17#define _SCRUBTYVARS_H
[51b73452]18
[78dd0da]19#include <string>
20
[51b73452]21#include "GenPoly.h"
22
23#include "SynTree/SynTree.h"
24#include "SynTree/Mutator.h"
25
26namespace GenPoly {
[01aeade]27 class ScrubTyVars : public Mutator {
28 public:
[3bb195cb]29 ScrubTyVars( const TyVarMap &tyVars, bool dynamicOnly = false ): tyVars( tyVars ), dynamicOnly( dynamicOnly ) {}
[f8b961b]30
[ebe9b3a]31 /// For all polymorphic types with type variables in `tyVars`, replaces generic types, dtypes, and ftypes with the appropriate void type,
32 /// and sizeof/alignof expressions with the proper variable
[01aeade]33 template< typename SynTreeClass >
34 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
[b18b0b5]35
[3bb195cb]36 /// For all dynamic-layout 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 *scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars );
40
[01aeade]41 virtual Type* mutate( TypeInstType *typeInst );
[b18b0b5]42 virtual Type* mutate( StructInstType *structInst );
43 virtual Type* mutate( UnionInstType *unionInst );
44 virtual Expression* mutate( SizeofExpr *szeof );
45 virtual Expression* mutate( AlignofExpr *algnof );
[01aeade]46 virtual Type* mutate( PointerType *pointer );
[b18b0b5]47
[01aeade]48 private:
[3bb195cb]49 /// Returns the type if it should be scrubbed, NULL otherwise.
50 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 );
59 }
60
[b18b0b5]61 /// Mutates (possibly generic) aggregate types appropriately
62 Type* mutateAggregateType( Type *ty );
63
[3bb195cb]64 const TyVarMap &tyVars; ///< Type variables to scrub
65 bool dynamicOnly; ///< only scrub the types with dynamic layout? [false]
[01aeade]66 };
67
[bdd516a]68 template< typename SynTreeClass >
[01aeade]69 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) {
[ebe9b3a]70 ScrubTyVars scrubber( tyVars );
[01aeade]71 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
72 }
73
[3bb195cb]74 template< typename SynTreeClass >
75 SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) {
76 ScrubTyVars scrubber( tyVars, true );
77 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) );
78 }
79
[51b73452]80} // namespace GenPoly
81
[01aeade]82#endif // _SCRUBTYVARS_H
83
[51587aa]84// Local Variables: //
85// tab-width: 4 //
86// mode: c++ //
87// compile-command: "make install" //
88// End: //
Note: See TracBrowser for help on using the repository browser.