Skip to content

Commit

Permalink
Attach ';' to macro-call statements' partitions.
Browse files Browse the repository at this point in the history
fixes #278

PiperOrigin-RevId: 308096014
  • Loading branch information
fangism authored and hzeller committed Apr 24, 2020
1 parent 47f3270 commit 5cf83fe
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
24 changes: 24 additions & 0 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,30 @@ static const std::initializer_list<FormatterTestCase> kFormatterTestCases = {
"task t;\n"
" ##`DELAY_VALUE;\n"
"endtask\n"},
{"task t;\n"
"`uvm_error( foo,bar);\n"
"endtask\n",
"task t;\n"
" `uvm_error(foo, bar);\n"
"endtask\n"},
{"task t;\n"
"`uvm_error(foo,bar)\n"
";\n" // null statement
"endtask\n",
"task t;\n"
" `uvm_error(foo, bar)\n"
" ;\n"
"endtask\n"},
{"task t;\n"
"if(expr)begin\t\n"
"`uvm_error(foo,bar);\n"
"end\n"
"endtask\n",
"task t;\n"
" if (expr) begin\n"
" `uvm_error(foo, bar);\n"
" end\n"
"endtask\n"},
{"task\nrabbit;$kill(the,\nrabbit)\n;endtask: rabbit\n",
"task rabbit;\n"
" $kill(the, rabbit);\n"
Expand Down
5 changes: 5 additions & 0 deletions verilog/formatting/tree_unwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,11 @@ void TreeUnwrapper::ReshapeTokenPartitions(
AttachTrailingSemicolonToPreviousPartition(&partition);
break;
}
case NodeEnum::kStatement: {
// This handles cases like macro-calls followed by a semicolon.
AttachTrailingSemicolonToPreviousPartition(&partition);
break;
}
case NodeEnum::kModuleHeader: {
// If there were any parameters or ports at all, expand.
// TODO(fangism): This should be done by inspecting the CST node,
Expand Down
32 changes: 32 additions & 0 deletions verilog/formatting/tree_unwrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,38 @@ const TreeUnwrapperTestData kUnwrapUvmTestCases[] = {
N(2, L(2, {"l1b", ","}), L(2, {"UVM_DEFAULT", ")"}))),
L(0, {"`uvm_field_utils_end"}),
},

{
"uvm macro statement test, with semicolon on same line",
"task t;\n"
"`uvm_error(foo, bar);\n"
"endtask\n",
TaskDeclaration(0, TaskHeader(0, {"task", "t", ";"}),
N(1, //
L(1, {"`uvm_error", "("}), //
N(3, //
L(3, {"foo", ","}), //
L(3, {"bar", ")", ";"}))),
L(0, {"endtask"})),
},
{
"uvm macro statement test, detached null statement semicolon",
"task t;\n"
"`uvm_error(foo, bar)\n"
";\n"
"endtask\n",
TaskDeclaration(
0, TaskHeader(0, {"task", "t", ";"}),
StatementList(1,
N(1, //
L(1, {"`uvm_error", "("}), //
N(3, //
L(3, {"foo", ","}), //
L(3, {"bar", ")"}))), //
L(1, {";"}) // null statement stays detached
),
L(0, {"endtask"})),
},
};

// Test that TreeUnwrapper produces the correct UnwrappedLines from code with
Expand Down

0 comments on commit 5cf83fe

Please sign in to comment.