aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/ExtractAPI/ExtractAPIConsumer.cpp')
-rw-r--r--clang/lib/ExtractAPI/ExtractAPIConsumer.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index eb533a934367..fe282dfb19e8 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -17,6 +17,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/FileEntry.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
@@ -167,6 +168,12 @@ std::optional<std::string> getRelativeIncludeName(const CompilerInstance &CI,
return std::nullopt;
}
+std::optional<std::string> getRelativeIncludeName(const CompilerInstance &CI,
+ FileEntryRef FE,
+ bool *IsQuoted = nullptr) {
+ return getRelativeIncludeName(CI, FE.getNameAsRequested(), IsQuoted);
+}
+
struct LocationFileChecker {
bool operator()(SourceLocation Loc) {
// If the loc refers to a macro expansion we need to first get the file
@@ -177,35 +184,31 @@ struct LocationFileChecker {
if (FID.isInvalid())
return false;
- const auto *File = SM.getFileEntryForID(FID);
+ OptionalFileEntryRef File = SM.getFileEntryRefForID(FID);
if (!File)
return false;
- if (KnownFileEntries.count(File))
+ if (KnownFileEntries.count(*File))
return true;
- if (ExternalFileEntries.count(File))
+ if (ExternalFileEntries.count(*File))
return false;
- StringRef FileName = File->tryGetRealPathName().empty()
- ? File->getName()
- : File->tryGetRealPathName();
-
// Try to reduce the include name the same way we tried to include it.
bool IsQuoted = false;
- if (auto IncludeName = getRelativeIncludeName(CI, FileName, &IsQuoted))
+ if (auto IncludeName = getRelativeIncludeName(CI, *File, &IsQuoted))
if (llvm::any_of(KnownFiles,
[&IsQuoted, &IncludeName](const auto &KnownFile) {
return KnownFile.first.equals(*IncludeName) &&
KnownFile.second == IsQuoted;
})) {
- KnownFileEntries.insert(File);
+ KnownFileEntries.insert(*File);
return true;
}
// Record that the file was not found to avoid future reverse lookup for
// the same file.
- ExternalFileEntries.insert(File);
+ ExternalFileEntries.insert(*File);
return false;
}