From e6ff07855cc3fed0a23004333cb75dc7d220cc8d Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Fri, 28 Jun 2019 15:12:44 -0500 Subject: [PATCH] Updates for issue #196 Adding test for after statement in clock process: 1) Enhanced testing 2) Added after_001 rule 3) Updated documentation 4) Fixed bug in detecting the end of a sequential statement 5) Updated classification logic --- docs/after_rules.rst | 39 +++++++++++++++++++ vsg/rules/after/__init__.py | 2 + vsg/rules/after/rule_001.py | 32 +++++++++++++++ vsg/tests/after/__init__.py | 0 vsg/tests/after/after_test_input.vhd | 27 +++++++++++++ vsg/tests/after/test_rule_after.py | 4 +- .../sequential/sequential_test_input.vhd | 2 +- vsg/tests/vhdlFile/test_vhdlFile_after.py | 15 ++++--- vsg/vhdlFile/classify/after.py | 7 +++- vsg/vhdlFile/classify/sequential.py | 2 +- 10 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 docs/after_rules.rst create mode 100644 vsg/rules/after/__init__.py create mode 100644 vsg/rules/after/rule_001.py create mode 100644 vsg/tests/after/__init__.py diff --git a/docs/after_rules.rst b/docs/after_rules.rst new file mode 100644 index 00000000..0d1c2595 --- /dev/null +++ b/docs/after_rules.rst @@ -0,0 +1,39 @@ +After Rules +----------- + +after_001 +######### + +This rule checks for **after x** in signal assignments in clock processes. + +**Violation** + +.. code-block:: vhdl + + CLK_PROC : process(clock, reset) is + begin + if (reset = '1') then + a <= '0'; + b <= '1'; + elsif (clock'event and clock = '1') then + a <= d; + b <= c; + end if; + end process CLK_PROC; + +**Fix** + +.. code-block:: vhdl + + CLK_PROC : process(clock, reset) is + begin + if (reset = '1') then + a <= '0'; + b <= '1'; + elsif (clock'event and clock = '1') then + a <= d after 1 ns; + b <= c after 1 ns; + end if; + end process CLK_PROC; + +.. NOTE:: This is disabled by default. diff --git a/vsg/rules/after/__init__.py b/vsg/rules/after/__init__.py new file mode 100644 index 00000000..c422df02 --- /dev/null +++ b/vsg/rules/after/__init__.py @@ -0,0 +1,2 @@ + +from .rule_001 import rule_001 diff --git a/vsg/rules/after/rule_001.py b/vsg/rules/after/rule_001.py new file mode 100644 index 00000000..cdf415fa --- /dev/null +++ b/vsg/rules/after/rule_001.py @@ -0,0 +1,32 @@ + +import re + +from vsg import rule +from vsg import utils + + +class rule_001(rule.rule): + ''' + After rule 001 checks for the "after" keyword in signal assignments in clock processes. + ''' + + def __init__(self): + rule.rule.__init__(self, 'after', '001') + self.fixable = False + self.phase = 1 + + def _pre_analyze(self): + self.sequentialStatement = "" + + def _analyze(self, oFile, oLine, iLineNumber): + if oLine.insideClockProcess: + if oLine.isSequentialEnd: + self.sequentialStatement += oLine.lineNoComment.replace('--', ' ') + print(self.sequentialStatement) + if not re.match('^\s*.*\safter\s', self.sequentialStatement): + self.add_violation(iLineNumber) + self.sequentialStatement = "" + elif oLine.insideSequential: + self.sequentialStatement += oLine.lineNoComment.replace('--', ' ') + elif oLine.isSequential: + self.sequentialStatement = oLine.lineNoComment.replace('--', ' ') diff --git a/vsg/tests/after/__init__.py b/vsg/tests/after/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/after/after_test_input.vhd b/vsg/tests/after/after_test_input.vhd index 39d52c64..ff09a027 100644 --- a/vsg/tests/after/after_test_input.vhd +++ b/vsg/tests/after/after_test_input.vhd @@ -36,6 +36,33 @@ begin end if; end process CLK_PROC; + -- This process checks for different alignments of the after statement + CLK_PROC : process (reset, clk) is + begin + + if (reset = '1') then + a <= '0'; + b <= '1'; + c <= '0'; + d <= '1'; + elsif (clk'event and clk = '1') then + a <= b -- after 1 ns; + after 1 ns; + b <= c + after + 1 + ns; + c <= d + after +-- some comment +1 -- more comments +ns -- another comment +; -- yet more comments + d <= e after 1 ns; + end if; + end process CLK_PROC; + + -- This process checks for incorrect times -- This process checks for incorrect times CLK_PROC : process (reset, clk) is begin diff --git a/vsg/tests/after/test_rule_after.py b/vsg/tests/after/test_rule_after.py index 6c27d5c6..018ea211 100644 --- a/vsg/tests/after/test_rule_after.py +++ b/vsg/tests/after/test_rule_after.py @@ -15,10 +15,10 @@ oFile = vhdlFile.vhdlFile(lFile) class testRuleAfterMethods(unittest.TestCase): def test_rule_001(self): - oRule = signal.rule_001() + oRule = after.rule_001() self.assertTrue(oRule) self.assertEqual(oRule.name, 'after') self.assertEqual(oRule.identifier, '001') - lExpected = [32, 33] + lExpected = [33, 34] oRule.analyze(oFile) self.assertEqual(oRule.violations, lExpected) diff --git a/vsg/tests/sequential/sequential_test_input.vhd b/vsg/tests/sequential/sequential_test_input.vhd index 649a5e61..b1eceff1 100644 --- a/vsg/tests/sequential/sequential_test_input.vhd +++ b/vsg/tests/sequential/sequential_test_input.vhd @@ -50,7 +50,7 @@ begin PROC_2 : process (a) is begin - a <= b or + a <= b or -- c = '2'; c or d = '1'; c1 <= d; diff --git a/vsg/tests/vhdlFile/test_vhdlFile_after.py b/vsg/tests/vhdlFile/test_vhdlFile_after.py index 6ef5284c..5e6de310 100644 --- a/vsg/tests/vhdlFile/test_vhdlFile_after.py +++ b/vsg/tests/vhdlFile/test_vhdlFile_after.py @@ -13,9 +13,13 @@ class testVhdlFileAfterMethods(unittest.TestCase): lExpected = [] lExpected.extend(range(15, 19)) lExpected.extend([32,35]) - lExpected.extend(range(49, 53)) - lExpected.extend(range(66, 70)) - lExpected.append(74) + lExpected.append(50) + lExpected.append(52) + lExpected.append(56) + lExpected.append(61) + lExpected.extend(range(76, 80)) + lExpected.extend(range(93, 97)) + lExpected.append(101) # Generic actual list lActual = [] for iIndex, oLine in enumerate(oFile.lines): @@ -28,8 +32,9 @@ class testVhdlFileAfterMethods(unittest.TestCase): lExpected = [] lExpected.extend(range(14, 21)) lExpected.extend(range(31, 38)) - lExpected.extend(range(48, 55)) - lExpected.extend(range(65, 72)) + lExpected.extend(range(48, 64)) + lExpected.extend(range(75, 82)) + lExpected.extend(range(92, 99)) # Generic actual list lActual = [] diff --git a/vsg/vhdlFile/classify/after.py b/vsg/vhdlFile/classify/after.py index f380b808..09db8c35 100644 --- a/vsg/vhdlFile/classify/after.py +++ b/vsg/vhdlFile/classify/after.py @@ -3,6 +3,9 @@ import re def after(dVars, oLine): - if oLine.isEndConcurrent or oLine.isSequentialEnd: - if re.match('^.*\safter\s', oLine.lineNoComment, flags=re.IGNORECASE): + if oLine.isEndConcurrent or oLine.isSequentialEnd or oLine.insideSequential: + if re.match('^.*\s+after\s', oLine.lineNoComment, flags=re.IGNORECASE): oLine.hasAfterKeyword = True + if re.match('^.*after$', oLine.lineNoComment, flags=re.IGNORECASE): + oLine.hasAfterKeyword = True + diff --git a/vsg/vhdlFile/classify/sequential.py b/vsg/vhdlFile/classify/sequential.py index 3febba3b..e5588983 100644 --- a/vsg/vhdlFile/classify/sequential.py +++ b/vsg/vhdlFile/classify/sequential.py @@ -11,5 +11,5 @@ def sequential(dVars, oLine): oLine.indentLevel = dVars['iCurrentIndentLevel'] oLine.sequentialAlignmentColumn = oLine.line.find('<=') if oLine.insideSequential: - if ';' in oLine.line: + if ';' in oLine.lineNoComment: oLine.isSequentialEnd = True