|
40 | 40 | #include "swift/Strings.h"
|
41 | 41 | #include "clang/AST/ASTContext.h"
|
42 | 42 | #include "clang/AST/Decl.h"
|
| 43 | +#include "clang/AST/DeclObjC.h" |
43 | 44 | #include "clang/Basic/Module.h"
|
44 | 45 | #include "llvm/ADT/StringSwitch.h"
|
45 | 46 | #include "llvm/Support/ConvertUTF.h"
|
@@ -1549,6 +1550,28 @@ bool swift::shouldPrint(const Decl *D, PrintOptions &Options) {
|
1549 | 1550 | if (auto *VD = dyn_cast<ValueDecl>(D)) {
|
1550 | 1551 | if (VD->getOverriddenDecl()) return false;
|
1551 | 1552 | if (!VD->getSatisfiedProtocolRequirements().empty()) return false;
|
| 1553 | + |
| 1554 | + if (auto clangDecl = VD->getClangDecl()) { |
| 1555 | + // If the Clang declaration is from a protocol but was mirrored into |
| 1556 | + // class or extension thereof, treat it as an override. |
| 1557 | + if (isa<clang::ObjCProtocolDecl>(clangDecl->getDeclContext()) && |
| 1558 | + VD->getDeclContext()->getAsClassOrClassExtensionContext()) |
| 1559 | + return false; |
| 1560 | + |
| 1561 | + // Check whether Clang considers it an override. |
| 1562 | + if (auto objcMethod = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) { |
| 1563 | + SmallVector<const clang::ObjCMethodDecl *, 4> overriddenMethods; |
| 1564 | + objcMethod->getOverriddenMethods(overriddenMethods); |
| 1565 | + if (!overriddenMethods.empty()) return false; |
| 1566 | + } else if (auto objcProperty |
| 1567 | + = dyn_cast<clang::ObjCPropertyDecl>(clangDecl)) { |
| 1568 | + if (auto getter = objcProperty->getGetterMethodDecl()) { |
| 1569 | + SmallVector<const clang::ObjCMethodDecl *, 4> overriddenMethods; |
| 1570 | + getter->getOverriddenMethods(overriddenMethods); |
| 1571 | + if (!overriddenMethods.empty()) return false; |
| 1572 | + } |
| 1573 | + } |
| 1574 | + } |
1552 | 1575 | }
|
1553 | 1576 | }
|
1554 | 1577 |
|
|
0 commit comments