r182597 - Improve formatting of braced lists.
Daniel Jasper
djasper at google.com
Thu May 23 11:05:18 PDT 2013
Author: djasper
Date: Thu May 23 13:05:18 2013
New Revision: 182597
URL: http://llvm.org/viewvc/llvm-project?rev=182597&view=rev
Log:
Improve formatting of braced lists.
Before: vector<int> v{ -1};
After: vector<int> v{-1};
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=182597&r1=182596&r2=182597&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu May 23 13:05:18 2013
@@ -100,8 +100,7 @@ template <> struct MappingTraits<clang::
IO.mapOptional("PointerBindsToType", Style.PointerBindsToType);
IO.mapOptional("SpacesBeforeTrailingComments",
Style.SpacesBeforeTrailingComments);
- IO.mapOptional("SpacesInBracedLists",
- Style.SpacesInBracedLists);
+ IO.mapOptional("SpacesInBracedLists", Style.SpacesInBracedLists);
IO.mapOptional("Standard", Style.Standard);
IO.mapOptional("IndentWidth", Style.IndentWidth);
IO.mapOptional("UseTab", Style.UseTab);
@@ -146,7 +145,7 @@ FormatStyle getGoogleStyle() {
GoogleStyle.AlignEscapedNewlinesLeft = true;
GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
- GoogleStyle.AllowShortLoopsOnASingleLine= true;
+ GoogleStyle.AllowShortLoopsOnASingleLine = true;
GoogleStyle.BinPackParameters = true;
GoogleStyle.ColumnLimit = 80;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=182597&r1=182596&r2=182597&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu May 23 13:05:18 2013
@@ -1092,6 +1092,9 @@ bool TokenAnnotator::spaceRequiredBetwee
return false; // No spaces in "{}".
if (Left.is(tok::l_brace) || Right.is(tok::r_brace))
return Style.SpacesInBracedLists;
+ if (Right.Type == TT_UnaryOperator)
+ return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
+ (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);
if (Left.is(tok::identifier) && Right.is(tok::l_brace) &&
Right.getNextNoneComment())
return false;
@@ -1131,10 +1134,6 @@ bool TokenAnnotator::spaceRequiredBefore
Tok.getNextNoneComment() != NULL && Tok.Type != TT_ObjCMethodExpr;
if (Tok.Parent->Type == TT_UnaryOperator || Tok.Parent->Type == TT_CastRParen)
return false;
- if (Tok.Type == TT_UnaryOperator)
- return !Tok.Parent->isOneOf(tok::l_paren, tok::l_square, tok::at) &&
- (Tok.Parent->isNot(tok::colon) ||
- Tok.Parent->Type != TT_ObjCMethodExpr);
if (Tok.Parent->is(tok::greater) && Tok.is(tok::greater)) {
return Tok.Type == TT_TemplateCloser &&
Tok.Parent->Type == TT_TemplateCloser &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182597&r1=182596&r2=182597&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 23 13:05:18 2013
@@ -3137,7 +3137,7 @@ TEST_F(FormatTest, LayoutCxx11Constructo
verifyFormat("vector<int> x{1, 2, 3, 4};", NoSpaces);
verifyFormat("vector<T> x{{}, {}, {}, {}};", NoSpaces);
verifyFormat("f({1, 2});", NoSpaces);
- verifyFormat("auto v = Foo{1};", NoSpaces);
+ verifyFormat("auto v = Foo{-1};", NoSpaces);
verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", NoSpaces);
}
More information about the cfe-commits
mailing list