Updates for issue #47

1)  Fix added for generic_016
  2)  Added documentation
  3)  Enhanced testing
This commit is contained in:
Jeremiah C Leary 2017-12-08 07:05:54 -06:00
parent b21c44d768
commit a0d5e28482
6 changed files with 93 additions and 13 deletions

26
docs/generic_rules.rst Normal file
View File

@ -0,0 +1,26 @@
Generic Rules
-------------
generic_016
###########
This rule checks for multiple generics defined on a single line.
It is easier to comprehend the generic map if each generic is on it's own line.
**Violation**
.. code-block:: vhdl
generic (
WIDTH : std_logic := '0';DEPTH : std_logic := '1'
);
**Fix**
.. code-block:: vhdl
generic (
WIDTH : std_logic := '0';
DEPTH : std_logic := '1'
);

View File

@ -7,6 +7,7 @@ The rules are divided into catagories depending on the part of the VHDL code bei
.. include:: component_rules.rst
.. include:: constant_rules.rst
.. include:: entity_rules.rst
.. include:: generic_rules.rst
.. include:: instantiation_rules.rst
.. include:: process_rules.rst
.. include:: subtype_rules.rst

View File

@ -1,21 +1,27 @@
from vsg.rules.generic import generic_rule
from vsg import utilities
import re
class rule_016(generic_rule):
'''Generic rule 016 checks for multiple generate terms on a single line.'''
'''
Generic rule 016 checks for multiple generic terms on a single line.
'''
def __init__(self):
generic_rule.__init__(self)
self.identifier = '016'
self.solution = 'Move multiple generics to their own lines.'
self.phase = 1
self.fixable = False # Need to figure out how to fix this
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isGenericDeclaration:
if re.match('^\s*\w+\s*:.*;\s*\w+\s*:', oLine.line):
self.add_violation(iLineNumber)
if oLine.isGenericDeclaration and oLine.line.count(';') > 1:
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations[::-1]:
for i in range(0, oFile.lines[iLineNumber].line.count(';')):
utilities.split_line_after_word(oFile, iLineNumber + i, ';')

View File

@ -0,0 +1,30 @@
entity ENTITY1 is
generic (
G_GENERIC1 : std_logic := '0';G_GENERIC2 : std_logic := '1';G_GENERIC3 : std_logic := '1';G_GENERIC4 : std_logic := '1';G_GENERIC5 : std_logic := '1'
);
port (
I_PORT1 : in std_logic;
O_PORT2 : out std_logic;
IO_PORT3 : inout std_logic;
port4 : in std_logic;
port5 : out std_logic;
port6 : inout std_logic
);
end entity ENTITY1
entity ENTITY1 is
generic (
G_GENERIC1 : std_logic := '0';
G_GENERIC2 : std_logic := '1'
);
port (
I_PORT1 : in std_logic;
O_PORT2 : out std_logic;
IO_PORT3 : inout std_logic;
port4 : in std_logic;
port5 : out std_logic;
port6 : inout std_logic
);
end entity ENTITY1

View File

@ -7,7 +7,8 @@ from vsg import vhdlFile
from vsg.tests import utils
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'..','generic','generic_test_input.vhd'))
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'generic_test_input.vhd'))
oFileMultiple = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'generic_multiple_on_one_line_test_input.vhd'))
class testFixRuleGenericMethods(unittest.TestCase):
@ -106,8 +107,17 @@ class testFixRuleGenericMethods(unittest.TestCase):
oRule.analyze(oFile)
self.assertEqual(oRule.violations, [])
# def test_fix_rule_016(self):
# oRule = generic.rule_016()
# oRule.fix(oFile)
# oRule.analyze(oFile)
# self.assertEqual(oRule.violations, [])
def test_fix_rule_016(self):
oRule = generic.rule_016()
oRule.fix(oFileMultiple)
oRule.analyze(oFileMultiple)
self.assertEqual(oRule.violations, [])
self.assertEqual(oFileMultiple.lines[4].line,' generic (')
self.assertEqual(oFileMultiple.lines[5].line,' G_GENERIC1 : std_logic := \'0\';')
self.assertEqual(oFileMultiple.lines[6].line,'G_GENERIC2 : std_logic := \'1\';')
self.assertEqual(oFileMultiple.lines[7].line,'G_GENERIC3 : std_logic := \'1\';')
self.assertEqual(oFileMultiple.lines[8].line,'G_GENERIC4 : std_logic := \'1\';')
self.assertEqual(oFileMultiple.lines[9].line,'G_GENERIC5 : std_logic := \'1\'')
self.assertEqual(oFileMultiple.lines[10].line,' );')

View File

@ -4,10 +4,11 @@ import unittest
from vsg.rules import generic
from vsg import vhdlFile
from vsg.tests import utils
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'..','generic','generic_test_input.vhd'))
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'generic_test_input.vhd'))
oFileMultiple = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'generic_multiple_on_one_line_test_input.vhd'))
class testRuleGenericMethods(unittest.TestCase):
@ -171,3 +172,9 @@ class testRuleGenericMethods(unittest.TestCase):
dExpected = [21]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
oRule.violations = []
dExpected = [5]
oRule.analyze(oFileMultiple)
self.assertEqual(oRule.violations, dExpected)