ObjC defines `@autoreleasepool` and `@synchronized` control blocks. These
used to be formatted according to the `AfterObjCDeclaration` brace-
wrapping flag, which is not very consistent.
This patch changes the behavior to use the `AfterControlStatement` flag
instead. This should not affect the behavior unless a custom brace
wrapping mode is used.
Reviewers: krasimir, djasper, klimek, benhamilton
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D43232
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326192
91177308-0d34-0410-b5e6-
96231b3b80d8
/// }
/// \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
}
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 ||
case tok::objc_autoreleasepool:
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BraceWrapping.AfterObjCDeclaration)
+ if (Style.BraceWrapping.AfterControlStatement)
addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/false);
}
// Skip synchronization object
parseParens();
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BraceWrapping.AfterObjCDeclaration)
+ if (Style.BraceWrapping.AfterControlStatement)
addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/false);
}
"@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"
"@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"