summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorFrancois Ferrand <thetypz@gmail.com>2018-02-27 13:48:27 +0000
committerFrancois Ferrand <thetypz@gmail.com>2018-02-27 13:48:27 +0000
commita2484b251bb821561b626d55702c435b33267df1 (patch)
treeaeba629e3ed1bf364d9110e84b0e419b07d0a581 /clang/lib
parentba91c3de383cbcc1f5cdb678412a622118096a78 (diff)
downloadbcm5719-llvm-a2484b251bb821561b626d55702c435b33267df1.tar.gz
bcm5719-llvm-a2484b251bb821561b626d55702c435b33267df1.zip
clang-format: use AfterControlStatement to format ObjC control blocks
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 llvm-svn: 326192
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp8
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp4
2 files changed, 10 insertions, 2 deletions
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);
}
OpenPOWER on IntegriCloud