]> granicus.if.org Git - clang/commitdiff
Fix formatting of multiplications in array subscripts.
authorDaniel Jasper <djasper@google.com>
Wed, 27 Feb 2013 11:43:50 +0000 (11:43 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 27 Feb 2013 11:43:50 +0000 (11:43 +0000)
Before:
a[a* a] = 1;

After:
a[a * a] = 1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176180 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 67ad08a389a8a91d600bac7bf344e772bdc85708..164b722f820c883b2fff3cd91aad2e93c01b56e5 100644 (file)
@@ -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;
index 87e89dbefd62796fe57e953982956be10c2effb9..5be319cba03bf1403a170ec407ca9403e0046774 100644 (file)
@@ -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);");