Skip to content

Commit 29e3b3d

Browse files
authored
Merge pull request #1513 from JHertz5/issue-1511
Issue#1511: Added new rule for variable declaration asssignment operator position
2 parents a26f66b + 620a669 commit 29e3b3d

File tree

7 files changed

+199
-0
lines changed

7 files changed

+199
-0
lines changed

docs/rule_groups/structure_rule_group.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Rules Enforcing Structure Rule Group
188188
* `variable_007 <../variable_rules.html#variable-007>`_
189189
* `variable_015 <../variable_rules.html#variable-015>`_
190190
* `variable_017 <../variable_rules.html#variable-017>`_
191+
* `variable_018 <../variable_rules.html#variable-018>`_
191192
* `variable_assignment_006 <../variable_assignment_rules.html#variable-assignment-006>`_
192193
* `variable_assignment_007 <../variable_assignment_rules.html#variable-assignment-007>`_
193194
* `variable_assignment_008 <../variable_assignment_rules.html#variable-assignment-008>`_

docs/variable_rules.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,31 @@ This rule checks the structure of variable constraints.
301301
element2(3 downto 0)
302302
);
303303
304+
variable_018
305+
############
306+
307+
|phase_1| |error| |structure|
308+
309+
This rule checks the **:=** is on the same line as the **variable** keyword.
310+
311+
**Violation**
312+
313+
.. code-block:: vhdl
314+
315+
variable size : integer
316+
:= 1;
317+
variable width : integer
318+
:= 32;
319+
320+
**Fix**
321+
322+
.. code-block:: vhdl
323+
324+
variable size : integer :=
325+
1;
326+
variable width : integer :=
327+
32;
328+
304329
variable_100
305330
############
306331

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
architecture RTL of FIFO is
3+
4+
begin
5+
6+
my_proc : process
7+
8+
variable c_width : integer;
9+
10+
variable c_width : integer := 16;
11+
12+
variable c_depth : integer :=
13+
512;
14+
15+
variable AVMM_MASTER_NULL : avmm_master_t := (
16+
(others => '0'),
17+
(others => '0'),
18+
'0',
19+
'0'
20+
);
21+
22+
--! Test stimulus
23+
CONSTANT c_stimulus : t_stimulus_array :=
24+
(
25+
(
26+
name => "Hold in reset ",
27+
clk_in => "0101010101010101",
28+
rst_in => "1111111111111111",
29+
cnt_en_in => "0000000000000000",
30+
cnt_out => "0000000000000000"
31+
),
32+
(
33+
name => "Not enabled ",
34+
clk_in => "0101010101010101",
35+
rst_in => "0000000000000000",
36+
cnt_en_in => "0000000000000000",
37+
cnt_out => "0000000000000000"
38+
)
39+
);
40+
41+
begin
42+
43+
end process;
44+
45+
end architecture RTL;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
architecture RTL of FIFO is
3+
4+
begin
5+
6+
my_proc : process
7+
8+
variable c_width : integer;
9+
10+
variable c_width : integer := 16;
11+
12+
variable c_depth : integer
13+
:= 512;
14+
15+
variable AVMM_MASTER_NULL : avmm_master_t := (
16+
(others => '0'),
17+
(others => '0'),
18+
'0',
19+
'0'
20+
);
21+
22+
--! Test stimulus
23+
CONSTANT c_stimulus : t_stimulus_array :=
24+
(
25+
(
26+
name => "Hold in reset ",
27+
clk_in => "0101010101010101",
28+
rst_in => "1111111111111111",
29+
cnt_en_in => "0000000000000000",
30+
cnt_out => "0000000000000000"
31+
),
32+
(
33+
name => "Not enabled ",
34+
clk_in => "0101010101010101",
35+
rst_in => "0000000000000000",
36+
cnt_en_in => "0000000000000000",
37+
cnt_out => "0000000000000000"
38+
)
39+
);
40+
41+
begin
42+
43+
end process;
44+
45+
end architecture RTL;

tests/variable/test_rule_018.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import unittest
5+
6+
from tests import utils
7+
from vsg import vhdlFile
8+
from vsg.rules import variable
9+
10+
sTestDir = os.path.dirname(__file__)
11+
12+
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_018_test_input.vhd"))
13+
14+
lExpected = []
15+
lExpected.append("")
16+
utils.read_file(os.path.join(sTestDir, "rule_018_test_input.fixed.vhd"), lExpected)
17+
18+
19+
class test_rule(unittest.TestCase):
20+
def setUp(self):
21+
self.oFile = vhdlFile.vhdlFile(lFile)
22+
self.assertIsNone(eError)
23+
24+
def test_rule_018(self):
25+
oRule = variable.rule_018()
26+
self.assertTrue(oRule)
27+
self.assertEqual(oRule.name, "variable")
28+
self.assertEqual(oRule.identifier, "018")
29+
self.assertEqual(oRule.groups, ["structure"])
30+
31+
lExpected = [12]
32+
33+
oRule.analyze(self.oFile)
34+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
35+
36+
def test_fix_rule_018(self):
37+
oRule = variable.rule_018()
38+
39+
oRule.fix(self.oFile)
40+
41+
lActual = self.oFile.get_lines()
42+
43+
self.assertEqual(lExpected, lActual)
44+
45+
oRule.analyze(self.oFile)
46+
self.assertEqual(oRule.violations, [])

vsg/rules/variable/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .rule_012 import rule_012
1313
from .rule_015 import rule_015
1414
from .rule_017 import rule_017
15+
from .rule_018 import rule_018
1516
from .rule_100 import rule_100
1617
from .rule_101 import rule_101
1718
from .rule_102 import rule_102

vsg/rules/variable/rule_018.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from vsg import token
4+
from vsg.rules import move_token_left_to_next_non_whitespace_token as Rule
5+
6+
lTokens = []
7+
lTokens.append(token.variable_declaration.assignment_operator)
8+
9+
10+
class rule_018(Rule):
11+
"""
12+
This rule checks the **:=** is on the same line as the **variable** keyword.
13+
14+
**Violation**
15+
16+
.. code-block:: vhdl
17+
18+
variable size : integer
19+
:= 1;
20+
variable width : integer
21+
:= 32;
22+
23+
**Fix**
24+
25+
.. code-block:: vhdl
26+
27+
variable size : integer :=
28+
1;
29+
variable width : integer :=
30+
32;
31+
"""
32+
33+
def __init__(self):
34+
super().__init__(lTokens)
35+
self.bRemoveTrailingWhitespace = False
36+
self.solution = "Move := operator"

0 commit comments

Comments
 (0)