[PATCH] D145888: [clang-format] Fix non-case colons in Verilog case lines
sstwcw via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 12 15:40:06 PDT 2023
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan, rymiel.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Back in D128714 <https://reviews.llvm.org/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`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145888
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestVerilog.cpp
Index: clang/unittests/Format/FormatTestVerilog.cpp
===================================================================
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -250,6 +250,33 @@
" 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, Declaration) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4420,8 +4420,6 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145888.504481.patch
Type: text/x-patch
Size: 2042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230312/43cc5a4b/attachment.bin>
More information about the cfe-commits
mailing list