[PATCH] Don't merge constructors with initializer lists to one line in WebKit style.
Alexander Kornienko
alexfh at google.com
Sat Dec 21 02:26:48 PST 2013
Hi djasper,
This is a follow-up to r196378, fixes inconsistency with the WebKit
style. Don't merge simple constructors to one line when initializer list is
present and BreakConstructorInitializersBeforeComma is set.
http://llvm-reviews.chandlerc.com/D2455
Files:
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -510,17 +510,27 @@
}
if (I[1]->First->Type == TT_FunctionLBrace &&
Style.BreakBeforeBraces != FormatStyle::BS_Attach) {
+ if (!Style.AllowShortFunctionsOnASingleLine)
+ return 0;
+ // The only well-known style using this option is WebKit, and it also
+ // doesn't allow merging constructors to a single line, if there's an
+ // initializer list.
+ if (Style.BreakConstructorInitializersBeforeComma) {
+ for (FormatToken *Tok = TheLine->First; Tok != NULL; Tok = Tok->Next)
+ if (Tok->Type == TT_CtorInitializerColon) {
+ if (I + 2 != E)
+ I[2]->First->MustBreakBefore = true;
+ return 0;
+ }
+ }
// Reduce the column limit by the number of spaces we need to insert
// around braces.
Limit = Limit > 3 ? Limit - 3 : 0;
- unsigned MergedLines = 0;
- if (Style.AllowShortFunctionsOnASingleLine) {
- MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
- // If we managed to merge the block, count the function header, which is
- // on a separate line.
- if (MergedLines > 0)
- ++MergedLines;
- }
+ unsigned MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
+ // If we managed to merge the block, count the function header, which is
+ // on a separate line.
+ if (MergedLines > 0)
+ ++MergedLines;
return MergedLines;
}
if (TheLine->First->is(tok::kw_if)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2455.1.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131221/52afee09/attachment.bin>
More information about the cfe-commits
mailing list