r273553 - clang-format: [Proto] Use more compact format for text-formatted options

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 23 02:40:19 PDT 2016


Author: djasper
Date: Thu Jun 23 04:40:19 2016
New Revision: 273553

URL: http://llvm.org/viewvc/llvm-project?rev=273553&view=rev
Log:
clang-format: [Proto] Use more compact format for text-formatted options

Before:
  enum Type {
    UNKNOWN = 0 [(some_options) = {
      a: aa,
      b: bb
    }];
  };

After:
  enum Type {
    UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];
  };

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=273553&r1=273552&r2=273553&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jun 23 04:40:19 2016
@@ -2332,9 +2332,6 @@ bool TokenAnnotator::mustBreakBefore(con
     return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
            (Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
            (Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
-  if (Style.Language == FormatStyle::LK_Proto && Left.isNot(tok::l_brace) &&
-      Right.is(TT_SelectorName))
-    return true;
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
     return true;
 

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=273553&r1=273552&r2=273553&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Jun 23 04:40:19 2016
@@ -74,8 +74,11 @@ TEST_F(FormatTestProto, FormatsEnums) {
                "  TYPE_B = 2;\n"
                "};");
   verifyFormat("enum Type {\n"
+               "  UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];\n"
+               "};");
+  verifyFormat("enum Type {\n"
                "  UNKNOWN = 0 [(some_options) = {\n"
-               "    a: aa,\n"
+               "    a: aa,  // wrap\n"
                "    b: bb\n"
                "  }];\n"
                "};");
@@ -153,10 +156,7 @@ TEST_F(FormatTestProto, FormatsOptions)
                "  field_a: OK\n"
                "  field_b: \"OK\"\n"
                "  field_c: \"OK\"\n"
-               "  msg_field: {\n"
-               "    field_d: 123\n"
-               "    field_e: OK\n"
-               "  }\n"
+               "  msg_field: {field_d: 123 field_e: OK}\n"
                "};");
   verifyFormat("option (MyProto.options) = {\n"
                "  field_a: OK  // Comment\n"




More information about the cfe-commits mailing list