diff --git a/include/swift/AST/DebuggerClient.h b/include/swift/AST/DebuggerClient.h index b21d96be80312..b51207788b51d 100644 --- a/include/swift/AST/DebuggerClient.h +++ b/include/swift/AST/DebuggerClient.h @@ -61,6 +61,25 @@ class DebuggerClient { SourceLoc Loc, bool IsTypeLookup, ResultVector &RV) = 0; + /// The following functions allow the debugger to modify the results of a + /// qualfied lookup as needed. These methods may add, remove or modify the + /// entries in `decls`. See the corresponding DeclContext::lookupInXYZ + /// functions defined in NameLookup.cpp for more context. + /// + + virtual void finishLookupInNominals(const DeclContext *dc, + ArrayRef types, + DeclName member, NLOptions options, + SmallVectorImpl &decls) {} + + virtual void finishLookupInModule(const DeclContext *dc, ModuleDecl *module, + DeclName member, NLOptions options, + SmallVectorImpl &decls) {} + + virtual void finishLookupInAnyObject(const DeclContext *dc, DeclName member, + NLOptions options, + SmallVectorImpl &decls) {} + /// When evaluating an expression in the context of an existing source file, /// we may want to prefer declarations from that source file. /// The DebuggerClient can return a private-discriminator to tell lookup to diff --git a/include/swift/AST/NameLookup.h b/include/swift/AST/NameLookup.h index 263286989282d..18851ddca2299 100644 --- a/include/swift/AST/NameLookup.h +++ b/include/swift/AST/NameLookup.h @@ -367,10 +367,10 @@ void forAllVisibleModules(const DeclContext *DC, const Fn &fn) { ->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn); } -/// Only name lookup has gathered a set of results, perform any necessary +/// Once name lookup has gathered a set of results, perform any necessary /// steps to prune the result set before returning it to the caller. -bool finishLookup(const DeclContext *dc, NLOptions options, - SmallVectorImpl &decls); +void pruneLookupResultSet(const DeclContext *dc, NLOptions options, + SmallVectorImpl &decls); /// Do nothing if debugClient is null. template diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 9180840fffe26..b7b8e0e062a2a 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -1356,8 +1356,8 @@ static bool isAcceptableLookupResult(const DeclContext *dc, return true; } -bool namelookup::finishLookup(const DeclContext *dc, NLOptions options, - SmallVectorImpl &decls) { +void namelookup::pruneLookupResultSet(const DeclContext *dc, NLOptions options, + SmallVectorImpl &decls) { // If we're supposed to remove overridden declarations, do so now. if (options & NL_RemoveOverridden) removeOverriddenDecls(decls); @@ -1368,9 +1368,6 @@ bool namelookup::finishLookup(const DeclContext *dc, NLOptions options, removeShadowedDecls(decls, M); filterForDiscriminator(decls, M->getDebugClient()); - - // We're done. Report success/failure. - return !decls.empty(); } /// Inspect the given type to determine which nominal type declarations it @@ -1574,7 +1571,13 @@ bool DeclContext::lookupQualified(ArrayRef typeDecls, } } - return finishLookup(this, options, decls); + pruneLookupResultSet(this, options, decls); + if (auto *debugClient = this->getParentModule()->getDebugClient()) { + debugClient->finishLookupInNominals(this, typeDecls, member, options, + decls); + } + // We're done. Report success/failure. + return !decls.empty(); } bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member, @@ -1626,7 +1629,13 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member, return !knownDecls.insert(vd).second; }), decls.end()); - return finishLookup(this, options, decls); + pruneLookupResultSet(this, options, decls); + + if (auto *debugClient = this->getParentModule()->getDebugClient()) { + debugClient->finishLookupInModule(this, module, member, options, decls); + } + // We're done. Report success/failure. + return !decls.empty(); } bool DeclContext::lookupAnyObject(DeclName member, NLOptions options, @@ -1681,7 +1690,12 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options, decls.push_back(decl); } - return finishLookup(this, options, decls); + pruneLookupResultSet(this, options, decls); + if (auto *debugClient = this->getParentModule()->getDebugClient()) { + debugClient->finishLookupInAnyObject(this, member, options, decls); + } + // We're done. Report success/failure. + return !decls.empty(); } void DeclContext::lookupAllObjCMethods(