4
4
5
5
// RUN: %check-interop-cxx-header-in-clang(%t/enums.h -Wno-unused-private-field -Wno-unused-function)
6
6
7
- // Use enums from docs/ABI/TypeLayout.rst to test various mappings between tag values and cases
7
+ // test case-related member functions: operator cases() and isXYZ predicates
8
8
9
9
public enum DataCase { case one( _ x: Int ) }
10
10
@@ -181,25 +181,37 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
181
181
// CHECK-NEXT: inline bool isThree() const {
182
182
// CHECK-NEXT: return *this == cases::three;
183
183
// CHECK-NEXT: }
184
+ // CHECK: inline int _getEnumTag() const {
185
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums9CLikeEnumOMa(0);
186
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
187
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
188
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
189
+ // CHECK-NEXT: }
184
190
185
191
// CHECK: class CharOrSectionMarker final {
186
192
187
193
// CHECK: inline operator cases() const {
188
194
// CHECK-NEXT: switch (_getEnumTag()) {
189
- // CHECK-NEXT: case 0: return cases::Char;
190
195
// CHECK-NEXT: case 1: return cases::Paragraph;
196
+ // CHECK-NEXT: case 0: return cases::Char;
191
197
// CHECK-NEXT: case 2: default: return cases::Chapter;
192
198
// CHECK-NEXT: }
193
199
// CHECK-NEXT: }
194
- // CHECK-NEXT: inline bool isChar() const {
195
- // CHECK-NEXT: return *this == cases::Char;
196
- // CHECK-NEXT: }
197
200
// CHECK-NEXT: inline bool isParagraph() const {
198
201
// CHECK-NEXT: return *this == cases::Paragraph;
199
202
// CHECK-NEXT: }
203
+ // CHECK-NEXT: inline bool isChar() const {
204
+ // CHECK-NEXT: return *this == cases::Char;
205
+ // CHECK-NEXT: }
200
206
// CHECK-NEXT: inline bool isChapter() const {
201
207
// CHECK-NEXT: return *this == cases::Chapter;
202
208
// CHECK-NEXT: }
209
+ // CHECK: inline int _getEnumTag() const {
210
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums19CharOrSectionMarkerOMa(0);
211
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
212
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
213
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
214
+ // CHECK-NEXT: }
203
215
204
216
// CHECK: class DataCase final {
205
217
@@ -211,6 +223,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
211
223
// CHECK-NEXT: inline bool isOne() const {
212
224
// CHECK-NEXT: return *this == cases::one;
213
225
// CHECK-NEXT: }
226
+ // CHECK: inline int _getEnumTag() const {
227
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums8DataCaseOMa(0);
228
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
229
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
230
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
231
+ // CHECK-NEXT: }
214
232
215
233
// CHECK: class IntDoubleOrBignum final {
216
234
@@ -230,38 +248,53 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
230
248
// CHECK-NEXT: inline bool isBignum() const {
231
249
// CHECK-NEXT: return *this == cases::Bignum;
232
250
// CHECK-NEXT: }
251
+ // CHECK: inline int _getEnumTag() const {
252
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums17IntDoubleOrBignumOMa(0);
253
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
254
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
255
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
256
+ // CHECK-NEXT: }
233
257
234
258
// CHECK: class IntOrInfinity final {
235
259
236
260
// CHECK: inline operator cases() const {
237
261
// CHECK-NEXT: switch (_getEnumTag()) {
238
- // CHECK-NEXT: case 0: return cases::Int;
239
262
// CHECK-NEXT: case 1: return cases::NegInfinity;
263
+ // CHECK-NEXT: case 0: return cases::Int;
240
264
// CHECK-NEXT: case 2: default: return cases::PosInfinity;
241
265
// CHECK-NEXT: }
242
266
// CHECK-NEXT: }
243
- // CHECK-NEXT: inline bool isInt() const {
244
- // CHECK-NEXT: return *this == cases::Int;
245
- // CHECK-NEXT: }
246
267
// CHECK-NEXT: inline bool isNegInfinity() const {
247
268
// CHECK-NEXT: return *this == cases::NegInfinity;
248
269
// CHECK-NEXT: }
270
+ // CHECK-NEXT: inline bool isInt() const {
271
+ // CHECK-NEXT: return *this == cases::Int;
272
+ // CHECK-NEXT: }
249
273
// CHECK-NEXT: inline bool isPosInfinity() const {
250
274
// CHECK-NEXT: return *this == cases::PosInfinity;
251
275
// CHECK-NEXT: }
276
+ // CHECK: inline int _getEnumTag() const {
277
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums13IntOrInfinityOMa(0);
278
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
279
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
280
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
281
+ // CHECK-NEXT: }
252
282
253
283
// CHECK: class TerminalChar final {
254
284
255
285
// CHECK: inline operator cases() const {
256
286
// CHECK-NEXT: switch (_getEnumTag()) {
287
+ // CHECK-NEXT: case 4: return cases::Cursor;
257
288
// CHECK-NEXT: case 0: return cases::Plain;
258
289
// CHECK-NEXT: case 1: return cases::Bold;
259
290
// CHECK-NEXT: case 2: return cases::Underline;
260
291
// CHECK-NEXT: case 3: return cases::Blink;
261
- // CHECK-NEXT: case 4: return cases::Cursor;
262
292
// CHECK-NEXT: case 5: default: return cases::Empty;
263
293
// CHECK-NEXT: }
264
294
// CHECK-NEXT: }
295
+ // CHECK-NEXT: inline bool isCursor() const {
296
+ // CHECK-NEXT: return *this == cases::Cursor;
297
+ // CHECK-NEXT: }
265
298
// CHECK-NEXT: inline bool isPlain() const {
266
299
// CHECK-NEXT: return *this == cases::Plain;
267
300
// CHECK-NEXT: }
@@ -274,9 +307,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
274
307
// CHECK-NEXT: inline bool isBlink() const {
275
308
// CHECK-NEXT: return *this == cases::Blink;
276
309
// CHECK-NEXT: }
277
- // CHECK-NEXT: inline bool isCursor() const {
278
- // CHECK-NEXT: return *this == cases::Cursor;
279
- // CHECK-NEXT: }
280
310
// CHECK-NEXT: inline bool isEmpty() const {
281
311
// CHECK-NEXT: return *this == cases::Empty;
282
312
// CHECK-NEXT: }
313
+ // CHECK: inline int _getEnumTag() const {
314
+ // CHECK-NEXT: auto metadata = _impl::$s5Enums12TerminalCharOMa(0);
315
+ // CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
316
+ // CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
317
+ // CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
318
+ // CHECK-NEXT: }
0 commit comments