|
20 | 20 | #include "swift/AST/ASTDemangler.h"
|
21 | 21 | #include "swift/AST/ASTPrinter.h"
|
22 | 22 | #include "swift/AST/Decl.h"
|
| 23 | +#include "swift/AST/LookupKinds.h" |
| 24 | +#include "swift/AST/ModuleNameLookup.h" |
23 | 25 | #include "swift/AST/NameLookup.h"
|
24 |
| -#include "swift/AST/NameLookupRequests.h" |
25 | 26 | #include "swift/AST/SwiftNameTranslation.h"
|
26 | 27 | #include "swift/AST/GenericSignature.h"
|
27 | 28 | #include "swift/Basic/SourceManager.h"
|
@@ -484,40 +485,48 @@ void SwiftLangSupport::printFullyAnnotatedSynthesizedDeclaration(
|
484 | 485 |
|
485 | 486 | template <typename FnTy>
|
486 | 487 | void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
|
487 |
| - llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen; |
488 |
| - ++NamesSeen[VD->getName()]; |
489 |
| - SmallVector<LookupResultEntry, 8> RelatedDecls; |
490 |
| - |
491 | 488 | if (isa<ParamDecl>(VD))
|
492 | 489 | return; // Parameters don't have interesting related declarations.
|
493 | 490 |
|
494 |
| - // FIXME: Extract useful related declarations, overloaded functions, |
495 |
| - // if VD is an initializer, we should extract other initializers etc. |
496 |
| - // For now we use unqualified lookup to fetch other declarations with the same |
497 |
| - // base name. |
498 | 491 | auto &ctx = VD->getASTContext();
|
499 |
| - auto descriptor = UnqualifiedLookupDescriptor(DeclNameRef(VD->getBaseName()), |
500 |
| - VD->getDeclContext()); |
501 |
| - auto lookup = evaluateOrDefault(ctx.evaluator, |
502 |
| - UnqualifiedLookupRequest{descriptor}, {}); |
503 |
| - for (auto result : lookup) { |
504 |
| - ValueDecl *RelatedVD = result.getValueDecl(); |
505 |
| - if (RelatedVD->getAttrs().isUnavailable(VD->getASTContext())) |
| 492 | + |
| 493 | + llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen; |
| 494 | + ++NamesSeen[VD->getName()]; |
| 495 | + |
| 496 | + |
| 497 | + auto *DC = VD->getDeclContext(); |
| 498 | + bool typeLookup = DC->isTypeContext(); |
| 499 | + |
| 500 | + SmallVector<ValueDecl *, 4> results; |
| 501 | + |
| 502 | + if (typeLookup) { |
| 503 | + auto type = DC->getDeclaredInterfaceType(); |
| 504 | + if (!type->is<ErrorType>()) { |
| 505 | + DC->lookupQualified(type, DeclNameRef(VD->getBaseName()), |
| 506 | + NL_QualifiedDefault, results); |
| 507 | + } |
| 508 | + } else { |
| 509 | + namelookup::lookupInModule(DC->getModuleScopeContext(), |
| 510 | + VD->getBaseName(), results, |
| 511 | + NLKind::UnqualifiedLookup, |
| 512 | + namelookup::ResolutionKind::Overloadable, |
| 513 | + DC->getModuleScopeContext()); |
| 514 | + } |
| 515 | + |
| 516 | + SmallVector<ValueDecl *, 8> RelatedDecls; |
| 517 | + for (auto result : results) { |
| 518 | + if (result->getAttrs().isUnavailable(ctx)) |
506 | 519 | continue;
|
507 | 520 |
|
508 |
| - if (RelatedVD != VD) { |
509 |
| - ++NamesSeen[RelatedVD->getName()]; |
| 521 | + if (result != VD) { |
| 522 | + ++NamesSeen[result->getName()]; |
510 | 523 | RelatedDecls.push_back(result);
|
511 | 524 | }
|
512 | 525 | }
|
513 | 526 |
|
514 | 527 | // Now provide the results along with whether the name is duplicate or not.
|
515 |
| - ValueDecl *OriginalBase = VD->getDeclContext()->getSelfNominalTypeDecl(); |
516 |
| - for (auto Related : RelatedDecls) { |
517 |
| - ValueDecl *RelatedVD = Related.getValueDecl(); |
518 |
| - bool SameBase = Related.getBaseDecl() && Related.getBaseDecl() == OriginalBase; |
519 |
| - Fn(RelatedVD, SameBase, NamesSeen[RelatedVD->getName()] > 1); |
520 |
| - } |
| 528 | + for (auto result : RelatedDecls) |
| 529 | + Fn(result, typeLookup, NamesSeen[result->getName()] > 1); |
521 | 530 | }
|
522 | 531 |
|
523 | 532 | //===----------------------------------------------------------------------===//
|
|
0 commit comments