[cfe-commits] r173160 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Tue Jan 22 06:28:24 PST 2013


Author: djasper
Date: Tue Jan 22 08:28:24 2013
New Revision: 173160

URL: http://llvm.org/viewvc/llvm-project?rev=173160&view=rev
Log:
Let the formatter be more restrictive for breaking around . and ->

Before:
aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa)
    .aaaaaaaaaaaaaaaaaa();

After:
aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa,
                aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();

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=173160&r1=173159&r2=173160&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Jan 22 08:28:24 2013
@@ -60,6 +60,7 @@
 enum LineType {
   LT_Invalid,
   LT_Other,
+  LT_BuilderTypeCall,
   LT_PreprocessorDirective,
   LT_VirtualFunctionDecl,
   LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
@@ -707,7 +708,7 @@
       return Level;
 
     if (Right.is(tok::arrow) || Right.is(tok::period)) {
-      if (Left.is(tok::r_paren))
+      if (Left.is(tok::r_paren) && Line.Type == LT_BuilderTypeCall)
         return 15; // Should be smaller than breaking at a nested comma.
       return 150;
     }
@@ -1162,18 +1163,27 @@
     }
 
     LineType parseLine() {
+      int PeriodsAndArrows = 0;
       if (CurrentToken->is(tok::hash)) {
         parsePreprocessorDirective();
         return LT_PreprocessorDirective;
       }
       while (CurrentToken != NULL) {
+        
         if (CurrentToken->is(tok::kw_virtual))
           KeywordVirtualFound = true;
+        if (CurrentToken->is(tok::period) || CurrentToken->is(tok::arrow))
+          ++PeriodsAndArrows;
         if (!consumeToken())
           return LT_Invalid;
       }
       if (KeywordVirtualFound)
         return LT_VirtualFunctionDecl;
+
+      // Assume a builder-type call if there are 2 or more "." and "->".
+      if (PeriodsAndArrows >= 2)
+        return LT_BuilderTypeCall;
+
       return LT_Other;
     }
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173160&r1=173159&r2=173160&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 22 08:28:24 2013
@@ -964,8 +964,9 @@
       "         aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));");
   verifyGoogleFormat(
-      "aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa)\n"
-      "    .aaaaaaaaaaaaaaaaaa();");
+      "aaaaaaaaaaaaaaa(aaaaaaaaa,\n"
+      "                aaaaaaaaa,\n"
+      "                aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();");
   verifyGoogleFormat(
       "somefunction(someotherFunction(ddddddddddddddddddddddddddddddddddd,\n"
       "                               ddddddddddddddddddddddddddddd),\n"





More information about the cfe-commits mailing list