r356833 - [clang-format] correctly format protobuf fields named "enum".
Paul Hoad via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 23 07:24:30 PDT 2019
Author: paulhoad
Date: Sat Mar 23 07:24:30 2019
New Revision: 356833
URL: http://llvm.org/viewvc/llvm-project?rev=356833&view=rev
Log:
[clang-format] correctly format protobuf fields named "enum".
Summary: Similar to TypeScript, "enum" is not a reserved word.
Reviewers: krasimir, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: MyDeveloperDay, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D59629
Patch by: dchai (Donald Chai)
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=356833&r1=356832&r2=356833&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Mar 23 07:24:30 2019
@@ -2018,6 +2018,10 @@ bool UnwrappedLineParser::parseEnum() {
FormatTok->isOneOf(tok::colon, tok::question))
return false;
+ // In protobuf, "enum" can be used as a field name.
+ if (Style.Language == FormatStyle::LK_Proto && FormatTok->is(tok::equal))
+ return false;
+
// Eat up enum class ...
if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct))
nextToken();
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=356833&r1=356832&r2=356833&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Sat Mar 23 07:24:30 2019
@@ -107,6 +107,12 @@ TEST_F(FormatTestProto, FormatsEnums) {
"};");
}
+TEST_F(FormatTestProto, EnumAsFieldName) {
+ verifyFormat("message SomeMessage {\n"
+ " required int32 enum = 1;\n"
+ "}");
+}
+
TEST_F(FormatTestProto, UnderstandsReturns) {
verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
}
More information about the cfe-commits
mailing list