Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatter: Fix constraint block expansion #761

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9240,8 +9240,24 @@ TEST(FormatterEndToEndTest, ConstraintExpressions) {
{"constraint only_vec_instr_c {soft only_vec_instr == 0;}",
"constraint only_vec_instr_c {soft only_vec_instr == 0;}\n"},

{"constraint\nnum_trans_c\n\n\n{\n\n\nnum_trans inside{[800:1000]};}",
"constraint num_trans_c {num_trans inside {[800 : 1000]};}\n"},
// constraint with brackets inside block item list
{"constraint\nnum_trans_c\n\n\n{num_trans inside{[800:1000]};}",
"constraint num_trans_c {\n"
" num_trans inside {[800 : 1000]};\n"
"}\n"},

{"constraint data_size_c {data.size() inside {[1 : 65536]};}",
"constraint data_size_c {\n"
" data.size() inside {[1 : 65536]};\n"
"}\n"},

{"constraint data_size_c {data.size() inside {[1 : 65536]};a==b;"
"num_trans inside{[800:1000]};}\n",
"constraint data_size_c {\n"
" data.size() inside {[1 : 65536]};\n"
" a == b;\n"
" num_trans inside {[800 : 1000]};\n"
"}\n"},

// if-vs-concatenation expression
{"constraint c_operation{ if(fixed_operation_en){"
Expand Down Expand Up @@ -9280,6 +9296,15 @@ TEST(FormatterEndToEndTest, ConstraintExpressions) {
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;\n"
" ccccccccccccccccccccccc == dddddddddddddddddddddd;\n"
"}\n"},

// FIXME: Find-out why formatter is preserving those newlines in
// constraint block
{"constraint\nnum_trans_c\n\n\n{\n\n\nnum_trans inside{[800:1000]};}",
"constraint num_trans_c {\n"
"\n"
"\n"
" num_trans inside {[800 : 1000]};\n"
"}\n"},
};
FormatStyle style;
style.column_limit =
Expand Down
11 changes: 11 additions & 0 deletions verilog/formatting/tree_unwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,17 @@ void TreeUnwrapper::ReshapeTokenPartitions(
if (PartitionIsCloseBrace(last)) {
verible::MergeLeafIntoPreviousLeaf(&last);
}
} else if (partition.Children().size() == 3) {
// Propagate partition expansion on flattened partitions
const auto& block_partition = partition.Children()[1];
const auto block_partition_policy =
block_partition.Value().PartitionPolicy();

if (block_partition.Children().size() == 0 &&
block_partition_policy == PartitionPolicyEnum::kAlwaysExpand) {
auto& uwline = partition.Value();
uwline.SetPartitionPolicy(PartitionPolicyEnum::kAlwaysExpand);
}
}
break;
}
Expand Down