r190126 - clang-format: Fix regression introduced by r189353.
Daniel Jasper
djasper at google.com
Fri Sep 6 01:54:25 PDT 2013
Author: djasper
Date: Fri Sep 6 03:54:24 2013
New Revision: 190126
URL: http://llvm.org/viewvc/llvm-project?rev=190126&view=rev
Log:
clang-format: Fix regression introduced by r189353.
Before:
FirstToken->WhitespaceRange.getBegin()
.getLocWithOffset(First->LastNewlineOffset);
After:
FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
First->LastNewlineOffset);
Re-add logic to prevent breaking after an empty set of parentheses.
Basically it seems that calling a function without parameters is more
like navigating along the same object than it is a separate step of a
builder-type call.
We might need to extends this in future to allow "short" parameters that
e.g. are an index accessing a specific element.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=190126&r1=190125&r2=190126&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Sep 6 03:54:24 2013
@@ -520,7 +520,7 @@ private:
LBrace.Children.size() == 0)
// The previous token does not open a block. Nothing to do. We don't
// assert so that we can simply call this function for all tokens.
- return true;
+ return true;
if (NewLine) {
unsigned ParentIndent = State.Stack.back().Indent;
@@ -624,7 +624,7 @@ private:
++FormatTok->NewlinesBefore;
// FIXME: This is technically incorrect, as it could also
// be a literal backslash at the end of the line.
- if (i == 0 || FormatTok->TokenText[i-1] != '\\')
+ if (i == 0 || FormatTok->TokenText[i - 1] != '\\')
FormatTok->HasUnescapedNewline = true;
FormatTok->LastNewlineOffset = WhitespaceLength + i + 1;
Column = 0;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=190126&r1=190125&r2=190126&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Sep 6 03:54:24 2013
@@ -1137,7 +1137,8 @@ unsigned TokenAnnotator::splitPenalty(co
return 2;
if (Right.isMemberAccess()) {
- if (Left.isOneOf(tok::r_paren, tok::r_square))
+ if (Left.isOneOf(tok::r_paren, tok::r_square) && Left.MatchingParen &&
+ Left.MatchingParen->ParameterCount > 0)
return 20; // Should be smaller than breaking at a nested comma.
return 150;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190126&r1=190125&r2=190126&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 6 03:54:24 2013
@@ -2970,6 +2970,10 @@ TEST_F(FormatTest, FormatsBuilderPattern
verifyFormat("aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()\n"
" ->aaaaaaaaaaaaaae(0)\n"
" ->aaaaaaaaaaaaaaa();");
+
+ // Prefer not to break after empty parentheses.
+ verifyFormat("FirstToken->WhitespaceRange.getBegin().getLocWithOffset(\n"
+ " First->LastNewlineOffset);");
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
More information about the cfe-commits
mailing list