aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Format/Format.cpp10
-rw-r--r--lib/Format/UnwrappedLineParser.cpp11
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index bb7e0fa7e5..a3c5e503b9 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -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)
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 28522a3e32..cdd77759fd 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -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::addUnwrappedLine() {
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 {