From 9b2aa42f00253d5a5fd8153bfb28481a62beb8d9 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 19 Feb 2018 15:31:25 +0000 Subject: [PATCH] [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 llvm-svn: 325509 --- clang/lib/Format/TokenAnnotator.cpp | 6 ++++++ clang/unittests/Format/FormatTestProto.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 75a3fdce8030..f56230ee88cd 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index 4c61ec1398f5..1d6b7502e098 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -168,6 +168,16 @@ TEST_F(FormatTestProto, MessageFieldAttributes) { " 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) { -- 2.34.1