diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 8 |
3 files changed, 17 insertions, 6 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index d2da252a606..a80e87ddfc8 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -499,7 +499,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, // is special cased. bool SkipFirstExtraIndent = (Previous && (Previous->opensScope() || Previous->is(tok::kw_return) || - Previous->getPrecedence() == prec::Assignment)); + Previous->getPrecedence() == prec::Assignment || + Previous->Type == TT_ObjCMethodExpr)); for (SmallVectorImpl<prec::Level>::const_reverse_iterator I = Current.FakeLParens.rbegin(), E = Current.FakeLParens.rend(); diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 757d3012b63..69e558571f9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -871,8 +871,11 @@ public: /// \brief Parse expressions with the given operatore precedence. void parse(int Precedence = 0) { - // Skip 'return' as it is not part of a binary expression. - while (Current && Current->is(tok::kw_return)) + // Skip 'return' and ObjC selector colons as they are not part of a binary + // expression. + while (Current && + (Current->is(tok::kw_return) || + (Current->is(tok::colon) && Current->Type == TT_ObjCMethodExpr))) next(); if (Current == NULL || Precedence > PrecedenceArrowAndPeriod) @@ -944,12 +947,11 @@ private: if (Current) { if (Current->Type == TT_ConditionalExpr) return prec::Conditional; - else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon) + else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon || + Current->Type == TT_ObjCSelectorName) return 0; else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma)) return Current->getPrecedence(); - else if (Current->Type == TT_ObjCSelectorName) - return prec::Assignment; else if (Current->isOneOf(tok::period, tok::arrow)) return PrecedenceArrowAndPeriod; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 63fe4a6a4e5..1822a24597e 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5373,10 +5373,18 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n" " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n" " aaaa:bbb];"); + verifyFormat( + "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n" + " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n" + " aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa];"); // Variadic parameters. verifyFormat( "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];"); + verifyFormat( + "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];"); } TEST_F(FormatTest, ObjCAt) { |