Skip to content

Commit

Permalink
Merge pull request #751 from antmicro/keep-parenthesis
Browse files Browse the repository at this point in the history
Adjust closing parenthesis penalties
  • Loading branch information
hzeller authored Apr 7, 2021
2 parents 4366c2c + bd4eb09 commit d4cd328
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,22 @@ static constexpr FormatterTestCase kFormatterTestCases[] = {
"`FOO(bar)\n"},
{// multiple argument macro call
" `FOO( bar , baz )\n", "`FOO(bar, baz)\n"},
{// long macro call breaking
" `ASSERT_INIT(S, (D == 4 && K inside {0, 1}) ||"
" (D == 3 && K== 4))\n",
"`ASSERT_INIT(S,\n"
" (D == 4 && K inside {0, 1})\n"
" || (D == 3 && K == 4))\n"},
{// long macro call breaking
" `AINIT(S, (D == 4 && K inside {0, 1}) ||"
" (D == 3 && K== 4))\n",
"`AINIT(S,\n"
" (D == 4 && K inside {0, 1}) || (\n"
" D == 3 && K == 4))\n"},
{// long macro call breaking
" `ASSERT_INIT(S, D == 4 && K inside {0, 1})\n",
"`ASSERT_INIT(S,\n"
" D == 4 && K inside {0, 1})\n"},
{// macro call in function
"function void foo( ); foo=`FOO( bar , baz ) ; endfunction\n",
"function void foo();\n"
Expand Down
4 changes: 4 additions & 0 deletions verilog/formatting/token_annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ static WithReason<int> BreakPenaltyBetweenTokens(
// TODO(fangism): ... except when () is used as precedence.
if (right.format_token_enum == FormatTokenType::open_group)
return {5, "right is open-group"};
// Prefer to keep ')' with whatever is on the left.
if (right.format_token_enum == FormatTokenType::close_group ||
right.TokenEnum() == verilog_tokentype::MacroCallCloseToEndLine)
return {10, "right is close-group"};

if (left.TokenEnum() == TK_DecNumber &&
right.TokenEnum() == TK_UnBasedNumber) {
Expand Down

0 comments on commit d4cd328

Please sign in to comment.