From e5ca972b09391789a71a2fbc6bceee51d79ed293 Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Sun, 3 Dec 2023 22:04:56 -0600 Subject: [PATCH] Issue#1057: Fixing classification of formal_part. (#1060) --- vsg/tests/generic_map/rule_601_test_input.vhd | 5 ++ vsg/tests/generic_map/test_rule_601.py | 4 +- .../classification_results.txt | 80 +++++++++++++++++++ .../classification_test_input.vhd | 15 ++++ vsg/tests/vhdlFile/test_generic_map_aspect.py | 29 +++++++ vsg/vhdlFile/classify/association_element.py | 7 +- vsg/vhdlFile/classify/formal_part.py | 23 ++++++ 7 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 vsg/tests/vhdlFile/generic_map_aspect/classification_results.txt create mode 100644 vsg/tests/vhdlFile/generic_map_aspect/classification_test_input.vhd create mode 100644 vsg/tests/vhdlFile/test_generic_map_aspect.py create mode 100644 vsg/vhdlFile/classify/formal_part.py diff --git a/vsg/tests/generic_map/rule_601_test_input.vhd b/vsg/tests/generic_map/rule_601_test_input.vhd index 588491f7..11a41d38 100644 --- a/vsg/tests/generic_map/rule_601_test_input.vhd +++ b/vsg/tests/generic_map/rule_601_test_input.vhd @@ -29,6 +29,11 @@ begin PORT_3 => w_port_3 ); + U_INST2 : INST2 + generic map ( + W_GEN_1(W_GEN_1) => 3, + G_GEN_2(W_GEN_1) => 10 + ); end architecture ARCH; diff --git a/vsg/tests/generic_map/test_rule_601.py b/vsg/tests/generic_map/test_rule_601.py index 4ebc48fe..cf8dc336 100644 --- a/vsg/tests/generic_map/test_rule_601.py +++ b/vsg/tests/generic_map/test_rule_601.py @@ -23,7 +23,7 @@ class test_generic_map_rule(unittest.TestCase): self.assertEqual(oRule.name, 'generic_map') self.assertEqual(oRule.identifier, '601') - lExpected = [22, 23, 24] + lExpected = [22, 23, 24, 34] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) @@ -35,7 +35,7 @@ class test_generic_map_rule(unittest.TestCase): self.assertEqual(oRule.name, 'generic_map') self.assertEqual(oRule.identifier, '601') - lExpected = [22, 23, 24] + lExpected = [22, 23, 24, 34] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/vsg/tests/vhdlFile/generic_map_aspect/classification_results.txt b/vsg/tests/vhdlFile/generic_map_aspect/classification_results.txt new file mode 100644 index 00000000..1fc632da --- /dev/null +++ b/vsg/tests/vhdlFile/generic_map_aspect/classification_results.txt @@ -0,0 +1,80 @@ +-------------------------------------------------------------------------------- +0 | +-------------------------------------------------------------------------------- +1 | architecture rtl of fifo is + + + + + +-------------------------------------------------------------------------------- +2 | + +-------------------------------------------------------------------------------- +3 | begin + +-------------------------------------------------------------------------------- +4 | + +-------------------------------------------------------------------------------- +5 | dut : entity work.ampersand + + + + + + +-------------------------------------------------------------------------------- +6 | generic map ( + + + +-------------------------------------------------------------------------------- +7 | g_FIRST => c_FIRST, + + + + +-------------------------------------------------------------------------------- +8 | g_SECOND(0) => c_SECOND + + + + + + +-------------------------------------------------------------------------------- +9 | ) + +-------------------------------------------------------------------------------- +10 | port map ( + + + +-------------------------------------------------------------------------------- +11 | i_thing => inthing, + + + + +-------------------------------------------------------------------------------- +12 | o_thing(0) => outthing + + + + + + +-------------------------------------------------------------------------------- +13 | ); + + +-------------------------------------------------------------------------------- +14 | + +-------------------------------------------------------------------------------- +15 | end architecture rtl; + + + + diff --git a/vsg/tests/vhdlFile/generic_map_aspect/classification_test_input.vhd b/vsg/tests/vhdlFile/generic_map_aspect/classification_test_input.vhd new file mode 100644 index 00000000..6a6b9655 --- /dev/null +++ b/vsg/tests/vhdlFile/generic_map_aspect/classification_test_input.vhd @@ -0,0 +1,15 @@ +architecture rtl of fifo is + +begin + + dut : entity work.ampersand + generic map ( + g_FIRST => c_FIRST, + g_SECOND(0) => c_SECOND + ) + port map ( + i_thing => inthing, + o_thing(0) => outthing + ); + +end architecture rtl; diff --git a/vsg/tests/vhdlFile/test_generic_map_aspect.py b/vsg/tests/vhdlFile/test_generic_map_aspect.py new file mode 100644 index 00000000..f70c36c1 --- /dev/null +++ b/vsg/tests/vhdlFile/test_generic_map_aspect.py @@ -0,0 +1,29 @@ +import os + +import unittest + +from vsg.tests import utils +from vsg import vhdlFile + +sLrmUnit = utils.extract_lrm_unit_name(__name__) + +lFile, eError =vhdlFile.utils.read_vhdlfile(os.path.join(os.path.dirname(__file__), sLrmUnit,'classification_test_input.vhd')) +oFile = vhdlFile.vhdlFile(lFile) + + +class test_token(unittest.TestCase): + + def test_classification(self): + self.maxDiff = None + sTestDir = os.path.join(os.path.dirname(__file__), sLrmUnit) + + lExpected = [] + utils.read_file(os.path.join(sTestDir, 'classification_results.txt'), lExpected, False) + + lActual = [] + + for oObject in utils.extract_objects(oFile, True): + lActual.append(str(oObject)) + + self.assertEqual(lExpected, lActual) + diff --git a/vsg/vhdlFile/classify/association_element.py b/vsg/vhdlFile/classify/association_element.py index 330619ee..6b84eb5a 100644 --- a/vsg/vhdlFile/classify/association_element.py +++ b/vsg/vhdlFile/classify/association_element.py @@ -3,6 +3,8 @@ from vsg.token import association_element as token from vsg.vhdlFile import utils +from vsg.vhdlFile.classify import formal_part + def detect(iCurrent, lObjects): ''' @@ -36,12 +38,9 @@ def detect(iCurrent, lObjects): def classify(iStart, iEnd, lObjects, sEnd): iCurrent = iStart - sPrint = '' - for oObject in lObjects[iStart:iEnd + 1]: - sPrint += oObject.get_value() # Classify formal part if it exists if utils.find_in_index_range('=>', iStart, iEnd, lObjects): - iCurrent = utils.assign_tokens_until('=>', token.formal_part, iCurrent, lObjects) + iCurrent = formal_part.classify(token.formal_part, iCurrent, lObjects) iCurrent = utils.assign_next_token_required('=>', token.assignment, iCurrent, lObjects) # Classify actual part diff --git a/vsg/vhdlFile/classify/formal_part.py b/vsg/vhdlFile/classify/formal_part.py new file mode 100644 index 00000000..3e037453 --- /dev/null +++ b/vsg/vhdlFile/classify/formal_part.py @@ -0,0 +1,23 @@ + +from vsg import parser + +from vsg.vhdlFile import utils + + +def classify(oTokenType, iToken, lObjects): + ''' + formal_part ::= + formal_designator + | function_name ( formal_designator ) + | type_mark ( formal_designator ) + + An association element will end with => + ''' + # Assign first token as formal part + iCurrent = utils.assign_next_token(oTokenType, iToken, lObjects) + + # Assign remaining tokens as todo + while not utils.are_next_consecutive_tokens_ignoring_whitespace(['=>'], iCurrent, lObjects): + iCurrent = utils.assign_next_token(parser.todo, iCurrent, lObjects) + + return iCurrent