Skip to content

Commit 1fa3846

Browse files
authored
Add more hooks for overriding name lookup in the DebuggerClient (#23031)
1 parent 7969705 commit 1fa3846

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

include/swift/AST/DebuggerClient.h

+19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ class DebuggerClient {
6161
SourceLoc Loc, bool IsTypeLookup,
6262
ResultVector &RV) = 0;
6363

64+
/// The following functions allow the debugger to modify the results of a
65+
/// qualfied lookup as needed. These methods may add, remove or modify the
66+
/// entries in `decls`. See the corresponding DeclContext::lookupInXYZ
67+
/// functions defined in NameLookup.cpp for more context.
68+
///
69+
70+
virtual void finishLookupInNominals(const DeclContext *dc,
71+
ArrayRef<NominalTypeDecl *> types,
72+
DeclName member, NLOptions options,
73+
SmallVectorImpl<ValueDecl *> &decls) {}
74+
75+
virtual void finishLookupInModule(const DeclContext *dc, ModuleDecl *module,
76+
DeclName member, NLOptions options,
77+
SmallVectorImpl<ValueDecl *> &decls) {}
78+
79+
virtual void finishLookupInAnyObject(const DeclContext *dc, DeclName member,
80+
NLOptions options,
81+
SmallVectorImpl<ValueDecl *> &decls) {}
82+
6483
/// When evaluating an expression in the context of an existing source file,
6584
/// we may want to prefer declarations from that source file.
6685
/// The DebuggerClient can return a private-discriminator to tell lookup to

include/swift/AST/NameLookup.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ void forAllVisibleModules(const DeclContext *DC, const Fn &fn) {
367367
->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn);
368368
}
369369

370-
/// Only name lookup has gathered a set of results, perform any necessary
370+
/// Once name lookup has gathered a set of results, perform any necessary
371371
/// steps to prune the result set before returning it to the caller.
372-
bool finishLookup(const DeclContext *dc, NLOptions options,
373-
SmallVectorImpl<ValueDecl *> &decls);
372+
void pruneLookupResultSet(const DeclContext *dc, NLOptions options,
373+
SmallVectorImpl<ValueDecl *> &decls);
374374

375375
/// Do nothing if debugClient is null.
376376
template <typename Result>

lib/AST/NameLookup.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,8 @@ static bool isAcceptableLookupResult(const DeclContext *dc,
13561356
return true;
13571357
}
13581358

1359-
bool namelookup::finishLookup(const DeclContext *dc, NLOptions options,
1360-
SmallVectorImpl<ValueDecl *> &decls) {
1359+
void namelookup::pruneLookupResultSet(const DeclContext *dc, NLOptions options,
1360+
SmallVectorImpl<ValueDecl *> &decls) {
13611361
// If we're supposed to remove overridden declarations, do so now.
13621362
if (options & NL_RemoveOverridden)
13631363
removeOverriddenDecls(decls);
@@ -1368,9 +1368,6 @@ bool namelookup::finishLookup(const DeclContext *dc, NLOptions options,
13681368
removeShadowedDecls(decls, M);
13691369

13701370
filterForDiscriminator(decls, M->getDebugClient());
1371-
1372-
// We're done. Report success/failure.
1373-
return !decls.empty();
13741371
}
13751372

13761373
/// Inspect the given type to determine which nominal type declarations it
@@ -1574,7 +1571,13 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
15741571
}
15751572
}
15761573

1577-
return finishLookup(this, options, decls);
1574+
pruneLookupResultSet(this, options, decls);
1575+
if (auto *debugClient = this->getParentModule()->getDebugClient()) {
1576+
debugClient->finishLookupInNominals(this, typeDecls, member, options,
1577+
decls);
1578+
}
1579+
// We're done. Report success/failure.
1580+
return !decls.empty();
15781581
}
15791582

15801583
bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
@@ -1626,7 +1629,13 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
16261629
return !knownDecls.insert(vd).second;
16271630
}), decls.end());
16281631

1629-
return finishLookup(this, options, decls);
1632+
pruneLookupResultSet(this, options, decls);
1633+
1634+
if (auto *debugClient = this->getParentModule()->getDebugClient()) {
1635+
debugClient->finishLookupInModule(this, module, member, options, decls);
1636+
}
1637+
// We're done. Report success/failure.
1638+
return !decls.empty();
16301639
}
16311640

16321641
bool DeclContext::lookupAnyObject(DeclName member, NLOptions options,
@@ -1681,7 +1690,12 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options,
16811690
decls.push_back(decl);
16821691
}
16831692

1684-
return finishLookup(this, options, decls);
1693+
pruneLookupResultSet(this, options, decls);
1694+
if (auto *debugClient = this->getParentModule()->getDebugClient()) {
1695+
debugClient->finishLookupInAnyObject(this, member, options, decls);
1696+
}
1697+
// We're done. Report success/failure.
1698+
return !decls.empty();
16851699
}
16861700

16871701
void DeclContext::lookupAllObjCMethods(

0 commit comments

Comments
 (0)