Updates for entity rules:

1)  Added rules to check case of generic and port keywords
  2)  Added rule to check for default assignments of ports
This commit is contained in:
Jeremiah Leary 2017-08-27 16:42:45 -05:00
parent 2b39f10166
commit 4bafb80cfd
4 changed files with 123 additions and 6 deletions

View File

@ -800,3 +800,77 @@ class rule_033(entity_rule):
if re.match('\s*entity', sLine.lower()):
fEntityFound = True
self.violations = lFailureLines
class rule_034(entity_rule):
'''Entity rule 034 checks the "generic" keyword is lowercase.'''
def __init__(self):
entity_rule.__init__(self)
self.identifier = '034'
self.description = 'Lowercase "generic" keyword.'
def analyze(self, lines):
lFailureLines = []
fEntityFound = False
fGenericMapFound = False
for iLineNumber, sLine in enumerate(lines):
if fEntityFound:
if re.match('^\s*port', sLine.lower()):
fEntityFound = False
fGenericMapFound = False
if re.match('^\s*generic', sLine.lower()):
if not re.match('^\s*generic', sLine):
lFailureLines.append(iLineNumber + 1)
if re.match('\s*entity', sLine.lower()):
fEntityFound = True
self.violations = lFailureLines
class rule_035(entity_rule):
'''Entity rule 035 checks the "port" keyword is lowercase.'''
def __init__(self):
entity_rule.__init__(self)
self.identifier = '035'
self.description = 'Lowercase "port" keyword.'
def analyze(self, lines):
lFailureLines = []
fEntityFound = False
for iLineNumber, sLine in enumerate(lines):
if fEntityFound:
if re.match('^\s*port', sLine.lower()):
fEntityFound = False
if not re.match('^\s*port', sLine):
lFailureLines.append(iLineNumber + 1)
if re.match('\s*entity', sLine.lower()):
fEntityFound = True
self.violations = lFailureLines
class rule_036(entity_rule):
'''Entity rule 036 checks for default assignments in port declarations.'''
def __init__(self):
entity_rule.__init__(self)
self.identifier = '036'
self.description = 'Remove default assignment in port declaration'
def analyze(self, lines):
lFailureLines = []
fEntityFound = False
fPortMapFound = False
for iLineNumber, sLine in enumerate(lines):
if fPortMapFound:
if re.match('^.*:=', sLine):
lFailureLines.append(iLineNumber + 1)
if fEntityFound:
if re.match('^\s*end', sLine.lower()):
fEntityFound = False
fPortMapFound = False
if re.match('^\s*port', sLine.lower()):
fPortMapFound = True
if re.match('\s*entity', sLine.lower()):
fEntityFound = True
self.violations = lFailureLines

View File

@ -53,6 +53,9 @@ class list():
self.rules.append(rule_entity.rule_031())
self.rules.append(rule_entity.rule_032())
self.rules.append(rule_entity.rule_033())
self.rules.append(rule_entity.rule_034())
self.rules.append(rule_entity.rule_035())
self.rules.append(rule_entity.rule_036())
def check_rules(self, lines):
dRuleViolations = {}

View File

@ -40,7 +40,7 @@ end ENTITY1
i_port1 : in std_logic;
o_port2 : out std_logic;
io_port3 : inout std_logic;
PORT4 : in std_logic;
PORT4 : in std_logic := '0';
PORT5 : out std_logic;
PORT6 : inout std_logic
);
@ -55,7 +55,7 @@ is
port (
I_PORT1 : in std_logic;
O_PORT2 :out std_logic;
O_PORT2 :out std_logic := '1';
IO_PORT3 : inout std_logic;
port4 : in std_logic;
port5 : out std_logic;
@ -63,7 +63,7 @@ IO_PORT3 : inout std_logic;
End ENTITY1
entity ENTITY1 is
generic (
geneRIC (
G_generic1 :std_logic := '0';
G_GENERIC2 : std_logic :='1'
);
@ -72,14 +72,14 @@ entity ENTITY1 is
O_PORT2 : out std_logic;
IO_PORT3 : inout std_logic;
port4 : in std_logic;
port5 : out std_logic;
port5 : out std_logic := '0';
port6 : inout std_logic
);
end ENTITY1
entity ENTITY1 is
generic (
gENEric (
G_GENERIC1 : std_logic := '0';
G_GENERIC2 : std_logic := '1'
);
@ -92,7 +92,7 @@ end ENTITY1
entity ENTITY1 is
generic (
Generic (
G_GENERIC1 : std_logic := '0';
G_GENERIC2 : std_logic := '1');
port (

View File

@ -448,5 +448,45 @@ class testRuleEntityMethods(unittest.TestCase):
oRule.analyze(lLines)
self.assertEqual(oRule.violations, dExpected)
def test_rule_034_exists(self):
oRule = rule_entity.rule_034()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'entity')
self.assertEqual(oRule.identifier, '034')
def test_rule_034(self):
oRule = rule_entity.rule_034()
dExpected = [66,82,95]
oRule.analyze(lLines)
self.assertEqual(oRule.violations, dExpected)
def test_rule_035_exists(self):
oRule = rule_entity.rule_035()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'entity')
self.assertEqual(oRule.identifier, '035')
def test_rule_035(self):
oRule = rule_entity.rule_035()
dExpected = [25,39]
oRule.analyze(lLines)
self.assertEqual(oRule.violations, dExpected)
def test_rule_036_exists(self):
oRule = rule_entity.rule_036()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'entity')
self.assertEqual(oRule.identifier, '036')
def test_rule_036(self):
oRule = rule_entity.rule_036()
dExpected = [43,58,75]
oRule.analyze(lLines)
self.assertEqual(oRule.violations, dExpected)
if __name__ == '__main__':
unittest.main()