Updates for issue #121:
1) Added attributes specific to enumerated types 2) Updated rules accordingly 3) Updated tests
This commit is contained in:
parent
4d312ff8f1
commit
ec85925bdc
|
|
@ -128,13 +128,16 @@ class line():
|
|||
self.isWhileLoopKeyword = False
|
||||
self.isWhileLoopEnd = False
|
||||
# Type attributes
|
||||
self.insideType = False
|
||||
self.isTypeKeyword = False
|
||||
self.isTypeEnd = False
|
||||
# Subtype attributes
|
||||
self.insideSubtype = False
|
||||
self.isSubtypeKeyword = False
|
||||
self.isSubtypeEnd = False
|
||||
# Enumerated Type attributes
|
||||
self.insideTypeEnumerated = False
|
||||
self.isTypeEnumeratedKeyword = False
|
||||
self.isTypeEnumeratedEnd = False
|
||||
# Type Array attributes
|
||||
self.insideTypeArray = False
|
||||
self.isTypeArrayKeyword = False
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class rule_005(rule.rule):
|
|||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.insideType and not oLine.isTypeKeyword and not oLine.isBlank:
|
||||
if oLine.insideTypeEnumerated and not oLine.isTypeEnumeratedKeyword and not oLine.isBlank:
|
||||
check.indent(self, oLine, iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class rule_008(rule.rule):
|
|||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.isTypeEnd and not oLine.isTypeKeyword and not oLine.isTypeArrayEnd and not oLine.isTypeRecordEnd:
|
||||
if oLine.isTypeEnumeratedEnd and not oLine.isTypeEnumeratedKeyword:
|
||||
if not re.match('^\s*\)\s*;', oLine.lineLower):
|
||||
self.add_violation(iLineNumber)
|
||||
|
||||
|
|
@ -25,7 +25,9 @@ class rule_008(rule.rule):
|
|||
for iLineNumber in self.violations[::-1]:
|
||||
oFile.lines[iLineNumber].line = re.sub(r'\)(\s*);', r' \1 ', oFile.lines[iLineNumber].line)
|
||||
oFile.lines[iLineNumber].isTypeEnd = False
|
||||
oFile.lines[iLineNumber].isTypeEnumeratedEnd = False
|
||||
oFile.lines.insert(iLineNumber + 1, line.line(' );'))
|
||||
oFile.lines[iLineNumber + 1].isTypeEnd = True
|
||||
oFile.lines[iLineNumber + 1].insideType = True
|
||||
oFile.lines[iLineNumber + 1].isTypeEnumeratedEnd = True
|
||||
oFile.lines[iLineNumber + 1].insideTypeEnumerated = True
|
||||
oFile.lines[iLineNumber + 1].indentLevel = oFile.lines[iLineNumber].indentLevel - 1
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class rule_009(rule.rule):
|
|||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.isTypeKeyword and not oLine.isTypeEnd:
|
||||
if oLine.isTypeEnumeratedKeyword and not oLine.isTypeEnumeratedEnd:
|
||||
if re.match('^.*\sis\s*\(\s*\w', oLine.lineLower):
|
||||
self.add_violation(iLineNumber)
|
||||
|
||||
|
|
@ -26,4 +26,5 @@ class rule_009(rule.rule):
|
|||
utilities.split_line_after_word(oFile, iLineNumber, '(')
|
||||
oLine = oFile.lines[iLineNumber + 1]
|
||||
oLine.isTypeKeyword = False
|
||||
oLine.isTypeEnumeratedKeyword = False
|
||||
oLine.indentLevel += 1
|
||||
|
|
|
|||
|
|
@ -578,11 +578,23 @@ class testLineMethods(unittest.TestCase):
|
|||
oLine.isTypeKeyword = True
|
||||
self.assertEqual(oLine.isTypeKeyword, True)
|
||||
|
||||
def test_insideType_attribute(self):
|
||||
def test_isTypeEnumeratedEnd_attribute(self):
|
||||
oLine = line.line('contents of Line')
|
||||
self.assertEqual(oLine.insideType, False)
|
||||
oLine.insideType= True
|
||||
self.assertEqual(oLine.insideType, True)
|
||||
self.assertEqual(oLine.isTypeEnumeratedEnd, False)
|
||||
oLine.isTypeEnumeratedEnd = True
|
||||
self.assertEqual(oLine.isTypeEnumeratedEnd, True)
|
||||
|
||||
def test_isTypeEnumeratedKeyword_attribute(self):
|
||||
oLine = line.line('contents of Line')
|
||||
self.assertEqual(oLine.isTypeEnumeratedKeyword, False)
|
||||
oLine.isTypeEnumeratedKeyword = True
|
||||
self.assertEqual(oLine.isTypeEnumeratedKeyword, True)
|
||||
|
||||
def test_insideTypeEnumerated_attribute(self):
|
||||
oLine = line.line('contents of Line')
|
||||
self.assertEqual(oLine.insideTypeEnumerated, False)
|
||||
oLine.insideTypeEnumerated = True
|
||||
self.assertEqual(oLine.insideTypeEnumerated, True)
|
||||
|
||||
def test_isSubtypeEnd_attribute(self):
|
||||
oLine = line.line('contents of Line')
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import unittest
|
|||
from vsg.rules import type_definition
|
||||
from vsg import vhdlFile
|
||||
|
||||
|
||||
# Read in test file used for all tests
|
||||
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'type_test_input.vhd'))
|
||||
|
||||
|
|
@ -74,6 +73,8 @@ class testFixRuleSignalMethods(unittest.TestCase):
|
|||
oRule.fix(oFile)
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
self.assertEqual(oFile.lines[6].line, ' type a is (')
|
||||
self.assertEqual(oFile.lines[7].line, ' B, C,')
|
||||
|
||||
def test_fix_rule_010(self):
|
||||
oRule = type_definition.rule_010()
|
||||
|
|
|
|||
|
|
@ -28,12 +28,32 @@ class testVhdlFileTypeAssignments(unittest.TestCase):
|
|||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_insideType(self):
|
||||
lExpected = [4,6,7,8,9,11,19,21,22,23,24,26,28,29,30,31,32,35,36,37,38,39,40]
|
||||
def test_isTypeEnumeratedKeyword(self):
|
||||
lExpected = [4,6,19,21,28,35]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.insideType:
|
||||
if oLine.isTypeEnumeratedKeyword:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isTypeEnumeratedEnd(self):
|
||||
lExpected = [4,9,19,24,32,40]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.isTypeEnumeratedEnd:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_insideTypeEnumerated(self):
|
||||
lExpected = [4,6,7,8,9,19,21,22,23,24,28,29,30,31,32,35,36,37,38,39,40]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.insideTypeEnumerated:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,14 @@ def type_definition(dVars, oLine):
|
|||
oLine.insideTypeRecord = True
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
dVars['iCurrentIndentLevel'] += 1
|
||||
elif re.match('^\s*type\s.*range', oLine.line, re.IGNORECASE):
|
||||
oLine.isTypeKeyword = True
|
||||
oLine.isTypeEnd = True
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
elif re.match('^\s*type\s', oLine.line, re.IGNORECASE):
|
||||
oLine.isTypeKeyword = True
|
||||
oLine.insideType = True
|
||||
oLine.isTypeEnumeratedKeyword = True
|
||||
oLine.insideTypeEnumerated = True
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
dVars['iCurrentIndentLevel'] += 1
|
||||
assign_array_attributes(oLine)
|
||||
|
|
@ -43,11 +48,13 @@ def assign_record_attributes(dVars, oLine):
|
|||
|
||||
|
||||
def assign_enumerated_attributes(dVars, oLine):
|
||||
if oLine.insideType:
|
||||
if not oLine.isTypeKeyword and not oLine.isBlank:
|
||||
if oLine.insideTypeEnumerated:
|
||||
if not oLine.isTypeEnumeratedKeyword and not oLine.isBlank:
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
if ';' in oLine.line:
|
||||
oLine.isTypeEnumeratedEnd = True
|
||||
oLine.isTypeEnd = True
|
||||
|
||||
dVars['iCurrentIndentLevel'] -= 1
|
||||
if re.match('^\s*\)\s*;', oLine.line):
|
||||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ def update_if_attributes(oPreviousLine, oCurrentLine):
|
|||
oCurrentLine.insideIf = True
|
||||
|
||||
|
||||
def update_type_attributes(oPreviousLine, oCurrentLine):
|
||||
def update_type_enumerated_attributes(oPreviousLine, oCurrentLine):
|
||||
|
||||
if oPreviousLine.insideType and not oPreviousLine.isTypeEnd:
|
||||
oCurrentLine.insideType = True
|
||||
if oPreviousLine.insideTypeEnumerated and not oPreviousLine.isTypeEnumeratedEnd:
|
||||
oCurrentLine.insideTypeEnumerated = True
|
||||
|
||||
|
||||
def update_subtype_attributes(oPreviousLine, oCurrentLine):
|
||||
|
|
@ -172,7 +172,7 @@ def inside_attributes(oPreviousLine, oCurrentLine):
|
|||
update_concurrent_attributes(oPreviousLine, oCurrentLine)
|
||||
update_sensitivity_list_attributes(oPreviousLine, oCurrentLine)
|
||||
update_if_attributes(oPreviousLine, oCurrentLine)
|
||||
update_type_attributes(oPreviousLine, oCurrentLine)
|
||||
update_type_enumerated_attributes(oPreviousLine, oCurrentLine)
|
||||
update_type_array_attributes(oPreviousLine, oCurrentLine)
|
||||
update_type_record_attributes(oPreviousLine, oCurrentLine)
|
||||
update_subtype_attributes(oPreviousLine, oCurrentLine)
|
||||
|
|
|
|||
Loading…
Reference in New Issue