]> granicus.if.org Git - clang/commitdiff
Reduce penalty for breaks after "(" for functions with parameters.
authorDaniel Jasper <djasper@google.com>
Wed, 20 Mar 2013 13:53:11 +0000 (13:53 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 20 Mar 2013 13:53:11 +0000 (13:53 +0000)
Before:
  aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
  aaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

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

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

index 0e4a2b797f51cad23ad3650ddc9665d40be2deaa..1a7dbe0936511686704e6d5f6313e51c5edd7382 100644 (file)
@@ -372,8 +372,8 @@ private:
   void alignComments(comment_iterator I, comment_iterator E, unsigned Column) {
     while (I != E) {
       unsigned Spaces = I->Spaces + Column - I->MinColumn;
-      storeReplacement(I->Tok, std::string(I->NewLines, '\n') +
-                               std::string(Spaces, ' '));
+      storeReplacement(
+          I->Tok, std::string(I->NewLines, '\n') + std::string(Spaces, ' '));
       ++I;
     }
   }
index c2b6c1b3e4231329270b54067c3bc89d25ea8ffb..7c4797978f07f4cb0db722c6b279a1c1b883459c 100644 (file)
@@ -937,7 +937,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
     return 20;
 
   if (opensScope(Left))
-    return 20;
+    return Left.ParameterCount > 1 ? prec::Comma : 20;
 
   if (Right.is(tok::lessless)) {
     if (Left.is(tok::string_literal)) {
index 6de861aa3c37782803c4d1df136ba52427e3c53d..7f9cecb031ee91b94d66f15448b09c1a6f356bda 100644 (file)
@@ -1485,6 +1485,10 @@ TEST_F(FormatTest, BreaksDesireably) {
   verifyFormat(
       "aaaaaa(aaa, new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "                aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaa(\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
   // This test case breaks on an incorrect memoization, i.e. an optimization not
   // taking into account the StopAt value.
@@ -1677,7 +1681,7 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
       "                                                    : aaaaaaaaaaaaa);");
   verifyFormat(
       "aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
-      "                   aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaa\n"
+      "                   aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
       "                                    : aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
       "                   aaaaaaaaaaaaa);");
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"