|
30 | 30 | #include "swift/Basic/Assertions.h"
|
31 | 31 | #include "swift/Basic/SourceManager.h"
|
32 | 32 | #include "swift/Basic/StringExtras.h"
|
| 33 | +#include "swift/ClangImporter/ClangImporter.h" |
33 | 34 | #include "swift/IDE/SourceEntityWalker.h"
|
34 | 35 | #include "swift/IDE/Utils.h"
|
35 | 36 | #include "swift/Markup/Markup.h"
|
36 | 37 | #include "swift/Sema/IDETypeChecking.h"
|
| 38 | +#include "clang/AST/Decl.h" |
37 | 39 | #include "llvm/ADT/APInt.h"
|
38 | 40 | #include "llvm/ADT/SmallVector.h"
|
39 | 41 | #include "llvm/Support/ErrorHandling.h"
|
@@ -431,6 +433,7 @@ struct MappedLoc {
|
431 | 433 |
|
432 | 434 | class IndexSwiftASTWalker : public SourceEntityWalker {
|
433 | 435 | IndexDataConsumer &IdxConsumer;
|
| 436 | + ASTContext &Ctx; |
434 | 437 | SourceManager &SrcMgr;
|
435 | 438 | std::optional<unsigned> BufferID;
|
436 | 439 | bool enableWarnings;
|
@@ -468,6 +471,31 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
|
468 | 471 | // let bindings.
|
469 | 472 | llvm::DenseMap<ValueDecl *, ValueDecl *> sameNamedCaptures;
|
470 | 473 |
|
| 474 | + bool isImporterSynthesizedWrapper(ValueDecl *D) { |
| 475 | + const ClangImporterSynthesizedTypeAttr *attr = |
| 476 | + D->getAttrs().getAttribute<ClangImporterSynthesizedTypeAttr>(); |
| 477 | + if (!attr) { |
| 478 | + const VarDecl *var = dyn_cast_or_null<VarDecl>(D); |
| 479 | + if (!var) { |
| 480 | + return false; |
| 481 | + } |
| 482 | + const NominalTypeDecl *type = |
| 483 | + var->getDeclContext()->getSelfNominalTypeDecl(); |
| 484 | + if (!type || |
| 485 | + !type->getAttrs().hasAttribute<ClangImporterSynthesizedTypeAttr>()) { |
| 486 | + return false; |
| 487 | + } |
| 488 | + attr = type->getAttrs().getAttribute<ClangImporterSynthesizedTypeAttr>(); |
| 489 | + } |
| 490 | + switch (attr->getKind()) { |
| 491 | + case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapper: |
| 492 | + case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapperAnon: |
| 493 | + return true; |
| 494 | + default: |
| 495 | + return false; |
| 496 | + } |
| 497 | + } |
| 498 | + |
471 | 499 | bool getNameAndUSR(ValueDecl *D, ExtensionDecl *ExtD,
|
472 | 500 | StringRef &name, StringRef &USR) {
|
473 | 501 | auto &result = nameAndUSRCache[ExtD ? (Decl*)ExtD : D];
|
@@ -594,7 +622,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
|
594 | 622 | public:
|
595 | 623 | IndexSwiftASTWalker(IndexDataConsumer &IdxConsumer, ASTContext &Ctx,
|
596 | 624 | SourceFile *SF = nullptr)
|
597 |
| - : IdxConsumer(IdxConsumer), SrcMgr(Ctx.SourceMgr), |
| 625 | + : IdxConsumer(IdxConsumer), Ctx(Ctx), SrcMgr(Ctx.SourceMgr), |
598 | 626 | BufferID(SF ? std::optional(SF->getBufferID()) : std::nullopt),
|
599 | 627 | enableWarnings(IdxConsumer.enableWarnings()) {}
|
600 | 628 |
|
@@ -901,6 +929,23 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
|
901 | 929 | return false;
|
902 | 930 | }
|
903 | 931 |
|
| 932 | + if (isImporterSynthesizedWrapper(D)) { |
| 933 | + auto *Importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader()); |
| 934 | + const ClangNode node = Importer->getEffectiveClangNode(D); |
| 935 | + if (!node.isNull()) { |
| 936 | + if (auto named = dyn_cast_or_null<clang::NamedDecl>(node.getAsDecl())) { |
| 937 | + if (const auto imported = Importer->importDeclCached(named)) { |
| 938 | + if (imported && imported.has_value()) { |
| 939 | + if (ValueDecl *VD = |
| 940 | + dyn_cast_or_null<ValueDecl>(imported.value())) { |
| 941 | + D = VD; |
| 942 | + } |
| 943 | + } |
| 944 | + } |
| 945 | + } |
| 946 | + } |
| 947 | + } |
| 948 | + |
904 | 949 | if (auto *GenParam = dyn_cast<GenericTypeParamDecl>(D)) {
|
905 | 950 | D = canonicalizeGenericTypeParamDeclForIndex(GenParam);
|
906 | 951 | }
|
|
0 commit comments