r199796 - clang-format: Treat "." in protos like namespace separators.

Daniel Jasper djasper at google.com
Wed Jan 22 00:04:52 PST 2014


Author: djasper
Date: Wed Jan 22 02:04:52 2014
New Revision: 199796

URL: http://llvm.org/viewvc/llvm-project?rev=199796&view=rev
Log:
clang-format: Treat "." in protos like namespace separators.

Before:
  optional really.really.long.and.qualified.type.aaaaaaa
      .aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2;

After:
  optional
     really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa
          another_fiiiiiiiiiiiiiiiiiiiiield = 2;

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=199796&r1=199795&r2=199796&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jan 22 02:04:52 2014
@@ -1184,7 +1184,8 @@ unsigned TokenAnnotator::splitPenalty(co
     return 150;
   if (Left.Type == TT_CastRParen)
     return 100;
-  if (Left.is(tok::coloncolon))
+  if (Left.is(tok::coloncolon) ||
+      (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto))
     return 500;
   if (Left.isOneOf(tok::kw_class, tok::kw_struct))
     return 5000;

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=199796&r1=199795&r2=199796&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Wed Jan 22 02:04:52 2014
@@ -32,7 +32,9 @@ protected:
   }
 
   static std::string format(llvm::StringRef Code) {
-    return format(Code, 0, Code.size(), getGoogleProtoStyle());
+    FormatStyle Style = getGoogleProtoStyle();
+    Style.ColumnLimit = 60; // To make writing tests easier.
+    return format(Code, 0, Code.size(), Style);
   }
 
   static void verifyFormat(llvm::StringRef Code) {
@@ -48,6 +50,14 @@ TEST_F(FormatTestProto, FormatsMessages)
                "  required int32 field1 = 1;\n"
                "  optional string field2 = 2 [default = \"2\"]\n"
                "}");
+
+  verifyFormat("message SomeMessage {\n"
+               "  optional really.really.long.and.qualified.type.aaaaaaa\n"
+               "      fiiiiiiiiiiiiiiiiiiiiiiiiield = 1;\n"
+               "  optional\n"
+               "      really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa\n"
+               "          another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n"
+               "}");
 }
 
 TEST_F(FormatTestProto, FormatsEnums) {





More information about the cfe-commits mailing list