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 all 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
19 changes: 19 additions & 0 deletions include/swift/AST/DebuggerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
6 changes: 3 additions & 3 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueDecl *> &decls);
void pruneLookupResultSet(const DeclContext *dc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls);

/// Do nothing if debugClient is null.
template <typename Result>
Expand Down
30 changes: 22 additions & 8 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,8 @@ static bool isAcceptableLookupResult(const DeclContext *dc,
return true;
}

bool namelookup::finishLookup(const DeclContext *dc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) {
void namelookup::pruneLookupResultSet(const DeclContext *dc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) {
// If we're supposed to remove overridden declarations, do so now.
if (options & NL_RemoveOverridden)
removeOverriddenDecls(decls);
Expand All @@ -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
Expand Down Expand Up @@ -1574,7 +1571,13 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> 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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down