From e6d22027bc22d3767a2acdc80299c76b91159867 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 26 Sep 2012 16:39:46 +0000 Subject: [PATCH] Have ASTUnit::Save() return a bool to indicate save error. Removes a dependency of ASTUnit to clang-c/Index.h. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164704 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 5 +++-- lib/Frontend/ASTUnit.cpp | 10 +++++----- tools/libclang/CIndex.cpp | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 9e4db4413d..5e69abb9ae 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -792,8 +792,9 @@ public: /// \brief Save this translation unit to a file with the given name. /// - /// \returns An indication of whether the save was successful or not. - CXSaveError Save(StringRef File); + /// \returns true if there was a file error or false if the save was + /// successful. + bool Save(StringRef File); /// \brief Serialize this translation unit with the given output stream. /// diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index cb7ff1efd3..c6c710a67a 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -2475,7 +2475,7 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, checkAndSanitizeDiags(StoredDiagnostics, getSourceManager()); } -CXSaveError ASTUnit::Save(StringRef File) { +bool ASTUnit::Save(StringRef File) { // Write to a temporary file and later rename it to the actual file, to avoid // possible race conditions. SmallString<128> TempPath; @@ -2484,7 +2484,7 @@ CXSaveError ASTUnit::Save(StringRef File) { int fd; if (llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath, /*makeAbsolute=*/false)) - return CXSaveError_Unknown; + return true; // FIXME: Can we somehow regenerate the stat cache here, or do we need to // unconditionally create a stat cache when we parse the file? @@ -2494,16 +2494,16 @@ CXSaveError ASTUnit::Save(StringRef File) { Out.close(); if (Out.has_error()) { Out.clear_error(); - return CXSaveError_Unknown; + return true; } if (llvm::sys::fs::rename(TempPath.str(), File)) { bool exists; llvm::sys::fs::remove(TempPath.str(), exists); - return CXSaveError_Unknown; + return true; } - return CXSaveError_None; + return false; } bool ASTUnit::serialize(raw_ostream &OS) { diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 2ca5f10271..f1080f68e8 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2717,7 +2717,8 @@ static void clang_saveTranslationUnit_Impl(void *UserData) { if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) setThreadBackgroundPriority(); - STUI->result = static_cast(STUI->TU->TUData)->Save(STUI->FileName); + bool hadError = static_cast(STUI->TU->TUData)->Save(STUI->FileName); + STUI->result = hadError ? CXSaveError_Unknown : CXSaveError_None; } int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, -- 2.40.0