r174291 - Fix bug in formatting of nested initializers.

Daniel Jasper djasper at google.com
Sun Feb 3 10:07:15 PST 2013


Author: djasper
Date: Sun Feb  3 12:07:15 2013
New Revision: 174291

URL: http://llvm.org/viewvc/llvm-project?rev=174291&view=rev
Log:
Fix bug in formatting of nested initializers.

We can now format:
SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } },
                          { { 111111111111111111111111111111,
                              222222222222222222222222222222,
                              333333333333333333333333333333 } },
                          { { 1, 2, 3 } }, { { 1, 2, 3 } } };

Before, we did strange things there.

Modified:
    cfe/trunk/lib/Format/Format.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=174291&r1=174290&r2=174291&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Feb  3 12:07:15 2013
@@ -528,7 +528,6 @@ private:
     if (Current.is(tok::question))
       State.Stack.back().QuestionColumn = State.Column;
     if (Current.is(tok::l_brace) && Current.MatchingParen != NULL &&
-        Current.Children[0].isNot(tok::l_brace) &&
         !Current.MatchingParen->MustBreakBefore) {
       AnnotatedToken *End = Current.MatchingParen;
       while (!End->Children.empty() && !End->Children[0].CanBreakBefore) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174291&r1=174290&r2=174291&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Feb  3 12:07:15 2013
@@ -693,6 +693,12 @@ TEST_F(FormatTest, NestedStaticInitializ
       "                              222222222222222222222222222222,\n"
       "                              333333333333333333333333333333 },\n"
       "                            { 1, 2, 3 }, { 1, 2, 3 } } };");
+  verifyFormat(
+      "SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } },\n"
+      "                          { { 111111111111111111111111111111,\n"
+      "                              222222222222222222222222222222,\n"
+      "                              333333333333333333333333333333 } },\n"
+      "                          { { 1, 2, 3 } }, { { 1, 2, 3 } } };");
 
   // FIXME: We might at some point want to handle this similar to parameter
   // lists, where we have an option to put each on a single line.





More information about the cfe-commits mailing list