Have ASTUnit::Save() return a bool to indicate save error.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 26 Sep 2012 16:39:46 +0000 (16:39 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 26 Sep 2012 16:39:46 +0000 (16:39 +0000)
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
lib/Frontend/ASTUnit.cpp
tools/libclang/CIndex.cpp

index 9e4db4413d0e6398bc897fb52ae380a3f44da560..5e69abb9aeba520bfe134514ee2fba289f5387a8 100644 (file)
@@ -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.
   ///
index cb7ff1efd31eb2458bfe46f47b28dcb30d2a4962..c6c710a67a580ff5186378353f445541a373b9b4 100644 (file)
@@ -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) {
index 2ca5f10271a68095dce7a05d6063e272762d7d11..f1080f68e800d01de9db4e489e8005f2543bdcf9 100644 (file)
@@ -2717,7 +2717,8 @@ static void clang_saveTranslationUnit_Impl(void *UserData) {
   if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
     setThreadBackgroundPriority();
 
-  STUI->result = static_cast<ASTUnit *>(STUI->TU->TUData)->Save(STUI->FileName);
+  bool hadError = static_cast<ASTUnit *>(STUI->TU->TUData)->Save(STUI->FileName);
+  STUI->result = hadError ? CXSaveError_Unknown : CXSaveError_None;
 }
 
 int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,