File tree Expand file tree Collapse file tree 7 files changed +48
-1
lines changed
Inputs/clang-importer-sdk/usr/include/objc Expand file tree Collapse file tree 7 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -1094,6 +1094,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
1094
1094
// / on macOS or Foundation on Linux.
1095
1095
bool isCGFloat ();
1096
1096
1097
+ // / Check if this is a ObjCBool type from the Objective-C module.
1098
+ bool isObjCBool ();
1099
+
1097
1100
// / Check if this is a std.string type from C++.
1098
1101
bool isCxxString ();
1099
1102
Original file line number Diff line number Diff line change @@ -1281,6 +1281,19 @@ bool TypeBase::isCGFloat() {
1281
1281
NTD->getName ().is (" CGFloat" );
1282
1282
}
1283
1283
1284
+ bool TypeBase::isObjCBool () {
1285
+ auto *NTD = getAnyNominal ();
1286
+ if (!NTD)
1287
+ return false ;
1288
+
1289
+ auto *DC = NTD->getDeclContext ();
1290
+ if (!DC->isModuleScopeContext ())
1291
+ return false ;
1292
+
1293
+ auto *module = DC->getParentModule ();
1294
+ return module ->getName ().is (" ObjectiveC" ) && NTD->getName ().is (" ObjCBool" );
1295
+ }
1296
+
1284
1297
bool TypeBase::isCxxString () {
1285
1298
auto *nominal = getAnyNominal ();
1286
1299
if (!nominal)
Original file line number Diff line number Diff line change @@ -4572,8 +4572,11 @@ namespace {
4572
4572
// CGFloats is special cased in the importer, and needs more handling.
4573
4573
bool isCGFloat = (type && type->isCGFloat ()) ||
4574
4574
(type && synthesizer.isCGFloat (type));
4575
+ // Do not attempts to import ObjCBool values, for similar reasons.
4576
+ bool isObjCBool = (type && type->isObjCBool ()) ||
4577
+ (type && synthesizer.isObjCBool (type));
4575
4578
4576
- if (type && !isCGFloat) {
4579
+ if (type && !isCGFloat && !isObjCBool ) {
4577
4580
auto convertKind = ConstantConvertKind::None;
4578
4581
// Request conversions on enums, and swift_wrapper((enum/struct))
4579
4582
// types
Original file line number Diff line number Diff line change @@ -195,6 +195,8 @@ Type SwiftDeclSynthesizer::getConstantLiteralType(
195
195
}
196
196
}
197
197
198
+ // This method is exposed on SwiftDeclSynthesizer to keep code that accesses
199
+ // RawTypes together.
198
200
bool SwiftDeclSynthesizer::isCGFloat (Type type) {
199
201
auto found = ImporterImpl.RawTypes .find (type->getAnyNominal ());
200
202
if (found == ImporterImpl.RawTypes .end ()) {
@@ -205,6 +207,18 @@ bool SwiftDeclSynthesizer::isCGFloat(Type type) {
205
207
return importTy->isCGFloat ();
206
208
}
207
209
210
+ // This method is exposed on SwiftDeclSynthesizer to keep code that accesses
211
+ // RawTypes together.
212
+ bool SwiftDeclSynthesizer::isObjCBool (Type type) {
213
+ auto found = ImporterImpl.RawTypes .find (type->getAnyNominal ());
214
+ if (found == ImporterImpl.RawTypes .end ()) {
215
+ return false ;
216
+ }
217
+
218
+ Type importTy = found->second ;
219
+ return importTy->isObjCBool ();
220
+ }
221
+
208
222
ValueDecl *SwiftDeclSynthesizer::createConstant (Identifier name,
209
223
DeclContext *dc, Type type,
210
224
const clang::APValue &value,
Original file line number Diff line number Diff line change @@ -354,6 +354,8 @@ class SwiftDeclSynthesizer {
354
354
355
355
bool isCGFloat (Type type);
356
356
357
+ bool isObjCBool (Type type);
358
+
357
359
private:
358
360
Type getConstantLiteralType (Type type, ConstantConvertKind convertKind);
359
361
Original file line number Diff line number Diff line change @@ -31,13 +31,18 @@ static const MyFloatType MyFloatTypeValue1 = 10;
31
31
static const MyFloatType MyFloatTypeValue2 = 20 ;
32
32
static const MyFloatType MyFloatTypeValue3 = 30 ;
33
33
34
+ static const BOOL MyBoolConstantValue1 = YES;
35
+ static const BOOL MyBoolConstantValue2 = NO;
36
+
34
37
//--- main.swift
35
38
func foo( ) {
36
39
print ( MyClass . value)
37
40
print ( myFloatConstValue)
38
41
print ( MyFloatType . value1)
39
42
print ( MyFloatType . value2)
40
43
print ( MyFloatType . value3)
44
+ print ( MyBoolConstantValue1)
45
+ print ( MyBoolConstantValue2)
41
46
}
42
47
43
48
// CHECK: // static MyClass.value.getter
@@ -57,3 +62,8 @@ func foo() {
57
62
// CHECK-NOT: // static MyFloatType.value1.getter
58
63
// CHECK-NOT: // static MyFloatType.value2.getter
59
64
// CHECK-NOT: // static MyFloatType.value3.getter
65
+
66
+ // ObjCBools are not imported:
67
+
68
+ // CHECK-NOT: // MyBoolConstantValue1.getter
69
+ // CHECK-NOT: // MyBoolConstantValue2.getter
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ typedef int NSInteger;
13
13
#endif
14
14
15
15
typedef __typeof__ (__objc_yes ) BOOL ;
16
+ #define YES __objc_yes
17
+ #define NO __objc_no
16
18
17
19
typedef struct objc_selector * SEL ;
18
20
SEL sel_registerName (const char * str );
You can’t perform that action at this time.
0 commit comments