source: src/ResolvExpr/CommonType.cpp@ 4d5c5b6a

Last change on this file since 4d5c5b6a was 90e683b, checked in by Andrew Beach <ajbeach@…>, 8 months ago

I set out to do a enum rework. It ended up being much the same and I unwound the core rework. But I hope the new names are a bit clearer and other minor fixes are helpful, so I am keeping those.

  • Property mode set to 100644
File size: 50.4 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// CommonType.cpp --
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 "CommonType.hpp"
17
18#include <cassert> // for strict_dynamic_cast
19#include <map> // for _Rb_tree_const_iterator
20#include <utility> // for pair
21
22#include "AST/Decl.hpp"
23#include "AST/Pass.hpp"
24#include "AST/Type.hpp"
25#include "Unify.hpp" // for unifyExact, WidenMode
26#include "Typeops.hpp" // for isFtype
27#include "Tuples/Tuples.hpp"
28
29// #define DEBUG
30#ifdef DEBUG
31#define PRINT(x) x
32#else
33#define PRINT(x)
34#endif
35
36namespace ResolvExpr {
37
38namespace {
39
40 // GENERATED START, DO NOT EDIT
41 // GENERATED BY BasicTypes-gen.cpp
42 #define BT ast::BasicKind::
43 static const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor
44 /* B C SC UC SI USI
45 I UI LI ULI LLI ULLI
46 __ID __UID _FH _FHC _F _FC
47 F FC _FX _FXC _FD _FDC
48 D DC _FDX _FDXC _F80 LD
49 LDC __FLD _FLD _FLDC _FLDX _FLDXC
50 */
51 {
52 /* B */ BT Bool, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt,
53 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
54 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
55 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
56 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
57 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
58 },
59 {
60 /* C */ BT Char, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt,
61 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
62 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
63 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
64 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
65 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
66 },
67 {
68 /* SC */ BT SignedChar, BT SignedChar, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt,
69 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
70 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
71 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
72 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
73 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
74 },
75 {
76 /* UC */ BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt,
77 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
78 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
79 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
80 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
81 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
82 },
83 {
84 /* SI */ BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortUnsignedInt,
85 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
86 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
87 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
88 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
89 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
90 },
91 {
92 /* USI */ BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt,
93 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
94 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
95 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
96 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
97 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
98 },
99 {
100 /* I */ BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt,
101 BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
102 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
103 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
104 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
105 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
106 },
107 {
108 /* UI */ BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt,
109 BT UnsignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
110 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
111 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
112 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
113 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
114 },
115 {
116 /* LI */ BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt,
117 BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
118 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
119 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
120 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
121 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
122 },
123 {
124 /* ULI */ BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt,
125 BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
126 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
127 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
128 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
129 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
130 },
131 {
132 /* LLI */ BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt,
133 BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt,
134 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
135 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
136 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
137 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
138 },
139 {
140 /* ULLI */ BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt,
141 BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt,
142 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
143 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
144 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
145 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
146 },
147 {
148 /* __ID */ BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128,
149 BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128,
150 BT SignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
151 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
152 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
153 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
154 },
155 {
156 /* __UID */ BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128,
157 BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128,
158 BT UnsignedInt128, BT UnsignedInt128, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
159 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
160 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
161 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
162 },
163 {
164 /* _FH */ BT Float16, BT Float16, BT Float16, BT Float16, BT Float16, BT Float16,
165 BT Float16, BT Float16, BT Float16, BT Float16, BT Float16, BT Float16,
166 BT Float16, BT Float16, BT Float16, BT Float16Complex, BT Float32, BT Float32Complex,
167 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
168 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
169 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
170 },
171 {
172 /* _FHC */ BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex,
173 BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex,
174 BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float16Complex, BT Float32Complex, BT Float32Complex,
175 BT FloatComplex, BT FloatComplex, BT Float32xComplex, BT Float32xComplex, BT Float64Complex, BT Float64Complex,
176 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
177 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
178 },
179 {
180 /* _F */ BT Float32, BT Float32, BT Float32, BT Float32, BT Float32, BT Float32,
181 BT Float32, BT Float32, BT Float32, BT Float32, BT Float32, BT Float32,
182 BT Float32, BT Float32, BT Float32, BT Float32Complex, BT Float32, BT Float32Complex,
183 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
184 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
185 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
186 },
187 {
188 /* _FC */ BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex,
189 BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex,
190 BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex, BT Float32Complex,
191 BT FloatComplex, BT FloatComplex, BT Float32xComplex, BT Float32xComplex, BT Float64Complex, BT Float64Complex,
192 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
193 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
194 },
195 {
196 /* F */ BT Float, BT Float, BT Float, BT Float, BT Float, BT Float,
197 BT Float, BT Float, BT Float, BT Float, BT Float, BT Float,
198 BT Float, BT Float, BT Float, BT FloatComplex, BT Float, BT FloatComplex,
199 BT Float, BT FloatComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
200 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
201 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
202 },
203 {
204 /* FC */ BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex,
205 BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex,
206 BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex,
207 BT FloatComplex, BT FloatComplex, BT Float32xComplex, BT Float32xComplex, BT Float64Complex, BT Float64Complex,
208 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
209 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
210 },
211 {
212 /* _FX */ BT Float32x, BT Float32x, BT Float32x, BT Float32x, BT Float32x, BT Float32x,
213 BT Float32x, BT Float32x, BT Float32x, BT Float32x, BT Float32x, BT Float32x,
214 BT Float32x, BT Float32x, BT Float32x, BT Float32xComplex, BT Float32x, BT Float32xComplex,
215 BT Float32x, BT Float32xComplex, BT Float32x, BT Float32xComplex, BT Float64, BT Float64Complex,
216 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
217 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
218 },
219 {
220 /* _FXC */ BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex,
221 BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex,
222 BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex,
223 BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float32xComplex, BT Float64Complex, BT Float64Complex,
224 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
225 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
226 },
227 {
228 /* _FD */ BT Float64, BT Float64, BT Float64, BT Float64, BT Float64, BT Float64,
229 BT Float64, BT Float64, BT Float64, BT Float64, BT Float64, BT Float64,
230 BT Float64, BT Float64, BT Float64, BT Float64Complex, BT Float64, BT Float64Complex,
231 BT Float64, BT Float64Complex, BT Float64, BT Float64Complex, BT Float64, BT Float64Complex,
232 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
233 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
234 },
235 {
236 /* _FDC */ BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex,
237 BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex,
238 BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex,
239 BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex, BT Float64Complex,
240 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
241 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
242 },
243 {
244 /* D */ BT Double, BT Double, BT Double, BT Double, BT Double, BT Double,
245 BT Double, BT Double, BT Double, BT Double, BT Double, BT Double,
246 BT Double, BT Double, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex,
247 BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex,
248 BT Double, BT DoubleComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
249 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
250 },
251 {
252 /* DC */ BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex,
253 BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex,
254 BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex,
255 BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex,
256 BT DoubleComplex, BT DoubleComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
257 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
258 },
259 {
260 /* _FDX */ BT Float64x, BT Float64x, BT Float64x, BT Float64x, BT Float64x, BT Float64x,
261 BT Float64x, BT Float64x, BT Float64x, BT Float64x, BT Float64x, BT Float64x,
262 BT Float64x, BT Float64x, BT Float64x, BT Float64xComplex, BT Float64x, BT Float64xComplex,
263 BT Float64x, BT Float64xComplex, BT Float64x, BT Float64xComplex, BT Float64x, BT Float64xComplex,
264 BT Float64x, BT Float64xComplex, BT Float64x, BT Float64xComplex, BT Float80, BT LongDouble,
265 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
266 },
267 {
268 /* _FDXC */ BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex,
269 BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex,
270 BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex,
271 BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex,
272 BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT Float64xComplex, BT LongDoubleComplex, BT LongDoubleComplex,
273 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
274 },
275 {
276 /* _F80 */ BT Float80, BT Float80, BT Float80, BT Float80, BT Float80, BT Float80,
277 BT Float80, BT Float80, BT Float80, BT Float80, BT Float80, BT Float80,
278 BT Float80, BT Float80, BT Float80, BT LongDoubleComplex, BT Float80, BT LongDoubleComplex,
279 BT Float80, BT LongDoubleComplex, BT Float80, BT LongDoubleComplex, BT Float80, BT LongDoubleComplex,
280 BT Float80, BT LongDoubleComplex, BT Float80, BT LongDoubleComplex, BT Float80, BT LongDouble,
281 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
282 },
283 {
284 /* LD */ BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble,
285 BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble,
286 BT LongDouble, BT LongDouble, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex,
287 BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex,
288 BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDouble,
289 BT LongDoubleComplex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
290 },
291 {
292 /* LDC */ BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex,
293 BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex,
294 BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex,
295 BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex,
296 BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex,
297 BT LongDoubleComplex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
298 },
299 {
300 /* __FLD */ BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128,
301 BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128,
302 BT uuFloat128, BT uuFloat128, BT uuFloat128, BT Float128Complex, BT uuFloat128, BT Float128Complex,
303 BT uuFloat128, BT Float128Complex, BT uuFloat128, BT Float128Complex, BT uuFloat128, BT Float128Complex,
304 BT uuFloat128, BT Float128Complex, BT uuFloat128, BT Float128Complex, BT uuFloat128, BT uuFloat128,
305 BT Float128Complex, BT uuFloat128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
306 },
307 {
308 /* _FLD */ BT Float128, BT Float128, BT Float128, BT Float128, BT Float128, BT Float128,
309 BT Float128, BT Float128, BT Float128, BT Float128, BT Float128, BT Float128,
310 BT Float128, BT Float128, BT Float128, BT Float128Complex, BT Float128, BT Float128Complex,
311 BT Float128, BT Float128Complex, BT Float128, BT Float128Complex, BT Float128, BT Float128Complex,
312 BT Float128, BT Float128Complex, BT Float128, BT Float128Complex, BT Float128, BT Float128,
313 BT Float128Complex, BT Float128, BT Float128, BT Float128Complex, BT Float128x, BT Float128xComplex,
314 },
315 {
316 /* _FLDC */ BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex,
317 BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex,
318 BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex,
319 BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex,
320 BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex,
321 BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128Complex, BT Float128xComplex, BT Float128xComplex,
322 },
323 {
324 /* _FLDX */ BT Float128x, BT Float128x, BT Float128x, BT Float128x, BT Float128x, BT Float128x,
325 BT Float128x, BT Float128x, BT Float128x, BT Float128x, BT Float128x, BT Float128x,
326 BT Float128x, BT Float128x, BT Float128x, BT Float128xComplex, BT Float128x, BT Float128xComplex,
327 BT Float128x, BT Float128xComplex, BT Float128x, BT Float128xComplex, BT Float128x, BT Float128xComplex,
328 BT Float128x, BT Float128xComplex, BT Float128x, BT Float128xComplex, BT Float128x, BT Float128x,
329 BT Float128xComplex, BT Float128x, BT Float128x, BT Float128xComplex, BT Float128x, BT Float128xComplex,
330 },
331 {
332 /* _FLDXC */ BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
333 BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
334 BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
335 BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
336 BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
337 BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex, BT Float128xComplex,
338 },
339 }; // commonTypes
340 #undef BT
341 // GENERATED END
342 static_assert(
343 sizeof(commonTypes)/sizeof(commonTypes[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,
344 "Each basic type kind should have a corresponding row in the combined type matrix"
345 );
346
347class CommonType final : public ast::WithShortCircuiting {
348 const ast::Type * type2;
349 WidenMode widen;
350 ast::TypeEnvironment & tenv;
351 const ast::OpenVarSet & open;
352 ast::AssertionSet & need;
353 ast::AssertionSet & have;
354public:
355 ast::ptr< ast::Type > result;
356
357 CommonType(
358 const ast::Type * t2, WidenMode w,
359 ast::TypeEnvironment & env, const ast::OpenVarSet & o,
360 ast::AssertionSet & need, ast::AssertionSet & have )
361 : type2( t2 ), widen( w ), tenv( env ), open( o ), need (need), have (have) ,result() {}
362
363 void previsit( const ast::Node * ) { visit_children = false; }
364
365 void postvisit( const ast::VoidType * ) {}
366
367 void postvisit( const ast::BasicType * basic ) {
368 if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) {
369 ast::BasicKind kind;
370 if (basic->kind != basic2->kind && !widen.first && !widen.second) return;
371 else if (!widen.first) kind = basic->kind; // widen.second
372 else if (!widen.second) kind = basic2->kind;
373 else kind = commonTypes[ basic->kind ][ basic2->kind ];
374 // xxx - what does qualifiers even do here??
375 if ( (basic->qualifiers >= basic2->qualifiers || widen.first)
376 && (basic->qualifiers <= basic2->qualifiers || widen.second) ) {
377 result = new ast::BasicType{ kind, basic->qualifiers | basic2->qualifiers };
378 }
379 } else if (
380 dynamic_cast< const ast::ZeroType * >( type2 )
381 || dynamic_cast< const ast::OneType * >( type2 )
382 ) {
383 if (widen.second) {
384 result = new ast::BasicType{ basic->kind, basic->qualifiers | type2->qualifiers };
385 }
386 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
387 const ast::EnumDecl* enumDecl = enumInst->base;
388 if ( enumDecl->is_c_enum() ) {
389 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
390 if (
391 ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
392 || widen.first )
393 && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers )
394 || widen.second )
395 ) {
396 result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers };
397 }
398 }
399 }
400 }
401
402private:
403 template< typename Pointer >
404 void getCommonWithVoidPointer( const Pointer * voidPtr, const Pointer * oPtr ) {
405 const ast::Type * base = oPtr->base;
406 if ( auto var = dynamic_cast< const ast::TypeInstType * >( base ) ) {
407 auto entry = open.find( *var );
408 if ( entry != open.end() ) {
409 ast::AssertionSet need, have;
410 if ( ! tenv.bindVar(
411 var, voidPtr->base, entry->second, need, have, open, widen )
412 ) return;
413 }
414 }
415 result = voidPtr;
416 add_qualifiers( result, oPtr->qualifiers );
417 }
418
419public:
420 void postvisit( const ast::PointerType * pointer ) {
421 if ( auto pointer2 = dynamic_cast< const ast::PointerType * >( type2 ) ) {
422 if (
423 widen.first
424 && pointer2->base.as< ast::VoidType >()
425 && ! ast::isFtype( pointer->base )
426 ) {
427 getCommonWithVoidPointer( pointer2, pointer );
428 } else if (
429 widen.second
430 && pointer->base.as< ast::VoidType >()
431 && ! ast::isFtype( pointer2->base )
432 ) {
433 getCommonWithVoidPointer( pointer, pointer2 );
434 } else if (
435 ( pointer->base->qualifiers >= pointer2->base->qualifiers || widen.first )
436 && ( pointer->base->qualifiers <= pointer2->base->qualifiers || widen.second )
437 ) {
438 ast::CV::Qualifiers q1 = pointer->base->qualifiers;
439 ast::CV::Qualifiers q2 = pointer2->base->qualifiers;
440
441 // force t{1,2} to be cloned if their qualifiers must be stripped, so that
442 // pointer{,2}->base are unchanged
443 ast::ptr< ast::Type > t1{ pointer->base }, t2{ pointer2->base };
444 reset_qualifiers( t1 );
445 reset_qualifiers( t2 );
446
447 ast::OpenVarSet newOpen{ open };
448 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
449 result = pointer;
450 if ( q1.val != q2.val ) {
451 // reset result->base->qualifiers to be union of two base qualifiers
452 strict_dynamic_cast< ast::PointerType * >(
453 result.get_and_mutate()
454 )->base.get_and_mutate()->qualifiers = q1 | q2;
455 }
456 } else if ( isFtype (t1) && isFtype (t2) ) {
457 auto f1 = t1.as<ast::FunctionType>();
458 if (!f1) return;
459 auto f2 = t2.strict_as<ast::FunctionType>();
460
461 assertf(f1->returns.size() <= 1, "Function return should not be a list");
462 assertf(f2->returns.size() <= 1, "Function return should not be a list");
463
464 if (
465 ( f1->params.size() != f2->params.size() || f1->returns.size() != f2->returns.size() )
466 && ! f1->isTtype()
467 && ! f2->isTtype()
468 ) return;
469
470 auto params1 = flattenList( f1->params, tenv );
471 auto params2 = flattenList( f2->params, tenv );
472
473 auto crnt1 = params1.begin();
474 auto crnt2 = params2.begin();
475 auto end1 = params1.end();
476 auto end2 = params2.end();
477
478 while (crnt1 != end1 && crnt2 != end2 ) {
479 const ast::Type * arg1 = *crnt1;
480 const ast::Type * arg2 = *crnt2;
481
482 bool isTuple1 = Tuples::isTtype( t1 );
483 bool isTuple2 = Tuples::isTtype( t2 );
484
485 // assumes here that ttype *must* be last parameter
486 if ( isTuple1 && ! isTuple2 ) {
487 // combine remainder of list2, then unify
488 if (unifyExact(
489 arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
490 noWiden() )) {
491 break;
492 } else return;
493 } else if ( ! isTuple1 && isTuple2 ) {
494 // combine remainder of list1, then unify
495 if (unifyExact(
496 tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open,
497 noWiden() )) {
498 break;
499 } else return;
500 }
501
502 // allow qualifiers of pointer and reference base to become more specific
503 if (auto ref1 = dynamic_cast<const ast::ReferenceType *> (arg1)) {
504 if (auto ref2 = dynamic_cast<const ast::ReferenceType *> (arg2)) {
505 ast::ptr<ast::Type> base1 = ref1->base;
506 ast::ptr<ast::Type> base2 = ref2->base;
507
508 // xxx - assume LHS is always the target type
509
510 if ( ! ((widen.second && ref2->qualifiers.is_mutex)
511 || (ref1->qualifiers.is_mutex == ref2->qualifiers.is_mutex ))) return;
512
513 if ( (widen.second && base1->qualifiers <= base2->qualifiers ) || (base2->qualifiers == base1->qualifiers) ) {
514
515 reset_qualifiers(base1);
516 reset_qualifiers(base2);
517
518 if ( !unifyExact(
519 base1, base2, tenv, need, have, open, noWiden() )
520 ) return;
521 }
522 } else return;
523 } else if (auto ptr1 = dynamic_cast<const ast::PointerType *> (arg1)) {
524 if (auto ptr2 = dynamic_cast<const ast::PointerType *> (arg2)) {
525 ast::ptr<ast::Type> base1 = ptr1->base;
526 ast::ptr<ast::Type> base2 = ptr2->base;
527
528 // xxx - assume LHS is always the target type
529 // a function accepting const can always be called by non-const arg
530
531 if ( (widen.second && base1->qualifiers <= base2->qualifiers ) || (base2->qualifiers == base1->qualifiers) ) {
532
533 reset_qualifiers(base1);
534 reset_qualifiers(base2);
535
536 if ( ! unifyExact(
537 base1, base2, tenv, need, have, open, noWiden() )
538 ) return;
539 }
540 } else return;
541 } else if (! unifyExact(
542 arg1, arg2, tenv, need, have, open, noWiden() )) {
543 return;
544 }
545 ++crnt1; ++crnt2;
546 }
547 if ( crnt1 != end1 ) {
548 // try unifying empty tuple with ttype
549 const ast::Type * t1 = *crnt1;
550 if (! Tuples::isTtype( t1 ) ) return;
551 if (! unifyExact(
552 t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
553 noWiden() )) return;
554 } else if ( crnt2 != end2 ) {
555 // try unifying empty tuple with ttype
556 const ast::Type * t2 = *crnt2;
557 if ( !Tuples::isTtype( t2 ) ) return;
558 if ( !unifyExact(
559 tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open,
560 noWiden() )) return;
561 }
562 if ((f1->returns.size() == 0 && f2->returns.size() == 0)
563 || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden()))) {
564 result = pointer;
565
566 for (auto & assn : f1->assertions) {
567 auto i = need.find(assn);
568 if (i != need.end()) i->second.isUsed = true;
569 auto j = have.find(assn);
570 if (j != have.end()) j->second.isUsed = true;
571 }
572
573 for (auto & assn : f2->assertions) {
574 auto i = need.find(assn);
575 if (i != need.end()) i->second.isUsed = true;
576 auto j = have.find(assn);
577 if (j != have.end()) j->second.isUsed = true;
578 }
579 }
580 } // if ftype
581 }
582 } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) {
583 result = pointer;
584 add_qualifiers( result, type2->qualifiers );
585 }
586 }
587
588 void postvisit( const ast::ArrayType * ) {}
589
590 void postvisit( const ast::ReferenceType * ref ) {
591 if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
592 if (
593 widen.first && ref2->base.as< ast::VoidType >() && ! ast::isFtype( ref->base )
594 ) {
595 getCommonWithVoidPointer( ref2, ref );
596 } else if (
597 widen.second && ref->base.as< ast::VoidType>() && ! ast::isFtype( ref2->base )
598 ) {
599 getCommonWithVoidPointer( ref, ref2 );
600 } else if (
601 ( ref->base->qualifiers >= ref2->base->qualifiers || widen.first )
602 && ( ref->base->qualifiers <= ref2->base->qualifiers || widen.second )
603 ) {
604 ast::CV::Qualifiers q1 = ref->base->qualifiers, q2 = ref2->base->qualifiers;
605
606 // force t{1,2} to be cloned if their qualifiers must be stripped, so that
607 // ref{,2}->base are unchanged
608 ast::ptr< ast::Type > t1{ ref->base }, t2{ ref2->base };
609 reset_qualifiers( t1 );
610 reset_qualifiers( t2 );
611
612 ast::OpenVarSet newOpen{ open };
613 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
614 result = ref;
615 if ( q1.val != q2.val ) {
616 // reset result->base->qualifiers to be union of two base qualifiers
617 strict_dynamic_cast< ast::ReferenceType * >(
618 result.get_and_mutate()
619 )->base.get_and_mutate()->qualifiers = q1 | q2;
620 }
621 }
622 }
623 } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) {
624 result = ref;
625 add_qualifiers( result, type2->qualifiers );
626 } else {
627 if (!dynamic_cast<const ast::EnumInstType *>(type2))
628 result = commonType( type2, ref, tenv, need, have, open, widen );
629 }
630 }
631
632 void postvisit( const ast::FunctionType * ) {}
633
634 void postvisit( const ast::StructInstType * ) {}
635
636 void postvisit( const ast::UnionInstType * ) {}
637
638 /// Is the target enum a child of the base enum?
639 static bool isChildEnum(
640 const ast::EnumDecl * decl, const ast::EnumDecl * target ) {
641 if ( decl == target ) return true;
642 for ( auto inlined : decl->inlinedDecl ) {
643 if ( isChildEnum( inlined->base, target ) ) return true;
644 }
645 return false;
646 }
647
648 void postvisit( const ast::EnumInstType * param ) {
649 auto argAsEnumInst = dynamic_cast<const ast::EnumInstType *>(type2);
650 if ( argAsEnumInst ) {
651 const ast::EnumDecl* paramDecl = param->base;
652 const ast::EnumDecl* argDecl = argAsEnumInst->base;
653 if ( isChildEnum( paramDecl, argDecl ) ) {
654 result = param;
655 }
656 } else if ( param->base && param->base->is_c_enum() ) {
657 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt );
658 result = commonType( basicType, type2, tenv, need, have, open, widen);
659 }
660 }
661
662 void postvisit( const ast::TraitInstType * ) {}
663
664 void postvisit( const ast::TypeInstType * ) {}
665
666 void postvisit( const ast::TupleType * ) {}
667
668 void postvisit( const ast::VarArgsType * ) {}
669
670 void postvisit( const ast::ZeroType * zero ) {
671 if ( !widen.first ) return;
672 if ( dynamic_cast< const ast::BasicType * >( type2 )
673 || dynamic_cast< const ast::PointerType * >( type2 ) ) {
674 if ( widen.second || zero->qualifiers <= type2->qualifiers ) {
675 result = type2;
676 add_qualifiers( result, zero->qualifiers );
677 }
678 } else if ( widen.second && dynamic_cast< const ast::OneType * >( type2 ) ) {
679 result = new ast::BasicType{
680 ast::BasicKind::SignedInt, zero->qualifiers | type2->qualifiers };
681 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
682 const ast::EnumDecl * enumDecl = enumInst->base;
683 if ( !enumDecl->base ) {
684 if ( widen.second || zero->qualifiers <= type2->qualifiers ) {
685 result = type2;
686 add_qualifiers( result, zero->qualifiers );
687 }
688 }
689 }
690 }
691
692 void postvisit( const ast::OneType * one ) {
693 if ( !widen.first ) return;
694 if ( dynamic_cast< const ast::BasicType * >( type2 ) ) {
695 if ( widen.second || one->qualifiers <= type2->qualifiers ) {
696 result = type2;
697 add_qualifiers( result, one->qualifiers );
698 }
699 } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) {
700 result = new ast::BasicType{
701 ast::BasicKind::SignedInt, one->qualifiers | type2->qualifiers };
702 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
703 const ast::EnumDecl * enumDecl = enumInst->base;
704 if ( !enumDecl->base ) {
705 if ( widen.second || one->qualifiers <= type2->qualifiers ) {
706 result = type2;
707 add_qualifiers( result, one->qualifiers );
708 }
709 }
710 }
711 }
712};
713
714// size_t CommonType::traceId = Stats::Heap::new_stacktrace_id("CommonType");
715
716ast::ptr< ast::Type > handleReference(
717 const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen,
718 ast::TypeEnvironment & env,
719 const ast::OpenVarSet & open
720) {
721 ast::ptr<ast::Type> common;
722 ast::AssertionSet have, need;
723 ast::OpenVarSet newOpen( open );
724
725 // need unify to bind type variables
726 if ( unify( t1, t2, env, have, need, newOpen, common ) ) {
727 ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers;
728 PRINT(
729 std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
730 )
731 if ( ( widen.first || q2 <= q1 ) && ( widen.second || q1 <= q2 ) ) {
732 PRINT(
733 std::cerr << "widen okay" << std::endl;
734 )
735 add_qualifiers( common, q1 | q2 );
736 return common;
737 }
738 }
739
740 PRINT(
741 std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl;
742 )
743 return { nullptr };
744}
745
746} // namespace
747
748ast::ptr< ast::Type > commonType(
749 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
750 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
751 const ast::OpenVarSet & open, WidenMode widen
752) {
753 unsigned depth1 = type1->referenceDepth();
754 unsigned depth2 = type2->referenceDepth();
755
756 if ( depth1 != depth2 ) { // implies depth1 > 0 || depth2 > 0
757 PRINT(
758 std::cerr << "reference depth diff: " << (depth1-depth2) << std::endl;
759 )
760 ast::ptr< ast::Type > result;
761 const ast::ReferenceType * ref1 = type1.as< ast::ReferenceType >();
762 const ast::ReferenceType * ref2 = type2.as< ast::ReferenceType >();
763
764 if ( depth1 > depth2 ) {
765 assert( ref1 );
766 result = handleReference( ref1->base, type2, widen, env, open );
767 } else { // Implies depth1 < depth2
768 assert( ref2 );
769 result = handleReference( type1, ref2->base, widen, env, open );
770 }
771
772 if ( result && ref1 ) {
773 // formal is reference, so result should be reference
774 PRINT(
775 std::cerr << "formal is reference; result should be reference" << std::endl;
776 )
777 result = new ast::ReferenceType{ result, ref1->qualifiers };
778 }
779
780 PRINT(
781 std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is "
782 "[" << result << "]" << std::endl;
783 )
784 return result;
785 }
786 // otherwise both are reference types of the same depth and this is handled by the visitor
787 return ast::Pass<CommonType>::read( type1.get(),
788 type2, widen, env, open, need, have );
789}
790
791} // namespace ResolvExpr
792
793// Local Variables: //
794// tab-width: 4 //
795// mode: c++ //
796// compile-command: "make install" //
797// End: //
Note: See TracBrowser for help on using the repository browser.