Skip to content

Commit

Permalink
[clang-format] Don't indent Verilog begin keyword on its own line
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eywdck2l committed May 7, 2023
1 parent e124285 commit df722b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
Style.IndentWidth;
}

if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) {
if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
(Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) {
if (Current.NestingLevel == 0 ||
(Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
State.NextToken->is(TT_LambdaLBrace))) {
Expand Down
33 changes: 33 additions & 0 deletions clang/unittests/Format/FormatTestVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,39 @@ TEST_F(FormatTestVerilog, Block) {
"x = x;");
verifyFormat("rand join x x;\n"
"x = x;");
// The begin keyword should not be indented if it is too long to fit on the
// same line.
verifyFormat("while (true) //\n"
"begin\n"
" while (true) //\n"
" begin\n"
" end\n"
"end");
verifyFormat("while (true) //\n"
"begin : x\n"
" while (true) //\n"
" begin : x\n"
" end : x\n"
"end : x");
verifyFormat("while (true) //\n"
"fork\n"
" while (true) //\n"
" fork\n"
" join\n"
"join");
auto Style = getDefaultStyle();
Style.ColumnLimit = 17;
verifyFormat("while (true)\n"
"begin\n"
" while (true)\n"
" begin\n"
" end\n"
"end",
"while (true) begin\n"
" while (true) begin"
" end\n"
"end",
Style);
}

TEST_F(FormatTestVerilog, Case) {
Expand Down

0 comments on commit df722b0

Please sign in to comment.