diff --git a/vsg/rules/generic_map/rule_008.py b/vsg/rules/generic_map/rule_008.py index b3b867fc..4ed60459 100644 --- a/vsg/rules/generic_map/rule_008.py +++ b/vsg/rules/generic_map/rule_008.py @@ -3,8 +3,8 @@ from vsg import token from vsg.rules import formal_part_in_association_element_between_tokens -lStart = token.port_map_aspect.open_parenthesis -lEnd = token.port_map_aspect.close_parenthesis +lStart = token.generic_map_aspect.open_parenthesis +lEnd = token.generic_map_aspect.close_parenthesis class rule_008(formal_part_in_association_element_between_tokens): diff --git a/vsg/tests/generic_map/rule_008_test_input.vhd b/vsg/tests/generic_map/rule_008_test_input.vhd index cbb7b973..2098f383 100644 --- a/vsg/tests/generic_map/rule_008_test_input.vhd +++ b/vsg/tests/generic_map/rule_008_test_input.vhd @@ -20,7 +20,7 @@ begin U_INST1 : INST1 generic map( G_GEN_1 => 3, - G_GEN_2 => 4, + 4, G_GEN_3 => 5 ) port map (w_port_1, @@ -30,9 +30,9 @@ begin U_INST1 : INST1 generic map ( - G_GEN_1 => 3, + 3, G_GEN_2 => 4, - G_GEN_3 => 5 + 5 ) port map (PORT_1 => w_port_1, w_port_2, diff --git a/vsg/tests/generic_map/test_rule_008.py b/vsg/tests/generic_map/test_rule_008.py index 69a3f263..b2eca49d 100644 --- a/vsg/tests/generic_map/test_rule_008.py +++ b/vsg/tests/generic_map/test_rule_008.py @@ -22,7 +22,7 @@ class test_generic_map_rule(unittest.TestCase): self.assertEqual(oRule.name, 'generic_map') self.assertEqual(oRule.identifier, '008') - lExpected = [26, 28, 38, 39] + lExpected = [23, 33, 35] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/vsg/vhdlFile/extract/__init__.py b/vsg/vhdlFile/extract/__init__.py index 2a0c8c42..0dd9d2bc 100644 --- a/vsg/vhdlFile/extract/__init__.py +++ b/vsg/vhdlFile/extract/__init__.py @@ -34,3 +34,4 @@ from .get_token_and_n_tokens_before_it_in_between_tokens import get_token_and_n_ from .get_token_and_n_tokens_after_it import get_token_and_n_tokens_after_it from .get_token_and_n_tokens_after_it_when_between_tokens import get_token_and_n_tokens_after_it_when_between_tokens from .get_blank_lines_below_line_ending_with_token import get_blank_lines_below_line_ending_with_token +from .get_association_elements_between_tokens import get_association_elements_between_tokens diff --git a/vsg/vhdlFile/extract/get_association_elements_between_tokens.py b/vsg/vhdlFile/extract/get_association_elements_between_tokens.py new file mode 100644 index 00000000..3731bcf7 --- /dev/null +++ b/vsg/vhdlFile/extract/get_association_elements_between_tokens.py @@ -0,0 +1,45 @@ + +from vsg import parser +from vsg import token + +from vsg.vhdlFile.extract import tokens + + +def get_association_elements_between_tokens(oStart, oEnd, lAllTokens, oTokenMap): + lReturn = [] + lStartIndexes, lEndIndexes = oTokenMap.get_token_pair_indexes(oStart, oEnd) + + for iStart, iEnd in zip(lStartIndexes, lEndIndexes): + iLine = oTokenMap.get_line_number_of_index(iStart) + lToi = lAllTokens[iStart:iEnd + 1] + + bStore = False + iLineNumber = None + lTemp = [] + for iIndex in range(0, len(lToi)): + oToken = lToi[iIndex] + if isinstance(oToken, token.association_element.formal_part): + bStore = True + iStartIndex = iIndex + iStart + iLineNumber = iLine + if isinstance(oToken, token.association_element.actual_part) and not bStore: + bStore = True + iStartIndex = iIndex + iStart + iLineNumber = iLine + + if bStore: + lTemp.append(lToi[iIndex]) + + if isinstance(oToken, token.association_list.comma): + lReturn.append(tokens.New(iStartIndex, iLineNumber, lTemp)) + lTemp = [] + bStore = False + + if isinstance(lToi[iIndex], parser.carriage_return): + iLine +=1 + else: + if len(lTemp) > 0: + lReturn.append(tokens.New(iStartIndex, iLineNumber, lTemp)) + + + return lReturn diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index b757a6a7..8ebc3ed1 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -219,45 +219,7 @@ class vhdlFile(): return extract.get_blank_lines_above_line_starting_with_token(lTokens, self.lAllObjects, self.oTokenMap) def get_association_elements_between_tokens(self, oStart, oEnd): - iLine = 1 - lReturn = [] - bSearch = False - bStore = False - lTemp = [] - iLineNumber = None - for iIndex in range(0, len(self.lAllObjects)): - if isinstance(self.lAllObjects[iIndex], oStart): - bSearch = True - if isinstance(self.lAllObjects[iIndex], oEnd): - bSearch = False - bStore = False - if len(lTemp) > 0: - lReturn.append(Tokens(iStart, iLineNumber, lTemp)) - lTemp = [] - - if bSearch: - oToken = self.lAllObjects[iIndex] - if isinstance(oToken, token.association_element.formal_part): - bStore = True - iStart = iIndex - iLineNumber = iLine - if isinstance(oToken, token.association_element.actual_part) and not bStore: - bStore = True - iStart = iIndex - iLineNumber = iLine - - if isinstance(oToken, token.association_list.comma): - lReturn.append(Tokens(iStart, iLineNumber, lTemp)) - lTemp = [] - bStore = False - - if bStore: - lTemp.append(self.lAllObjects[iIndex]) - - if isinstance(self.lAllObjects[iIndex], parser.carriage_return): - iLine +=1 - - return lReturn + return extract.get_association_elements_between_tokens(oStart, oEnd, self.lAllObjects, self.oTokenMap) def get_interface_elements_between_tokens(self, oStart, oEnd, include_end_of_line_comments=False): iLine = 1