Fix case rules for port rules.
This commit is contained in:
parent
27bc5d6020
commit
d166aa461b
|
|
@ -430,7 +430,9 @@ This rule checks the **port** keyword has proper case.
|
|||
port_018
|
||||
########
|
||||
|
||||
This rule checks the port type is lowercase if it is a VHDL keyword.
|
||||
This rule checks the port type has proper case if it is a VHDL keyword.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
**Violation**
|
||||
|
||||
|
|
@ -457,7 +459,9 @@ This rule checks the port type is lowercase if it is a VHDL keyword.
|
|||
port_019
|
||||
########
|
||||
|
||||
This rule checks the port direction is lowercase.
|
||||
This rule checks the port direction has proper case.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
**Violation**
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +1,16 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import check
|
||||
from vsg import fix
|
||||
from vsg.rules import case_rule
|
||||
from vsg import utils
|
||||
|
||||
|
||||
class rule_018(rule.rule):
|
||||
class rule_018(case_rule):
|
||||
'''
|
||||
Port rule 018 checks the port type is lowercase.
|
||||
Port rule 018 checks the port type has proper case.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'port', '018')
|
||||
self.solution = 'Change port type to lowercase.'
|
||||
self.phase = 6
|
||||
case_rule.__init__(self, 'port', '018', 'isPortDeclaration')
|
||||
self.solution = 'Change port type name to '
|
||||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if self._is_vsg_off(oLine):
|
||||
continue
|
||||
if oLine.isPortDeclaration:
|
||||
sLine = oLine.line.split(':')[1]
|
||||
if '(' in sLine:
|
||||
sLine = sLine.split('(')[0]
|
||||
if not utils.is_port_mode(sLine.split()[0]):
|
||||
continue
|
||||
if utils.is_vhdl_keyword(sLine.split()[1]):
|
||||
check.is_lowercase(self, sLine.split()[1], iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
oLine = oFile.lines[iLineNumber]
|
||||
sLine = oLine.line.split(':')[1]
|
||||
if '(' in sLine:
|
||||
sLine = sLine.split('(')[0]
|
||||
sWord = sLine.split()[1]
|
||||
fix.lower_case(oLine, sWord)
|
||||
def _extract(self, oLine):
|
||||
return utils.extract_type_name_from_port_vhdl_only(oLine)
|
||||
|
|
|
|||
|
|
@ -1,25 +1,15 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import fix
|
||||
from vsg import check
|
||||
from vsg.rules import case_rule
|
||||
|
||||
|
||||
class rule_019(rule.rule):
|
||||
class rule_019(case_rule):
|
||||
'''
|
||||
Port rule 019 checks the port direction is lowercase.
|
||||
Port rule 019 checks the port direction has proper case.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'port', '019')
|
||||
self.solution = 'Change port direction to lowercase.'
|
||||
self.phase = 6
|
||||
case_rule.__init__(self, 'port', '019', 'isPortDeclaration')
|
||||
self.solution = 'Change port direction to .'
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isPortDeclaration:
|
||||
sLine = oLine.line.split(':')[1]
|
||||
check.is_lowercase(self, sLine.split()[0], iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
sLine = oFile.lines[iLineNumber].line.split(':')[1]
|
||||
fix.lower_case(oFile.lines[iLineNumber], sLine.split()[0])
|
||||
def _extract(self, oLine):
|
||||
return [oLine.line.split(':')[1].split()[0]]
|
||||
|
|
|
|||
|
|
@ -282,6 +282,25 @@ class testExtractFunctions(unittest.TestCase):
|
|||
sActual = utils.extract_type_name_vhdl_only(oLine)
|
||||
self.assertEqual(sExpected, sActual)
|
||||
|
||||
def test_extract_type_name_from_port(self):
|
||||
oLine = line.blank_line()
|
||||
oLine.update_line('PORT( CLK_I : in STD_LOGIC;')
|
||||
sExpected = ['STD_LOGIC']
|
||||
sActual = utils.extract_type_name_from_port(oLine)
|
||||
self.assertEqual(sExpected, sActual)
|
||||
|
||||
oLine = line.blank_line()
|
||||
oLine.update_line('d : in std_logic_vector(WIDTH-1 downto 0),')
|
||||
sExpected = ['std_logic_vector']
|
||||
sActual = utils.extract_type_name_from_port(oLine)
|
||||
self.assertEqual(sExpected, sActual)
|
||||
|
||||
oLine = line.blank_line()
|
||||
oLine.update_line('d : in std_logic;')
|
||||
sExpected = ['std_logic']
|
||||
sActual = utils.extract_type_name_from_port(oLine)
|
||||
self.assertEqual(sExpected, sActual)
|
||||
|
||||
def test_extract_label(self):
|
||||
oLine = line.blank_line()
|
||||
oLine.update_line(' cp: CPU')
|
||||
|
|
|
|||
39
vsg/utils.py
39
vsg/utils.py
|
|
@ -637,6 +637,45 @@ def extract_type_name_vhdl_only(oLine):
|
|||
return []
|
||||
|
||||
|
||||
def extract_type_name_from_port(oLine):
|
||||
'''
|
||||
Returns the name of a type in port declaration.
|
||||
|
||||
Parameters:
|
||||
|
||||
oLine: (line object)
|
||||
|
||||
Returns: (one element list of strings)
|
||||
'''
|
||||
sLine = oLine.line.split(':')[1]
|
||||
sLine = sLine.replace('(', ' ')
|
||||
sLine = sLine.replace(')', ' ')
|
||||
sLine = sLine.replace(';', ' ')
|
||||
|
||||
try:
|
||||
return [sLine.split()[1]]
|
||||
except:
|
||||
return []
|
||||
|
||||
|
||||
def extract_type_name_from_port_vhdl_only(oLine):
|
||||
'''
|
||||
Returns the name of a VHDL only types in port declaration.
|
||||
|
||||
Parameters:
|
||||
|
||||
oLine: (line object)
|
||||
|
||||
Returns: (one element list of strings)
|
||||
'''
|
||||
name = extract_type_name_from_port(oLine)
|
||||
|
||||
if name and is_vhdl_keyword(name[0]):
|
||||
return name
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def extract_type_identifier(oLine):
|
||||
'''
|
||||
Returns the type identifier from type declaration.
|
||||
|
|
|
|||
Loading…
Reference in New Issue