summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp b/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp
index be09a36..ae41dec 100644
--- a/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp
+++ b/contrib/llvm/tools/clang/lib/Rewrite/Rewriter.cpp
@@ -15,11 +15,9 @@
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticIDs.h"
-#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/Config/llvm-config.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
@@ -35,7 +33,7 @@ raw_ostream &RewriteBuffer::write(raw_ostream &os) const {
/// \brief Return true if this character is non-new-line whitespace:
/// ' ', '\\t', '\\f', '\\v', '\\r'.
-static inline bool isWhitespace(unsigned char c) {
+static inline bool isWhitespaceExceptNL(unsigned char c) {
switch (c) {
case ' ':
case '\t':
@@ -80,7 +78,7 @@ void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size,
unsigned lineSize = 0;
posI = curLineStart;
- while (posI != end() && isWhitespace(*posI)) {
+ while (posI != end() && isWhitespaceExceptNL(*posI)) {
++posI;
++lineSize;
}
@@ -256,7 +254,7 @@ bool Rewriter::InsertText(SourceLocation Loc, StringRef Str,
StringRef indentSpace;
{
unsigned i = lineOffs;
- while (isWhitespace(MB[i]))
+ while (isWhitespaceExceptNL(MB[i]))
++i;
indentSpace = MB.substr(lineOffs, i-lineOffs);
}
@@ -363,12 +361,12 @@ bool Rewriter::IncreaseIndentation(CharSourceRange range,
StringRef parentSpace, startSpace;
{
unsigned i = parentLineOffs;
- while (isWhitespace(MB[i]))
+ while (isWhitespaceExceptNL(MB[i]))
++i;
parentSpace = MB.substr(parentLineOffs, i-parentLineOffs);
i = startLineOffs;
- while (isWhitespace(MB[i]))
+ while (isWhitespaceExceptNL(MB[i]))
++i;
startSpace = MB.substr(startLineOffs, i-startLineOffs);
}
@@ -384,7 +382,7 @@ bool Rewriter::IncreaseIndentation(CharSourceRange range,
for (unsigned lineNo = startLineNo; lineNo <= endLineNo; ++lineNo) {
unsigned offs = Content->SourceLineCache[lineNo];
unsigned i = offs;
- while (isWhitespace(MB[i]))
+ while (isWhitespaceExceptNL(MB[i]))
++i;
StringRef origIndent = MB.substr(offs, i-offs);
if (origIndent.startswith(startSpace))
@@ -409,7 +407,7 @@ public:
TempFilename = Filename;
TempFilename += "-%%%%%%%%";
int FD;
- if (llvm::sys::fs::createUniqueFile(TempFilename.str(), FD, TempFilename)) {
+ if (llvm::sys::fs::createUniqueFile(TempFilename, FD, TempFilename)) {
AllWritten = false;
Diagnostics.Report(clang::diag::err_unable_to_make_temp)
<< TempFilename;
@@ -421,19 +419,15 @@ public:
~AtomicallyMovedFile() {
if (!ok()) return;
- FileStream->flush();
-#ifdef LLVM_ON_WIN32
- // Win32 does not allow rename/removing opened files.
- FileStream.reset();
-#endif
- if (std::error_code ec =
- llvm::sys::fs::rename(TempFilename.str(), Filename)) {
+ // Close (will also flush) theFileStream.
+ FileStream->close();
+ if (std::error_code ec = llvm::sys::fs::rename(TempFilename, Filename)) {
AllWritten = false;
Diagnostics.Report(clang::diag::err_unable_to_rename_temp)
<< TempFilename << Filename << ec.message();
// If the remove fails, there's not a lot we can do - this is already an
// error.
- llvm::sys::fs::remove(TempFilename.str());
+ llvm::sys::fs::remove(TempFilename);
}
}
OpenPOWER on IntegriCloud