]> granicus.if.org Git - clang/commitdiff
clang-format: Understand proto text format without commas.
authorDaniel Jasper <djasper@google.com>
Tue, 15 Apr 2014 09:54:30 +0000 (09:54 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 15 Apr 2014 09:54:30 +0000 (09:54 +0000)
Also removed spaces before colons as they don't seem to be used
frequently.

Before:
optional int32 b = 2
    [(foo_options) = {aaaaaaaaaaaaaaaaaaa : 123 bbbbbbbbbbbbbbbbbbbbbbbb :
                          "baz"}];

After:
optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa: 123,
                                       bbbbbbbbbbbbbbbbbbbbbbbb:"baz"}];

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

lib/Format/ContinuationIndenter.cpp
lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp

index 0ad8c1eb419053b3537fc033f7ca2e7de041d1a8..35dc182a2d1e08609c613082b9ccbb254678dc00 100644 (file)
@@ -472,6 +472,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
     else
       return State.FirstIndent;
   }
+  if (Current.is(tok::identifier) && Current.Next &&
+      Current.Next->Type == TT_DictLiteral)
+    return State.Stack.back().Indent;
   if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)
     return State.StartOfStringLiteral;
   if (NextNonComment->is(tok::lessless) &&
index 4a9c37e08419f97248c215da6d65950586348857..00e012138b1cfa739f0132ca7c0f6c94a75db4d6 100644 (file)
@@ -343,6 +343,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
     GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_Proto) {
     GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+    GoogleStyle.SpacesInContainerLiterals = false;
   }
 
   return GoogleStyle;
index c4fa784f2a992d877ffdd413eb0eb7aca7d4b623..98323fcc57cb2f86bdcf1f87561d03089a687031 100644 (file)
@@ -1243,7 +1243,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
 
   if (Left.is(tok::semi))
     return 0;
-  if (Left.is(tok::comma))
+  if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next &&
+                              Right.Next->Type == TT_DictLiteral))
     return 1;
   if (Right.is(tok::l_square)) {
     if (Style.Language == FormatStyle::LK_Proto)
@@ -1647,6 +1648,10 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
   if (Left.is(tok::identifier) && Right.is(tok::string_literal))
     return true;
 
+  if (Right.is(tok::identifier) && Right.Next &&
+      Right.Next->Type == TT_DictLiteral)
+    return true;
+
   if (Left.Type == TT_CtorInitializerComma &&
       Style.BreakConstructorInitializersBeforeComma)
     return false;
index ceac2db5f46a834bc9b56a63093e33e7463f5244..84d0d7d32ee7d5e6322e7cfba78e016f308206f6 100644 (file)
@@ -81,13 +81,13 @@ TEST_F(FormatTestProto, MessageFieldAttributes) {
   verifyFormat("optional LongMessageType long_proto_field = 1\n"
                "    [default = REALLY_REALLY_LONG_CONSTANT_VALUE];");
   verifyFormat("repeated double value = 1\n"
-               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}];");
+               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa: AAAAAAAA}];");
   verifyFormat("repeated double value = 1\n"
-               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa : AAAAAAAAAA,\n"
-               "                            bbbbbbbbbbbbbbbb : BBBBBBBBBB}];");
+               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
+               "                            bbbbbbbbbbbbbbbb: BBBBBBBBBB}];");
   verifyFormat("repeated double value = 1\n"
-               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa : AAAAAAAAAA\n"
-               "                            bbbbbbbbbbbbbbbb : BBBBBBBBBB}];");
+               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
+               "                            bbbbbbbbbbbbbbbb: BBBBBBBBBB}];");
 }
 
 TEST_F(FormatTestProto, FormatsOptions) {