summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp11
-rw-r--r--clang/lib/Format/FormatToken.h1
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp10
-rw-r--r--clang/unittests/Format/FormatTest.cpp4
4 files changed, 14 insertions, 12 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index cb4e4f53b2f..431be41e0a3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -636,16 +636,11 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
}
State.Stack.pop_back();
}
- bool IsObjCBlock =
- Previous &&
- (Previous->is(tok::caret) ||
- (Previous->is(tok::r_paren) && Previous->MatchingParen &&
- Previous->MatchingParen->Previous &&
- Previous->MatchingParen->Previous->is(tok::caret)));
// For some reason, ObjC blocks are indented like continuations.
NewIndent =
- State.Stack.back().LastSpace +
- (IsObjCBlock ? Style.ContinuationIndentWidth : Style.IndentWidth);
+ State.Stack.back().LastSpace + (Current.Type == TT_ObjCBlockLBrace
+ ? Style.ContinuationIndentWidth
+ : Style.IndentWidth);
++NewIndentLevel;
BreakBeforeParameter = true;
} else {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 04587244c37..42d4a8dc249 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -45,6 +45,7 @@ enum TokenType {
TT_LambdaLSquare,
TT_LineComment,
TT_ObjCBlockLParen,
+ TT_ObjCBlockLBrace,
TT_ObjCDecl,
TT_ObjCForIn,
TT_ObjCMethodExpr,
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 369a37b082e..19bc5a6a96b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -76,9 +76,6 @@ 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.
@@ -109,7 +106,7 @@ private:
Left->Previous->MatchingParen->Type == TT_LambdaLSquare) {
// This is a parameter list of a lambda expression.
Contexts.back().IsExpression = false;
- } else if (AfterCaret) {
+ } else if (Contexts[Contexts.size() - 2].CaretFound) {
// This is the parameter list of an ObjC block.
Contexts.back().IsExpression = false;
} else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
@@ -273,6 +270,11 @@ private:
bool parseBrace() {
if (CurrentToken != NULL) {
FormatToken *Left = CurrentToken->Previous;
+
+ if (Contexts.back().CaretFound)
+ Left->Type = TT_ObjCBlockLBrace;
+ Contexts.back().CaretFound = false;
+
ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
Contexts.back().ColonIsDictLiteral = true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 3da478c0923..fa8ed3828d4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8167,6 +8167,10 @@ TEST_F(FormatTest, FormatsBlocks) {
" secondBlock:^(Bar *b) {\n"
" // ...\n"
" int i;\n"
+ " }\n"
+ " thirdBlock:^Foo(Bar *b) {\n"
+ " // ...\n"
+ " int i;\n"
" }];");
verifyFormat("f(^{\n"
OpenPOWER on IntegriCloud