mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SourceKit: Refactor walkRelatedDecls() to not use unqualified lookup
This function used to perform an unqualified lookup without a source location, to either find top-level members or members of a type. Since this form of unqualified lookup is no longer supported, let's instead explicitly call lookupInModule() or lookupQualified(), depending on whether we're looking inside a type or not.
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
#include "swift/AST/ASTDemangler.h"
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/LookupKinds.h"
|
||||
#include "swift/AST/ModuleNameLookup.h"
|
||||
#include "swift/AST/NameLookup.h"
|
||||
#include "swift/AST/NameLookupRequests.h"
|
||||
#include "swift/AST/SwiftNameTranslation.h"
|
||||
#include "swift/AST/GenericSignature.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
@@ -484,40 +485,48 @@ void SwiftLangSupport::printFullyAnnotatedSynthesizedDeclaration(
|
||||
|
||||
template <typename FnTy>
|
||||
void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
|
||||
llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen;
|
||||
++NamesSeen[VD->getName()];
|
||||
SmallVector<LookupResultEntry, 8> RelatedDecls;
|
||||
|
||||
if (isa<ParamDecl>(VD))
|
||||
return; // Parameters don't have interesting related declarations.
|
||||
|
||||
// FIXME: Extract useful related declarations, overloaded functions,
|
||||
// if VD is an initializer, we should extract other initializers etc.
|
||||
// For now we use unqualified lookup to fetch other declarations with the same
|
||||
// base name.
|
||||
auto &ctx = VD->getASTContext();
|
||||
auto descriptor = UnqualifiedLookupDescriptor(DeclNameRef(VD->getBaseName()),
|
||||
VD->getDeclContext());
|
||||
auto lookup = evaluateOrDefault(ctx.evaluator,
|
||||
UnqualifiedLookupRequest{descriptor}, {});
|
||||
for (auto result : lookup) {
|
||||
ValueDecl *RelatedVD = result.getValueDecl();
|
||||
if (RelatedVD->getAttrs().isUnavailable(VD->getASTContext()))
|
||||
|
||||
llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen;
|
||||
++NamesSeen[VD->getName()];
|
||||
|
||||
|
||||
auto *DC = VD->getDeclContext();
|
||||
bool typeLookup = DC->isTypeContext();
|
||||
|
||||
SmallVector<ValueDecl *, 4> results;
|
||||
|
||||
if (typeLookup) {
|
||||
auto type = DC->getDeclaredInterfaceType();
|
||||
if (!type->is<ErrorType>()) {
|
||||
DC->lookupQualified(type, DeclNameRef(VD->getBaseName()),
|
||||
NL_QualifiedDefault, results);
|
||||
}
|
||||
} else {
|
||||
namelookup::lookupInModule(DC->getModuleScopeContext(),
|
||||
VD->getBaseName(), results,
|
||||
NLKind::UnqualifiedLookup,
|
||||
namelookup::ResolutionKind::Overloadable,
|
||||
DC->getModuleScopeContext());
|
||||
}
|
||||
|
||||
SmallVector<ValueDecl *, 8> RelatedDecls;
|
||||
for (auto result : results) {
|
||||
if (result->getAttrs().isUnavailable(ctx))
|
||||
continue;
|
||||
|
||||
if (RelatedVD != VD) {
|
||||
++NamesSeen[RelatedVD->getName()];
|
||||
if (result != VD) {
|
||||
++NamesSeen[result->getName()];
|
||||
RelatedDecls.push_back(result);
|
||||
}
|
||||
}
|
||||
|
||||
// Now provide the results along with whether the name is duplicate or not.
|
||||
ValueDecl *OriginalBase = VD->getDeclContext()->getSelfNominalTypeDecl();
|
||||
for (auto Related : RelatedDecls) {
|
||||
ValueDecl *RelatedVD = Related.getValueDecl();
|
||||
bool SameBase = Related.getBaseDecl() && Related.getBaseDecl() == OriginalBase;
|
||||
Fn(RelatedVD, SameBase, NamesSeen[RelatedVD->getName()] > 1);
|
||||
}
|
||||
for (auto result : RelatedDecls)
|
||||
Fn(result, typeLookup, NamesSeen[result->getName()] > 1);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user