diff --git a/vsg/line.py b/vsg/line.py index 3eb48120..7f3778eb 100644 --- a/vsg/line.py +++ b/vsg/line.py @@ -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 diff --git a/vsg/rules/type_definition/rule_005.py b/vsg/rules/type_definition/rule_005.py index 6d749573..daa4c1a1 100644 --- a/vsg/rules/type_definition/rule_005.py +++ b/vsg/rules/type_definition/rule_005.py @@ -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): diff --git a/vsg/rules/type_definition/rule_008.py b/vsg/rules/type_definition/rule_008.py index bcdd9a6b..9bcf874d 100644 --- a/vsg/rules/type_definition/rule_008.py +++ b/vsg/rules/type_definition/rule_008.py @@ -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 diff --git a/vsg/rules/type_definition/rule_009.py b/vsg/rules/type_definition/rule_009.py index e9fab9c0..0b89108b 100644 --- a/vsg/rules/type_definition/rule_009.py +++ b/vsg/rules/type_definition/rule_009.py @@ -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 diff --git a/vsg/tests/line/test_line.py b/vsg/tests/line/test_line.py index 3666d851..53d2c0db 100644 --- a/vsg/tests/line/test_line.py +++ b/vsg/tests/line/test_line.py @@ -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') diff --git a/vsg/tests/type_definition/test_fix_rule_type.py b/vsg/tests/type_definition/test_fix_rule_type.py index 599b6b82..fc8dfc9b 100644 --- a/vsg/tests/type_definition/test_fix_rule_type.py +++ b/vsg/tests/type_definition/test_fix_rule_type.py @@ -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() diff --git a/vsg/tests/vhdlFile/test_vhdlFile_type_assignments.py b/vsg/tests/vhdlFile/test_vhdlFile_type_assignments.py index 07c745e0..9ef044af 100644 --- a/vsg/tests/vhdlFile/test_vhdlFile_type_assignments.py +++ b/vsg/tests/vhdlFile/test_vhdlFile_type_assignments.py @@ -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) diff --git a/vsg/vhdlFile/classify/type_definition.py b/vsg/vhdlFile/classify/type_definition.py index 1b06b4a7..e4f634e3 100644 --- a/vsg/vhdlFile/classify/type_definition.py +++ b/vsg/vhdlFile/classify/type_definition.py @@ -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'] diff --git a/vsg/vhdlFile/update.py b/vsg/vhdlFile/update.py index 63574a6d..daea7420 100644 --- a/vsg/vhdlFile/update.py +++ b/vsg/vhdlFile/update.py @@ -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)