]> granicus.if.org Git - clang/commitdiff
Add extra indent for nested calls inside if's.
authorDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 20:41:06 +0000 (20:41 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 20:41:06 +0000 (20:41 +0000)
Before:
if (aaaaaaaaaa(
    aaaaaaaaaa)) {}

After:
if (aaaaaaaaaa(
        aaaaaaaaaa)) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173290 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index eb18be82b3d056ba73464b056524ccb091a53e36..b16eb15318411133a175793478c4bd182c91d249 100644 (file)
@@ -604,10 +604,14 @@ private:
           Current.isNot(tok::comment))
         State.Stack[ParenLevel].HasMultiParameterLine = true;
 
-      // Top-level spaces are exempt as that mostly leads to better results.
       State.Column += Spaces;
-      if (Spaces > 0 && ParenLevel != 0)
-        State.Stack[ParenLevel].LastSpace = State.Column;
+      if (Current.is(tok::l_paren) && Previous.is(tok::kw_if))
+        // Treat the condition inside an if as if it was a second function
+        // parameter, i.e. let nested calls have an indent of 4.
+        State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".
+      else if (Spaces > 0 && ParenLevel != 0)
+        // Top-level spaces are exempt as that mostly leads to better results.
+        State.Stack.back().LastSpace = State.Column;
     }
 
     // If we break after an {, we should also break before the corresponding }.
index a588dbabece3301e0df925b6f0422f30c09735da..d8a6ddcb688579b9c7c03646e1e37028df390bcf 100644 (file)
@@ -928,6 +928,9 @@ TEST_F(FormatTest, BreaksDesireably) {
   verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
                "    aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
                "    aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {\n}");
+  verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)) {\n"
+               "}");
 
   verifyFormat(
       "aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"