From c54aed6c27122f6565fd64a04850f544f24f63c9 Mon Sep 17 00:00:00 2001 From: Gogul Balakrishnan Date: Fri, 1 Mar 2019 15:14:18 -0800 Subject: [PATCH] Added three versions of finishLookups. --- include/swift/AST/DebuggerClient.h | 21 +++++++++++++---- lib/AST/NameLookup.cpp | 37 +++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/include/swift/AST/DebuggerClient.h b/include/swift/AST/DebuggerClient.h index eb8960ed997c2..c46e952a40f4a 100644 --- a/include/swift/AST/DebuggerClient.h +++ b/include/swift/AST/DebuggerClient.h @@ -61,10 +61,23 @@ class DebuggerClient { SourceLoc Loc, bool IsTypeLookup, ResultVector &RV) = 0; - /// Allows the DebuggerClient to prune the results of a name lookup before - /// returning to the caller. (See finishLookup in NameLookup.cpp.) - virtual void finishLookup(const DeclContext *dc, NLOptions options, - SmallVectorImpl &decls) {} + /// The following functions allow the debugger to prune the results of a a + /// qualfied lookup as needed. See the corresponding finishLookupInXYZ + /// functions defined in NameLookup.cpp. + /// + + 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. diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 6687ba1195c85..c1ac69c3dc94b 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -1369,7 +1369,38 @@ bool namelookup::finishLookup(const DeclContext *dc, NLOptions options, removeShadowedDecls(decls, M); filterForDiscriminator(decls, M->getDebugClient()); +} + +static bool finishLookupInNominals(const DeclContext *dc, + ArrayRef types, + DeclName member, NLOptions options, + SmallVectorImpl &decls) { + finishLookup(dc, options, decls); + if (auto *debugClient = dc->getParentModule()->getDebugClient()) { + debugClient->finishLookupInNominals(dc, types, member, options, decls); + } + // We're done. Report success/failure. + return !decls.empty(); +} +static bool finishLookupInModule(const DeclContext *dc, ModuleDecl *module, + DeclName member, NLOptions options, + SmallVectorImpl &decls) { + finishLookup(dc, options, decls); + if (auto *debugClient = dc->getParentModule()->getDebugClient()) { + debugClient->finishLookupInModule(dc, module, member, options, decls); + } + // We're done. Report success/failure. + return !decls.empty(); +} + +static bool finishLookupInAnyObject(const DeclContext *dc, DeclName member, + NLOptions options, + SmallVectorImpl &decls) { + finishLookup(dc, options, decls); + if (auto *debugClient = dc->getParentModule()->getDebugClient()) { + debugClient->finishLookupInAnyObject(dc, member, options, decls); + } // We're done. Report success/failure. return !decls.empty(); } @@ -1575,7 +1606,7 @@ bool DeclContext::lookupQualified(ArrayRef typeDecls, } } - return finishLookup(this, options, decls); + return finishLookupInNominals(this, typeDecls, member, options, decls); } bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member, @@ -1627,7 +1658,7 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member, return !knownDecls.insert(vd).second; }), decls.end()); - return finishLookup(this, options, decls); + return finishLookupInModule(this, module, member, options, decls); } bool DeclContext::lookupAnyObject(DeclName member, NLOptions options, @@ -1682,7 +1713,7 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options, decls.push_back(decl); } - return finishLookup(this, options, decls); + return finishLookupInAnyObject(this, member, options, decls); } void DeclContext::lookupAllObjCMethods(