Skip to content

Commit df722b0

Browse files
committed
[clang-format] Don't indent Verilog begin keyword on its own line
When the line is too long and the `begin` keyword wraps to the next line, it shouldn't be indented. Reviewed By: HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D149657
1 parent e124285 commit df722b0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
11251125
Style.IndentWidth;
11261126
}
11271127

1128-
if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) {
1128+
if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
1129+
(Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) {
11291130
if (Current.NestingLevel == 0 ||
11301131
(Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
11311132
State.NextToken->is(TT_LambdaLBrace))) {

clang/unittests/Format/FormatTestVerilog.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,39 @@ TEST_F(FormatTestVerilog, Block) {
162162
"x = x;");
163163
verifyFormat("rand join x x;\n"
164164
"x = x;");
165+
// The begin keyword should not be indented if it is too long to fit on the
166+
// same line.
167+
verifyFormat("while (true) //\n"
168+
"begin\n"
169+
" while (true) //\n"
170+
" begin\n"
171+
" end\n"
172+
"end");
173+
verifyFormat("while (true) //\n"
174+
"begin : x\n"
175+
" while (true) //\n"
176+
" begin : x\n"
177+
" end : x\n"
178+
"end : x");
179+
verifyFormat("while (true) //\n"
180+
"fork\n"
181+
" while (true) //\n"
182+
" fork\n"
183+
" join\n"
184+
"join");
185+
auto Style = getDefaultStyle();
186+
Style.ColumnLimit = 17;
187+
verifyFormat("while (true)\n"
188+
"begin\n"
189+
" while (true)\n"
190+
" begin\n"
191+
" end\n"
192+
"end",
193+
"while (true) begin\n"
194+
" while (true) begin"
195+
" end\n"
196+
"end",
197+
Style);
165198
}
166199

167200
TEST_F(FormatTestVerilog, Case) {

0 commit comments

Comments
 (0)