Have ASTUnit::Save() return a bool to indicate save error.
Removes a dependency of ASTUnit to clang-c/Index.h. llvm-svn: 164704
This commit is contained in:
parent
df461db533
commit
39a76387e0
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue