Skip to content

Commit 8c84a06

Browse files
committed
Clang importer: include subscripts in the Swift name lookup tables.
1 parent bbab40a commit 8c84a06

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ void ClangImporter::Implementation::addEntryToLookupTable(
709709
// Also add the alias, if needed.
710710
if (importedName.Alias)
711711
table.addEntry(importedName.Alias, named, effectiveContext);
712+
713+
// Also add the subscript entry, if needed.
714+
if (importedName.IsSubscriptAccessor)
715+
table.addEntry(DeclName(SwiftContext, SwiftContext.Id_subscript, { }),
716+
named, effectiveContext);
712717
}
713718
}
714719

@@ -2259,6 +2264,16 @@ auto ClangImporter::Implementation::importFullName(
22592264
/*hasCustomName=*/false);
22602265

22612266
isFunction = true;
2267+
2268+
// Is this one of the accessors for subscripts?
2269+
if (objcMethod->getMethodFamily() == clang::OMF_None &&
2270+
objcMethod->isInstanceMethod() &&
2271+
(objcMethod->getSelector() == objectAtIndexedSubscript ||
2272+
objcMethod->getSelector() == setObjectAtIndexedSubscript ||
2273+
objcMethod->getSelector() == objectForKeyedSubscript ||
2274+
objcMethod->getSelector() == setObjectForKeyedSubscript))
2275+
result.IsSubscriptAccessor = true;
2276+
22622277
break;
22632278
}
22642279
}

lib/ClangImporter/ImporterImpl.h

+3
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
779779
/// than refuse to import the initializer.
780780
bool DroppedVariadic = false;
781781

782+
/// Whether this declaration is a subscript accessor (getter or setter).
783+
bool IsSubscriptAccessor = false;
784+
782785
/// For an initializer, the kind of initializer to import.
783786
CtorInitializerKind InitKind = CtorInitializerKind::Designated;
784787

test/IDE/Inputs/swift_name_objc.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SWIFT_NAME(SomeProtocol)
3838
@interface SNSomeClass (Category1) <SNSomeProtocol>
3939
- (void)categoryMethodWithX:(float)x y:(float)y;
4040
- (void)categoryMethodWithX:(float)x y:(float)y z:(float)z;
41+
- (object)objectAtIndexedSubscript:(NSInteger)index;
4142
@end
4243

4344
@interface SNCollision

test/IDE/dump_swift_lookup_tables_objc.swift

+6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
// CHECK-NEXT: instanceMethodWithX --> instanceMethodWithX(_:y:z:)
2929
// CHECK-NEXT: method --> method()
3030
// CHECK-NEXT: methodWithFloat --> methodWithFloat(_:)
31+
// CHECK-NEXT: objectAtIndexedSubscript --> objectAtIndexedSubscript(_:)
3132
// CHECK-NEXT: protoInstanceMethodWithX --> protoInstanceMethodWithX(_:y:)
3233
// CHECK-NEXT: setAccessibilityFloat --> setAccessibilityFloat(_:)
34+
// CHECK-NEXT: subscript --> subscript()
3335

3436
// CHECK: Full name -> entry mappings:
3537
// CHECK-NEXT: CCItem:
@@ -89,10 +91,14 @@
8991
// CHECK-NEXT: NSErrorImports: -[NSErrorImports methodAndReturnError:]
9092
// CHECK-NEXT: methodWithFloat(_:):
9193
// CHECK-NEXT: NSErrorImports: -[NSErrorImports methodWithFloat:error:]
94+
// CHECK-NEXT: objectAtIndexedSubscript(_:):
95+
// CHECK-NEXT: SNSomeClass: -[SNSomeClass objectAtIndexedSubscript:]
9296
// CHECK-NEXT: protoInstanceMethodWithX(_:y:):
9397
// CHECK-NEXT: SNSomeProtocol: -[SNSomeProtocol protoInstanceMethodWithX:y:]
9498
// CHECK-NEXT: setAccessibilityFloat(_:):
9599
// CHECK-NEXT: NSAccessibility: -[NSAccessibility setAccessibilityFloat:]
100+
// CHECK-NEXT: subscript():
101+
// CHECK-NEXT: SNSomeClass: -[SNSomeClass objectAtIndexedSubscript:]
96102

97103
// CHECK-OMIT-NEEDLESS-WORDS: Base -> full name mappings:
98104
// CHECK-OMIT-NEEDLESS-WORDS: instanceMethodWithX --> instanceMethodWithX(_:y:z:)

0 commit comments

Comments
 (0)