diff --git a/vsg/line.py b/vsg/line.py index 9accee4a..3068d3cb 100644 --- a/vsg/line.py +++ b/vsg/line.py @@ -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): ''' diff --git a/vsg/tests/code_tags/__init__.py b/vsg/tests/code_tags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/code_tags/code_tag_test_input.vhd b/vsg/tests/code_tags/code_tag_test_input.vhd new file mode 100644 index 00000000..d547e91e --- /dev/null +++ b/vsg/tests/code_tags/code_tag_test_input.vhd @@ -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 + + + + + diff --git a/vsg/tests/vhdlFile/test_vhdlFile_code_tags.py b/vsg/tests/vhdlFile/test_vhdlFile_code_tags.py new file mode 100644 index 00000000..012a2a48 --- /dev/null +++ b/vsg/tests/vhdlFile/test_vhdlFile_code_tags.py @@ -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) diff --git a/vsg/vhdlFile/classify/__init__.py b/vsg/vhdlFile/classify/__init__.py index e475f847..431c034a 100644 --- a/vsg/vhdlFile/classify/__init__.py +++ b/vsg/vhdlFile/classify/__init__.py @@ -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 diff --git a/vsg/vhdlFile/classify/code_tags.py b/vsg/vhdlFile/classify/code_tags.py new file mode 100644 index 00000000..791700b6 --- /dev/null +++ b/vsg/vhdlFile/classify/code_tags.py @@ -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'] diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index 8626e6be..9c8e4621 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -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)