[AST] Hack SourceFile::lookupLocalType() to look through local types.

This is only currently exercised by swift-remoteast-test, so do the
minimum to ensure that we’re getting cached mangled names, but don’t
fret over the linear-time search.
This commit is contained in:
Doug Gregor
2019-01-25 17:08:34 -08:00
parent 2be98a232e
commit 9bf404380f
2 changed files with 19 additions and 0 deletions

View File

@@ -32,6 +32,7 @@
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PrintOptions.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/Statistic.h"
@@ -565,6 +566,22 @@ void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
Results.append(LocalTypeDecls.begin(), LocalTypeDecls.end());
}
TypeDecl *SourceFile::lookupLocalType(llvm::StringRef mangledName) const {
ASTContext &ctx = getASTContext();
for (auto typeDecl : LocalTypeDecls) {
auto typeMangledName = evaluateOrDefault(ctx.evaluator,
USRGenerationRequest { typeDecl },
std::string());
if (typeMangledName.find("s:") == 0)
typeMangledName = typeMangledName.substr(2);
if (mangledName == typeMangledName)
return typeDecl;
}
return nullptr;
}
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
// FIXME: Should this do extra access control filtering?
FORWARD(getDisplayDecls, (Results));