diff --git a/docs/assert_rules.rst b/docs/assert_rules.rst index 0ff90209..ee590610 100644 --- a/docs/assert_rules.rst +++ b/docs/assert_rules.rst @@ -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 ########## diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index 0e974cf8..06cf1121 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -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 diff --git a/vsg/rules/assert_statement/rule_002.py b/vsg/rules/assert_statement/rule_002.py index e1c8e8d1..4cdd3750 100644 --- a/vsg/rules/assert_statement/rule_002.py +++ b/vsg/rules/assert_statement/rule_002.py @@ -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." diff --git a/vsg/rules/assert_statement/rule_003.py b/vsg/rules/assert_statement/rule_003.py index c9b6270f..b1dc33e9 100644 --- a/vsg/rules/assert_statement/rule_003.py +++ b/vsg/rules/assert_statement/rule_003.py @@ -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." diff --git a/vsg/rules/assert_statement/rule_004.py b/vsg/rules/assert_statement/rule_004.py index 129a4831..49cbce1a 100644 --- a/vsg/rules/assert_statement/rule_004.py +++ b/vsg/rules/assert_statement/rule_004.py @@ -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." diff --git a/vsg/rules/assert_statement/rule_005.py b/vsg/rules/assert_statement/rule_005.py index 2d97e77e..acfb9f0d 100644 --- a/vsg/rules/assert_statement/rule_005.py +++ b/vsg/rules/assert_statement/rule_005.py @@ -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." diff --git a/vsg/rules/split_line_at_token_when_between_tokens_unless_token_is_found.py b/vsg/rules/split_line_at_token_when_between_tokens_unless_token_is_found.py new file mode 100644 index 00000000..2e8ce643 --- /dev/null +++ b/vsg/rules/split_line_at_token_when_between_tokens_unless_token_is_found.py @@ -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) diff --git a/vsg/tests/assert_statement/rule_002_test_input.fixed.vhd b/vsg/tests/assert_statement/rule_002_test_input.fixed.vhd index 191d313c..5a393bbf 100644 --- a/vsg/tests/assert_statement/rule_002_test_input.fixed.vhd +++ b/vsg/tests/assert_statement/rule_002_test_input.fixed.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_002_test_input.vhd b/vsg/tests/assert_statement/rule_002_test_input.vhd index 1d3b2507..346ebddf 100644 --- a/vsg/tests/assert_statement/rule_002_test_input.vhd +++ b/vsg/tests/assert_statement/rule_002_test_input.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_003_test_input.fixed.vhd b/vsg/tests/assert_statement/rule_003_test_input.fixed.vhd index 196ece0a..06182304 100644 --- a/vsg/tests/assert_statement/rule_003_test_input.fixed.vhd +++ b/vsg/tests/assert_statement/rule_003_test_input.fixed.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_003_test_input.vhd b/vsg/tests/assert_statement/rule_003_test_input.vhd index fa80f26b..97efbdc0 100644 --- a/vsg/tests/assert_statement/rule_003_test_input.vhd +++ b/vsg/tests/assert_statement/rule_003_test_input.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_004_test_input.fixed.vhd b/vsg/tests/assert_statement/rule_004_test_input.fixed.vhd index dfd99ddb..f2f73a75 100644 --- a/vsg/tests/assert_statement/rule_004_test_input.fixed.vhd +++ b/vsg/tests/assert_statement/rule_004_test_input.fixed.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_004_test_input.vhd b/vsg/tests/assert_statement/rule_004_test_input.vhd index 1d3b2507..c7c0c642 100644 --- a/vsg/tests/assert_statement/rule_004_test_input.vhd +++ b/vsg/tests/assert_statement/rule_004_test_input.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_005_test_input.fixed.vhd b/vsg/tests/assert_statement/rule_005_test_input.fixed.vhd index f3741989..c97f3d5a 100644 --- a/vsg/tests/assert_statement/rule_005_test_input.fixed.vhd +++ b/vsg/tests/assert_statement/rule_005_test_input.fixed.vhd @@ -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; diff --git a/vsg/tests/assert_statement/rule_005_test_input.vhd b/vsg/tests/assert_statement/rule_005_test_input.vhd index fa80f26b..3c4b7ce6 100644 --- a/vsg/tests/assert_statement/rule_005_test_input.vhd +++ b/vsg/tests/assert_statement/rule_005_test_input.vhd @@ -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; diff --git a/vsg/tests/assert_statement/test_rule_002.py b/vsg/tests/assert_statement/test_rule_002.py index 80491bbf..67ea91f6 100644 --- a/vsg/tests/assert_statement/test_rule_002.py +++ b/vsg/tests/assert_statement/test_rule_002.py @@ -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)) diff --git a/vsg/tests/assert_statement/test_rule_003.py b/vsg/tests/assert_statement/test_rule_003.py index fe317a8a..685b14a2 100644 --- a/vsg/tests/assert_statement/test_rule_003.py +++ b/vsg/tests/assert_statement/test_rule_003.py @@ -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)) diff --git a/vsg/tests/assert_statement/test_rule_004.py b/vsg/tests/assert_statement/test_rule_004.py index 57ddd131..1fa36989 100644 --- a/vsg/tests/assert_statement/test_rule_004.py +++ b/vsg/tests/assert_statement/test_rule_004.py @@ -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)) diff --git a/vsg/tests/assert_statement/test_rule_005.py b/vsg/tests/assert_statement/test_rule_005.py index 6160d347..5f46849a 100644 --- a/vsg/tests/assert_statement/test_rule_005.py +++ b/vsg/tests/assert_statement/test_rule_005.py @@ -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)) diff --git a/vsg/vhdlFile/extract/__init__.py b/vsg/vhdlFile/extract/__init__.py index a416b450..5e5a8497 100644 --- a/vsg/vhdlFile/extract/__init__.py +++ b/vsg/vhdlFile/extract/__init__.py @@ -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 diff --git a/vsg/vhdlFile/extract/get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found.py b/vsg/vhdlFile/extract/get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found.py new file mode 100644 index 00000000..9e2c8185 --- /dev/null +++ b/vsg/vhdlFile/extract/get_token_and_n_tokens_before_it_in_between_tokens_unless_token_is_found.py @@ -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 diff --git a/vsg/vhdlFile/extract/utils.py b/vsg/vhdlFile/extract/utils.py index 8ccc73f7..ac07b5af 100644 --- a/vsg/vhdlFile/extract/utils.py +++ b/vsg/vhdlFile/extract/utils.py @@ -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. diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index 09bb5158..6beafb92 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -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)