summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Format/Format.h4
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp8
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp4
-rw-r--r--clang/unittests/Format/FormatTestObjC.cpp6
4 files changed, 17 insertions, 5 deletions
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 94df954b605..3060d9b944e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -662,7 +662,9 @@ struct FormatStyle {
/// }
/// \endcode
bool AfterNamespace;
- /// \brief Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
+ /// \brief Wrap ObjC definitions (interfaces, implementations...).
+ /// \note @autoreleasepool and @synchronized blocks are wrapped
+ /// according to `AfterControlStatement` flag.
bool AfterObjCDeclaration;
/// \brief Wrap struct definitions.
/// \code
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 253f89da9d1..2ce39fb04c6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -314,6 +314,14 @@ private:
}
return MergedLines;
}
+ // Don't merge block with left brace wrapped after ObjC special blocks
+ if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() &&
+ I[-1]->First->is(tok::at) && I[-1]->First->Next) {
+ tok::ObjCKeywordKind kwId = I[-1]->First->Next->Tok.getObjCKeywordID();
+ if (kwId == clang::tok::objc_autoreleasepool ||
+ kwId == clang::tok::objc_synchronized)
+ return 0;
+ }
// Try to merge a block with left brace wrapped that wasn't yet covered
if (TheLine->Last->is(tok::l_brace)) {
return !Style.BraceWrapping.AfterFunction ||
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 8ab61f900c9..5ab5cc46cdc 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1129,7 +1129,7 @@ void UnwrappedLineParser::parseStructuralElement() {
case tok::objc_autoreleasepool:
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BraceWrapping.AfterObjCDeclaration)
+ if (Style.BraceWrapping.AfterControlStatement)
addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/false);
}
@@ -1141,7 +1141,7 @@ void UnwrappedLineParser::parseStructuralElement() {
// Skip synchronization object
parseParens();
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BraceWrapping.AfterObjCDeclaration)
+ if (Style.BraceWrapping.AfterControlStatement)
addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/false);
}
diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp
index d592b39a482..15c3d7622cf 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -187,7 +187,8 @@ TEST_F(FormatTestObjC, FormatObjCAutoreleasepool) {
"@autoreleasepool {\n"
" f();\n"
"}\n");
- Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterControlStatement = true;
verifyFormat("@autoreleasepool\n"
"{\n"
" f();\n"
@@ -216,7 +217,8 @@ TEST_F(FormatTestObjC, FormatObjCSynchronized) {
"@synchronized(self) {\n"
" f();\n"
"}\n");
- Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterControlStatement = true;
verifyFormat("@synchronized(self)\n"
"{\n"
" f();\n"
OpenPOWER on IntegriCloud