Skip to content

Commit caf393d

Browse files
fowleskrasimirgg
authored andcommitted
Fix format for case in .proto files
Fix format for `case` in .proto files Reviewed By: krasimir, echristo Differential Revision: https://reviews.llvm.org/D141547
1 parent c512eda commit caf393d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
590590
[[fallthrough]];
591591
}
592592
case tok::kw_case:
593-
if (Style.isVerilog() ||
593+
if (Style.isProto() || Style.isVerilog() ||
594594
(Style.isJavaScript() && Line->MustBeDeclaration)) {
595+
// Proto: there are no switch/case statements
595596
// Verilog: Case labels don't have this word. We handle case
596597
// labels including default in TokenAnnotator.
597598
// JavaScript: A 'case: string' style field declaration.
@@ -1620,7 +1621,11 @@ void UnwrappedLineParser::parseStructuralElement(
16201621
// e.g. "default void f() {}" in a Java interface.
16211622
break;
16221623
case tok::kw_case:
1623-
// In Verilog switch is called case.
1624+
// Proto: there are no switch/case statements.
1625+
if (Style.isProto()) {
1626+
nextToken();
1627+
return;
1628+
}
16241629
if (Style.isVerilog()) {
16251630
parseBlock();
16261631
addUnwrappedLine();
@@ -2100,6 +2105,11 @@ void UnwrappedLineParser::parseStructuralElement(
21002105
parseNew();
21012106
break;
21022107
case tok::kw_case:
2108+
// Proto: there are no switch/case statements.
2109+
if (Style.isProto()) {
2110+
nextToken();
2111+
return;
2112+
}
21032113
// In Verilog switch is called case.
21042114
if (Style.isVerilog()) {
21052115
parseBlock();

clang/unittests/Format/FormatTestProto.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ TEST_F(FormatTestProto, EnumAsFieldName) {
113113
"}");
114114
}
115115

116+
TEST_F(FormatTestProto, CaseAsFieldName) {
117+
verifyFormat("message SomeMessage {\n"
118+
" required string case = 1;\n"
119+
" repeated int32 fizz = 2;\n"
120+
"}");
121+
}
122+
116123
TEST_F(FormatTestProto, UnderstandsReturns) {
117124
verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
118125
}

0 commit comments

Comments
 (0)