From 8e55927153da2b4ace252cacf51c38a70d5d9aa0 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 27 Feb 2013 11:43:50 +0000 Subject: [PATCH] Fix formatting of multiplications in array subscripts. Before: a[a* a] = 1; After: a[a * a] = 1; llvm-svn: 176180 --- clang/lib/Format/TokenAnnotator.cpp | 3 +++ clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 67ad08a..164b722 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -190,6 +190,7 @@ private: // expression, or it could the the start of an Objective-C array literal. AnnotatedToken *Left = CurrentToken->Parent; AnnotatedToken *Parent = getPreviousToken(*Left); + Contexts.back().IsExpression = true; bool StartsObjCMethodExpr = !Parent || Parent->is(tok::colon) || Parent->is(tok::l_square) || Parent->is(tok::l_paren) || Parent->is(tok::kw_return) || @@ -550,6 +551,8 @@ private: for (AnnotatedToken *Previous = Current.Parent; Previous && Previous->isNot(tok::comma); Previous = Previous->Parent) { + if (Previous->is(tok::r_square)) + Previous = Previous->MatchingParen; if (Previous->Type == TT_BinaryOperator && (Previous->is(tok::star) || Previous->is(tok::amp))) { Previous->Type = TT_PointerOrReference; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 87e89db..5be319c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1813,6 +1813,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("a * ++b;"); verifyIndependentOfContext("a * --b;"); verifyIndependentOfContext("a[4] * b;"); + verifyIndependentOfContext("a[a * a] = 1;"); verifyIndependentOfContext("f() * b;"); verifyIndependentOfContext("a * [self dostuff];"); verifyIndependentOfContext("a * (a + b);"); -- 2.7.4