r325509 - [clang-format] Fixup a case of text proto message attributes
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 19 07:31:25 PST 2018
Author: krasimir
Date: Mon Feb 19 07:31:25 2018
New Revision: 325509
URL: http://llvm.org/viewvc/llvm-project?rev=325509&view=rev
Log:
[clang-format] Fixup a case of text proto message attributes
Summary: This patch fixes a case where a proto message attribute is wrongly identified as an text proto extension.
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43465
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=325509&r1=325508&r2=325509&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 19 07:31:25 2018
@@ -375,6 +375,10 @@ private:
// (aaa) = aaa
// ];
//
+ // extensions 123 [
+ // (aaa) = aaa
+ // ];
+ //
// or text proto extensions (in options):
//
// option (Aaa.options) = {
@@ -394,6 +398,8 @@ private:
Left->Type = TT_ArrayInitializerLSquare;
if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
tok::equal) &&
+ !Left->endsSequence(tok::l_square, tok::numeric_constant,
+ tok::identifier) &&
!Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
Left->Type = TT_ProtoExtensionLSquare;
BindingIncrease = 10;
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=325509&r1=325508&r2=325509&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Mon Feb 19 07:31:25 2018
@@ -168,6 +168,16 @@ TEST_F(FormatTestProto, MessageFieldAttr
" aaaaaaaaaaaaaaaa: true\n"
" }\n"
"];");
+ verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.bbbb'];");
+ verifyFormat("extensions 20\n"
+ " [(proto3.type) = 'Aaaa.bbbb', (aaa.Aaa) = 'aaa.bbb'];");
+ verifyFormat("extensions 123 [\n"
+ " (aaa) = aaaa,\n"
+ " (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
+ " aaaaaaaaaaaaaaaaa: true,\n"
+ " aaaaaaaaaaaaaaaa: true\n"
+ " }\n"
+ "];");
}
TEST_F(FormatTestProto, DoesntWrapFileOptions) {
More information about the cfe-commits
mailing list