]> granicus.if.org Git - clang/commitdiff
Rename highly-confusing isWhitespace that returns false on \n to
authorYaron Keren <yaron.keren@gmail.com>
Mon, 27 Jul 2015 06:35:22 +0000 (06:35 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Mon, 27 Jul 2015 06:35:22 +0000 (06:35 +0000)
isWhitespaceExceptNL. If that's wasn't bad enough, we have an identically
named function in Basic/CharInfo.h.

While at it, remove unnecessary includes, .str() calls and #ifdef.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243260 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/Rewriter.cpp

index be09a363a61ff590f7a668b6514131b61fb79e2f..04d79f0ce6a143249ed86f0b84b0c7074504b779 100644 (file)
 #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;
@@ -33,9 +31,10 @@ raw_ostream &RewriteBuffer::write(raw_ostream &os) const {
   return os;
 }
 
+namespace {
 /// \brief Return true if this character is non-new-line whitespace:
 /// ' ', '\\t', '\\f', '\\v', '\\r'.
-static inline bool isWhitespace(unsigned char c) {
+inline bool isWhitespaceExceptNL(unsigned char c) {
   switch (c) {
   case ' ':
   case '\t':
@@ -47,6 +46,7 @@ static inline bool isWhitespace(unsigned char c) {
     return false;
   }
 }
+}
 
 void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size,
                                bool removeLineIfEmpty) {
@@ -80,7 +80,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 +256,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 +363,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 +384,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 +409,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 +421,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);
     }
   }