r256737 - clang-format: [Proto] Basic support for options with <> for repeated fields.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 3 23:28:12 PST 2016
Author: djasper
Date: Mon Jan 4 01:28:12 2016
New Revision: 256737
URL: http://llvm.org/viewvc/llvm-project?rev=256737&view=rev
Log:
clang-format: [Proto] Basic support for options with <> for repeated fields.
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=256737&r1=256736&r2=256737&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 4 01:28:12 2016
@@ -459,7 +459,8 @@ private:
break;
}
}
- if (Contexts.back().ColonIsDictLiteral) {
+ if (Contexts.back().ColonIsDictLiteral ||
+ Style.Language == FormatStyle::LK_Proto) {
Tok->Type = TT_DictLiteral;
} else if (Contexts.back().ColonIsObjCMethodExpr ||
Line.startsWith(TT_ObjCMethodSpecifier)) {
@@ -1878,6 +1879,8 @@ bool TokenAnnotator::spaceRequiredBetwee
tok::numeric_constant, tok::l_paren, tok::l_brace,
tok::kw_true, tok::kw_false))
return false;
+ if (Left.is(tok::colon))
+ return !Left.is(TT_ObjCMethodExpr);
if (Left.is(tok::coloncolon))
return false;
if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
@@ -1928,8 +1931,6 @@ bool TokenAnnotator::spaceRequiredBetwee
!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare) &&
!Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
return false;
- if (Left.is(tok::colon))
- return !Left.is(TT_ObjCMethodExpr);
if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
return !Left.Children.empty(); // No spaces in "{}".
if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=256737&r1=256736&r2=256737&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Mon Jan 4 01:28:12 2016
@@ -168,6 +168,12 @@ TEST_F(FormatTestProto, FormatsOptions)
" field_c: \"OK\"\n"
" msg_field{field_d: 123}\n"
"};");
+
+ // Support syntax with <> instead of {}.
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_c: \"OK\",\n"
+ " msg_field: <field_d: 123>\n"
+ "};");
}
TEST_F(FormatTestProto, FormatsService) {
More information about the cfe-commits
mailing list