Skip to content

Commit

Permalink
PR #332: Handle cycle/delay range like other range contexts
Browse files Browse the repository at this point in the history
Fixes #258.

GitHub PR #332

Copybara import of the project:

  - 04629a5 Handle cycle/delay range like other range contexts by Rafal Kapuscik <[email protected]>

Closes #332

PiperOrigin-RevId: 317753549
  • Loading branch information
Rafal Kapuscik authored and hzeller committed Jun 23, 2020
1 parent c9d4d5e commit d104c3c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
12 changes: 8 additions & 4 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4870,12 +4870,16 @@ static const std::initializer_list<FormatterTestCase> kFormatterTestCases = {
" a |-> ##1 b;\n" // with delay
" endproperty\n"
"endmodule\n"},
{"module mp ;property p1 ; a|->## [0:1] b;endproperty endmodule",
{"module mp ;property p1 ; a|->## [0: 1] b;endproperty endmodule",
"module mp;\n"
" property p1;\n"
" a |-> ##[0: 1] b;\n" // with delay range
// TODO(b/152411381): fix spacing between "0:"
// (context-sensitive)
" a |-> ##[0:1] b;\n" // prefer no spaces with delay range
" endproperty\n"
"endmodule\n"},
{"module mp ;property p1 ; a|->## [0 : 1] b;endproperty endmodule",
"module mp;\n"
" property p1;\n"
" a |-> ##[0 : 1] b;\n" // limit to one space, symmetrize
" endproperty\n"
"endmodule\n"},
{"module mp ;property p1 ; a## 1 b;endproperty endmodule",
Expand Down
2 changes: 1 addition & 1 deletion verilog/formatting/token_annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static bool PairwiseNonmergeable(const PreFormatToken& ftoken) {
static bool InRangeLikeContext(const SyntaxTreeContext& context) {
return context.IsInsideFirst(
{NodeEnum::kSelectVariableDimension, NodeEnum::kDimensionRange,
NodeEnum::kDimensionSlice},
NodeEnum::kDimensionSlice, NodeEnum::kCycleDelayRange},
{});
}

Expand Down
36 changes: 36 additions & 0 deletions verilog/formatting/token_annotator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,42 @@ TEST(TokenAnnotatorTest, AnnotateFormattingWithContextTest) {
// no spaces preceding ':' in unit test context
{0, SpacingOptions::Undecided},
},
{
// [1:0]
DefaultStyle,
{verilog_tokentype::TK_DecNumber, "1"},
{':', ":"},
{NodeEnum::kCycleDelayRange},
// no spaces preceding ':' in unit test context
{0, SpacingOptions::Undecided},
},
{
// [1:0]
DefaultStyle,
{':', ":"},
{verilog_tokentype::TK_DecNumber, "0"},
{NodeEnum::kCycleDelayRange},
// no spaces preceding ':' in unit test context
{0, SpacingOptions::Undecided},
},
{
// [a:b]
DefaultStyle,
{SymbolIdentifier, "a"},
{':', ":"},
{NodeEnum::kCycleDelayRange},
// no spaces preceding ':' in unit test context
{0, SpacingOptions::Undecided},
},
{
// [a:b]
DefaultStyle,
{':', ":"},
{SymbolIdentifier, "b"},
{NodeEnum::kCycleDelayRange},
// no spaces preceding ':' in unit test context
{0, SpacingOptions::Undecided},
},
{
// [1:0]
DefaultStyle,
Expand Down

0 comments on commit d104c3c

Please sign in to comment.