Updates for issue #129
1) Added ability to correctly classify nested generates. 2) Added tests
This commit is contained in:
parent
41510950d9
commit
8b18201fe7
|
|
@ -61,4 +61,24 @@ END GENERATE generate_1;
|
|||
a <= b;
|
||||
end generate GENERATE_1;
|
||||
|
||||
|
||||
GENERATE_1 : for i in 0 to 7 generate
|
||||
a <= b;
|
||||
|
||||
GENERATE_2 : for i in 0 to 7 generate
|
||||
a <= b;
|
||||
|
||||
GENERATE_3 : for i in 0 to 7 generate
|
||||
a <= b;
|
||||
end generate GENERATE_3;
|
||||
|
||||
end generate GENERATE_2;
|
||||
|
||||
GENERATE_4 : for i in 0 to 7 generate
|
||||
a <= b;
|
||||
end generate GENERATE_4;
|
||||
|
||||
end generate GENERATE_1;
|
||||
|
||||
|
||||
end architecture ARCH;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class testVhdlFileGenerateAssignments(unittest.TestCase):
|
|||
|
||||
|
||||
def test_isGenerateKeyword(self):
|
||||
lExpected = [6,11,16,21,26,31,36,41,46,51,56,60]
|
||||
lExpected = [6,11,16,21,26,31,36,41,46,51,56,60,65,68,71,77]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -29,7 +29,7 @@ class testVhdlFileGenerateAssignments(unittest.TestCase):
|
|||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isGenerateEnd(self):
|
||||
lExpected = [9,14,19,24,29,34,39,44,49,54,58,62]
|
||||
lExpected = [9,14,19,24,29,34,39,44,49,54,58,62,73,75,79,81]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -38,6 +38,16 @@ class testVhdlFileGenerateAssignments(unittest.TestCase):
|
|||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isEndArchitecture(self):
|
||||
lExpected = [84]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.isEndArchitecture:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_GenerateIndent(self):
|
||||
# [ 0, 1,2, 3,4, 5,6,7,8,9, 10,11,12,13,14, 15]
|
||||
lExpected = [None,None,0,None,0,None,1,1,2,1,None, 1, 1, 2, 1,None]
|
||||
|
|
@ -50,3 +60,14 @@ class testVhdlFileGenerateAssignments(unittest.TestCase):
|
|||
lActual.append(oLine.indentLevel)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_insideGenerate(self):
|
||||
lExpected = [6,7,8,9,11,12,13,14,16,17,18,19,21,22,23,24,26,27,28,29,31,32,33,34,36,37,38,39,41,42,43,44,46,47,48,49,51,52,53,54,56,57,58,60,61,62,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.insideGenerate:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ def generate(dVars, oLine):
|
|||
|
||||
if re.match('^\s*\w+\s*:\s*if', oLine.lineLower) or re.match('^\s*\w+\s*:\s*for\s.*\sgenerate', oLine.lineLower):
|
||||
oLine.insideGenerate = True
|
||||
dVars['iGenerateLevel'] += 1
|
||||
if oLine.insideGenerate:
|
||||
if re.match('^\s*\w+\s*:\s*if\s.*\sgenerate', oLine.lineLower) or re.match('^\s*\w+\s*:\s*for\s.*\sgenerate', oLine.lineLower):
|
||||
oLine.isGenerateKeyword = True
|
||||
|
|
@ -17,3 +18,4 @@ def generate(dVars, oLine):
|
|||
oLine.isGenerateEnd = True
|
||||
dVars['iCurrentIndentLevel'] -= 1
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
dVars['iGenerateLevel'] -= 1
|
||||
|
|
|
|||
|
|
@ -143,9 +143,12 @@ def update_function_attributes(oPreviousLine, oCurrentLine):
|
|||
oCurrentLine.insideFunction = True
|
||||
|
||||
|
||||
def update_generate_attributes(oPreviousLine, oCurrentLine):
|
||||
def update_generate_attributes(dVars, oPreviousLine, oCurrentLine):
|
||||
|
||||
if oPreviousLine.insideGenerate and not oPreviousLine.isGenerateEnd:
|
||||
if oPreviousLine.insideGenerate and oPreviousLine.isGenerateEnd:
|
||||
if dVars['iGenerateLevel'] > 0:
|
||||
oCurrentLine.insideGenerate = True
|
||||
elif oPreviousLine.insideGenerate and not oPreviousLine.isGenerateEnd:
|
||||
oCurrentLine.insideGenerate = True
|
||||
|
||||
|
||||
|
|
@ -173,7 +176,7 @@ def update_file_attributes(oPreviousLine, oCurrentLine):
|
|||
oCurrentLine.insideFile = True
|
||||
|
||||
|
||||
def inside_attributes(oPreviousLine, oCurrentLine):
|
||||
def inside_attributes(dVars, oPreviousLine, oCurrentLine):
|
||||
|
||||
update_entity_attributes(oPreviousLine, oCurrentLine)
|
||||
update_port_map_attributes(oPreviousLine, oCurrentLine)
|
||||
|
|
@ -199,7 +202,7 @@ def inside_attributes(oPreviousLine, oCurrentLine):
|
|||
update_package_attributes(oPreviousLine, oCurrentLine)
|
||||
update_package_body_attributes(oPreviousLine, oCurrentLine)
|
||||
update_function_attributes(oPreviousLine, oCurrentLine)
|
||||
update_generate_attributes(oPreviousLine, oCurrentLine)
|
||||
update_generate_attributes(dVars, oPreviousLine, oCurrentLine)
|
||||
update_for_loop_attributes(oPreviousLine, oCurrentLine)
|
||||
update_while_loop_attributes(oPreviousLine, oCurrentLine)
|
||||
update_attribute_attributes(oPreviousLine, oCurrentLine)
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@ class vhdlFile():
|
|||
dVars['iOpenParenthesis'] = 0
|
||||
dVars['iCloseParenthesis'] = 0
|
||||
dVars['iCurrentIndentLevel'] = 0
|
||||
dVars['iGenerateLevel'] = 0
|
||||
|
||||
with open(self.filename) as oFile:
|
||||
for sLine in oFile:
|
||||
oLine = line.line(sLine.replace('\t', ' ').rstrip())
|
||||
update.inside_attributes(self.lines[-1], oLine)
|
||||
update.inside_attributes(dVars, self.lines[-1], oLine)
|
||||
|
||||
classify.blank(oLine)
|
||||
classify.comment(dVars, oLine)
|
||||
|
|
|
|||
Loading…
Reference in New Issue