r176361 - Remove whitespace at end of file.
Daniel Jasper
djasper at google.com
Fri Mar 1 10:11:39 PST 2013
Author: djasper
Date: Fri Mar 1 12:11:39 2013
New Revision: 176361
URL: http://llvm.org/viewvc/llvm-project?rev=176361&view=rev
Log:
Remove whitespace at end of file.
This fixes the rest of llvm.org/PR15062.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=176361&r1=176360&r2=176361&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Mar 1 12:11:39 2013
@@ -1132,7 +1132,15 @@ public:
IndentForLevel.resize(TheLine.Level + 1);
bool WasMoved =
PreviousLineWasTouched && TheLine.First.FormatTok.NewlinesBefore == 0;
- if (TheLine.Type != LT_Invalid && (WasMoved || touchesRanges(TheLine))) {
+ if (TheLine.First.is(tok::eof)) {
+ if (PreviousLineWasTouched) {
+ unsigned NewLines =
+ std::min(TheLine.First.FormatTok.NewlinesBefore, 1u);
+ Whitespaces.replaceWhitespace(TheLine.First, NewLines, /*Indent*/ 0,
+ /*WhitespaceStartColumn*/ 0, Style);
+ }
+ } else if (TheLine.Type != LT_Invalid &&
+ (WasMoved || touchesRanges(TheLine))) {
unsigned LevelIndent = getIndent(IndentForLevel, TheLine.Level);
unsigned Indent = LevelIndent;
if (static_cast<int>(Indent) + Offset >= 0)
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=176361&r1=176360&r2=176361&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Mar 1 12:11:39 2013
@@ -138,6 +138,11 @@ bool UnwrappedLineParser::parse() {
I != E; ++I) {
Callback.consumeUnwrappedLine(*I);
}
+
+ // Create line with eof token.
+ pushToken(FormatTok);
+ Callback.consumeUnwrappedLine(*Line);
+
return Error;
}
@@ -776,14 +781,14 @@ void UnwrappedLineParser::addUnwrappedLi
CurrentLines->push_back(*Line);
Line->Tokens.clear();
if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) {
- for (std::vector<UnwrappedLine>::iterator I = PreprocessorDirectives
- .begin(), E = PreprocessorDirectives.end();
+ for (std::vector<UnwrappedLine>::iterator
+ I = PreprocessorDirectives.begin(),
+ E = PreprocessorDirectives.end();
I != E; ++I) {
CurrentLines->push_back(*I);
}
PreprocessorDirectives.clear();
}
-
}
bool UnwrappedLineParser::eof() const {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176361&r1=176360&r2=176361&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Mar 1 12:11:39 2013
@@ -166,6 +166,10 @@ TEST_F(FormatTest, OnlyGeneratesNecessar
TEST_F(FormatTest, RemovesTrailingWhitespaceOfFormattedLine) {
EXPECT_EQ("int a;\nint b;", format("int a; \nint b;", 0, 0, getLLVMStyle()));
+ EXPECT_EQ("int a;", format("int a; "));
+ EXPECT_EQ("int a;\n", format("int a; \n \n \n "));
+ EXPECT_EQ("int a;\nint b; ",
+ format("int a; \nint b; ", 0, 0, getLLVMStyle()));
}
TEST_F(FormatTest, ReformatsMovedLines) {
More information about the cfe-commits
mailing list