[PATCH] Fixes issue with Allman BreakBeforeBraces for Objective C @interface (PR19511)
Dinesh Dwivedi
dinesh.d at samsung.com
Wed Apr 30 04:33:07 PDT 2014
Hi djasper, klimek,
I am not sure if this is real issue. But if we decide to fix this, we may use this patch.
issue:
libformat has code comment stating that if interface has instance variables, it keeps '{' in
same line ragardless of BreakBeforeBraces setting.
UnwrappedLineParser::parseObjCInterfaceOrImplementation()
{
...
// If instance variables are present, keep the '{' on the first line too.
if (FormatTok->Tok.is(tok::l_brace))
parseBlock(/*MustBeDeclaration=*/true);
...
}
But for Allman and GNU style of BreakBeforeBraces, we should break before '{'
http://reviews.llvm.org/D3565
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1291,9 +1291,12 @@
if (FormatTok->Tok.is(tok::less))
parseObjCProtocolList();
- // If instance variables are present, keep the '{' on the first line too.
- if (FormatTok->Tok.is(tok::l_brace))
+ if (FormatTok->Tok.is(tok::l_brace)) {
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
+ Style.BreakBeforeBraces == FormatStyle::BS_GNU)
+ addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/true);
+ }
// With instance variables, this puts '}' on its own line. Without instance
// variables, this ends the @interface line.
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7444,6 +7444,14 @@
"}\n",
BreakBeforeBrace);
+ verifyFormat("@interface BSApplicationController ()\n"
+ "{\n"
+ "@private\n"
+ " id _extraIvar;\n"
+ "}\n"
+ "@end\n",
+ BreakBeforeBrace);
+
BreakBeforeBrace.ColumnLimit = 19;
verifyFormat("void f() { int i; }", BreakBeforeBrace);
BreakBeforeBrace.ColumnLimit = 18;
@@ -7564,6 +7572,14 @@
" Y = 0,\n"
"}\n",
GNUBraceStyle);
+
+ verifyFormat("@interface BSApplicationController ()\n"
+ "{\n"
+ "@private\n"
+ " id _extraIvar;\n"
+ "}\n"
+ "@end\n",
+ GNUBraceStyle);
}
TEST_F(FormatTest, CatchExceptionReferenceBinding) {
verifyFormat("void f() {\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3565.8968.patch
Type: text/x-patch
Size: 1815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140430/3e45a72a/attachment.bin>
More information about the cfe-commits
mailing list