Refactoring rule process_020 for new parser.
This commit is contained in:
parent
65ed94baae
commit
065ec579c6
|
|
@ -25,21 +25,23 @@ class multiline_alignment_between_tokens(rule_item.Rule):
|
|||
object type to apply the case check against
|
||||
'''
|
||||
|
||||
def __init__(self, name, identifier, lTokenPairs):
|
||||
def __init__(self, name, identifier, lTokenPairs, bExcludeLastToken=False):
|
||||
rule_item.Rule.__init__(self, name=name, identifier=identifier)
|
||||
self.solution = 'Align with open parenthesis on previous line.'
|
||||
self.phase = 4
|
||||
self.lTokenPairs = lTokenPairs
|
||||
self.bExcludeLastToken = bExcludeLastToken
|
||||
|
||||
def analyze(self, oFile):
|
||||
lToi = []
|
||||
for lTokenPair in self.lTokenPairs:
|
||||
aToi = oFile.get_tokens_bounded_by(lTokenPair[0], lTokenPair[1])
|
||||
aToi = oFile.get_tokens_bounded_by(lTokenPair[0], lTokenPair[1], bExcludeLastToken=self.bExcludeLastToken)
|
||||
lToi = utils.combine_two_token_class_lists(lToi, aToi)
|
||||
|
||||
for oToi in lToi:
|
||||
|
||||
iLine, lTokens = utils.get_toi_parameters(oToi)
|
||||
|
||||
iStartColumn = calculate_start_column(oFile, oToi)
|
||||
lColumn = []
|
||||
lColumn.append(iStartColumn)
|
||||
|
|
|
|||
|
|
@ -1,34 +1,16 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import check
|
||||
from vsg import fix
|
||||
from vsg.rules import multiline_alignment_between_tokens
|
||||
|
||||
import re
|
||||
from vsg import token
|
||||
|
||||
lTokenPairs = []
|
||||
lTokenPairs.append([token.process_statement.open_parenthesis, token.process_statement.close_parenthesis])
|
||||
|
||||
|
||||
class rule_020(rule.rule):
|
||||
class rule_020(multiline_alignment_between_tokens):
|
||||
'''
|
||||
Process rule 020 checks the indentation on multiline sensitivity lists.
|
||||
Checks the alignment of multiline sensitivity lists.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'process', '020')
|
||||
self.solution = 'Fix indentation of sensitivity list.'
|
||||
self.phase = 5
|
||||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if not self._is_vsg_off(oLine):
|
||||
if oLine.isSensitivityListBegin and oLine.isSensitivityListEnd:
|
||||
continue
|
||||
if oLine.insideSensitivityList:
|
||||
if oLine.isSensitivityListBegin:
|
||||
iAlignmentColumn = oLine.line.find('(')
|
||||
elif oLine.isSensitivityListEnd and re.match('^\s*\)', oLine.line):
|
||||
continue
|
||||
else:
|
||||
check.multiline_alignment(self, iAlignmentColumn + 1, oLine, iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.dFix['violations']:
|
||||
fix.multiline_alignment(self, oFile, iLineNumber)
|
||||
multiline_alignment_between_tokens.__init__(self, 'process', '020', lTokenPairs, True)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
architecture ARCH of ENTITY is
|
||||
|
||||
begin
|
||||
|
||||
process (a, b, c, d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
-- Violations
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
|
||||
end architecture ARCH;
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
architecture ARCH of ENTITY is
|
||||
|
||||
begin
|
||||
|
||||
process (a, b, c, d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
-- Violations
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
process (a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
)
|
||||
begin
|
||||
end process;
|
||||
|
||||
|
||||
end architecture ARCH;
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from vsg.rules import process
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
sTestDir = os.path.dirname(__file__)
|
||||
|
||||
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_020_test_input.vhd'))
|
||||
|
||||
lExpected = []
|
||||
lExpected.append('')
|
||||
utils.read_file(os.path.join(sTestDir, 'rule_020_test_input.fixed.vhd'), lExpected)
|
||||
|
||||
|
||||
class test_process_rule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
def test_rule_020(self):
|
||||
oRule = process.rule_020()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'process')
|
||||
self.assertEqual(oRule.identifier, '020')
|
||||
|
||||
lExpected = [28, 30, 35, 36]
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
|
||||
def test_fix_rule_020(self):
|
||||
oRule = process.rule_020()
|
||||
|
||||
oRule.fix(self.oFile)
|
||||
|
||||
lActual = []
|
||||
for oLine in self.oFile.lines:
|
||||
lActual.append(oLine.line)
|
||||
|
||||
self.assertEqual(lExpected, lActual)
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, [])
|
||||
|
|
@ -16,15 +16,6 @@ oFileSensitivity = vhdlFile.vhdlFile(lFileSensitivity)
|
|||
|
||||
class testRuleProcessMethods(unittest.TestCase):
|
||||
|
||||
def test_rule_020(self):
|
||||
oRule = process.rule_020()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'process')
|
||||
self.assertEqual(oRule.identifier, '020')
|
||||
dExpected = utils.add_violation_list([19,25,26])
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_028(self):
|
||||
oRule = process.rule_028()
|
||||
self.assertTrue(oRule)
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ class vhdlFile():
|
|||
|
||||
return lReturn
|
||||
|
||||
def get_tokens_bounded_by(self, oLeft, oRight, include_trailing_whitespace=False):
|
||||
def get_tokens_bounded_by(self, oLeft, oRight, include_trailing_whitespace=False, bExcludeLastToken=False):
|
||||
iLine = 1
|
||||
lTemp = []
|
||||
lReturn = []
|
||||
|
|
@ -542,6 +542,12 @@ class vhdlFile():
|
|||
bStore = False
|
||||
if isinstance(self.lAllObjects[iIndex], oRight) and bStore:
|
||||
if not include_trailing_whitespace:
|
||||
if bExcludeLastToken:
|
||||
lTemp.pop()
|
||||
if isinstance(lTemp[-1], parser.whitespace):
|
||||
lTemp.pop()
|
||||
if isinstance(lTemp[-1], parser.carriage_return):
|
||||
lTemp.pop()
|
||||
lReturn.append(Tokens(iStart, iStartLine, lTemp))
|
||||
lTemp = []
|
||||
bStore = False
|
||||
|
|
|
|||
Loading…
Reference in New Issue