Refactored process rules.

This commit is contained in:
Jeremiah C Leary 2017-12-23 13:36:08 -06:00
parent 20e1f0baff
commit fb09a153a7
25 changed files with 67 additions and 151 deletions

View File

@ -49,6 +49,7 @@ class line():
self.insideProcess = False
self.isProcessBegin = False
self.isProcessKeyword = False
self.isProcessLabel = False
self.isProcessDeclarative = False
self.isEndProcess = False
self.insideSensitivityList = False

View File

@ -11,16 +11,13 @@ class rule_005(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '005'
rule.rule.__init__(self, 'process', '005')
self.solution = 'Lowercase the "process" keyword.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isProcessKeyword:
if not re.match('^\s*.*process', oLine.line):
if oLine.isProcessKeyword and not re.match('^\s*.*process', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):

View File

@ -1,28 +1,12 @@
from vsg import rule
from vsg import fix
import re
from vsg.rules import single_space_after_rule
class rule_007(rule.rule):
class rule_007(single_space_after_rule):
'''
Process rule 007 checks for a single space between the "end" and "process" keywords.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '007'
single_space_after_rule.__init__(self, 'process', '007', 'isEndProcess', 'end')
self.solution = 'Ensure there are only one space between the "end" and "process" keywords.'
self.phase = 2
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isEndProcess:
if not re.match('^\s*\S+\s\S', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
fix.enforce_one_space_after_word(self, oFile.lines[iLineNumber], 'end')

View File

@ -1,27 +1,12 @@
from vsg import rule
from vsg import utilities
from vsg import fix
from vsg import check
from vsg.rules import lower_case_rule
class rule_008(rule.rule):
class rule_008(lower_case_rule):
'''
Process rule 008 checks the "end" keyword is lowercase.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '008'
lower_case_rule.__init__(self, 'process', '008', 'isEndProcess', 'end')
self.solution = 'Lowercase the "end" keyword.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isEndProcess:
check.is_lowercase(self, utilities.get_first_word(oLine), iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
fix.lower_case(self, oFile.lines[iLineNumber], 'end')

View File

@ -11,17 +11,14 @@ class rule_009(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '009'
rule.rule.__init__(self, 'process', '009')
self.solution = 'Lowercase the "process" keyword.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isEndProcess:
if not re.match('^\s*\w+\s+process', oLine.line):
self.add_violation(iLineNumber)
if oLine.isEndProcess and not re.match('^\s*\w+\s+process', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -12,9 +12,7 @@ class rule_010(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '010'
rule.rule.__init__(self, 'process', '010')
self.solution = 'Place "begin" keyword on seperate line.'
self.phase = 1

View File

@ -8,7 +8,4 @@ class rule_011(line_below_rule):
'''
def __init__(self):
line_below_rule.__init__(self)
self.name = 'process'
self.identifier = '011'
self.condition = 'isEndProcess'
line_below_rule.__init__(self, 'process', '011', 'isEndProcess')

View File

@ -10,9 +10,7 @@ class rule_012(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '012'
rule.rule.__init__(self, 'process', '012')
self.solution = 'Add "is" keyword after the closing parenthesis.'
self.phase = 1

View File

@ -11,18 +11,15 @@ class rule_013(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '013'
rule.rule.__init__(self, 'process', '013')
self.solution = 'Lowercase "is" keyword.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isSensitivityListEnd:
if re.match('^.*\)\s*is', oLine.lineLower):
if not re.match('^.*\)\s*is', oLine.line):
self.add_violation(iLineNumber)
if oLine.isSensitivityListEnd and re.match('^.*\)\s*is', oLine.lineLower):
if not re.match('^.*\)\s*is', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -11,18 +11,15 @@ class rule_014(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '014'
rule.rule.__init__(self, 'process', '014')
self.solution = 'Ensure only a single space exists between the ) and "is" keyword.'
self.phase = 2
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isSensitivityListEnd:
if re.match('^.*\)\s*is', oLine.lineLower):
if not re.match('^.*\)\sis', oLine.lineLower):
self.add_violation(iLineNumber)
if oLine.isSensitivityListEnd and re.match('^.*\)\s*is', oLine.lineLower):
if not re.match('^.*\)\sis', oLine.lineLower):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -9,9 +9,7 @@ class rule_015(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '015'
rule.rule.__init__(self, 'process', '015')
self.solution = 'Add a space or a comment above the "process" keyword.'
self.phase = 3

View File

@ -17,5 +17,5 @@ class rule_016(rule.rule):
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isProcessKeyword and not re.match('^\s*\S+\s*:', oLine.line):
if oLine.isProcessKeyword and not oLine.isProcessLabel:
self.add_violation(iLineNumber)

View File

@ -1,5 +1,6 @@
from vsg import rule
from vsg import check
from vsg import fix
import re
@ -11,19 +12,15 @@ class rule_017(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '017'
rule.rule.__init__(self, 'process', '017')
self.solution = 'Uppercase process label.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isProcessKeyword:
if re.match('^\s*\S+\s*:', oLine.line):
lLine = oLine.line.split(':')
if not lLine[0] == lLine[0].upper():
self.add_violation(iLineNumber)
if oLine.isProcessLabel:
lLine = oLine.line.split(':')
check.is_uppercase(self, lLine[0], iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -12,17 +12,14 @@ class rule_019(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '019'
rule.rule.__init__(self, 'process', '019')
self.solution = 'Uppercase the label.'
self.phase = 6
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isEndProcess:
if re.match('^\s*\w+\s+\w+\s+\w+', oLine.line):
check.is_uppercase(self, oLine.line.split()[2], iLineNumber)
if oLine.isEndProcess and re.match('^\s*\w+\s+\w+\s+\w+', oLine.line):
check.is_uppercase(self, oLine.line.split()[2], iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -12,9 +12,7 @@ class rule_020(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '020'
rule.rule.__init__(self, 'process', '020')
self.solution = 'Fix indentation of sensitivity list.'
self.phase = 5

View File

@ -9,9 +9,7 @@ class rule_021(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '021'
rule.rule.__init__(self, 'process', '021')
self.solution = 'Remove blank lines between the end of the sensitivity list and before the "begin" keyword.'
self.phase = 3

View File

@ -8,7 +8,4 @@ class rule_022(line_below_rule):
'''
def __init__(self):
line_below_rule.__init__(self)
self.name = 'process'
self.identifier = '022'
self.condition = 'isProcessBegin'
line_below_rule.__init__(self, 'process', '022', 'isProcessBegin')

View File

@ -8,7 +8,4 @@ class rule_023(line_above_rule):
'''
def __init__(self):
line_above_rule.__init__(self)
self.name = 'process'
self.identifier = '023'
self.condition = 'isEndProcess'
line_above_rule.__init__(self, 'process', '023', 'isEndProcess')

View File

@ -1,29 +1,12 @@
from vsg import rule
from vsg import fix
import re
from vsg.rules import single_space_before_character_rule
class rule_024(rule.rule):
class rule_024(single_space_before_character_rule):
'''
Process rule 024 checks for a single space after the process label and the :.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '024'
single_space_before_character_rule.__init__(self, 'process', '024', 'isProcessLabel', ':')
self.solution = 'Ensure a single space exists between process label and :.'
self.phase = 2
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isProcessKeyword:
if re.match('^\s*\S+\s*:', oLine.line):
if not re.match('^\s*\S+\s:', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
fix.enforce_one_space_before_word(self, oFile.lines[iLineNumber], ':')

View File

@ -1,29 +1,12 @@
from vsg import rule
from vsg import fix
import re
from vsg.rules import single_space_after_character_rule
class rule_025(rule.rule):
class rule_025(single_space_after_character_rule):
'''
Process rule 025 checks for a single space after the : and before the "process" keyword.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '025'
single_space_after_character_rule.__init__(self, 'process', '025', 'isProcessLabel', ':')
self.solution = 'Ensure a single space exists between the : and the "process" keyword.'
self.phase = 2
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isProcessKeyword:
if re.match('^\s*\S+\s*:\s*\S+', oLine.line):
if not re.match('^\s*\S+\s*:\s\S', oLine.line):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
fix.enforce_one_space_after_word(self, oFile.lines[iLineNumber], ':')

View File

@ -9,9 +9,7 @@ class rule_026(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '026'
rule.rule.__init__(self, 'process', '026')
self.solution = 'Ensure a single blank line between the end of the sensitivity list and the next non-blank line.'
self.phase = 3

View File

@ -12,9 +12,7 @@ class rule_028(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '028'
rule.rule.__init__(self, 'process', '028')
self.solution = 'Align closing parenthesis with opening parenthesis.'
self.phase = 5

View File

@ -188,6 +188,12 @@ class testLineMethods(unittest.TestCase):
oLine.isProcessKeyword = True
self.assertEqual(oLine.isProcessKeyword, True)
def test_isProcessLabel_attribute(self):
oLine = line.line('contents of Line')
self.assertEqual(oLine.isProcessLabel, False)
oLine.isProcessLabel = True
self.assertEqual(oLine.isProcessLabel, True)
def test_isEndProcess_attribute(self):
oLine = line.line('contents of Line')
self.assertEqual(oLine.isEndProcess, False)

View File

@ -334,6 +334,16 @@ class testVhdlFileMethods(unittest.TestCase):
# Compare
self.assertEqual(lActual, lExpected)
def test_isProcessLabel_assignment(self):
lExpected = [46,63,68,75,81,88,97]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileProcess.lines):
if oLine.isProcessLabel:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isEndProcess_assignment(self):
lExpected = [9,15,22,30,36,42,48,53,60,65,72,79,86,94,103]
# Generic actual list

View File

@ -2,10 +2,15 @@ import re
def process(dVars, oLine):
if re.match('^\s*process', oLine.lineLower) or re.match('^\s*\S+\s*:\s*process', oLine.lineLower) and not oLine.isComment:
if re.match('^\s*process', oLine.lineLower):
oLine.isProcessKeyword = True
oLine.insideProcess = True
oLine.indentLevel = dVars['iCurrentIndentLevel']
if re.match('^\s*\S+\s*:\s*process', oLine.lineLower):
oLine.isProcessKeyword = True
oLine.insideProcess = True
oLine.indentLevel = dVars['iCurrentIndentLevel']
oLine.isProcessLabel = True
if oLine.insideProcess:
# Check sensitivity list
if '(' in oLine.line and not oLine.insideSensitivityList and not dVars['fFoundProcessBegin'] and not dVars['SensitivityListFound']: