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.cc -- |
---|
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 : Thu Mar 16 15:44:27 2017 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
16 | #include <sstream> |
---|
17 | #include <string> |
---|
18 | |
---|
19 | #include "GenPoly.h" |
---|
20 | #include "ScrubTyVars.h" |
---|
21 | |
---|
22 | #include "SynTree/Mutator.h" |
---|
23 | #include "SynTree/Type.h" |
---|
24 | #include "SynTree/Expression.h" |
---|
25 | |
---|
26 | namespace GenPoly { |
---|
27 | Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { |
---|
28 | if ( ! tyVars ) { |
---|
29 | if ( typeInst->get_isFtype() ) { |
---|
30 | delete typeInst; |
---|
31 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); |
---|
32 | } else { |
---|
33 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); |
---|
34 | delete typeInst; |
---|
35 | return ret; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | TyVarMap::const_iterator tyVar = tyVars->find( typeInst->get_name() ); |
---|
40 | if ( tyVar != tyVars->end() ) { |
---|
41 | switch ( tyVar->second.kind ) { |
---|
42 | case TypeDecl::Any: |
---|
43 | case TypeDecl::Dtype: |
---|
44 | case TypeDecl::Ttype: |
---|
45 | { |
---|
46 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); |
---|
47 | delete typeInst; |
---|
48 | return ret; |
---|
49 | } |
---|
50 | case TypeDecl::Ftype: |
---|
51 | delete typeInst; |
---|
52 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); |
---|
53 | } // switch |
---|
54 | } // if |
---|
55 | return typeInst; |
---|
56 | } |
---|
57 | |
---|
58 | Type * ScrubTyVars::mutateAggregateType( Type *ty ) { |
---|
59 | if ( shouldScrub( ty ) ) { |
---|
60 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) ); |
---|
61 | delete ty; |
---|
62 | return ret; |
---|
63 | } |
---|
64 | return ty; |
---|
65 | } |
---|
66 | |
---|
67 | Type * ScrubTyVars::mutate( StructInstType *structInst ) { |
---|
68 | return mutateAggregateType( structInst ); |
---|
69 | } |
---|
70 | |
---|
71 | Type * ScrubTyVars::mutate( UnionInstType *unionInst ) { |
---|
72 | return mutateAggregateType( unionInst ); |
---|
73 | } |
---|
74 | |
---|
75 | Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { |
---|
76 | // sizeof( T ) => _sizeof_T parameter, which is the size of T |
---|
77 | if ( Type *dynType = shouldScrub( szeof->get_type() ) ) { |
---|
78 | Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) ); |
---|
79 | return expr; |
---|
80 | } else { |
---|
81 | return Mutator::mutate( szeof ); |
---|
82 | } // if |
---|
83 | } |
---|
84 | |
---|
85 | Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) { |
---|
86 | // alignof( T ) => _alignof_T parameter, which is the alignment of T |
---|
87 | if ( Type *dynType = shouldScrub( algnof->get_type() ) ) { |
---|
88 | Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) ); |
---|
89 | return expr; |
---|
90 | } else { |
---|
91 | return Mutator::mutate( algnof ); |
---|
92 | } // if |
---|
93 | } |
---|
94 | |
---|
95 | Type * ScrubTyVars::mutate( PointerType *pointer ) { |
---|
96 | // // special case of shouldScrub that takes all TypeInstType pointer bases, even if they're not dynamic |
---|
97 | // Type *base = pointer->get_base(); |
---|
98 | // Type *dynType = 0; |
---|
99 | // if ( dynamicOnly ) { |
---|
100 | // if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( base ) ) { |
---|
101 | // if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { dynType = typeInst; } |
---|
102 | // } else { |
---|
103 | // dynType = isDynType( base, tyVars ); |
---|
104 | // } |
---|
105 | // } else { |
---|
106 | // dynType = isPolyType( base, tyVars ); |
---|
107 | // } |
---|
108 | // if ( dynType ) { |
---|
109 | if ( Type *dynType = shouldScrub( pointer->get_base() ) ) { |
---|
110 | Type *ret = dynType->acceptMutator( *this ); |
---|
111 | ret->get_qualifiers() |= pointer->get_qualifiers(); |
---|
112 | pointer->set_base( 0 ); |
---|
113 | delete pointer; |
---|
114 | return ret; |
---|
115 | } |
---|
116 | return Mutator::mutate( pointer ); |
---|
117 | } |
---|
118 | } // namespace GenPoly |
---|
119 | |
---|
120 | // Local Variables: // |
---|
121 | // tab-width: 4 // |
---|
122 | // mode: c++ // |
---|
123 | // compile-command: "make install" // |
---|
124 | // End: // |
---|