Skip to content

Commit

Permalink
Added three versions of finishLookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgogul committed Mar 1, 2019
1 parent 6c603c4 commit c54aed6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
21 changes: 17 additions & 4 deletions include/swift/AST/DebuggerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueDecl *> &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<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.
Expand Down
37 changes: 34 additions & 3 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -1575,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 @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c54aed6

Please sign in to comment.