r209725 - clang-format: Don't break before a case's colon.
Daniel Jasper
djasper at google.com
Wed May 28 03:09:11 PDT 2014
Author: djasper
Date: Wed May 28 05:09:11 2014
New Revision: 209725
URL: http://llvm.org/viewvc/llvm-project?rev=209725&view=rev
Log:
clang-format: Don't break before a case's colon.
Before (with just the right line length:
switch (a) {
case some_namespace::some_constant
:
return;
}
After:
switch (a) {
case some_namespace::
some_constant:
return;
}
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=209725&r1=209724&r2=209725&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed May 28 05:09:11 2014
@@ -392,7 +392,8 @@ private:
Tok->Type = TT_RangeBasedForLoopColon;
} else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
Tok->Type = TT_BitFieldColon;
- } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) {
+ } else if (Contexts.size() == 1 &&
+ !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) {
Tok->Type = TT_InheritanceColon;
} else if (Contexts.back().ContextKind == tok::l_paren) {
Tok->Type = TT_InlineASMColon;
@@ -1655,11 +1656,11 @@ bool TokenAnnotator::canBreakBefore(cons
return Style.BreakBeforeTernaryOperators;
if (Left.Type == TT_ConditionalExpr || Left.is(tok::question))
return !Style.BreakBeforeTernaryOperators;
- if (Right.is(tok::colon) &&
- (Right.Type == TT_DictLiteral || Right.Type == TT_ObjCMethodExpr))
- return false;
if (Right.Type == TT_InheritanceColon)
return true;
+ if (Right.is(tok::colon) && (Right.Type != TT_CtorInitializerColon &&
+ Right.Type != TT_InlineASMColon))
+ return false;
if (Left.is(tok::colon) &&
(Left.Type == TT_DictLiteral || Left.Type == TT_ObjCMethodExpr))
return true;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=209725&r1=209724&r2=209725&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 28 05:09:11 2014
@@ -683,6 +683,13 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"case (b):\n"
" return;\n"
"}");
+
+ verifyFormat("switch (a) {\n"
+ "case some_namespace::\n"
+ " some_constant:\n"
+ " return;\n"
+ "}",
+ getLLVMStyleWithColumns(34));
}
TEST_F(FormatTest, CaseRanges) {
More information about the cfe-commits
mailing list