Updates for issue #548:

Fixing assert rules to correctly determine when to move tokens to the next line.

  1)  Updated documentation
  2)  Updated tests to expose invalid splitting
  3)  Updated rules to split correctly
This commit is contained in:
Jeremiah Leary 2021-09-21 22:27:12 -05:00
parent bec4264ac1
commit 4d2da359ed
23 changed files with 223 additions and 17 deletions

View File

@ -29,6 +29,8 @@ This rule checks indent of multiline assert statements.
assert_002
##########
|phase_4| |error|
This rule checks the **report** keyword is on it's own line for concurrent assertion statements.
**Violation**
@ -59,7 +61,9 @@ This rule checks the **report** keyword is on it's own line for concurrent asser
assert_003
##########
This rule checks the **report** keyword is on it's own line for assertion statements.
|phase_4| |error|
This rule checks the **report** keyword is on it's own line for sequential assertion statements.
**Violation**
@ -99,6 +103,8 @@ This rule checks the **report** keyword is on it's own line for assertion statem
assert_004
##########
|phase_4| |error|
This rule checks the **severity** keyword is on it's own line for concurrent assertion statements.
**Violation**
@ -126,6 +132,44 @@ This rule checks the **severity** keyword is on it's own line for concurrent ass
end architecture rtl;
assert_005
##########
|phase_4| |error|
This rule checks the **severity** keyword is on it's own line for sequential assertion statements.
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
begin
process begin
assert WIDTH > 16 report "FIFO width is limited to 16 bits." severity FAILURE;
end process;
end architecture rtl;
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is
begin
process begin
assert WIDTH > 16
report "FIFO width is limited to 16 bits." severity FAILURE;
end process;
end architecture rtl;
assert_400
##########

View File

@ -54,6 +54,7 @@ from .token_suffix import token_suffix
from .token_suffix_between_tokens import token_suffix_between_tokens
from .split_line_at_token import split_line_at_token
from .split_line_at_token_when_between_tokens import split_line_at_token_when_between_tokens
from .split_line_at_token_when_between_tokens_unless_token_is_found import split_line_at_token_when_between_tokens_unless_token_is_found
from .insert_token_right_of_token_if_it_does_not_exist_before_token import insert_token_right_of_token_if_it_does_not_exist_before_token
from .insert_tokens_right_of_token_if_it_does_not_exist_before_token import insert_tokens_right_of_token_if_it_does_not_exist_before_token
from .insert_token_right_of_possible_tokens_if_it_does_not_exist_before_token import insert_token_right_of_possible_tokens_if_it_does_not_exist_before_token

View File

@ -1,5 +1,5 @@
from vsg.rules import split_line_at_token_when_between_tokens
from vsg.rules import split_line_at_token_when_between_tokens_unless_token_is_found
from vsg import token
@ -8,13 +8,14 @@ lTokens.append(token.assertion.report_keyword)
oStart = token.assertion.keyword
oEnd = token.concurrent_assertion_statement.semicolon
oStop = token.assertion_statement.semicolon
class rule_002(split_line_at_token_when_between_tokens):
class rule_002(split_line_at_token_when_between_tokens_unless_token_is_found):
'''
Checks the report keyword is on it's own line for concurrent assertion statements.
'''
def __init__(self):
split_line_at_token_when_between_tokens.__init__(self, 'assert', '002', lTokens, oStart, oEnd)
split_line_at_token_when_between_tokens_unless_token_is_found.__init__(self, 'assert', '002', lTokens, oStart, oEnd, oStop)
self.solution = "Place **report** keyword on it's own line."

View File

@ -1,5 +1,5 @@
from vsg.rules import split_line_at_token_when_between_tokens
from vsg.rules import split_line_at_token_when_between_tokens_unless_token_is_found
from vsg import token
@ -8,13 +8,14 @@ lTokens.append(token.assertion.report_keyword)
oStart = token.assertion.keyword
oEnd = token.assertion_statement.semicolon
oStop = token.concurrent_assertion_statement.semicolon
class rule_003(split_line_at_token_when_between_tokens):
class rule_003(split_line_at_token_when_between_tokens_unless_token_is_found):
'''
Checks the report keyword is on it's own line for assertion statements.
'''
def __init__(self):
split_line_at_token_when_between_tokens.__init__(self, 'assert', '003', lTokens, oStart, oEnd)
split_line_at_token_when_between_tokens_unless_token_is_found.__init__(self, 'assert', '003', lTokens, oStart, oEnd, oStop)
self.solution = "Place **report** keyword on it's own line."

View File

@ -1,5 +1,5 @@
from vsg.rules import split_line_at_token_when_between_tokens
from vsg.rules import split_line_at_token_when_between_tokens_unless_token_is_found
from vsg import token
@ -8,13 +8,14 @@ lTokens.append(token.assertion.severity_keyword)
oStart = token.assertion.keyword
oEnd = token.concurrent_assertion_statement.semicolon
oStop = token.assertion_statement.semicolon
class rule_004(split_line_at_token_when_between_tokens):
class rule_004(split_line_at_token_when_between_tokens_unless_token_is_found):
'''
Checks the severity keyword is on it's own line for concurrent assertion statements.
'''
def __init__(self):
split_line_at_token_when_between_tokens.__init__(self, 'assert', '004', lTokens, oStart, oEnd)
split_line_at_token_when_between_tokens_unless_token_is_found.__init__(self, 'assert', '004', lTokens, oStart, oEnd, oStop)
self.solution = "Place **severity** keyword on it's own line."

View File

@ -1,5 +1,5 @@
from vsg.rules import split_line_at_token_when_between_tokens
from vsg.rules import split_line_at_token_when_between_tokens_unless_token_is_found
from vsg import token
@ -8,13 +8,14 @@ lTokens.append(token.assertion.severity_keyword)
oStart = token.assertion.keyword
oEnd = token.assertion_statement.semicolon
oStop = token.concurrent_assertion_statement.semicolon
class rule_005(split_line_at_token_when_between_tokens):
class rule_005(split_line_at_token_when_between_tokens_unless_token_is_found):
'''
Checks the severity keyword is on it's own line for assertion statements.
'''
def __init__(self):
split_line_at_token_when_between_tokens.__init__(self, 'assert', '005', lTokens, oStart, oEnd)
split_line_at_token_when_between_tokens_unless_token_is_found.__init__(self, 'assert', '005', lTokens, oStart, oEnd, oStop)
self.solution = "Place **severity** keyword on it's own line."

View File

@ -0,0 +1,60 @@
from vsg import rule
from vsg import parser
from vsg import violation
from vsg.rules import utils as rules_utils
class split_line_at_token_when_between_tokens_unless_token_is_found(rule.Rule):
'''
Checks the case for words.
Parameters
----------
name : string
The group the rule belongs to.
identifier : string
unique identifier. Usually in the form of 00N.
lTokens : list of parser object types
object type to split a line at
oStart : token type
The start of the range
oEnd : token type
The end of the range
'''
def __init__(self, name, identifier, lTokens, oStart, oEnd, oStop):
rule.Rule.__init__(self, name=name, identifier=identifier)
self.solution = None
self.phase = 1
self.lTokens = lTokens
self.oStart = oStart
self.oEnd = oEnd
self.oStop = oStop
def _get_tokens_of_interest(self, oFile):
return oFile.get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found(self.lTokens, 2, self.oStart, self.oEnd, self.oStop)
def _analyze(self, lToi):
for oToi in lToi:
lTokens = oToi.get_tokens()
if isinstance(lTokens[0], parser.carriage_return) or isinstance(lTokens[1], parser.carriage_return):
continue
sSolution = self.solution
oViolation = violation.New(oToi.get_line_number(), oToi, sSolution)
self.add_violation(oViolation)
def _fix_violation(self, oViolation):
lTokens = oViolation.get_tokens()
if isinstance(lTokens[1], parser.whitespace):
rules_utils.insert_carriage_return(lTokens, -2)
else:
rules_utils.insert_carriage_return(lTokens, -1)
oViolation.set_tokens(lTokens)

View File

@ -31,4 +31,11 @@ begin
report "Something"
severity FAILURE;
process begin
assert boolean report "Something" severity FAILURE;
end process;
assert boolean
report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -27,4 +27,10 @@ begin
report "Something"
severity FAILURE;
process begin
assert boolean report "Something" severity FAILURE;
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -3,6 +3,8 @@ architecture ARCH of ENTITY1 is
begin
assert boolean report "Something" severity FAILURE;
process begin
LABEL : assert boolean
@ -35,4 +37,6 @@ begin
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -3,6 +3,8 @@ architecture ARCH of ENTITY1 is
begin
assert boolean report "Something" severity FAILURE;
process begin
LABEL : assert boolean report "Something" severity FAILURE;
@ -31,4 +33,6 @@ begin
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -31,4 +31,12 @@ begin
report "Something"
severity FAILURE;
process begin
assert boolean report "Something" severity FAILURE;
assert boolean report "Something" severity FAILURE;
end process;
assert boolean report "Something"
severity FAILURE;
end architecture ARCH;

View File

@ -27,4 +27,11 @@ begin
report "Something"
severity FAILURE;
process begin
assert boolean report "Something" severity FAILURE;
assert boolean report "Something" severity FAILURE;
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -3,6 +3,8 @@ architecture ARCH of ENTITY1 is
begin
assert boolean report "Something" severity FAILURE;
process begin
LABEL : assert boolean report "Something"
@ -33,6 +35,16 @@ begin
report "Something"
severity FAILURE;
if a then
assert (sel_0(4 downto 0) = "11001") report "Results wrong"
severity warning;
else
assert (sel_0(4 downto 0) = "11001") report "Results wrong"
severity warning;
end if;
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -3,6 +3,8 @@ architecture ARCH of ENTITY1 is
begin
assert boolean report "Something" severity FAILURE;
process begin
LABEL : assert boolean report "Something" severity FAILURE;
@ -29,6 +31,14 @@ begin
report "Something"
severity FAILURE;
if a then
assert (sel_0(4 downto 0) = "11001") report "Results wrong" severity warning;
else
assert (sel_0(4 downto 0) = "11001") report "Results wrong" severity warning;
end if;
end process;
assert boolean report "Something" severity FAILURE;
end architecture ARCH;

View File

@ -33,7 +33,7 @@ class test_assert_rule(unittest.TestCase):
self.assertEqual(oRule.name, 'assert')
self.assertEqual(oRule.identifier, '002')
lExpected = [6, 11, 18, 23]
lExpected = [6, 11, 18, 23, 34]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -33,7 +33,7 @@ class test_assert_rule(unittest.TestCase):
self.assertEqual(oRule.name, 'assert')
self.assertEqual(oRule.identifier, '003')
lExpected = [8, 13, 20, 25]
lExpected = [10, 15, 22, 27]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -33,7 +33,7 @@ class test_assert_rule(unittest.TestCase):
self.assertEqual(oRule.name, 'assert')
self.assertEqual(oRule.identifier, '004')
lExpected = [6, 9, 18, 21]
lExpected = [6, 9, 18, 21, 35]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -33,7 +33,7 @@ class test_assert_rule(unittest.TestCase):
self.assertEqual(oRule.name, 'assert')
self.assertEqual(oRule.identifier, '005')
lExpected = [8, 11, 20, 23]
lExpected = [10, 13, 22, 25, 35, 37]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -36,6 +36,7 @@ from .get_consecutive_lines_starting_with_token import get_consecutive_lines_sta
from .get_consecutive_lines_starting_with_token_and_stopping_when_token_starting_line_is_found import get_consecutive_lines_starting_with_token_and_stopping_when_token_starting_line_is_found
from .get_tokens_where_line_starts_with_token_until_ending_token_is_found import get_tokens_where_line_starts_with_token_until_ending_token_is_found
from .get_token_and_n_tokens_before_it_in_between_tokens import get_token_and_n_tokens_before_it_in_between_tokens
from .get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found import get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found
from .get_token_and_n_tokens_after_it import get_token_and_n_tokens_after_it
from .get_token_and_n_tokens_after_it_when_between_tokens import get_token_and_n_tokens_after_it_when_between_tokens
from .get_blank_lines_below_line_ending_with_token import get_blank_lines_below_line_ending_with_token

View File

@ -0,0 +1,17 @@
from vsg.vhdlFile.extract import tokens
from vsg.vhdlFile.extract import utils
def get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found(lTokens, iTokens, oStart, oEnd, oStop, lAllTokens, oTokenMap):
lReturn = []
lIndexes = utils.filter_tokens_between_tokens_unless_token_exists_between_them(lTokens, oStart, oEnd, oStop, oTokenMap)
for iIndex in lIndexes:
iStart = iIndex - iTokens
if iStart >= 0:
iLine = oTokenMap.get_line_number_of_index(iStart)
lReturn.append(tokens.New(iStart, iLine, lAllTokens[iStart:iIndex + 1]))
return lReturn

View File

@ -84,6 +84,24 @@ def filter_tokens_between_tokens(lTokens, oStart, oEnd, oTokenMap):
return lReturn
def filter_tokens_between_tokens_unless_token_exists_between_them(lTokens, oStart, oEnd, oStop, oTokenMap):
lStart = oTokenMap.get_token_indexes(oStart)
lEnd = oTokenMap.get_token_indexes(oEnd)
lStop = oTokenMap.get_token_indexes(oStop)
lReturn = []
for oToken in lTokens:
for iStart in lStart:
for iEnd in lEnd:
if iEnd > iStart:
for iStop in lStop:
if iStart < iStop < iEnd:
break
else:
lReturn.extend(oTokenMap.get_token_indexes_between_indexes(oToken, iStart, iEnd))
break
return lReturn
def get_indexes_of_tokens_between(lStartToken, lEndTokens, oTokenMap):
'''
This function will take a list of start tokens and a list of end tokens.

View File

@ -243,6 +243,9 @@ class vhdlFile():
def get_token_and_n_tokens_before_it_in_between_tokens(self, lTokens, iTokens, oStart, oEnd):
return extract.get_token_and_n_tokens_before_it_in_between_tokens(lTokens, iTokens, oStart, oEnd, self.lAllObjects, self.oTokenMap)
def get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found(self, lTokens, iTokens, oStart, oEnd, oStop):
return extract.get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found(lTokens, iTokens, oStart, oEnd, oStop, self.lAllObjects, self.oTokenMap)
def get_token_and_n_tokens_after_it(self, lTokens, iTokens):
return extract.get_token_and_n_tokens_after_it(lTokens, iTokens, self.lAllObjects, self.oTokenMap)