Skip to content

Commit

Permalink
[clang-format] Fix non-case colons in Verilog case lines
Browse files Browse the repository at this point in the history
Back in D128714, we should have replaced the old rule about colons when
we added the new one.  Because we didn't, all colons got mistaken as
case colons as long as the line began with `case` or `default`.  Now we
remove the rule that we forgot to remove.

Reviewed By: MyDeveloperDay, rymiel

Differential Revision: https://reviews.llvm.org/D145888
  • Loading branch information
eywdck2l committed Mar 19, 2023
1 parent 84870c4 commit b688b58
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 0 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -4426,8 +4426,6 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Line.First->isOneOf(tok::kw_default, tok::kw_case))) {
return Style.SpaceBeforeCaseColon;
}
if (Line.First->isOneOf(tok::kw_default, tok::kw_case))
return Style.SpaceBeforeCaseColon;
const FormatToken *Next = Right.getNextNonComment();
if (!Next || Next->is(tok::semi))
return false;
Expand Down
33 changes: 33 additions & 0 deletions clang/unittests/Format/FormatTestVerilog.cpp
Expand Up @@ -250,6 +250,39 @@ TEST_F(FormatTestVerilog, Case) {
" end\n"
"endcase",
Style);
// Other colons should not be mistaken as case colons.
Style = getLLVMStyle(FormatStyle::LK_Verilog);
Style.BitFieldColonSpacing = FormatStyle::BFCS_None;
verifyFormat("case (x[1:0])\n"
"endcase",
Style);
verifyFormat("default:\n"
" x[1:0] = x[1:0];",
Style);
Style.BitFieldColonSpacing = FormatStyle::BFCS_Both;
verifyFormat("case (x[1 : 0])\n"
"endcase",
Style);
verifyFormat("default:\n"
" x[1 : 0] = x[1 : 0];",
Style);
Style = getLLVMStyle(FormatStyle::LK_Verilog);
Style.SpacesInContainerLiterals = true;
verifyFormat("case ('{x : x, default : 9})\n"
"endcase",
Style);
verifyFormat("x = '{x : x, default : 9};\n", Style);
verifyFormat("default:\n"
" x = '{x : x, default : 9};\n",
Style);
Style.SpacesInContainerLiterals = false;
verifyFormat("case ('{x: x, default: 9})\n"
"endcase",
Style);
verifyFormat("x = '{x: x, default: 9};\n", Style);
verifyFormat("default:\n"
" x = '{x: x, default: 9};\n",
Style);
}

TEST_F(FormatTestVerilog, Coverage) {
Expand Down

0 comments on commit b688b58

Please sign in to comment.