Skip to content

Commit 0823759

Browse files
authored
Improve indentation of concurrent properties and sequences (#1836) (#1837) (#1838)
* verilog-mode.el (verilog-property-re, verilog-beg-of-statement, verilog-calc-1): Concurrent SVA statement pattern-matching learns 'restrict property' and 'cover sequence' expression for proper indentation around those constructs. This addresses more patterns in IEEE 1800-2017's 'concurrent_sasertion_statement' grammar. * tests{,_ok}/indent_assert_property.v: Add test cases from GitHub user 'pbing'
1 parent 3ab6351 commit 0823759

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

tests/indent_assert_property.v

+14
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ end
2323
always @(posedge clk) begin
2424
end
2525
endmodule
26+
27+
// https://github.com/veripool/verilog-mode/issues/1836
28+
module tb1;
29+
a: restrict property (1);
30+
b: assume property (1);
31+
c: assume property (1);
32+
endmodule
33+
34+
// https://github.com/veripool/verilog-mode/issues/1837
35+
module tb2;
36+
a: cover sequence (1);
37+
b: cover property (1);
38+
c: cover property (1);
39+
endmodule

tests_ok/indent_assert_property.v

+14
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ module myassert(input clk,
2323
always @(posedge clk) begin
2424
end
2525
endmodule
26+
27+
// https://github.com/veripool/verilog-mode/issues/1836
28+
module tb1;
29+
a: restrict property (1);
30+
b: assume property (1);
31+
c: assume property (1);
32+
endmodule
33+
34+
// https://github.com/veripool/verilog-mode/issues/1837
35+
module tb2;
36+
a: cover sequence (1);
37+
b: cover property (1);
38+
c: cover property (1);
39+
endmodule

verilog-mode.el

+15-10
Original file line numberDiff line numberDiff line change
@@ -2556,11 +2556,13 @@ find the errors."
25562556
(defconst verilog-assignment-operation-re-2
25572557
(concat "\\(.*?\\)" verilog-assignment-operator-re))
25582558

2559+
;; Loosely related to IEEE 1800's concurrent_assertion_statement
2560+
(defconst verilog-concurrent-assertion-statement-re
2561+
"\\(\\<\\(assert\\|assume\\|cover\\|restrict\\)\\>\\s-+\\<\\(property\\|sequence\\)\\>\\)\\|\\(\\<assert\\>\\)")
2562+
25592563
(defconst verilog-label-re (concat verilog-identifier-sym-re "\\s-*:\\s-*"))
25602564
(defconst verilog-property-re
2561-
(concat "\\(" verilog-label-re "\\)?"
2562-
;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2563-
"\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2565+
(concat "\\(" verilog-label-re "\\)?" verilog-concurrent-assertion-statement-re))
25642566

25652567
(defconst verilog-no-indent-begin-re
25662568
(eval-when-compile
@@ -2715,7 +2717,6 @@ find the errors."
27152717
"\\(\\<fork\\>\\)\\|" ; 7
27162718
"\\(\\<if\\>\\)\\|"
27172719
verilog-property-re "\\|"
2718-
"\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
27192720
"\\(\\<clocking\\>\\)\\|"
27202721
"\\(\\<task\\>\\)\\|"
27212722
"\\(\\<function\\>\\)\\|"
@@ -4843,7 +4844,7 @@ Uses `verilog-scan' cache."
48434844
(not (or (looking-at "\\<") (forward-word-strictly -1)))
48444845
;; stop if we see an assertion (perhaps labeled)
48454846
(and
4846-
(looking-at "\\(\\w+\\W*:\\W*\\)?\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4847+
(looking-at (concat "\\(\\w+\\W*:\\W*\\)?" verilog-concurrent-assertion-statement-re))
48474848
(progn
48484849
(setq h (point))
48494850
(save-excursion
@@ -6271,12 +6272,16 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
62716272
(throw 'nesting 'defun))))
62726273

62736274
;;
6274-
((looking-at "\\<property\\>")
6275+
((looking-at "\\<\\(property\\|sequence\\)\\>")
62756276
;; *sigh*
6276-
;; {assert|assume|cover} property (); are complete
6277-
;; and could also be labeled: - foo: assert property
6278-
;; but
6279-
;; property ID () ... needs endproperty
6277+
;; - {assert|assume|cover|restrict} property (); are complete
6278+
;; - cover sequence (); is complete
6279+
;; and could also be labeled:
6280+
;; - foo: assert property
6281+
;; - bar: cover sequence
6282+
;; but:
6283+
;; - property ID () ... needs endproperty
6284+
;; - sequence ID () ... needs endsequence
62806285
(verilog-beg-of-statement)
62816286
(if (looking-at verilog-property-re)
62826287
(throw 'continue 'statement) ; We don't need an endproperty for these

0 commit comments

Comments
 (0)