Updates for issue #114

1)  Fixed classification of the end of the port map.
  2)  Added port_021
  3)  Refactored utilities.search_for_and_replace_is_keyword
This commit is contained in:
Jeremiah C Leary 2017-12-17 13:14:19 -06:00
parent dbbb0bfb80
commit 66cfbc751f
11 changed files with 80 additions and 18 deletions

View File

@ -27,4 +27,4 @@ class rule_006(rule.rule):
for iLineNumber in self.violations:
oLine = oFile.lines[iLineNumber]
oLine.update_line(re.sub(r'^(\s*architecture\s+\w+\s+of\s+\w+)', r'\1 is', oLine.line, re.IGNORECASE))
utilities.search_for_and_remove_is_keyword(oFile, iLineNumber)
utilities.search_for_and_remove_keyword(oFile, iLineNumber, 'is')

View File

@ -27,4 +27,4 @@ class rule_005(rule.rule):
for iLineNumber in self.violations:
oLine = oFile.lines[iLineNumber]
oLine.update_line(re.sub(r'^(\s*entity\s+\w+)', r'\1 is', oLine.line, re.IGNORECASE))
utilities.search_for_and_remove_is_keyword(oFile, iLineNumber)
utilities.search_for_and_remove_keyword(oFile, iLineNumber, 'is')

View File

@ -19,3 +19,4 @@ from rule_017 import rule_017
from rule_018 import rule_018
from rule_019 import rule_019
from rule_020 import rule_020
from rule_021 import rule_021

View File

@ -1,7 +1,7 @@
from vsg import rule
import re
from vsg import check
from vsg import fix
class rule_003(rule.rule):
@ -18,10 +18,10 @@ class rule_003(rule.rule):
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isPortKeyword and not re.match('^\s*\S+\s\(', oLine.line):
self.add_violation(iLineNumber)
if oLine.isPortKeyword and '(' in oLine.line:
check.is_single_space_after(self, 'port', oLine, iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
oLine = oFile.lines[iLineNumber]
oLine.update_line(re.sub(r'(port)\s*\(', r'\1 (', oLine.line, flags=re.IGNORECASE))
fix.enforce_one_space_after_word(self, oLine, 'port')

View File

@ -0,0 +1,31 @@
from vsg import rule
from vsg import check
from vsg import fix
from vsg import utilities
import re
class rule_021(rule.rule):
'''
Port rule 021 checks the **port** keyword is on the same line as the (.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'port'
self.identifier = '021'
self.solution = 'Move the ( to the same line as the "port" keyword.'
self.phase = 2
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isPortKeyword and '(' not in oLine.lineNoComment:
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
oLine = oFile.lines[iLineNumber]
oLine.update_line(re.sub('port', 'port (', oLine.line, 1, re.IGNORECASE))
utilities.search_for_and_remove_keyword(oFile, iLineNumber, '\(')

View File

@ -143,3 +143,12 @@ entity ENTITY1 is
--- debug ports: can be removed or left unconnected for the application circuit ---
);
end entity ENTITY1
-- Check if port opening parenthesis is on the same line
entity ENTITY1 is
port
(
PORT1 : in std_logic
);
end entity ENTITY1;

View File

@ -155,3 +155,12 @@ class testFixRulePortMethods(unittest.TestCase):
oRule.fix(oFile)
oRule.analyze(oFile)
self.assertEqual(oRule.violations, [])
def test_fix_rule_021(self):
oRule = port.rule_021()
oRule.fix(oFile)
oRule.analyze(oFile)
self.assertEqual(oRule.violations, [])
self.assertEqual(oFile.lines[152].line, ' port (')
self.assertEqual(oFile.lines[153].line, '')
self.assertEqual(oFile.lines[153].isBlank, True)

View File

@ -119,7 +119,7 @@ class testRulePortMethods(unittest.TestCase):
self.assertEqual(oRule.identifier, '011')
oRule.port_direction = 'Prefix'
dExpected = [12,13,14,29,30,31,43,44,45,60,61,62,74,75,76,99,100,101]
dExpected = [12,13,14,29,30,31,43,44,45,60,61,62,74,75,76,99,100,101,152]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
@ -135,7 +135,7 @@ class testRulePortMethods(unittest.TestCase):
oRule = port.rule_011()
oRule.port_direction = 'Suffix'
dExpected = [9,10,11,12,13,14,26,27,28,29,30,31,40,41,42,43,44,45,57,58,59,60,61,62,71,72,73,74,75,76,87,88,89,119,120,121,129,130,131,141,142]
dExpected = [9,10,11,12,13,14,26,27,28,29,30,31,40,41,42,43,44,45,57,58,59,60,61,62,71,72,73,74,75,76,87,88,89,119,120,121,129,130,131,141,142,152]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
@ -228,3 +228,13 @@ class testRulePortMethods(unittest.TestCase):
dExpected = [141]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
def test_rule_021(self):
oRule = port.rule_021()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'port')
self.assertEqual(oRule.identifier, '021')
dExpected = [150]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)

View File

@ -134,7 +134,7 @@ class testVhdlFileMethods(unittest.TestCase):
self.assertEqual(lActual, lExpected)
def test_insidePortMap_assignment(self):
lExpected = [8,9,10,11,12,13,14,15,25,26,27,28,29,30,31,39,40,41,42,43,44,45,46,56,57,58,59,60,61,62,70,71,72,73,74,75,76,77,86,87,88,89,90,98,99,100,101,102,118,119,120,121,122,128,129,130,131,132,133,140,141,142,143,144]
lExpected = [8,9,10,11,12,13,14,15,25,26,27,28,29,30,31,39,40,41,42,43,44,45,46,56,57,58,59,60,61,62,70,71,72,73,74,75,76,77,86,87,88,89,90,98,99,100,101,102,118,119,120,121,122,128,129,130,131,132,133,140,141,142,143,144,150,151,152,153]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFilePort.lines):
@ -144,7 +144,7 @@ class testVhdlFileMethods(unittest.TestCase):
self.assertEqual(lActual, lExpected)
def test_isPortKeyword_assignment(self):
lExpected = [8,25,39,56,70,86,98,118,128,140]
lExpected = [8,25,39,56,70,86,98,118,128,140,150]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFilePort.lines):
@ -154,7 +154,7 @@ class testVhdlFileMethods(unittest.TestCase):
self.assertEqual(lActual, lExpected)
def test_isEndPortMap_assignment(self):
lExpected = [15,31,46,62,77,90,102,122,133,144]
lExpected = [15,31,46,62,77,90,102,122,133,144,153]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFilePort.lines):
@ -164,7 +164,7 @@ class testVhdlFileMethods(unittest.TestCase):
self.assertEqual(lActual, lExpected)
def test_isPortDeclaration_assignment(self):
lExpected = [9,10,11,12,13,14,26,27,28,29,30,31,40,41,42,43,44,45,57,58,59,60,61,62,71,72,73,74,75,76,87,88,89,99,100,101,119,120,121,129,130,131,141,142]
lExpected = [9,10,11,12,13,14,26,27,28,29,30,31,40,41,42,43,44,45,57,58,59,60,61,62,71,72,73,74,75,76,87,88,89,99,100,101,119,120,121,129,130,131,141,142,152]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFilePort.lines):

View File

@ -64,20 +64,20 @@ def is_vhdl_keyword(sWord):
return False
def clear_is_from_line(oLine):
oLine.update_line(re.sub(r'^(\s*)is', r'\1 ', oLine.line))
def clear_keyword_from_line(oLine, sKeyword):
oLine.update_line(re.sub(r'^(\s*)' + sKeyword, r'\1 ', oLine.line))
if re.match('^\s*$', oLine.line):
oLine.update_line('')
oLine.isBlank = True
def search_for_and_remove_is_keyword(oFile, iLineNumber):
def search_for_and_remove_keyword(oFile, iLineNumber, sKeyword):
iSearchIndex = iLineNumber
while True:
iSearchIndex += 1
oLine = oFile.lines[iSearchIndex]
if re.match('^\s*is', oLine.line, re.IGNORECASE):
clear_is_from_line(oLine)
if re.match('^\s*' + sKeyword, oLine.line, re.IGNORECASE):
clear_keyword_from_line(oLine, sKeyword)
if not oLine.isBlank:
break

View File

@ -11,6 +11,8 @@ def port(dVars, oLine):
else:
oLine.indentLevel = 2
dVars['iCurrentIndentLevel'] = 3
if not '(' in oLine.line:
return
if oLine.insidePortMap:
if re.match('^\s*\w+.*:', oLine.line) and not oLine.isComment and not oLine.isPortKeyword: