1515#include " clang/Rewrite/Core/Rewriter.h"
1616#include " clang/Basic/Diagnostic.h"
1717#include " clang/Basic/DiagnosticIDs.h"
18- #include " clang/Basic/FileManager.h"
1918#include " clang/Basic/SourceManager.h"
2019#include " clang/Lex/Lexer.h"
2120#include " llvm/ADT/SmallString.h"
22- #include " llvm/Config/llvm-config.h"
2321#include " llvm/Support/FileSystem.h"
2422#include " llvm/Support/raw_ostream.h"
2523using namespace clang ;
@@ -33,9 +31,10 @@ raw_ostream &RewriteBuffer::write(raw_ostream &os) const {
3331 return os;
3432}
3533
34+ namespace {
3635// / \brief Return true if this character is non-new-line whitespace:
3736// / ' ', '\\t', '\\f', '\\v', '\\r'.
38- static inline bool isWhitespace (unsigned char c) {
37+ inline bool isWhitespaceExceptNL (unsigned char c) {
3938 switch (c) {
4039 case ' ' :
4140 case ' \t ' :
@@ -47,6 +46,7 @@ static inline bool isWhitespace(unsigned char c) {
4746 return false ;
4847 }
4948}
49+ }
5050
5151void RewriteBuffer::RemoveText (unsigned OrigOffset, unsigned Size,
5252 bool removeLineIfEmpty) {
@@ -80,7 +80,7 @@ void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size,
8080
8181 unsigned lineSize = 0 ;
8282 posI = curLineStart;
83- while (posI != end () && isWhitespace (*posI)) {
83+ while (posI != end () && isWhitespaceExceptNL (*posI)) {
8484 ++posI;
8585 ++lineSize;
8686 }
@@ -256,7 +256,7 @@ bool Rewriter::InsertText(SourceLocation Loc, StringRef Str,
256256 StringRef indentSpace;
257257 {
258258 unsigned i = lineOffs;
259- while (isWhitespace (MB[i]))
259+ while (isWhitespaceExceptNL (MB[i]))
260260 ++i;
261261 indentSpace = MB.substr (lineOffs, i-lineOffs);
262262 }
@@ -363,12 +363,12 @@ bool Rewriter::IncreaseIndentation(CharSourceRange range,
363363 StringRef parentSpace, startSpace;
364364 {
365365 unsigned i = parentLineOffs;
366- while (isWhitespace (MB[i]))
366+ while (isWhitespaceExceptNL (MB[i]))
367367 ++i;
368368 parentSpace = MB.substr (parentLineOffs, i-parentLineOffs);
369369
370370 i = startLineOffs;
371- while (isWhitespace (MB[i]))
371+ while (isWhitespaceExceptNL (MB[i]))
372372 ++i;
373373 startSpace = MB.substr (startLineOffs, i-startLineOffs);
374374 }
@@ -384,7 +384,7 @@ bool Rewriter::IncreaseIndentation(CharSourceRange range,
384384 for (unsigned lineNo = startLineNo; lineNo <= endLineNo; ++lineNo) {
385385 unsigned offs = Content->SourceLineCache [lineNo];
386386 unsigned i = offs;
387- while (isWhitespace (MB[i]))
387+ while (isWhitespaceExceptNL (MB[i]))
388388 ++i;
389389 StringRef origIndent = MB.substr (offs, i-offs);
390390 if (origIndent.startswith (startSpace))
@@ -409,7 +409,7 @@ class AtomicallyMovedFile {
409409 TempFilename = Filename;
410410 TempFilename += " -%%%%%%%%" ;
411411 int FD;
412- if (llvm::sys::fs::createUniqueFile (TempFilename. str () , FD, TempFilename)) {
412+ if (llvm::sys::fs::createUniqueFile (TempFilename, FD, TempFilename)) {
413413 AllWritten = false ;
414414 Diagnostics.Report (clang::diag::err_unable_to_make_temp)
415415 << TempFilename;
@@ -421,19 +421,15 @@ class AtomicallyMovedFile {
421421 ~AtomicallyMovedFile () {
422422 if (!ok ()) return ;
423423
424- FileStream->flush ();
425- #ifdef LLVM_ON_WIN32
426- // Win32 does not allow rename/removing opened files.
427- FileStream.reset ();
428- #endif
429- if (std::error_code ec =
430- llvm::sys::fs::rename (TempFilename.str (), Filename)) {
424+ // Close (will also flush) theFileStream.
425+ FileStream->close ();
426+ if (std::error_code ec = llvm::sys::fs::rename (TempFilename, Filename)) {
431427 AllWritten = false ;
432428 Diagnostics.Report (clang::diag::err_unable_to_rename_temp)
433429 << TempFilename << Filename << ec.message ();
434430 // If the remove fails, there's not a lot we can do - this is already an
435431 // error.
436- llvm::sys::fs::remove (TempFilename. str () );
432+ llvm::sys::fs::remove (TempFilename);
437433 }
438434 }
439435
0 commit comments