diff options
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 14 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6db3f278d49..b04ccd0ba75 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -75,6 +75,9 @@ private: bool parseParens(bool LookForDecls = false) { if (CurrentToken == NULL) return false; + bool AfterCaret = Contexts.back().CaretFound; + Contexts.back().CaretFound = false; + ScopedContextCreator ContextCreator(*this, tok::l_paren, 1); // FIXME: This is a bit of a hack. Do better. @@ -103,8 +106,7 @@ private: Left->Previous->MatchingParen->Type == TT_LambdaLSquare) { // This is a parameter list of a lambda expression. Contexts.back().IsExpression = false; - } else if (Left->Previous && Left->Previous->is(tok::caret) && - Left->Previous->Type == TT_UnaryOperator) { + } else if (AfterCaret) { // This is the parameter list of an ObjC block. Contexts.back().IsExpression = false; } @@ -581,7 +583,7 @@ private: ColonIsForRangeExpr(false), ColonIsDictLiteral(false), ColonIsObjCMethodExpr(false), FirstObjCSelectorName(NULL), FirstStartOfName(NULL), IsExpression(IsExpression), - CanBeExpression(true), InCtorInitializer(false) {} + CanBeExpression(true), InCtorInitializer(false), CaretFound(false) {} tok::TokenKind ContextKind; unsigned BindingStrength; @@ -595,6 +597,7 @@ private: bool IsExpression; bool CanBeExpression; bool InCtorInitializer; + bool CaretFound; }; /// \brief Puts a new \c Context onto the stack \c Contexts for the lifetime @@ -673,8 +676,11 @@ private: Contexts.back().IsExpression); } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) { Current.Type = determinePlusMinusCaretUsage(Current); - if (Current.Type == TT_UnaryOperator) + if (Current.Type == TT_UnaryOperator) { ++Contexts.back().NumBlockParameters; + if (Current.is(tok::caret)) + Contexts.back().CaretFound = true; + } } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) { Current.Type = determineIncrementUsage(Current); } else if (Current.is(tok::exclaim)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 910df459761..c75df9ce151 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7907,6 +7907,10 @@ TEST_F(FormatTest, FormatsBlocks) { verifyFormat("int i = {[operation setCompletionBlock : ^{ [self " "onOperationDone]; }] };"); verifyFormat("[operation setCompletionBlock:^(int *i) { f(); }];"); + verifyFormat("int a = [operation block:^int(int *i) { return 1; }];"); + verifyFormat("[myObject doSomethingWith:arg1\n" + " aaa:^int(int *a) { return 1; }\n" + " bbb:f(a * b)];"); verifyFormat("[operation setCompletionBlock:^{\n" " [self.delegate newDataAvailable];\n" |

