r230620 - clang-format: Allow breaking after "else if(" as a last resort.
Daniel Jasper
djasper at google.com
Thu Feb 26 01:49:08 PST 2015
Author: djasper
Date: Thu Feb 26 03:49:08 2015
New Revision: 230620
URL: http://llvm.org/viewvc/llvm-project?rev=230620&view=rev
Log:
clang-format: Allow breaking after "else if(" as a last resort.
This isn't generally nice, but better than violating the column limit.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=230620&r1=230619&r2=230620&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Feb 26 03:49:08 2015
@@ -1582,6 +1582,8 @@ unsigned TokenAnnotator::splitPenalty(co
if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)
return 100;
+ if (Left.is(tok::l_paren) && Left.Previous && Left.Previous->is(tok::kw_if))
+ return 1000;
if (Left.is(tok::equal) && InFunctionDecl)
return 110;
if (Right.is(tok::r_brace))
@@ -2009,8 +2011,7 @@ bool TokenAnnotator::canBreakBefore(cons
if (Left.is(tok::l_paren) && Left.is(TT_AttributeParen))
return false;
if (Left.is(tok::l_paren) && Left.Previous &&
- (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen) ||
- Left.Previous->is(tok::kw_if)))
+ (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen)))
return false;
if (Right.is(TT_ImplicitStringLiteral))
return false;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=230620&r1=230619&r2=230620&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb 26 03:49:08 2015
@@ -493,6 +493,11 @@ TEST_F(FormatTest, ElseIf) {
"} else if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa)) {\n"
"}");
+ verifyFormat("if (a) {\n"
+ "} else if (\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
+ "}",
+ getLLVMStyleWithColumns(62));
}
TEST_F(FormatTest, FormatsForLoop) {
More information about the cfe-commits
mailing list