diff --git a/tests/autoreset_latch.v b/tests/autoreset_latch.v index 04b3eb93..04762560 100644 --- a/tests/autoreset_latch.v +++ b/tests/autoreset_latch.v @@ -5,7 +5,7 @@ module device( output logic pass, fail input [7:0] D, in0,in1 ); - enum logic [2:0] {IDLE, START, RUN, PASS, FAIL } state, next_state; + enum logic [2:0] {IDLE, START, RUN, PASS, FAIL } state, next_state; logic ready, next_ready; logic next_pass, next_fail; diff --git a/tests/indent_enum.v b/tests/indent_enum.v index 0601c23c..8a39936f 100644 --- a/tests/indent_enum.v +++ b/tests/indent_enum.v @@ -1,10 +1,14 @@ +module indent_enum; + enum int unsigned { - STATE_0 = 0, - STATE_2 = 2 +STATE_0 = 0, +STATE_2 = 2 } state; enum int unsigned { - STATE_0 = 0, - STATE_1, - STATE_2 - } state, next; +STATE_0 = 0, +STATE_1, +STATE_2 +} state, next; + +endmodule diff --git a/tests/indent_list_nil_typedef_enum.sv b/tests/indent_list_nil_typedef_enum.sv new file mode 100644 index 00000000..5029f968 --- /dev/null +++ b/tests/indent_list_nil_typedef_enum.sv @@ -0,0 +1,111 @@ +module typedef_enum_indent; + +logic variable1; +logic signed [1:0] variable2; +logic variable3; +logic signed [1:0] variable4; + +typedef enum logic [1:0] {STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum logic [1:0] {STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] { +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] { +STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum logic [1:0] +{STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} +enum_t; + +typedef enum {STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum {STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum { +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum { +STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum +{STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} +enum_t; + + +endmodule + + +// Local Variables: +// verilog-indent-lists: nil +// End: + diff --git a/tests/indent_struct.v b/tests/indent_struct.v index 7074891b..a7b20d66 100644 --- a/tests/indent_struct.v +++ b/tests/indent_struct.v @@ -1,45 +1,45 @@ module foo; - - a = { g + c; }; - a = c; - - typedef struct { - reg r; - ahb_op_t op; // Read, write, etc. - ahb_cycle_type_t cti; // Cycle type for bursts - ahb_incr_type_t incr; // Increment type (for bursts) - bit b; - reg r; - ahb_thingy a; - bit [31:2] addr; // Starting address - bit [3:0] byte_sel; // Byte lane select - int len; // Length of transfer - bit [31:0] data[0:7]; // Write data - } ahb_req_t; - - struct { - reg f; - xyzzy b; - }; - struct packed { - int a; // ok - }; - struct packed signed { - int a; // woops - }; - struct packed unsigned { - int a; // woops - }; - + +a = { g + c; }; +a = c; + +typedef struct { +reg r; +ahb_op_t op; // Read, write, etc. +ahb_cycle_type_t cti; // Cycle type for bursts +ahb_incr_type_t incr; // Increment type (for bursts) +bit b; +reg r; +ahb_thingy a; +bit [31:2] addr; // Starting address +bit [3:0] byte_sel; // Byte lane select +int len; // Length of transfer +bit [31:0] data[0:7]; // Write data +} ahb_req_t; + +struct { +reg f; +xyzzy b; +}; +struct packed { +int a; // ok +}; +struct packed signed { +int a; // woops +}; +struct packed unsigned { +int a; // woops +}; + endmodule // foo module foo ( - input a; - input c; - output d; - ); - always @(a) g; - - +input a; +input c; +output d; +); +always @(a) g; + + endmodule // foo diff --git a/tests/indent_typedef_enum.sv b/tests/indent_typedef_enum.sv new file mode 100644 index 00000000..a3c860e6 --- /dev/null +++ b/tests/indent_typedef_enum.sv @@ -0,0 +1,106 @@ +module typedef_enum_indent; + +logic variable1; +logic signed [1:0] variable2; +logic variable3; +logic signed [1:0] variable4; + +typedef enum logic [1:0] {STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum logic [1:0] {STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] { +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] { +STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum logic [1:0] +{STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum logic [1:0] +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} +enum_t; + +typedef enum {STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum {STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum { +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum { +STATE_0, +STATE_1, +STATE_2, +STATE_3} enum_t; + +typedef enum +{STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} enum_t; + +typedef enum +{ +STATE_0, +STATE_1, +STATE_2, +STATE_3 +} +enum_t; + + +endmodule + diff --git a/tests_ok/autoreset_latch.v b/tests_ok/autoreset_latch.v index 77a7997b..33e2e382 100644 --- a/tests_ok/autoreset_latch.v +++ b/tests_ok/autoreset_latch.v @@ -5,7 +5,7 @@ module device( output logic pass, fail input [7:0] D, in0,in1 ); - enum logic [2:0] {IDLE, START, RUN, PASS, FAIL } state, next_state; + enum logic [2:0] {IDLE, START, RUN, PASS, FAIL } state, next_state; logic ready, next_ready; logic next_pass, next_fail; diff --git a/tests_ok/autowire_pkg_bug195.v b/tests_ok/autowire_pkg_bug195.v index 720f08ab..5b9b5399 100644 --- a/tests_ok/autowire_pkg_bug195.v +++ b/tests_ok/autowire_pkg_bug195.v @@ -6,7 +6,7 @@ package testcase_pkg; localparam uint SIZE = 8; - typedef enum {ENUM1, ENUM2} enum_t; + typedef enum {ENUM1, ENUM2} enum_t; endpackage diff --git a/tests_ok/indent_enum.v b/tests_ok/indent_enum.v index f7f0d799..e5db3c23 100644 --- a/tests_ok/indent_enum.v +++ b/tests_ok/indent_enum.v @@ -1,10 +1,14 @@ -enum int unsigned { - STATE_0 = 0, - STATE_2 = 2 -} state; - -enum int unsigned { - STATE_0 = 0, - STATE_1, - STATE_2 -} state, next; +module indent_enum; + + enum int unsigned { + STATE_0 = 0, + STATE_2 = 2 + } state; + + enum int unsigned { + STATE_0 = 0, + STATE_1, + STATE_2 + } state, next; + +endmodule diff --git a/tests_ok/indent_list_nil_typedef_enum.sv b/tests_ok/indent_list_nil_typedef_enum.sv new file mode 100644 index 00000000..e0179e30 --- /dev/null +++ b/tests_ok/indent_list_nil_typedef_enum.sv @@ -0,0 +1,111 @@ +module typedef_enum_indent; + + logic variable1; + logic signed [1:0] variable2; + logic variable3; + logic signed [1:0] variable4; + + typedef enum logic [1:0] {STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum logic [1:0] {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] { + STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum logic [1:0] + {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } + enum_t; + + typedef enum {STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum { + STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum + {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } + enum_t; + + +endmodule + + +// Local Variables: +// verilog-indent-lists: nil +// End: + diff --git a/tests_ok/indent_modeln.v b/tests_ok/indent_modeln.v index 07143714..85407a27 100644 --- a/tests_ok/indent_modeln.v +++ b/tests_ok/indent_modeln.v @@ -6,12 +6,12 @@ class i_sb_c extends base_sb_c; `uvm_register_cb(i_sb_c, sb_i_cb_c) //------------ - int drain_time_ns = 5000; + int drain_time_ns = 5000; //------------ typedef struct { - pem_intf_defs::pem_ncb_err_rsp_t err_rsp; + pem_intf_defs::pem_ncb_err_rsp_t err_rsp; int rcv_time; } ncbi_err_rsp_t; diff --git a/tests_ok/indent_typedef_enum.sv b/tests_ok/indent_typedef_enum.sv new file mode 100644 index 00000000..7d925ce2 --- /dev/null +++ b/tests_ok/indent_typedef_enum.sv @@ -0,0 +1,106 @@ +module typedef_enum_indent; + + logic variable1; + logic signed [1:0] variable2; + logic variable3; + logic signed [1:0] variable4; + + typedef enum logic [1:0] {STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum logic [1:0] {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] { + STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum logic [1:0] + {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum logic [1:0] + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } + enum_t; + + typedef enum {STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum { + STATE_0, + STATE_1, + STATE_2, + STATE_3} enum_t; + + typedef enum + {STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } enum_t; + + typedef enum + { + STATE_0, + STATE_1, + STATE_2, + STATE_3 + } + enum_t; + + +endmodule + diff --git a/tests_ok/v2k_typedef_yee_inc.v b/tests_ok/v2k_typedef_yee_inc.v index 788dc5a4..ad7304ef 100644 --- a/tests_ok/v2k_typedef_yee_inc.v +++ b/tests_ok/v2k_typedef_yee_inc.v @@ -10,8 +10,8 @@ typedef bit logic_t; // Use two-state logic typedef logic logic_t; // Use four-state logic `endif -typedef reg ff_t; // Default F/F type -typedef reg lat_t; // Default latch type +typedef reg ff_t; // Default F/F type +typedef reg lat_t; // Default latch type //---------------------------- // 24 bit wide pixel types diff --git a/verilog-mode.el b/verilog-mode.el index 18d278af..f041dad1 100644 --- a/verilog-mode.el +++ b/verilog-mode.el @@ -2861,6 +2861,8 @@ find the errors." (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") (defconst verilog-interface-modport-re "\\(\\s-*\\([a-zA-Z0-9`_$]+\\.[a-zA-Z0-9`_$]+\\)[ \t\f]+\\)") (defconst verilog-comment-start-regexp "//\\|/\\*" "Dual comment value for `comment-start-regexp'.") +(defconst verilog-typedef-enum-re + (concat "^\\s-*\\(typedef\\s-+\\)?enum\\s-+" "\\(" verilog-declaration-core-re "\\s-*" verilog-optional-signed-range-re "\\)?")) (defconst verilog-declaration-simple-re (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) @@ -4001,6 +4003,12 @@ Use filename, if current buffer being edited shorten to just buffer name." (t verilog-declaration-re))) +(defun verilog-looking-at-decl-to-align () + "Return non-nil if pointing at a Verilog variable declaration that must be aligned." + (and (looking-at (verilog-get-declaration-re)) + (not (verilog-at-struct-decl-p)) + (not (verilog-at-enum-decl-p)))) + ;; ;; ;; Mode @@ -6784,6 +6792,33 @@ Also move point to constraint." (verilog-in-struct-p) (looking-at "}\\(?:\\s-*\\w+\\s-*\\(?:,\\s-*\\w+\\s-*\\)*\\)?;"))) +(defun verilog-at-struct-decl-p () + "Return non-nil if at a struct declaration." + (interactive) + (save-excursion + (verilog-re-search-forward "{" (point-at-eol) t) + (unless (bobp) + (backward-char)) + (verilog-at-struct-p))) + +(defun verilog-at-enum-p () + "If at the { of a enum, return true, not moving point." + (save-excursion + (when (equal (char-after) ?\{) + (verilog-beg-of-statement) + (beginning-of-line) + (when (verilog-re-search-forward verilog-typedef-enum-re (point-at-eol) t) + t)))) + +(defun verilog-at-enum-decl-p () + "Return non-nil if at a enum declaration." + (interactive) + (save-excursion + (verilog-re-search-forward "{" (save-excursion (verilog-end-of-statement)) t) + (unless (bobp) + (backward-char)) + (verilog-at-enum-p))) + (defun verilog-parenthesis-depth () "Return non zero if in parenthetical-expression." (save-excursion (nth 1 (verilog-syntax-ppss)))) @@ -6953,7 +6988,7 @@ Only look at a few lines to determine indent level." (= (preceding-char) ?\,) (save-excursion (verilog-beg-of-statement-1) - (looking-at (verilog-get-declaration-re)))) + (verilog-looking-at-decl-to-align))) (let* ( fst (val (save-excursion @@ -7057,7 +7092,7 @@ Only look at a few lines to determine indent level." (and (or (eq type 'defun) (eq type 'block)) - (looking-at (verilog-get-declaration-re)) + (verilog-looking-at-decl-to-align) ;; Do not consider "virtual function", "virtual task", "virtual class" ;; as declarations (not (looking-at (concat (verilog-get-declaration-re) @@ -7221,7 +7256,7 @@ Be verbose about progress unless optional QUIET set." (beginning-of-line) (verilog-forward-syntactic-ws) (or (and (not (verilog-in-directive-p)) ; could have `define input foo - (looking-at (verilog-get-declaration-re))) + (verilog-looking-at-decl-to-align)) (and (verilog-parenthesis-depth) (looking-at verilog-interface-modport-re)))) (progn @@ -7253,7 +7288,7 @@ Be verbose about progress unless optional QUIET set." (setq start (progn (verilog-beg-of-statement-1) - (while (and (looking-at (verilog-get-declaration-re)) + (while (and (verilog-looking-at-decl-to-align) (not (bobp))) (skip-chars-backward " \t") (setq e (point)) @@ -7267,7 +7302,7 @@ Be verbose about progress unless optional QUIET set." (verilog-end-of-statement) (setq e (point)) ;Might be on last line (verilog-forward-syntactic-ws) - (while (looking-at (verilog-get-declaration-re)) + (while (verilog-looking-at-decl-to-align) (verilog-end-of-statement) (setq e (point)) (verilog-forward-syntactic-ws))