Skip to content

Commit a94e91f

Browse files
committed
[Omit needless words] Properly compute context names for ObjC protocols.
1 parent ca736fd commit a94e91f

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,18 +1927,6 @@ namespace llvm {
19271927
/// printing.
19281928
static StringRef getClangDeclContextName(const clang::DeclContext *dc) {
19291929
auto type = ClangImporter::Implementation::getClangDeclContextType(dc);
1930-
1931-
// FIXME: Hack to work around getClangDeclContextType() failing for
1932-
// protocols.
1933-
if (type.isNull()) {
1934-
if (auto constProto = dyn_cast<clang::ObjCProtocolDecl>(dc)) {
1935-
auto proto = const_cast<clang::ObjCProtocolDecl *>(constProto);
1936-
clang::ASTContext &ctx = dc->getParentASTContext();
1937-
type = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, { }, { proto }, false);
1938-
type = ctx.getObjCObjectPointerType(type);
1939-
}
1940-
}
1941-
19421930
if (type.isNull()) return StringRef();
19431931

19441932
return ClangImporter::Implementation::getClangTypeNameForOmission(

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,13 @@ clang::QualType ClangImporter::Implementation::getClangDeclContextType(
18671867
objcCategory->getClassInterface()));
18681868
}
18691869

1870+
if (auto constProto = dyn_cast<clang::ObjCProtocolDecl>(dc)) {
1871+
auto proto = const_cast<clang::ObjCProtocolDecl *>(constProto);
1872+
auto type = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, { }, { proto },
1873+
false);
1874+
return ctx.getObjCObjectPointerType(type);
1875+
}
1876+
18701877
if (auto tag = dyn_cast<clang::TagDecl>(dc)) {
18711878
return ctx.getTagDeclType(tag);
18721879
}

test/IDE/Inputs/custom-modules/OmitNeedlessWords.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
-(void)drawGreebies:(nonnull SEGreebieArray*)greebies;
3333
@end
3434

35+
@protocol OMWLanding
36+
-(void)flipLanding;
37+
@end
38+
3539
@protocol OMWWiggle
3640
-(void)joinSub;
3741
-(void)conflicting1 NS_SWIFT_NAME(wiggle1());

test/IDE/print_omit_needless_words.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@
309309
// Non-parameterized Objective-C class ending in "Array".
310310
// CHECK-OMIT-NEEDLESS-WORDS: func draw(_: SEGreebieArray)
311311

312+
// Protocols as contexts
313+
// CHECK-OMIT-NEEDLESS-WORDS: protocol OMWLanding {
314+
// CHECK-OMIT-NEEDLESS-WORDS-NEXT: func flip()
315+
312316
// Verify that we get the Swift name from the original declaration.
313317
// CHECK-OMIT-NEEDLESS-WORDS: protocol OMWWiggle
314318
// CHECK-OMIT-NEEDLESS-WORDS-NEXT: func joinSub()

0 commit comments

Comments
 (0)