File tree Expand file tree Collapse file tree 7 files changed +199
-0
lines changed
Expand file tree Collapse file tree 7 files changed +199
-0
lines changed Original file line number Diff line number Diff 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 >`_
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff line change 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 , [])
Original file line number Diff line number Diff line change 1212from .rule_012 import rule_012
1313from .rule_015 import rule_015
1414from .rule_017 import rule_017
15+ from .rule_018 import rule_018
1516from .rule_100 import rule_100
1617from .rule_101 import rule_101
1718from .rule_102 import rule_102
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments