]> granicus.if.org Git - clang/commitdiff
Fix some alignment and line break decisions.
authorDaniel Jasper <djasper@google.com>
Fri, 25 Jan 2013 15:43:32 +0000 (15:43 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 25 Jan 2013 15:43:32 +0000 (15:43 +0000)
This combines two small changes:
1) Put a penalty on breaking after "<"
2) Only produce a hanging indent when parameters are separated by
commas.

Before:
aaaaaaaaaaaaaaaaaaaaaaaa<
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
               aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));

After:
aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));

This changes one ObjC test, but AFAICT this is not according to any
style guide (neither before nor after). We probably should be aligning
on the ":" there according to:
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml?showone=Method_Invocations#Method_Invocations

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

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

index 1cac334125b3e4910d2e41bbde6785d0517ca3cd..ed7f35486c6383c61c81bf6a762facb0d01291f8 100644 (file)
@@ -609,7 +609,7 @@ private:
         // 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)
+      else if (Previous.is(tok::comma) && ParenLevel != 0)
         // Top-level spaces are exempt as that mostly leads to better results.
         State.Stack.back().LastSpace = State.Column;
     }
@@ -706,7 +706,7 @@ private:
     if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
       return 20;
 
-    if (Left.is(tok::l_paren))
+    if (Left.is(tok::l_paren) || Left.Type == TT_TemplateOpener)
       return 20;
 
     if (Left.is(tok::question) || Left.Type == TT_ConditionalExpr)
index 2250c03b583b7971920af4d44e4f2fc9033f3643..7d274832a3043b4dd189edd0194ade634633d6e2 100644 (file)
@@ -909,7 +909,7 @@ TEST_F(FormatTest, ConstructorInitializers) {
 
   // This test takes VERY long when memoization is broken.
   std::string input = "Constructor()\n"
-                 "    : aaaa(a,\n";
+                      "    : aaaa(a,\n";
   for (unsigned i = 0, e = 80; i != e; ++i) {
     input += "           a,\n";
   }
@@ -952,6 +952,12 @@ TEST_F(FormatTest, BreaksDesireably) {
   verifyFormat(
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n"
       "                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+  verifyFormat(
+      "aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
+  verifyFormat(
+      "aaaaaa(aaa, new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+      "                aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
 
   // This test case breaks on an incorrect memoization, i.e. an optimization not
   // taking into account the StopAt value.
@@ -1202,6 +1208,9 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
       "template <typename T1, typename T2 = char, typename T3 = char,\n"
       "          typename T4 = char>\n"
       "void f();");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 }
 
 TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
@@ -2071,7 +2080,7 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
   verifyFormat(
       "void f() {\n"
       "  if ((self = [super initWithContentRect:contentRect styleMask:styleMask\n"
-      "                  backing:NSBackingStoreBuffered defer:YES]))");
+      "          backing:NSBackingStoreBuffered defer:YES]))");
   
   verifyFormat("[foo checkThatBreakingAfterColonWorksOk:\n"
                "    [bar ifItDoes:reduceOverallLineLengthLikeInThisCase]];");