]> granicus.if.org Git - clang/commitdiff
clang-format: [Proto] Handle enum bodies differently.
authorDaniel Jasper <djasper@google.com>
Thu, 16 Jul 2015 14:25:43 +0000 (14:25 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 16 Jul 2015 14:25:43 +0000 (14:25 +0000)
In proto, enum constants can contain complex options and should be
handled more like individual declarations.

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

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

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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestProto.cpp

index 97fd98ecb9479d151130feddf62a2c4233f8f9b4..e705c98c67b661078efebf17e94a868c49b8891e 100644 (file)
@@ -811,9 +811,8 @@ void UnwrappedLineParser::parseStructuralElement() {
       // parseEnum falls through and does not yet add an unwrapped line as an
       // enum definition can start a structural element.
       parseEnum();
-      // This does not apply for Java and JavaScript.
-      if (Style.Language == FormatStyle::LK_Java ||
-          Style.Language == FormatStyle::LK_JavaScript) {
+      // This only applies for C++.
+      if (Style.Language != FormatStyle::LK_Cpp) {
         addUnwrappedLine();
         return;
       }
@@ -1554,6 +1553,9 @@ void UnwrappedLineParser::parseEnum() {
     // Java enums are different.
     parseJavaEnumBody();
     return;
+  } else if (Style.Language == FormatStyle::LK_Proto) {
+    parseBlock(/*MustBeDeclaration=*/true);
+    return;
   }
 
   // Parse enum body.
index 74f7005b219fb428e63b43e9ae210c3ed87fe015..0dadd3b673100675fa24c43e000512cbc1c69c86 100644 (file)
@@ -73,6 +73,12 @@ TEST_F(FormatTestProto, FormatsEnums) {
                "  TYPE_A = 1;\n"
                "  TYPE_B = 2;\n"
                "};");
+  verifyFormat("enum Type {\n"
+               "  UNKNOWN = 0 [(some_options) = {\n"
+               "    a: aa,\n"
+               "    b: bb\n"
+               "  }];\n"
+               "};");
 }
 
 TEST_F(FormatTestProto, UnderstandsReturns) {