diff options
author | Daniel Jasper <djasper@google.com> | 2013-10-06 11:40:08 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-10-06 11:40:08 +0000 |
commit | 320997e6b37f738d50b3834b62004c11e37eccf7 (patch) | |
tree | 3c926c06178593e3a2ee7553a7a2bf07a2f19636 | |
parent | 0c4813e6953029cd8d304db715758f7995e11b74 (diff) | |
download | bcm5719-llvm-320997e6b37f738d50b3834b62004c11e37eccf7.tar.gz bcm5719-llvm-320997e6b37f738d50b3834b62004c11e37eccf7.zip |
clang-format: Remove empty lines after visibility modifiers.
Formatting:
class C {
public:
f();
};
Now leads to:
class C {
public:
f();
};
llvm-svn: 192062
-rw-r--r-- | clang/lib/Format/Format.cpp | 16 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 12 |
2 files changed, 22 insertions, 6 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 8ee770af954..129c119532e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -832,7 +832,7 @@ public: std::vector<int> IndentForLevel; bool PreviousLineWasTouched = false; - const FormatToken *PreviousLineLastToken = 0; + const AnnotatedLine *PreviousLine = NULL; bool FormatPPDirective = false; for (SmallVectorImpl<AnnotatedLine *>::iterator I = AnnotatedLines.begin(), E = AnnotatedLines.end(); @@ -872,7 +872,7 @@ public: // Insert a break even if there is a structural error in case where // we break apart a line consisting of multiple unwrapped lines. (FirstTok->NewlinesBefore == 0 || !StructuralError)) { - formatFirstToken(*TheLine.First, PreviousLineLastToken, Indent, + formatFirstToken(*TheLine.First, PreviousLine, Indent, TheLine.InPPDirective); } else { Indent = LevelIndent = FirstTok->OriginalColumn; @@ -914,7 +914,7 @@ public: // Remove trailing whitespace of the previous line if it was // touched. if (PreviousLineWasTouched || touchesEmptyLineBefore(TheLine)) { - formatFirstToken(*Tok, PreviousLineLastToken, LevelIndent, + formatFirstToken(*Tok, PreviousLine, LevelIndent, TheLine.InPPDirective); } else { Whitespaces.addUntouchableToken(*Tok, TheLine.InPPDirective); @@ -933,7 +933,7 @@ public: // last token. PreviousLineWasTouched = false; } - PreviousLineLastToken = TheLine.Last; + PreviousLine = *I; } return Whitespaces.generateReplacements(); } @@ -1222,7 +1222,7 @@ private: /// of the \c UnwrappedLine if there was no structural parsing error. /// Returns the indent level of the \c UnwrappedLine. void formatFirstToken(const FormatToken &RootToken, - const FormatToken *PreviousToken, unsigned Indent, + const AnnotatedLine *PreviousLine, unsigned Indent, bool InPPDirective) { unsigned Newlines = std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1); @@ -1235,10 +1235,14 @@ private: Newlines = 1; // Insert extra new line before access specifiers. - if (PreviousToken && PreviousToken->isOneOf(tok::semi, tok::r_brace) && + if (PreviousLine && PreviousLine->Last->isOneOf(tok::semi, tok::r_brace) && RootToken.isAccessSpecifier() && RootToken.NewlinesBefore == 1) ++Newlines; + // Remove empty lines after access specifiers. + if (PreviousLine && PreviousLine->First->isAccessSpecifier()) + Newlines = std::min(1u, Newlines); + Whitespaces.replaceWhitespace( RootToken, Newlines, Indent / Style.IndentWidth, Indent, Indent, InPPDirective && !RootToken.HasUnescapedNewline); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index dfdeae1a1e0..85813bcaffc 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1492,6 +1492,18 @@ TEST_F(FormatTest, SeparatesLogicalBlocks) { "protected:\n" "int h;\n" "};")); + EXPECT_EQ("class A {\n" + "protected:\n" + "public:\n" + " void f();\n" + "};", + format("class A {\n" + "protected:\n" + "\n" + "public:\n" + "\n" + " void f();\n" + "};")); } TEST_F(FormatTest, FormatsClasses) { |