Skip to content

Commit

Permalink
Clang importer: include subscripts in the Swift name lookup tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
DougGregor committed Dec 3, 2015
1 parent bbab40a commit 8c84a06
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ void ClangImporter::Implementation::addEntryToLookupTable(
// Also add the alias, if needed.
if (importedName.Alias)
table.addEntry(importedName.Alias, named, effectiveContext);

// Also add the subscript entry, if needed.
if (importedName.IsSubscriptAccessor)
table.addEntry(DeclName(SwiftContext, SwiftContext.Id_subscript, { }),
named, effectiveContext);
}
}

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

isFunction = true;

// Is this one of the accessors for subscripts?
if (objcMethod->getMethodFamily() == clang::OMF_None &&
objcMethod->isInstanceMethod() &&
(objcMethod->getSelector() == objectAtIndexedSubscript ||
objcMethod->getSelector() == setObjectAtIndexedSubscript ||
objcMethod->getSelector() == objectForKeyedSubscript ||
objcMethod->getSelector() == setObjectForKeyedSubscript))
result.IsSubscriptAccessor = true;

break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
/// than refuse to import the initializer.
bool DroppedVariadic = false;

/// Whether this declaration is a subscript accessor (getter or setter).
bool IsSubscriptAccessor = false;

/// For an initializer, the kind of initializer to import.
CtorInitializerKind InitKind = CtorInitializerKind::Designated;

Expand Down
1 change: 1 addition & 0 deletions test/IDE/Inputs/swift_name_objc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SWIFT_NAME(SomeProtocol)
@interface SNSomeClass (Category1) <SNSomeProtocol>
- (void)categoryMethodWithX:(float)x y:(float)y;
- (void)categoryMethodWithX:(float)x y:(float)y z:(float)z;
- (object)objectAtIndexedSubscript:(NSInteger)index;
@end

@interface SNCollision
Expand Down
6 changes: 6 additions & 0 deletions test/IDE/dump_swift_lookup_tables_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
// CHECK-NEXT: instanceMethodWithX --> instanceMethodWithX(_:y:z:)
// CHECK-NEXT: method --> method()
// CHECK-NEXT: methodWithFloat --> methodWithFloat(_:)
// CHECK-NEXT: objectAtIndexedSubscript --> objectAtIndexedSubscript(_:)
// CHECK-NEXT: protoInstanceMethodWithX --> protoInstanceMethodWithX(_:y:)
// CHECK-NEXT: setAccessibilityFloat --> setAccessibilityFloat(_:)
// CHECK-NEXT: subscript --> subscript()

// CHECK: Full name -> entry mappings:
// CHECK-NEXT: CCItem:
Expand Down Expand Up @@ -89,10 +91,14 @@
// CHECK-NEXT: NSErrorImports: -[NSErrorImports methodAndReturnError:]
// CHECK-NEXT: methodWithFloat(_:):
// CHECK-NEXT: NSErrorImports: -[NSErrorImports methodWithFloat:error:]
// CHECK-NEXT: objectAtIndexedSubscript(_:):
// CHECK-NEXT: SNSomeClass: -[SNSomeClass objectAtIndexedSubscript:]
// CHECK-NEXT: protoInstanceMethodWithX(_:y:):
// CHECK-NEXT: SNSomeProtocol: -[SNSomeProtocol protoInstanceMethodWithX:y:]
// CHECK-NEXT: setAccessibilityFloat(_:):
// CHECK-NEXT: NSAccessibility: -[NSAccessibility setAccessibilityFloat:]
// CHECK-NEXT: subscript():
// CHECK-NEXT: SNSomeClass: -[SNSomeClass objectAtIndexedSubscript:]

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

0 comments on commit 8c84a06

Please sign in to comment.