forked from OSchip/llvm-project
Rename highly-confusing isWhitespace that returns false on \n to
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. llvm-svn: 243260
This commit is contained in:
parent
9b88a4cdf4
commit
a96ffd5337
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue