Skip to content

Commit

Permalink
Issue#1061: Updates for pragma use cases (#1063)
Browse files Browse the repository at this point in the history
* Issue#1061:  Updates for pragma use cases

Pragmas are now treated as comments:

  *  Pragmas are now a subclass of comments
  *  Move rules will not move tokens if it crosses a pragma

* Fixing issue with expression classification causing infinite loop.
  • Loading branch information
jeremiah-c-leary authored Dec 12, 2023
1 parent e128204 commit 33a209b
Show file tree
Hide file tree
Showing 31 changed files with 188 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/block_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This rule checks the **is** keyword is on the same line as the **block** keyword

.. code-block:: vhdl
block_labeel : block is
block_label : block is
block_004
#########
Expand Down
2 changes: 1 addition & 1 deletion vsg/__parser__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():

configuration = config.New(commandLineArguments)

oVhdlFile = vhdlFile.vhdlFile(lLines[0], None, None, configuration)
oVhdlFile = vhdlFile.vhdlFile(lLines[0], commandLineArguments, None, None, configuration)
oVhdlFile.filename = sFileName

utils.print_objects(oVhdlFile, not commandLineArguments.whitespace)
Expand Down
2 changes: 1 addition & 1 deletion vsg/rules/block/rule_003.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class rule_003(move_token_to_the_right_of_several_possible_tokens_if_it_exists_b
.. code-block:: vhdl
block_labeel : block is
block_label : block is
'''

def __init__(self):
Expand Down
8 changes: 5 additions & 3 deletions vsg/rules/move_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ def __init__(self, name, identifier, oToken):

def _get_tokens_of_interest(self, oFile):
if self.action == 'new_line' and not self.preserve_comment:
return get_toi_for_new_line_option(self, oFile)
lToi = get_toi_for_new_line_option(self, oFile)
elif self.action == 'new_line' and self.preserve_comment:
return get_toi_for_new_line_option_with_preserve_comment(self, oFile)
lToi = get_toi_for_new_line_option_with_preserve_comment(self, oFile)
else:
return get_toi_for_move_left_option(self, oFile)
lToi = get_toi_for_move_left_option(self, oFile)

return rules_utils.remove_tois_with_pragmas(lToi)

def _analyze(self, lToi):
if self.action == 'new_line' and not self.preserve_comment:
Expand Down
3 changes: 3 additions & 0 deletions vsg/rules/move_token_left_to_next_non_whitespace_token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


from vsg import parser
from vsg import token
from vsg import violation

from vsg.rules import utils as rules_utils
Expand Down Expand Up @@ -46,6 +47,8 @@ def _get_tokens_of_interest(self, oFile):
lTokens = oToi.get_tokens()
if skip_based_on_whitespace(self.bInsertWhitespace, lTokens):
continue
if oToi.token_type_exists(token.pragma.pragma):
continue
lReturn.append(oToi)
return lReturn

Expand Down
3 changes: 2 additions & 1 deletion vsg/rules/move_token_next_to_another_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self, name, identifier, anchor_token, token_to_move):
self.configuration_documentation_link = None

def _get_tokens_of_interest(self, oFile):
return oFile.get_tokens_bounded_by(self.anchor_token, self.token_to_move, bIncludeTillEndOfLine=True)
lToi = oFile.get_tokens_bounded_by(self.anchor_token, self.token_to_move, bIncludeTillEndOfLine=True)
return rules_utils.remove_tois_with_pragmas(lToi)

def _analyze(self, lToi):
for oToi in lToi:
Expand Down
2 changes: 1 addition & 1 deletion vsg/rules/move_token_right_to_next_non_whitespace_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def filter_toi(self, lToi):
if skip_based_on_whitespace(self.bInsertWhitespace, oToi):
continue
lReturn.append(oToi)
return lReturn
return rules_utils.remove_tois_with_pragmas(lReturn)


def skip_based_on_whitespace(bInsertWhitespace, oToi):
Expand Down
2 changes: 1 addition & 1 deletion vsg/rules/move_token_sequences_left_of_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _get_tokens_of_interest(self, oFile):
aToi = oFile.get_tokens_bounded_by(lSequence[0], self.oLeftToken, bIncludeTillBeginningOfLine=True)
lToi = utils.combine_two_token_class_lists(lToi, aToi)
lPrevious.append(lSequence[0])
return lToi
return rules_utils.remove_tois_with_pragmas(lToi)

def _analyze(self, lToi):
for oToi in lToi:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, name, identifier, oMoveToken, lAnchorTokens, oStartToken, oEn
self.configuration_documentation_link = None

def _get_tokens_of_interest(self, oFile):
return oFile.get_tokens_bounded_by(self.oStartToken, self.oEndToken, bIncludeTillEndOfLine=True)
lToi = oFile.get_tokens_bounded_by(self.oStartToken, self.oEndToken, bIncludeTillEndOfLine=True)
return rules_utils.remove_tois_with_pragmas(lToi)

def _analyze(self, lToi):
for oToi in lToi:
Expand Down
8 changes: 8 additions & 0 deletions vsg/rules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,11 @@ def close_paren_detected_at_end_of_tokens(lTokens):
return True
lTokens.reverse()
return False


def remove_tois_with_pragmas(lToi):
lReturn = []
for oToi in lToi:
if not oToi.token_type_exists(token.pragma.pragma):
lReturn.append(oToi)
return lReturn
4 changes: 4 additions & 0 deletions vsg/tests/block/rule_001_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ begin

BLOCK_LABEL : block is begin end block;

BLOCK_LABEL :
-- synthesis translate_off
block is begin end block;

end architecture RTL;
4 changes: 4 additions & 0 deletions vsg/tests/block/rule_001_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ begin
BLOCK_LABEL :
block is begin end block;

BLOCK_LABEL :
-- synthesis translate_off
block is begin end block;

end architecture RTL;
4 changes: 4 additions & 0 deletions vsg/tests/block/rule_003_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ begin
BLOCK_LABEL : block (guard_condition) is
begin end block;

BLOCK_LABEL : block
-- synthesis translate_off
is begin end block;

end architecture RTL;
4 changes: 4 additions & 0 deletions vsg/tests/block/rule_003_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ begin
BLOCK_LABEL : block (guard_condition)
is begin end block;

BLOCK_LABEL : block
-- synthesis translate_off
is begin end block;

end architecture RTL;
5 changes: 5 additions & 0 deletions vsg/tests/if_statement/rule_036_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ begin
b <= '1';
end if;

if a = '1'
-- synthesis translate_off
then
end if;

end process;

end architecture RTL;
5 changes: 5 additions & 0 deletions vsg/tests/if_statement/rule_036_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ begin
b <= '1';
end if;

if a = '1'
-- synthesis translate_off
then
end if;

end process;

end architecture RTL;
18 changes: 18 additions & 0 deletions vsg/tests/library/rule_007_test_input.fixed_no_blank_line.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ use work.utility_pkg.all;
package body fifo_pkg is end package body;
use work.utility_pkg.all;


library ieee;

-- comment
use ieee.std_logic_1164.all;

library ieee;
-- comment
use ieee.std_logic_1164.all;

library ieee;
use ieee.std_logic_1164.all;

-- comment
-- comment
-- comment
use work.all;

Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ use work.utility_pkg.all;
package body fifo_pkg is end package body;
use work.utility_pkg.all;


library ieee;

-- comment
use ieee.std_logic_1164.all;

library ieee;
-- comment
use ieee.std_logic_1164.all;

library ieee;
use ieee.std_logic_1164.all;

-- comment
-- comment
-- comment
use work.all;

19 changes: 19 additions & 0 deletions vsg/tests/library/rule_007_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,22 @@ use work.utility_pkg.all;
package body fifo_pkg is end package body;
use work.utility_pkg.all;


library ieee;

-- comment

use ieee.std_logic_1164.all;

library ieee;
-- comment
use ieee.std_logic_1164.all;

library ieee;
use ieee.std_logic_1164.all;

-- comment
-- comment
-- comment
use work.all;

4 changes: 2 additions & 2 deletions vsg/tests/library/test_rule_007.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_rule_007_no_blank_line(self):
self.assertEqual(oRule.name, 'library')
self.assertEqual(oRule.identifier, '007')

lExpected = [11, 16, 22, 24, 27, 33, 42, 51, 60, 69, 78, 87, 96]
lExpected = [11, 16, 22, 24, 27, 33, 42, 51, 60, 69, 78, 87, 96, 106]

oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
Expand All @@ -51,7 +51,7 @@ def test_rule_007_no_blank_line_unless_different_library(self):
oRule = library.rule_007()
oRule.style = 'no_blank_line_unless_different_library'

lExpected = [11, 16, 22, 27]
lExpected = [11, 16, 22, 27, 106]

oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
Expand Down
12 changes: 12 additions & 0 deletions vsg/tests/port/rule_014_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ entity FIFO is
O_DATA : out std_logic_vector(31 downto 0)
);
end entity FIFO;


entity FIFO is
port (
I_WR_EN : in std_logic;
I_DATA : out std_logic_vector(31 downto 0);
I_RD_EN : in std_logic;
O_DATA : out std_logic_vector(31 downto 0)
-- synthesis translate_off
);
end entity FIFO;

12 changes: 12 additions & 0 deletions vsg/tests/port/rule_014_test_input.fixed_move_left.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ entity FIFO is
I_RD_EN : in std_logic;
O_DATA : out std_logic_vector(31 downto 0));
end entity FIFO;


entity FIFO is
port (
I_WR_EN : in std_logic;
I_DATA : out std_logic_vector(31 downto 0);
I_RD_EN : in std_logic;
O_DATA : out std_logic_vector(31 downto 0)
-- synthesis translate_off
);
end entity FIFO;

12 changes: 12 additions & 0 deletions vsg/tests/port/rule_014_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ entity FIFO is
I_RD_EN : in std_logic;
O_DATA : out std_logic_vector(31 downto 0));
end entity FIFO;


entity FIFO is
port (
I_WR_EN : in std_logic;
I_DATA : out std_logic_vector(31 downto 0);
I_RD_EN : in std_logic;
O_DATA : out std_logic_vector(31 downto 0)
-- synthesis translate_off
);
end entity FIFO;

5 changes: 5 additions & 0 deletions vsg/tests/process/rule_039_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ begin

postponed process begin end process;


PROC_LABEL : postponed
-- synthesis translate_off
process begin end process;

end;
5 changes: 5 additions & 0 deletions vsg/tests/process/rule_039_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ begin

process begin end process;


PROC_LABEL : postponed
-- synthesis translate_off
process begin end process;

end;
10 changes: 10 additions & 0 deletions vsg/tests/type_definition/rule_018_test_input.fixed.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ architecture RTL of FIFO is

(idle, write, read, done);

-- Honor comments

type state_machine is
-- some comment
(idle, write, read, done);

type state_machine
-- synthesis translate_off
is (idle, write, read, done);

begin

end architecture RTL;
10 changes: 10 additions & 0 deletions vsg/tests/type_definition/rule_018_test_input.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ architecture RTL of FIFO is

is (idle, write, read, done);

-- Honor comments

type state_machine
-- some comment
is (idle, write, read, done);

type state_machine
-- synthesis translate_off
is (idle, write, read, done);

begin

end architecture RTL;
2 changes: 1 addition & 1 deletion vsg/tests/type_definition/test_rule_018.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_rule_018(self):
self.assertEqual(oRule.name, 'type')
self.assertEqual(oRule.identifier, '018')

lExpected = [8, 11]
lExpected = [8, 11, 18]

oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
Expand Down
4 changes: 2 additions & 2 deletions vsg/token/pragma.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def __init__(self, sString):
parser.item.__init__(self, sString)


class pragma(parser.item):
class pragma(parser.comment):
'''
unique_id = pragma : pragma
'''

def __init__(self, sString):
parser.item.__init__(self, sString)
parser.comment.__init__(self, sString)
3 changes: 3 additions & 0 deletions vsg/token_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pprint

from vsg import parser
from vsg import token


class New():
Expand Down Expand Up @@ -123,6 +124,8 @@ def is_token_at_index_whitespace(self, iIndex):
def is_token_at_index_whitespace_or_comment(self, iIndex):
if self.is_token_at_index(parser.whitespace, iIndex):
return True
if self.is_token_at_index(token.pragma.pragma, iIndex):
return True
if self.is_token_at_index(parser.comment, iIndex):
return True
if self.is_token_at_index(parser.carriage_return, iIndex):
Expand Down
Loading

0 comments on commit 33a209b

Please sign in to comment.