Skip to content

Commit

Permalink
Merge pull request #1568 from antmicro/msrs/fix-comment-following-a-d…
Browse files Browse the repository at this point in the history
…elay

Fix comment following a delay
  • Loading branch information
hzeller authored Jan 10, 2023
2 parents c17eaab + 7b3d07e commit 9c1489d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
37 changes: 37 additions & 0 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5517,6 +5517,43 @@ static constexpr FormatterTestCase kFormatterTestCases[] = {
" );\n"
"endmodule\n"},

{// comment following a delay in next line
"module t;\n"
"reg x;\n"
"initial begin\n"
"#20\n"
"//comment\n"
"x = 1;\n"
"x = 2;\n"
"end\n"
"endmodule\n",
"module t;\n"
" reg x;\n"
" initial begin\n"
" #20\n"
" //comment\n"
" x = 1;\n"
" x = 2;\n"
" end\n"
"endmodule\n"},
{// comment following a delay in the same line
"module t;\n"
"reg x;\n"
"initial begin\n"
"#20 //comment\n"
"x = 1;\n"
"x = 2;\n"
"end\n"
"endmodule\n",
"module t;\n"
" reg x;\n"
" initial begin\n"
" #20 //comment\n"
" x = 1;\n"
" x = 2;\n"
" end\n"
"endmodule\n"},

{
// test that alternate top-syntax mode works
"// verilog_syntax: parse-as-module-body\n"
Expand Down
11 changes: 7 additions & 4 deletions verilog/formatting/tree_unwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -971,9 +971,11 @@ void TreeUnwrapper::SetIndentationsAndCreatePartitions(
{
// Single statements directly inside a flow-control construct
// should be properly indented one level.
const int indent = ShouldIndentRelativeToDirectParent(Context())
? style_.indentation_spaces
: 0;
const int indent = Context().IsInside(NodeEnum::kBlockItemStatementList)
? 0
: ShouldIndentRelativeToDirectParent(Context())
? style_.indentation_spaces
: 0;
VisitIndentedSection(node, indent,
PartitionPolicyEnum::kFitOnLineElseExpand);
break;
Expand Down Expand Up @@ -2874,7 +2876,8 @@ void TreeUnwrapper::ReshapeTokenPartitions(
// RHS may have been further partitioned, e.g. a macro call.
auto& children = partition.Children();
if (children.size() == 2 &&
verible::is_leaf(children.front()) /* left side */) {
verible::is_leaf(children.front()) /* left side */ &&
!PartitionIsForcedIntoNewLine(children.back())) {
verible::MergeLeafIntoNextLeaf(&children.front());
VLOG(4) << "after merge leaf (left-into-right):\n" << partition;
}
Expand Down

0 comments on commit 9c1489d

Please sign in to comment.