Skip to content

Add more hooks for overriding name lookup in the DebuggerClient #23031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/swift/AST/DebuggerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ class DebuggerClient {
SourceLoc Loc, bool IsTypeLookup,
ResultVector &RV) = 0;

/// 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<NominalTypeDecl *> types,
DeclName member, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) {}

virtual void finishLookupInModule(const DeclContext *dc, ModuleDecl *module,
DeclName member, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) {}

virtual void finishLookupInAnyObject(const DeclContext *dc, DeclName member,
NLOptions options,
SmallVectorImpl<ValueDecl *> &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
Expand Down
38 changes: 35 additions & 3 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/DebuggerClient.h"
#include "swift/AST/DeclContext.h"
#include "swift/AST/ExistentialLayout.h"
#include "swift/AST/LazyResolver.h"
#include "swift/AST/Initializer.h"
Expand Down Expand Up @@ -1368,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<NominalTypeDecl *> types,
DeclName member, NLOptions options,
SmallVectorImpl<ValueDecl *> &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<ValueDecl *> &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<ValueDecl *> &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();
}
Expand Down Expand Up @@ -1574,7 +1606,7 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
}
}

return finishLookup(this, options, decls);
return finishLookupInNominals(this, typeDecls, member, options, decls);
}

bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
Expand Down Expand Up @@ -1626,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,
Expand Down Expand Up @@ -1681,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(
Expand Down