summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarlan Haskins <harlan@harlanhaskins.com>2019-08-01 21:32:01 +0000
committerHarlan Haskins <harlan@harlanhaskins.com>2019-08-01 21:32:01 +0000
commita02f85768d2d1a77c7735ddd43226e1be51f3730 (patch)
tree331b92c088cb3249848f387a358206770da95180
parent8d323d150610bed1feeb79d7a29c9958a4c8bcac (diff)
downloadbcm5719-llvm-a02f85768d2d1a77c7735ddd43226e1be51f3730.tar.gz
bcm5719-llvm-a02f85768d2d1a77c7735ddd43226e1be51f3730.zip
[clang-tools-extra] Adopt FileManager's error-returning APIs
The FileManager has been updated to return llvm::ErrorOr from getFile and getDirectory, this commit updates all the callers of those APIs from clang. llvm-svn: 367617
-rw-r--r--clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp6
-rw-r--r--clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp8
-rw-r--r--clang-tools-extra/clang-include-fixer/IncludeFixer.cpp5
-rw-r--r--clang-tools-extra/clang-move/Move.cpp10
-rw-r--r--clang-tools-extra/clang-move/tool/ClangMove.cpp4
-rw-r--r--clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidy.cpp7
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp3
-rw-r--r--clang-tools-extra/clangd/SourceCode.cpp4
-rw-r--r--clang-tools-extra/clangd/index/SymbolCollector.cpp7
-rw-r--r--clang-tools-extra/modularize/ModularizeUtilities.cpp15
11 files changed, 41 insertions, 32 deletions
diff --git a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
index 4a6707bae3a..6a8366465ca 100644
--- a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -151,13 +151,13 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
auto AddToGroup = [&](const tooling::Replacement &R, bool FromDiag) {
// Use the file manager to deduplicate paths. FileEntries are
// automatically canonicalized.
- if (const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath())) {
+ if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) {
if (FromDiag) {
- auto &Replaces = DiagReplacements[Entry];
+ auto &Replaces = DiagReplacements[*Entry];
if (!Replaces.insert(R).second)
return;
}
- GroupedReplacements[Entry].push_back(R);
+ GroupedReplacements[*Entry].push_back(R);
} else if (Warned.insert(R.getFilePath()).second) {
errs() << "Described file '" << R.getFilePath()
<< "' doesn't exist. Ignoring...\n";
diff --git a/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp b/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
index d5f06552e39..a97be99b0bd 100644
--- a/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
+++ b/clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp
@@ -147,8 +147,8 @@ int main(int argc, const char **argv) {
for (auto I = ChangedFiles.begin(), E = ChangedFiles.end(); I != E; ++I) {
OS << " {\n";
OS << " \"FilePath\": \"" << *I << "\",\n";
- const auto *Entry = FileMgr.getFile(*I);
- auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User);
+ const auto Entry = FileMgr.getFile(*I);
+ auto ID = Sources.getOrCreateFileID(*Entry, SrcMgr::C_User);
std::string Content;
llvm::raw_string_ostream ContentStream(Content);
Rewrite.getEditBuffer(ID).write(ContentStream);
@@ -165,9 +165,9 @@ int main(int argc, const char **argv) {
}
for (const auto &File : ChangedFiles) {
- const auto *Entry = FileMgr.getFile(File);
+ const auto Entry = FileMgr.getFile(File);
- auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User);
+ auto ID = Sources.getOrCreateFileID(*Entry, SrcMgr::C_User);
outs() << "============== " << File << " ==============\n";
Rewrite.getEditBuffer(ID).write(llvm::outs());
outs() << "\n============================================\n";
diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
index c4173426277..c07add2c760 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
@@ -306,8 +306,7 @@ std::string IncludeFixerSemaSource::minimizeInclude(
// Get the FileEntry for the include.
StringRef StrippedInclude = Include.trim("\"<>");
- const FileEntry *Entry =
- SourceManager.getFileManager().getFile(StrippedInclude);
+ auto Entry = SourceManager.getFileManager().getFile(StrippedInclude);
// If the file doesn't exist return the path from the database.
// FIXME: This should never happen.
@@ -316,7 +315,7 @@ std::string IncludeFixerSemaSource::minimizeInclude(
bool IsSystem = false;
std::string Suggestion =
- HeaderSearch.suggestPathToFileForDiagnostics(Entry, "", &IsSystem);
+ HeaderSearch.suggestPathToFileForDiagnostics(*Entry, "", &IsSystem);
return IsSystem ? '<' + Suggestion + '>' : '"' + Suggestion + '"';
}
diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp
index efb67c68adb..e8438935c84 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -92,10 +92,10 @@ std::string MakeAbsolutePath(const SourceManager &SM, StringRef Path) {
<< '\n';
// Handle symbolic link path cases.
// We are trying to get the real file path of the symlink.
- const DirectoryEntry *Dir = SM.getFileManager().getDirectory(
+ auto Dir = SM.getFileManager().getDirectory(
llvm::sys::path::parent_path(AbsolutePath.str()));
if (Dir) {
- StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
+ StringRef DirName = SM.getFileManager().getCanonicalName(*Dir);
// FIXME: getCanonicalName might fail to get real path on VFS.
if (llvm::sys::path::is_absolute(DirName)) {
SmallString<128> AbsoluteFilename;
@@ -115,7 +115,7 @@ AST_POLYMORPHIC_MATCHER_P(isExpansionInFile,
auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
if (ExpansionLoc.isInvalid())
return false;
- auto FileEntry =
+ auto *FileEntry =
SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc));
if (!FileEntry)
return false;
@@ -842,12 +842,12 @@ void ClangMoveTool::moveDeclsToNewFiles() {
// Move all contents from OldFile to NewFile.
void ClangMoveTool::moveAll(SourceManager &SM, StringRef OldFile,
StringRef NewFile) {
- const FileEntry *FE = SM.getFileManager().getFile(makeAbsolutePath(OldFile));
+ auto FE = SM.getFileManager().getFile(makeAbsolutePath(OldFile));
if (!FE) {
llvm::errs() << "Failed to get file: " << OldFile << "\n";
return;
}
- FileID ID = SM.getOrCreateFileID(FE, SrcMgr::C_User);
+ FileID ID = SM.getOrCreateFileID(*FE, SrcMgr::C_User);
auto Begin = SM.getLocForStartOfFile(ID);
auto End = SM.getLocForEndOfFile(ID);
tooling::Replacement RemoveAll(SM, CharSourceRange::getCharRange(Begin, End),
diff --git a/clang-tools-extra/clang-move/tool/ClangMove.cpp b/clang-tools-extra/clang-move/tool/ClangMove.cpp
index 807425bb742..3b0d15f6535 100644
--- a/clang-tools-extra/clang-move/tool/ClangMove.cpp
+++ b/clang-tools-extra/clang-move/tool/ClangMove.cpp
@@ -191,8 +191,8 @@ int main(int argc, const char **argv) {
for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
OS << " {\n";
OS << " \"FilePath\": \"" << *I << "\",\n";
- const auto *Entry = FileMgr.getFile(*I);
- auto ID = SM.translateFile(Entry);
+ const auto Entry = FileMgr.getFile(*I);
+ auto ID = SM.translateFile(*Entry);
std::string Content;
llvm::raw_string_ostream ContentStream(Content);
Rewrite.getEditBuffer(ID).write(ContentStream);
diff --git a/clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp b/clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
index bae3f4c6651..5150dc4bc55 100644
--- a/clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ b/clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -78,8 +78,8 @@ int main(int argc, const char **argv) {
Tool.applyAllReplacements(Rewrite);
for (const auto &File : Files) {
- const auto *Entry = FileMgr.getFile(File);
- const auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User);
+ auto Entry = FileMgr.getFile(File);
+ const auto ID = Sources.getOrCreateFileID(*Entry, SrcMgr::C_User);
Rewrite.getEditBuffer(ID).write(outs());
}
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 1d813d65f8d..f0ef809338b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -236,8 +236,11 @@ private:
if (FilePath.empty())
return SourceLocation();
- const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
- FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
+ auto File = SourceMgr.getFileManager().getFile(FilePath);
+ if (!File)
+ return SourceLocation();
+
+ FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
}
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index 35c0dcd47d2..076c73acf98 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -236,7 +236,8 @@ private:
for (const auto &Inc : Includes.MainFileIncludes) {
const FileEntry *File = nullptr;
if (Inc.Resolved != "")
- File = SM.getFileManager().getFile(Inc.Resolved);
+ if (auto FE = SM.getFileManager().getFile(Inc.Resolved))
+ File = *FE;
llvm::StringRef WrittenFilename =
llvm::StringRef(Inc.Written).drop_front().drop_back();
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index d9911647a5f..eb9eb48cc48 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -442,10 +442,10 @@ llvm::Optional<std::string> getCanonicalPath(const FileEntry *F,
//
// The file path of Symbol is "/project/src/foo.h" instead of
// "/tmp/build/foo.h"
- if (const DirectoryEntry *Dir = SourceMgr.getFileManager().getDirectory(
+ if (auto Dir = SourceMgr.getFileManager().getDirectory(
llvm::sys::path::parent_path(FilePath))) {
llvm::SmallString<128> RealPath;
- llvm::StringRef DirName = SourceMgr.getFileManager().getCanonicalName(Dir);
+ llvm::StringRef DirName = SourceMgr.getFileManager().getCanonicalName(*Dir);
llvm::sys::path::append(RealPath, DirName,
llvm::sys::path::filename(FilePath));
return RealPath.str().str();
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index cca8b004ca3..cc4217ad741 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -56,9 +56,10 @@ const NamedDecl &getTemplateOrThis(const NamedDecl &ND) {
std::string toURI(const SourceManager &SM, llvm::StringRef Path,
const SymbolCollector::Options &Opts) {
llvm::SmallString<128> AbsolutePath(Path);
- if (auto CanonPath =
- getCanonicalPath(SM.getFileManager().getFile(Path), SM)) {
- AbsolutePath = *CanonPath;
+ if (auto File = SM.getFileManager().getFile(Path)) {
+ if (auto CanonPath = getCanonicalPath(*File, SM)) {
+ AbsolutePath = *CanonPath;
+ }
}
// We don't perform is_absolute check in an else branch because makeAbsolute
// might return a relative path on some InMemoryFileSystems.
diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index c4e13abcc25..f11273dda75 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -258,14 +258,15 @@ std::error_code ModularizeUtilities::loadProblemHeaderList(
std::error_code ModularizeUtilities::loadModuleMap(
llvm::StringRef InputPath) {
// Get file entry for module.modulemap file.
- const FileEntry *ModuleMapEntry =
+ auto ModuleMapEntryOrErr =
SourceMgr->getFileManager().getFile(InputPath);
// return error if not found.
- if (!ModuleMapEntry) {
+ if (!ModuleMapEntryOrErr) {
llvm::errs() << "error: File \"" << InputPath << "\" not found.\n";
- return std::error_code(1, std::generic_category());
+ return ModuleMapEntryOrErr.getError();
}
+ const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr;
// Because the module map parser uses a ForwardingDiagnosticConsumer,
// which doesn't forward the BeginSourceFile call, we do it explicitly here.
@@ -276,8 +277,12 @@ std::error_code ModularizeUtilities::loadModuleMap(
StringRef DirName(Dir->getName());
if (llvm::sys::path::filename(DirName) == "Modules") {
DirName = llvm::sys::path::parent_path(DirName);
- if (DirName.endswith(".framework"))
- Dir = FileMgr->getDirectory(DirName);
+ if (DirName.endswith(".framework")) {
+ if (auto DirEntry = FileMgr->getDirectory(DirName))
+ Dir = *DirEntry;
+ else
+ Dir = nullptr;
+ }
// FIXME: This assert can fail if there's a race between the above check
// and the removal of the directory.
assert(Dir && "parent must exist");
OpenPOWER on IntegriCloud