Refactoring method get_association_elements_between_tokens:

1)  Moving from vsg.vhdlFile to vsg.vhdlFile.extract
  2)  Partial refactoring to use token map
  3)  Fixed generic_map_008 to use correct tokens
This commit is contained in:
Jeremiah Leary 2020-12-03 14:02:47 -06:00
parent e84064751f
commit 3bc58bb783
6 changed files with 53 additions and 45 deletions

View File

@ -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):

View File

@ -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,

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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