[clang] b688b58 - [clang-format] Fix non-case colons in Verilog case lines
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 19 14:41:58 PDT 2023
Author: sstwcw
Date: 2023-03-19T21:41:14Z
New Revision: b688b58f83ceb48dbe185be95372e45de1d51401
URL: https://github.com/llvm/llvm-project/commit/b688b58f83ceb48dbe185be95372e45de1d51401
DIFF: https://github.com/llvm/llvm-project/commit/b688b58f83ceb48dbe185be95372e45de1d51401.diff
LOG: [clang-format] Fix non-case colons in Verilog case lines
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
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestVerilog.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 8613f51cd8a04..12beeba7c70cc 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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;
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index aae62668c4b84..a4d6b540bd831 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -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) {
More information about the cfe-commits
mailing list