From 95b6f907c8a6beeda8b6b2db28c842b20285573b Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Thu, 1 Nov 2018 19:21:41 -0500 Subject: [PATCH] Updates for issue #172 Fixed mis-classification of less than or equal to (<=) in concurrent statements: 1) Updated tests --- .../concurrent/keyword_alignment_rule.py | 37 ++++++++++++++++++- .../concurrent/concurrent_test_input.vhd | 7 ++++ vsg/tests/vhdlFile/test_vhdlFile.py | 6 +-- vsg/vhdlFile/classify/concurrent.py | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/vsg/rules/concurrent/keyword_alignment_rule.py b/vsg/rules/concurrent/keyword_alignment_rule.py index 354bf0f2..d5c1c21d 100644 --- a/vsg/rules/concurrent/keyword_alignment_rule.py +++ b/vsg/rules/concurrent/keyword_alignment_rule.py @@ -48,7 +48,7 @@ class keyword_alignment_rule(rule.rule): iStartGroupIndex = iLineNumber if not oLine.__dict__[self.sEndGroupTrigger] and fGroupFound: fGroupFound = False - check.keyword_alignment(self, iStartGroupIndex, self.sKeyword, lGroup) + concurrent_keyword_alignment(self, iStartGroupIndex, self.sKeyword, lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: @@ -56,3 +56,38 @@ class keyword_alignment_rule(rule.rule): def _fix_violations(self, oFile): fix.keyword_alignment(self, oFile) + + +def concurrent_keyword_alignment(self, iLineNumber, sKeyword, lGroup): + ''' + Checks keywords in a group of line objects are aligned in the same column. + + Parameters: + + self: (rule object) + + iLineNumber: (integer) + + sKeyword: (string) + + lGroup: (list of line objects) + ''' + iKeywordAlignment = None + iMaximumKeywordColumn = 0 + sViolationRange = str(iLineNumber) + '-' + str(iLineNumber + len(lGroup) - 1) + self.dFix['violations'][sViolationRange] = {} + self.dFix['violations'][sViolationRange]['line'] = {} + + for iIndex, oGroupLine in enumerate(lGroup): + if sKeyword in oGroupLine.line and oGroupLine.isConcurrentBegin: + self.dFix['violations'][sViolationRange]['line'][iLineNumber + iIndex] = {} + self.dFix['violations'][sViolationRange]['line'][iLineNumber + iIndex]['keywordColumn'] = oGroupLine.line.find(sKeyword) + + iMaximumKeywordColumn = check.get_maximum_keyword_column(oGroupLine, sKeyword, iMaximumKeywordColumn) + + iKeywordAlignment = check.update_keyword_alignment(oGroupLine, sKeyword, iKeywordAlignment) + + if not iKeywordAlignment == oGroupLine.line.find(sKeyword): + check.add_range_violation(self, sViolationRange) + + self.dFix['violations'][sViolationRange]['maximumKeywordColumn'] = iMaximumKeywordColumn diff --git a/vsg/tests/concurrent/concurrent_test_input.vhd b/vsg/tests/concurrent/concurrent_test_input.vhd index 2a2ced2b..25673747 100644 --- a/vsg/tests/concurrent/concurrent_test_input.vhd +++ b/vsg/tests/concurrent/concurrent_test_input.vhd @@ -47,4 +47,11 @@ label:a<=b; a <= b when g = '1' else '1'; -- Not an error + a <= b when g = '1' else + c when g => 10 else + d when g <= 20 else + e when g < 5 else + f when g > 13 else + z; + end architecture ARCH; diff --git a/vsg/tests/vhdlFile/test_vhdlFile.py b/vsg/tests/vhdlFile/test_vhdlFile.py index d0c06646..3ac7d43c 100644 --- a/vsg/tests/vhdlFile/test_vhdlFile.py +++ b/vsg/tests/vhdlFile/test_vhdlFile.py @@ -288,7 +288,7 @@ class testVhdlFileMethods(unittest.TestCase): self.assertEqual(lActual, lExpected) def test_insideConcurrent_assignment(self): - lExpected = [6,7,8,9,10,11,23,24,26,27,28,29,30,32,33,34,35,36,38,39,40,41,42,44,45,46,48] + lExpected = [6,7,8,9,10,11,23,24,26,27,28,29,30,32,33,34,35,36,38,39,40,41,42,44,45,46,48,50,51,52,53,54,55] # Generic actual list lActual = [] for iIndex, oLine in enumerate(oFileConcurrent.lines): @@ -298,7 +298,7 @@ class testVhdlFileMethods(unittest.TestCase): self.assertEqual(lActual, lExpected) def test_isConcurrentBegin_assignment(self): - lExpected = [6,7,8,9,11,23,24,26,32,33,34,35,38,39,42,44,45,48] + lExpected = [6,7,8,9,11,23,24,26,32,33,34,35,38,39,42,44,45,48,50] # Generic actual list lActual = [] for iIndex, oLine in enumerate(oFileConcurrent.lines): @@ -308,7 +308,7 @@ class testVhdlFileMethods(unittest.TestCase): self.assertEqual(lActual, lExpected) def test_isEndConcurrent_assignment(self): - lExpected = [6,7,8,10,11,23,24,30,32,33,34,36,38,41,42,44,46,48] + lExpected = [6,7,8,10,11,23,24,30,32,33,34,36,38,41,42,44,46,48,55] # Generic actual list lActual = [] for iIndex, oLine in enumerate(oFileConcurrent.lines): diff --git a/vsg/vhdlFile/classify/concurrent.py b/vsg/vhdlFile/classify/concurrent.py index 9a290ab5..d191951c 100644 --- a/vsg/vhdlFile/classify/concurrent.py +++ b/vsg/vhdlFile/classify/concurrent.py @@ -5,7 +5,7 @@ def concurrent(dVars, oLine): if not (oLine.insideArchitecture and not oLine.insideProcess): return if re.match('^\s*\w+.*\s*<=', oLine.lineNoComment) or re.match('^\s*\w+\s*:\s*\w+.*\s*<=', oLine.lineNoComment): - if not oLine.insideAssert: + if not oLine.insideAssert and not oLine.insideConcurrent: oLine.indentLevel = dVars['iCurrentIndentLevel'] oLine.isConcurrentBegin = True oLine.insideConcurrent = True