From d104c3c1c2e2b4e6f92c3ed6dc2f6341f4481998 Mon Sep 17 00:00:00 2001 From: Rafal Kapuscik Date: Mon, 22 Jun 2020 16:01:00 -0700 Subject: [PATCH] PR #332: Handle cycle/delay range like other range contexts Fixes #258. GitHub PR https://github.com/google/verible/pull/332 Copybara import of the project: - 04629a5efc966842f3e7b8e00bab6753ef2f588c Handle cycle/delay range like other range contexts by Rafal Kapuscik Closes #332 PiperOrigin-RevId: 317753549 --- verilog/formatting/formatter_test.cc | 12 +++++--- verilog/formatting/token_annotator.cc | 2 +- verilog/formatting/token_annotator_test.cc | 36 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/verilog/formatting/formatter_test.cc b/verilog/formatting/formatter_test.cc index b7397c01e..bf438b9d1 100644 --- a/verilog/formatting/formatter_test.cc +++ b/verilog/formatting/formatter_test.cc @@ -4870,12 +4870,16 @@ static const std::initializer_list 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", diff --git a/verilog/formatting/token_annotator.cc b/verilog/formatting/token_annotator.cc index 62a5f9f73..1815ae9c1 100644 --- a/verilog/formatting/token_annotator.cc +++ b/verilog/formatting/token_annotator.cc @@ -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}, {}); } diff --git a/verilog/formatting/token_annotator_test.cc b/verilog/formatting/token_annotator_test.cc index d0fa2e288..50346864c 100644 --- a/verilog/formatting/token_annotator_test.cc +++ b/verilog/formatting/token_annotator_test.cc @@ -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,