r194276 - clang-format: Improve formatting of operators forced to new lines.
Daniel Jasper
djasper at google.com
Fri Nov 8 11:56:28 PST 2013
Author: djasper
Date: Fri Nov 8 13:56:28 2013
New Revision: 194276
URL: http://llvm.org/viewvc/llvm-project?rev=194276&view=rev
Log:
clang-format: Improve formatting of operators forced to new lines.
Before:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+
sizeof(int32_t) // Offset of CU in the .debug_info section
+
sizeof(int8_t) // Pointer Size (in bytes)
+
sizeof(int8_t); // Segment Size (in bytes)
After:
unsigned ContentSize =
sizeof(int16_t) // DWARF ARange version number
+ sizeof(int32_t) // Offset of CU in the .debug_info section
+ sizeof(int8_t) // Pointer Size (in bytes)
+ sizeof(int8_t); // Segment Size (in bytes)
This fixes llvm.org/PR17687.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=194276&r1=194275&r2=194276&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 8 13:56:28 2013
@@ -439,10 +439,12 @@ unsigned ContinuationIndenter::addTokenO
for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
State.Stack[i].BreakBeforeParameter = true;
}
- const FormatToken *TokenBefore = Current.getPreviousNonComment();
- if (TokenBefore && !TokenBefore->isOneOf(tok::comma, tok::semi) &&
- TokenBefore->Type != TT_TemplateCloser &&
- TokenBefore->Type != TT_BinaryOperator && !TokenBefore->opensScope())
+ if (PreviousNonComment &&
+ !PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
+ PreviousNonComment->Type != TT_TemplateCloser &&
+ PreviousNonComment->Type != TT_BinaryOperator &&
+ Current.Type != TT_BinaryOperator &&
+ !PreviousNonComment->opensScope())
State.Stack.back().BreakBeforeParameter = true;
// If we break after { or the [ of an array initializer, we should also break
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194276&r1=194275&r2=194276&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 8 13:56:28 2013
@@ -2668,6 +2668,14 @@ TEST_F(FormatTest, ExpressionIndentation
" > ccccc) {\n"
"}",
Style);
+
+ // Forced by comments.
+ verifyFormat(
+ "unsigned ContentSize =\n"
+ " sizeof(int16_t) // DWARF ARange version number\n"
+ " + sizeof(int32_t) // Offset of CU in the .debug_info section\n"
+ " + sizeof(int8_t) // Pointer Size (in bytes)\n"
+ " + sizeof(int8_t); // Segment Size (in bytes)");
}
TEST_F(FormatTest, ConstructorInitializers) {
More information about the cfe-commits
mailing list