Updates for issue #181

Adding code tag classifier.
This commit is contained in:
Jeremiah C Leary 2019-03-10 11:09:02 -05:00
parent ba1e447c3c
commit f2f0ac5bc9
7 changed files with 177 additions and 0 deletions

View File

@ -5,6 +5,21 @@ from vsg import utilities
class line():
'''
This class holds line contents and attributes associated with the content.
codeTags is an attribute represented by a dictionary.
The valid keys into the dictionary are:
vsg_off
vsg_on
If vsg_off and vsg_on are empty lists, then every rule is disabled.
codeTags['vsg_off'][]
otherwise individual rules are disabled:
codeTags['vsg_off']['library_008', 'process_002']
'''
def __init__(self, line):
@ -199,6 +214,9 @@ class line():
self.isEndBlock = False
# Wait attributes
self.isWait = False
# Code tags
self.hasCodeTag = False
self.codeTags = {}
def update_line(self, sLine):
'''

View File

View File

@ -0,0 +1,37 @@
-- vsg_off library_008 process_012
library ieee;
use ieee.std_logic_arith.all;
-- vsg_on library_008 process_012
library ieee;
use ieee.std_logic.all;
-- vsg_off
entity FIFO is
port (
WRITE_EN : in std_logic;
READ_EN : in std_logic
);
end entity;
-- vsg_on
-- vsg_off library_001 process_001
-- vsg_on library_001
-- vsg_off case_001
-- vsg_on process_001
-- vsg_off library_001
-- vsg_on case_001 library_001

View File

@ -0,0 +1,85 @@
import os
import unittest
from vsg import vhdlFile
from vsg.tests import utils
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','code_tags','code_tag_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
class testCodeTags(unittest.TestCase):
def test_hasCodeTag(self):
lExpected = range(2, 6)
lExpected.extend(range(10, 18))
lExpected.extend(range(20, 33))
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_library_008_tag(self):
lExpected = range(2, 6)
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag and 'vsg_off' in oLine.codeTags:
if 'library_008' in oLine.codeTags['vsg_off']:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_empty_code_tags(self):
lExpected = range(10, 18)
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag and 'vsg_off' in oLine.codeTags:
if len(oLine.codeTags['vsg_off']) == 0:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_library_001_tag(self):
lExpected = range(20, 24)
lExpected.extend(range(30, 33))
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag and 'vsg_off' in oLine.codeTags:
if 'library_001' in oLine.codeTags['vsg_off']:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_process_001_tag(self):
lExpected = range(20, 29)
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag and 'vsg_off' in oLine.codeTags:
if 'process_001' in oLine.codeTags['vsg_off']:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_case_001_tag(self):
lExpected = range(26, 33)
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFile.lines):
if oLine.hasCodeTag and 'vsg_off' in oLine.codeTags:
if 'case_001' in oLine.codeTags['vsg_off']:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)

View File

@ -3,6 +3,7 @@ from .assert_statement import assert_statement
from .attribute import attribute
from .blank import blank
from .case import case
from .code_tags import code_tags
from .comment import comment
from .component import component
from .concurrent import concurrent

View File

@ -0,0 +1,34 @@
import re
import copy
def code_tags(dVars, oLine, oLinePrevious):
if oLinePrevious.hasCodeTag:
oLine.hasCodeTag = True
oLine.codeTags = copy.deepcopy(oLinePrevious.codeTags)
if re.match('^\s*--\s*vsg_off$', oLine.line):
oLine.hasCodeTag = True
oLine.codeTags['vsg_off'] = []
if re.match('^\s*--\s*vsg_on$', oLinePrevious.line):
oLine.hasCodeTag = False
del oLine.codeTags['vsg_off']
if re.match('^\s*--\s*vsg_off\s+\w', oLine.line):
oLine.hasCodeTag = True
lRules = oLine.line.split()[2::]
for sRule in lRules:
try:
oLine.codeTags['vsg_off'].append(sRule)
except KeyError:
oLine.codeTags['vsg_off'] = [sRule]
if re.match('^\s*--\s*vsg_on\s+\w', oLinePrevious.line):
lRules = oLinePrevious.line.split()[2::]
for sRule in lRules:
oLine.codeTags['vsg_off'].remove(sRule)
if len(oLine.codeTags['vsg_off']) == 0:
oLine.hasCodeTag = False
del oLine.codeTags['vsg_off']

View File

@ -56,6 +56,8 @@ class vhdlFile():
classify.entity(self, dVars, oLine)
classify.assert_statement(dVars, oLine)
classify.code_tags(dVars, oLine, oLinePrevious)
classify.port(dVars, oLine)
classify.generic(dVars, oLine)