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 | // CommonType.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 06:59:27 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Thu Feb 14 17:10:10 2019 |
---|
13 | // Update Count : 24 |
---|
14 | // |
---|
15 | |
---|
16 | #include <cassert> // for strict_dynamic_cast |
---|
17 | #include <map> // for _Rb_tree_const_iterator |
---|
18 | #include <utility> // for pair |
---|
19 | |
---|
20 | #include "Common/PassVisitor.h" |
---|
21 | #include "ResolvExpr/TypeEnvironment.h" // for OpenVarSet, AssertionSet |
---|
22 | #include "SymTab/Indexer.h" // for Indexer |
---|
23 | #include "SynTree/Declaration.h" // for TypeDecl, NamedTypeDecl (ptr... |
---|
24 | #include "SynTree/Type.h" // for BasicType, BasicType::Kind::... |
---|
25 | #include "SynTree/Visitor.h" // for Visitor |
---|
26 | #include "Unify.h" // for unifyExact, WidenMode |
---|
27 | #include "typeops.h" // for isFtype |
---|
28 | |
---|
29 | // #define DEBUG |
---|
30 | #ifdef DEBUG |
---|
31 | #define PRINT(x) x |
---|
32 | #else |
---|
33 | #define PRINT(x) |
---|
34 | #endif |
---|
35 | |
---|
36 | namespace ResolvExpr { |
---|
37 | struct CommonType : public WithShortCircuiting { |
---|
38 | CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
39 | Type *get_result() const { return result; } |
---|
40 | |
---|
41 | void previsit( BaseSyntaxNode * ) { visit_children = false; } |
---|
42 | |
---|
43 | void postvisit( VoidType * voidType ); |
---|
44 | void postvisit( BasicType * basicType ); |
---|
45 | void postvisit( PointerType * pointerType ); |
---|
46 | void postvisit( ArrayType * arrayType ); |
---|
47 | void postvisit( ReferenceType * refType ); |
---|
48 | void postvisit( FunctionType * functionType ); |
---|
49 | void postvisit( StructInstType * aggregateUseType ); |
---|
50 | void postvisit( UnionInstType * aggregateUseType ); |
---|
51 | void postvisit( EnumInstType * aggregateUseType ); |
---|
52 | void postvisit( TraitInstType * aggregateUseType ); |
---|
53 | void postvisit( TypeInstType * aggregateUseType ); |
---|
54 | void postvisit( TupleType * tupleType ); |
---|
55 | void postvisit( VarArgsType * varArgsType ); |
---|
56 | void postvisit( ZeroType * zeroType ); |
---|
57 | void postvisit( OneType * oneType ); |
---|
58 | |
---|
59 | private: |
---|
60 | template< typename Pointer > void getCommonWithVoidPointer( Pointer* voidPointer, Pointer* otherPointer ); |
---|
61 | template< typename RefType > void handleRefType( RefType *inst, Type *other ); |
---|
62 | |
---|
63 | Type *result; |
---|
64 | Type *type2; // inherited |
---|
65 | bool widenFirst, widenSecond; |
---|
66 | const SymTab::Indexer &indexer; |
---|
67 | TypeEnvironment &env; |
---|
68 | const OpenVarSet &openVars; |
---|
69 | }; |
---|
70 | |
---|
71 | Type * handleReference( Type * t1, Type * t2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment & env, const OpenVarSet &openVars ) { |
---|
72 | Type * common = nullptr; |
---|
73 | AssertionSet have, need; |
---|
74 | OpenVarSet newOpen( openVars ); |
---|
75 | // need unify to bind type variables |
---|
76 | if ( unify( t1, t2, env, have, need, newOpen, indexer, common ) ) { |
---|
77 | PRINT( |
---|
78 | std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl; |
---|
79 | ) |
---|
80 | if ( (widenFirst || t2->get_qualifiers() <= t1->get_qualifiers()) && (widenSecond || t1->get_qualifiers() <= t2->get_qualifiers()) ) { |
---|
81 | PRINT( |
---|
82 | std::cerr << "widen okay" << std::endl; |
---|
83 | ) |
---|
84 | common->get_qualifiers() |= t1->get_qualifiers(); |
---|
85 | common->get_qualifiers() |= t2->get_qualifiers(); |
---|
86 | return common; |
---|
87 | } |
---|
88 | } |
---|
89 | PRINT( |
---|
90 | std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl; |
---|
91 | ) |
---|
92 | return nullptr; |
---|
93 | } |
---|
94 | |
---|
95 | Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) { |
---|
96 | PassVisitor<CommonType> visitor( type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
97 | |
---|
98 | int depth1 = type1->referenceDepth(); |
---|
99 | int depth2 = type2->referenceDepth(); |
---|
100 | if ( depth1 > 0 || depth2 > 0 ) { |
---|
101 | int diff = depth1-depth2; |
---|
102 | // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed. |
---|
103 | // if ( diff > 1 || diff < -1 ) return nullptr; |
---|
104 | |
---|
105 | // special case where one type has a reference depth of 1 larger than the other |
---|
106 | if ( diff > 0 || diff < 0 ) { |
---|
107 | PRINT( |
---|
108 | std::cerr << "reference depth diff: " << diff << std::endl; |
---|
109 | ) |
---|
110 | Type * result = nullptr; |
---|
111 | ReferenceType * ref1 = dynamic_cast< ReferenceType * >( type1 ); |
---|
112 | ReferenceType * ref2 = dynamic_cast< ReferenceType * >( type2 ); |
---|
113 | if ( diff > 0 ) { |
---|
114 | // deeper on the left |
---|
115 | assert( ref1 ); |
---|
116 | result = handleReference( ref1->base, type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
117 | } else { |
---|
118 | // deeper on the right |
---|
119 | assert( ref2 ); |
---|
120 | result = handleReference( type1, ref2->base, widenFirst, widenSecond, indexer, env, openVars ); |
---|
121 | } |
---|
122 | if ( result && ref1 ) { |
---|
123 | // formal is reference, so result should be reference |
---|
124 | PRINT( |
---|
125 | std::cerr << "formal is reference; result should be reference" << std::endl; |
---|
126 | ) |
---|
127 | result = new ReferenceType( ref1->get_qualifiers(), result ); |
---|
128 | } |
---|
129 | PRINT( |
---|
130 | std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl; |
---|
131 | ) |
---|
132 | return result; |
---|
133 | } |
---|
134 | // otherwise, both are reference types of the same depth and this is handled by the CommonType visitor. |
---|
135 | } |
---|
136 | |
---|
137 | type1->accept( visitor ); |
---|
138 | Type *result = visitor.pass.get_result(); |
---|
139 | if ( ! result ) { |
---|
140 | // this appears to be handling for opaque type declarations |
---|
141 | if ( widenSecond ) { |
---|
142 | if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) { |
---|
143 | if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) { |
---|
144 | TypeDecl *type = strict_dynamic_cast< TypeDecl* >( nt ); |
---|
145 | if ( type->get_base() ) { |
---|
146 | Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
147 | AssertionSet have, need; |
---|
148 | OpenVarSet newOpen( openVars ); |
---|
149 | type1->get_qualifiers() = Type::Qualifiers(); |
---|
150 | type->get_base()->get_qualifiers() = tq1; |
---|
151 | if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
152 | result = type1->clone(); |
---|
153 | result->get_qualifiers() = tq1 | tq2; |
---|
154 | } // if |
---|
155 | type1->get_qualifiers() = tq1; |
---|
156 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
157 | } // if |
---|
158 | } // if |
---|
159 | } // if |
---|
160 | } // if |
---|
161 | } // if |
---|
162 | #ifdef DEBUG |
---|
163 | std::cerr << "============= commonType" << std::endl << "type1 is "; |
---|
164 | type1->print( std::cerr ); |
---|
165 | std::cerr << " type2 is "; |
---|
166 | type2->print( std::cerr ); |
---|
167 | if ( result ) { |
---|
168 | std::cerr << " common type is "; |
---|
169 | result->print( std::cerr ); |
---|
170 | } else { |
---|
171 | std::cerr << " no common type"; |
---|
172 | } // if |
---|
173 | std::cerr << std::endl; |
---|
174 | #endif |
---|
175 | return result; |
---|
176 | } |
---|
177 | |
---|
178 | // GENERATED START, DO NOT EDIT |
---|
179 | // GENERATED BY BasicTypes-gen.cc |
---|
180 | #define BT BasicType:: |
---|
181 | static const BasicType::Kind commonTypes[BasicType::NUMBER_OF_BASIC_TYPES][BasicType::NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor |
---|
182 | /* B C SC UC SI SUI |
---|
183 | I UI LI LUI LLI LLUI |
---|
184 | IB UIB _FH _FH _F _FC |
---|
185 | F FC _FX _FXC FD _FDC |
---|
186 | D DC F80X _FDXC F80 _FB |
---|
187 | _FLDC FB LD LDC _FBX _FLDXC |
---|
188 | */ |
---|
189 | { |
---|
190 | /* B*/ BT Bool, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
191 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
192 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
193 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
194 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
195 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
196 | }, |
---|
197 | { |
---|
198 | /* C*/ BT Char, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
199 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
200 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
201 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
202 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
203 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
204 | }, |
---|
205 | { |
---|
206 | /* SC*/ BT SignedChar, BT SignedChar, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
207 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
208 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
209 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
210 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
211 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
212 | }, |
---|
213 | { |
---|
214 | /* UC*/ BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
215 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
216 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
217 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
218 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
219 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
220 | }, |
---|
221 | { |
---|
222 | /* SI*/ BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
223 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
224 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
225 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
226 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
227 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
228 | }, |
---|
229 | { |
---|
230 | /* SUI*/ BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, |
---|
231 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
232 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
233 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
234 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
235 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
236 | }, |
---|
237 | { |
---|
238 | /* I*/ BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, |
---|
239 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
240 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
241 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
242 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
243 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
244 | }, |
---|
245 | { |
---|
246 | /* UI*/ BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, |
---|
247 | BT UnsignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
248 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
249 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
250 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
251 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
252 | }, |
---|
253 | { |
---|
254 | /* LI*/ BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, |
---|
255 | BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
256 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
257 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
258 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
259 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
260 | }, |
---|
261 | { |
---|
262 | /* LUI*/ BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, |
---|
263 | BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
264 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
265 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
266 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
267 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
268 | }, |
---|
269 | { |
---|
270 | /* LLI*/ BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, |
---|
271 | BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
272 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
273 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
274 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
275 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
276 | }, |
---|
277 | { |
---|
278 | /* LLUI*/ BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, |
---|
279 | BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, |
---|
280 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
281 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
282 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
283 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
284 | }, |
---|
285 | { |
---|
286 | /* IB*/ BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, |
---|
287 | BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, |
---|
288 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
289 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
290 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
291 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
292 | }, |
---|
293 | { |
---|
294 | /* UIB*/ BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, |
---|
295 | BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, |
---|
296 | BT UnsignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
297 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
298 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
299 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
300 | }, |
---|
301 | { |
---|
302 | /* _FH*/ BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, |
---|
303 | BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, |
---|
304 | BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
305 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
306 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
307 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
308 | }, |
---|
309 | { |
---|
310 | /* _FH*/ BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, |
---|
311 | BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, |
---|
312 | BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
313 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
314 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
315 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
316 | }, |
---|
317 | { |
---|
318 | /* _F*/ BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, |
---|
319 | BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, |
---|
320 | BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32Complex, BT uFloat32, BT uFloat32Complex, |
---|
321 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
322 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
323 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
324 | }, |
---|
325 | { |
---|
326 | /* _FC*/ BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
327 | BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
328 | BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
329 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
330 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
331 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
332 | }, |
---|
333 | { |
---|
334 | /* F*/ BT Float, BT Float, BT Float, BT Float, BT Float, BT Float, |
---|
335 | BT Float, BT Float, BT Float, BT Float, BT Float, BT Float, |
---|
336 | BT Float, BT Float, BT Float, BT FloatComplex, BT Float, BT FloatComplex, |
---|
337 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
338 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
339 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
340 | }, |
---|
341 | { |
---|
342 | /* FC*/ BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
343 | BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
344 | BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
345 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
346 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
347 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
348 | }, |
---|
349 | { |
---|
350 | /* _FX*/ BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, |
---|
351 | BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, |
---|
352 | BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32xComplex, BT uFloat32x, BT uFloat32xComplex, |
---|
353 | BT uFloat32x, BT uFloat32xComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
354 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
355 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
356 | }, |
---|
357 | { |
---|
358 | /* _FXC*/ BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
359 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
360 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
361 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
362 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
363 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
364 | }, |
---|
365 | { |
---|
366 | /* FD*/ BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, |
---|
367 | BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, |
---|
368 | BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, |
---|
369 | BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, |
---|
370 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
371 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
372 | }, |
---|
373 | { |
---|
374 | /* _FDC*/ BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
375 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
376 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
377 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
378 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
379 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
380 | }, |
---|
381 | { |
---|
382 | /* D*/ BT Double, BT Double, BT Double, BT Double, BT Double, BT Double, |
---|
383 | BT Double, BT Double, BT Double, BT Double, BT Double, BT Double, |
---|
384 | BT Double, BT Double, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, |
---|
385 | BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, |
---|
386 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
387 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
388 | }, |
---|
389 | { |
---|
390 | /* DC*/ BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
391 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
392 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
393 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
394 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
395 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
396 | }, |
---|
397 | { |
---|
398 | /* F80X*/ BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, |
---|
399 | BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, |
---|
400 | BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, |
---|
401 | BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, |
---|
402 | BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
403 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
404 | }, |
---|
405 | { |
---|
406 | /* _FDXC*/ BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
407 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
408 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
409 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
410 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
411 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
412 | }, |
---|
413 | { |
---|
414 | /* F80*/ BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, |
---|
415 | BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, |
---|
416 | BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, |
---|
417 | BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, |
---|
418 | BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
419 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
420 | }, |
---|
421 | { |
---|
422 | /* _FB*/ BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, |
---|
423 | BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, |
---|
424 | BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, |
---|
425 | BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, |
---|
426 | BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128, |
---|
427 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
428 | }, |
---|
429 | { |
---|
430 | /* _FLDC*/ BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
431 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
432 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
433 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
434 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
435 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
436 | }, |
---|
437 | { |
---|
438 | /* FB*/ BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, |
---|
439 | BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, |
---|
440 | BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, |
---|
441 | BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, |
---|
442 | BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uuFloat128, |
---|
443 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
444 | }, |
---|
445 | { |
---|
446 | /* LD*/ BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, |
---|
447 | BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, |
---|
448 | BT LongDouble, BT LongDouble, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, |
---|
449 | BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, |
---|
450 | BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDouble, |
---|
451 | BT LongDoubleComplex, BT LongDouble, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
452 | }, |
---|
453 | { |
---|
454 | /* LDC*/ BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
455 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
456 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
457 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
458 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
459 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
460 | }, |
---|
461 | { |
---|
462 | /* _FBX*/ BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, |
---|
463 | BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, |
---|
464 | BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
465 | BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
466 | BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128x, |
---|
467 | BT uFloat128xComplex, BT uFloat128x, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
468 | }, |
---|
469 | { |
---|
470 | /*_FLDXC*/ BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
471 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
472 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
473 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
474 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
475 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
476 | }, |
---|
477 | }; // commonTypes |
---|
478 | #undef BT |
---|
479 | // GENERATED END |
---|
480 | static_assert( |
---|
481 | sizeof(commonTypes)/sizeof(commonTypes[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES, |
---|
482 | "Each basic type kind should have a corresponding row in the combined type matrix" |
---|
483 | ); |
---|
484 | |
---|
485 | CommonType::CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) |
---|
486 | : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) { |
---|
487 | } |
---|
488 | |
---|
489 | void CommonType::postvisit( VoidType * ) {} |
---|
490 | |
---|
491 | void CommonType::postvisit( BasicType *basicType ) { |
---|
492 | if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) { |
---|
493 | BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ otherBasic->get_kind() ]; |
---|
494 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) { |
---|
495 | result = new BasicType( basicType->get_qualifiers() | otherBasic->get_qualifiers(), newType ); |
---|
496 | } // if |
---|
497 | } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
498 | // use signed int in lieu of the enum/zero/one type |
---|
499 | BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
500 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) { |
---|
501 | result = new BasicType( basicType->get_qualifiers() | type2->get_qualifiers(), newType ); |
---|
502 | } // if |
---|
503 | } // if |
---|
504 | } |
---|
505 | |
---|
506 | template< typename Pointer > |
---|
507 | void CommonType::getCommonWithVoidPointer( Pointer* voidPointer, Pointer* otherPointer ) { |
---|
508 | if ( TypeInstType* var = dynamic_cast< TypeInstType* >( otherPointer->get_base() ) ) { |
---|
509 | OpenVarSet::const_iterator entry = openVars.find( var->get_name() ); |
---|
510 | if ( entry != openVars.end() ) { |
---|
511 | AssertionSet need, have; |
---|
512 | WidenMode widen( widenFirst, widenSecond ); |
---|
513 | if ( entry != openVars.end() && ! env.bindVar(var, voidPointer->get_base(), entry->second, need, have, openVars, widen, indexer ) ) return; |
---|
514 | } |
---|
515 | } |
---|
516 | result = voidPointer->clone(); |
---|
517 | result->get_qualifiers() |= otherPointer->get_qualifiers(); |
---|
518 | } |
---|
519 | |
---|
520 | void CommonType::postvisit( PointerType *pointerType ) { |
---|
521 | if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { |
---|
522 | // std::cerr << "commonType: two pointers: " << pointerType << " / " << otherPointer << std::endl; |
---|
523 | if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) { |
---|
524 | getCommonWithVoidPointer( otherPointer, pointerType ); |
---|
525 | } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) { |
---|
526 | getCommonWithVoidPointer( pointerType, otherPointer ); |
---|
527 | } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst ) |
---|
528 | && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) { |
---|
529 | // std::cerr << "middle case" << std::endl; |
---|
530 | Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers(); |
---|
531 | pointerType->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
532 | otherPointer->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
533 | AssertionSet have, need; |
---|
534 | OpenVarSet newOpen( openVars ); |
---|
535 | if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
536 | // std::cerr << "unifyExact success" << std::endl; |
---|
537 | if ( tq1 < tq2 ) { |
---|
538 | result = pointerType->clone(); |
---|
539 | } else { |
---|
540 | result = otherPointer->clone(); |
---|
541 | } // if |
---|
542 | strict_dynamic_cast<PointerType*>(result)->base->get_qualifiers() = tq1 | tq2; |
---|
543 | } else { |
---|
544 | /// std::cerr << "place for ptr-to-type" << std::endl; |
---|
545 | } // if |
---|
546 | pointerType->get_base()->get_qualifiers() = tq1; |
---|
547 | otherPointer->get_base()->get_qualifiers() = tq2; |
---|
548 | } // if |
---|
549 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
550 | result = pointerType->clone(); |
---|
551 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
552 | } // if |
---|
553 | } |
---|
554 | |
---|
555 | void CommonType::postvisit( ArrayType * ) {} |
---|
556 | |
---|
557 | void CommonType::postvisit( ReferenceType *refType ) { |
---|
558 | if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) { |
---|
559 | // std::cerr << "commonType: both references: " << refType << " / " << otherRef << std::endl; |
---|
560 | // std::cerr << ( refType->get_base()->get_qualifiers() >= otherRef->get_base()->get_qualifiers() || widenFirst ) << (refType->get_base()->get_qualifiers() <= otherRef->get_base()->get_qualifiers() || widenSecond) << std::endl; |
---|
561 | if ( widenFirst && dynamic_cast< VoidType* >( otherRef->get_base() ) && ! isFtype(refType->get_base()) ) { |
---|
562 | getCommonWithVoidPointer( otherRef, refType ); |
---|
563 | } else if ( widenSecond && dynamic_cast< VoidType* >( refType->get_base() ) && ! isFtype(otherRef->get_base()) ) { |
---|
564 | getCommonWithVoidPointer( refType, otherRef ); |
---|
565 | } else if ( ( refType->get_base()->get_qualifiers() >= otherRef->get_base()->get_qualifiers() || widenFirst ) |
---|
566 | && ( refType->get_base()->get_qualifiers() <= otherRef->get_base()->get_qualifiers() || widenSecond ) ) { |
---|
567 | // std::cerr << "middle case" << std::endl; |
---|
568 | Type::Qualifiers tq1 = refType->get_base()->get_qualifiers(), tq2 = otherRef->get_base()->get_qualifiers(); |
---|
569 | refType->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
570 | otherRef->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
571 | AssertionSet have, need; |
---|
572 | OpenVarSet newOpen( openVars ); |
---|
573 | if ( unifyExact( refType->get_base(), otherRef->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
574 | if ( tq1 < tq2 ) { |
---|
575 | result = refType->clone(); |
---|
576 | } else { |
---|
577 | result = otherRef->clone(); |
---|
578 | } // if |
---|
579 | strict_dynamic_cast<ReferenceType*>(result)->base->get_qualifiers() = tq1 | tq2; |
---|
580 | } else { |
---|
581 | /// std::cerr << "place for ptr-to-type" << std::endl; |
---|
582 | } // if |
---|
583 | refType->get_base()->get_qualifiers() = tq1; |
---|
584 | otherRef->get_base()->get_qualifiers() = tq2; |
---|
585 | } // if |
---|
586 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
587 | result = refType->clone(); |
---|
588 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
589 | } // if |
---|
590 | } |
---|
591 | |
---|
592 | void CommonType::postvisit( FunctionType * ) {} |
---|
593 | void CommonType::postvisit( StructInstType * ) {} |
---|
594 | void CommonType::postvisit( UnionInstType * ) {} |
---|
595 | |
---|
596 | void CommonType::postvisit( EnumInstType *enumInstType ) { |
---|
597 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
598 | // reuse BasicType, EnumInstType code by swapping type2 with enumInstType |
---|
599 | result = commonType( type2, enumInstType, widenSecond, widenFirst, indexer, env, openVars ); |
---|
600 | } // if |
---|
601 | } |
---|
602 | |
---|
603 | void CommonType::postvisit( TraitInstType * ) { |
---|
604 | } |
---|
605 | |
---|
606 | void CommonType::postvisit( TypeInstType *inst ) { |
---|
607 | if ( widenFirst ) { |
---|
608 | NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); |
---|
609 | if ( nt ) { |
---|
610 | TypeDecl *type = strict_dynamic_cast< TypeDecl* >( nt ); |
---|
611 | if ( type->get_base() ) { |
---|
612 | Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
613 | AssertionSet have, need; |
---|
614 | OpenVarSet newOpen( openVars ); |
---|
615 | type2->get_qualifiers() = Type::Qualifiers(); |
---|
616 | type->get_base()->get_qualifiers() = tq1; |
---|
617 | if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) { |
---|
618 | result = type2->clone(); |
---|
619 | result->get_qualifiers() = tq1 | tq2; |
---|
620 | } // if |
---|
621 | type2->get_qualifiers() = tq2; |
---|
622 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
623 | } // if |
---|
624 | } // if |
---|
625 | } // if |
---|
626 | } |
---|
627 | |
---|
628 | void CommonType::postvisit( TupleType * ) {} |
---|
629 | void CommonType::postvisit( VarArgsType * ) {} |
---|
630 | |
---|
631 | void CommonType::postvisit( ZeroType *zeroType ) { |
---|
632 | if ( widenFirst ) { |
---|
633 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
634 | if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
635 | result = type2->clone(); |
---|
636 | result->get_qualifiers() |= zeroType->get_qualifiers(); |
---|
637 | } |
---|
638 | } else if ( widenSecond && dynamic_cast< OneType* >( type2 ) ) { |
---|
639 | result = new BasicType( zeroType->get_qualifiers(), BasicType::SignedInt ); |
---|
640 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | void CommonType::postvisit( OneType *oneType ) { |
---|
646 | if ( widenFirst ) { |
---|
647 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
648 | if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
649 | result = type2->clone(); |
---|
650 | result->get_qualifiers() |= oneType->get_qualifiers(); |
---|
651 | } |
---|
652 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
653 | result = new BasicType( oneType->get_qualifiers(), BasicType::SignedInt ); |
---|
654 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
655 | } |
---|
656 | } |
---|
657 | } |
---|
658 | } // namespace ResolvExpr |
---|
659 | |
---|
660 | // Local Variables: // |
---|
661 | // tab-width: 4 // |
---|
662 | // mode: c++ // |
---|
663 | // compile-command: "make install" // |
---|
664 | // End: // |
---|