aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp42
-rw-r--r--clang/unittests/Format/FormatTest.cpp16
2 files changed, 13 insertions, 45 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index f229742..33be74d 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,12 +1418,19 @@ unsigned UnwrappedLineFormatter::format(
return Penalty;
}
-static auto newlinesBeforeLine(const AnnotatedLine &Line,
- const AnnotatedLine *PreviousLine,
- const AnnotatedLine *PrevPrevLine,
- const SmallVectorImpl<AnnotatedLine *> &Lines,
- const FormatStyle &Style) {
- const auto &RootToken = *Line.First;
+void UnwrappedLineFormatter::formatFirstToken(
+ const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+ const AnnotatedLine *PrevPrevLine,
+ const SmallVectorImpl<AnnotatedLine *> &Lines, unsigned Indent,
+ unsigned NewlineIndent) {
+ FormatToken &RootToken = *Line.First;
+ if (RootToken.is(tok::eof)) {
+ unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
+ unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+ Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+ TokenIndent);
+ return;
+ }
unsigned Newlines =
std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
// Remove empty lines before "}" where applicable.
@@ -1503,29 +1510,6 @@ static auto newlinesBeforeLine(const AnnotatedLine &Line,
}
}
- return Newlines;
-}
-
-void UnwrappedLineFormatter::formatFirstToken(
- const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
- const AnnotatedLine *PrevPrevLine,
- const SmallVectorImpl<AnnotatedLine *> &Lines, unsigned Indent,
- unsigned NewlineIndent) {
- FormatToken &RootToken = *Line.First;
- if (RootToken.is(tok::eof)) {
- unsigned Newlines =
- std::min(RootToken.NewlinesBefore,
- Style.KeepEmptyLinesAtEOF ? Style.MaxEmptyLinesToKeep + 1 : 1);
- unsigned TokenIndent = Newlines ? NewlineIndent : 0;
- Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
- TokenIndent);
- return;
- }
-
- const auto Newlines =
- RootToken.Finalized
- ? RootToken.NewlinesBefore
- : newlinesBeforeLine(Line, PreviousLine, PrevPrevLine, Lines, Style);
if (Newlines)
Indent = NewlineIndent;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index adc1eda..9a0194b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12856,22 +12856,6 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) {
" void f() {}\n"
"};\n",
Style);
- verifyFormat("struct foo {\n"
- "#ifdef FOO\n"
- "#else\n"
- "private:\n"
- "\n"
- "#endif\n"
- "};",
- "struct foo {\n"
- "#ifdef FOO\n"
- "#else\n"
- "private:\n"
- "\n"
- "\n"
- "#endif\n"
- "};",
- Style);
Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
verifyFormat("struct foo {\n"