r190124 - clang-format: Fix regression introduced by r189337.
Daniel Jasper
djasper at google.com
Fri Sep 6 01:08:15 PDT 2013
Author: djasper
Date: Fri Sep 6 03:08:14 2013
New Revision: 190124
URL: http://llvm.org/viewvc/llvm-project?rev=190124&view=rev
Log:
clang-format: Fix regression introduced by r189337.
Before:
if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ...
After:
if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
== 5) ...
Also precompute startsBinaryExpression() to improve performance.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.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=190124&r1=190123&r2=190124&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Sep 6 03:08:14 2013
@@ -38,15 +38,6 @@ static unsigned getLengthToMatchingParen
return End->TotalLength - Tok.TotalLength + 1;
}
-// Returns \c true if \c Tok starts a binary expression.
-static bool startsBinaryExpression(const FormatToken &Tok) {
- for (unsigned i = 0, e = Tok.FakeLParens.size(); i != e; ++i) {
- if (Tok.FakeLParens[i] > prec::Unknown)
- return true;
- }
- return false;
-}
-
// Returns \c true if \c Tok is the "." or "->" of a call and starts the next
// segment of a builder type call.
static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) {
@@ -156,7 +147,7 @@ bool ContinuationIndenter::mustBreak(con
Previous.Previous &&
Previous.Previous->Type != TT_BinaryOperator; // For >>.
bool LHSIsBinaryExpr =
- Previous.Previous && Previous.Previous->FakeRParens > 0;
+ Previous.Previous && Previous.Previous->EndsBinaryExpression;
if (Previous.Type == TT_BinaryOperator &&
(!IsComparison || LHSIsBinaryExpr) &&
Current.Type != TT_BinaryOperator && // For >>.
@@ -394,7 +385,7 @@ unsigned ContinuationIndenter::addTokenT
Previous.Type == TT_UnaryOperator ||
Previous.Type == TT_CtorInitializerColon) &&
(Previous.getPrecedence() != prec::Assignment ||
- startsBinaryExpression(Current)))
+ Current.StartsBinaryExpression))
// Always indent relative to the RHS of the expression unless this is a
// simple assignment without binary expression on the RHS. Also indent
// relative to unary operators and the colons of constructor initializers.
@@ -455,7 +446,7 @@ unsigned ContinuationIndenter::moveState
}
// If return returns a binary expression, align after it.
- if (Current.is(tok::kw_return) && startsBinaryExpression(Current))
+ if (Current.is(tok::kw_return) && Current.StartsBinaryExpression)
State.Stack.back().LastSpace = State.Column + 7;
// In ObjC method declaration we align on the ":" of parameters, but we need
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=190124&r1=190123&r2=190124&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Fri Sep 6 03:08:14 2013
@@ -89,9 +89,10 @@ struct FormatToken {
CanBreakBefore(false), ClosesTemplateDeclaration(false),
ParameterCount(0), PackingKind(PPK_Inconclusive), TotalLength(0),
UnbreakableTailLength(0), BindingStrength(0), SplitPenalty(0),
- LongestObjCSelectorName(0), FakeRParens(0), LastInChainOfCalls(false),
- PartOfMultiVariableDeclStmt(false), MatchingParen(NULL), Previous(NULL),
- Next(NULL) {}
+ LongestObjCSelectorName(0), FakeRParens(0),
+ StartsBinaryExpression(false), EndsBinaryExpression(false),
+ LastInChainOfCalls(false), PartOfMultiVariableDeclStmt(false),
+ MatchingParen(NULL), Previous(NULL), Next(NULL) {}
/// \brief The \c Token.
Token Tok;
@@ -221,6 +222,12 @@ struct FormatToken {
/// \brief Insert this many fake ) after this token for correct indentation.
unsigned FakeRParens;
+ /// \brief \c true if this token starts a binary expression, i.e. has at least
+ /// one fake l_paren with a precedence greater than prec::Unknown.
+ bool StartsBinaryExpression;
+ /// \brief \c true if this token ends a binary expression.
+ bool EndsBinaryExpression;
+
/// \brief Is this the last "." or "->" in a builder-type call?
bool LastInChainOfCalls;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=190124&r1=190123&r2=190124&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Sep 6 03:08:14 2013
@@ -928,8 +928,13 @@ private:
void addFakeParenthesis(FormatToken *Start, prec::Level Precedence) {
Start->FakeLParens.push_back(Precedence);
- if (Current)
+ if (Precedence > prec::Unknown)
+ Start->StartsBinaryExpression = true;
+ if (Current) {
++Current->Previous->FakeRParens;
+ if (Precedence > prec::Unknown)
+ Current->Previous->EndsBinaryExpression = true;
+ }
}
/// \brief Parse unary operator expressions and surround them with fake
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190124&r1=190123&r2=190124&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 6 03:08:14 2013
@@ -2341,6 +2341,10 @@ TEST_F(FormatTest, LineBreakingInBinaryE
"if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) {\n"
"}");
+ verifyFormat(
+ "if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) {\n"
+ "}");
// Even explicit parentheses stress the precedence enough to make the
// additional break unnecessary.
verifyFormat(
More information about the cfe-commits
mailing list