Refactored architecture_006, concurrent_006, and concurrent_008 rules.

This commit is contained in:
Jeremiah C Leary 2017-12-28 16:26:57 -06:00
parent f584accb4a
commit 64274e5010
6 changed files with 102 additions and 59 deletions

View File

@ -11,17 +11,16 @@ class rule_006(rule.rule):
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'architecture'
self.identifier = '006'
rule.rule.__init__(self, 'architecture', '006')
self.solution = 'Ensure "is" keyword is on the same line as the "architecture" keyword.'
self.phase = 1
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isArchitectureKeyword and re.match('^\s*architecture\s+\w+\s+of\s+\w+', oLine.line, re.IGNORECASE):
if not re.match('^\s*architecture\s+\w+\s+of\s+\w+\s+is', oLine.line, re.IGNORECASE):
self.add_violation(iLineNumber)
if oLine.isArchitectureKeyword and \
re.match('^\s*architecture\s+\w+\s+of\s+\w+', oLine.line, re.IGNORECASE) and \
not re.match('^\s*architecture\s+\w+\s+of\s+\w+\s+is', oLine.line, re.IGNORECASE):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:

View File

@ -1,4 +1,6 @@
from keyword_alignment_rule import keyword_alignment_rule
from rule_001 import rule_001
from rule_002 import rule_002
from rule_003 import rule_003

View File

@ -0,0 +1,58 @@
from vsg import rule
from vsg import check
from vsg import fix
class keyword_alignment_rule(rule.rule):
'''
Checks for keyword alignment in consecutive concurrent statements.
Parameters
----------
name : string
The group the rule belongs to.
identifier : string
unique identifier. Usually in the form of 00N.
Attributes
----------
sKeyword : string
The keyword to align.
sStartGroupTrigger: string
The line attribute which marks the start of a group to align.
sEndGroupTrigger: string
The line attribute which ends the group to align.
NOTE: This is inversed to allow for grouping of consecutive lines.
'''
def __init__(self, name, identifier):
rule.rule.__init__(self, name, identifier)
self.phase = 5
self.sKeyword = None
self.sStartGroupTrigger = None
self.sEndGroupTrigger = None
def analyze(self, oFile):
lGroup = []
fGroupFound = False
iStartGroupIndex = None
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.__dict__[self.sStartGroupTrigger] and not fGroupFound:
fGroupFound = True
iStartGroupIndex = iLineNumber
if not oLine.__dict__[self.sEndGroupTrigger] and fGroupFound:
fGroupFound = False
check.keyword_alignment(self, iStartGroupIndex, self.sKeyword, lGroup)
lGroup = []
iStartGroupIndex = None
if fGroupFound:
lGroup.append(oLine)
def _fix_violations(self, oFile):
fix.keyword_alignment(self, oFile)

View File

@ -1,34 +1,15 @@
from vsg import rule
from vsg import check
from vsg import fix
from vsg.rules.concurrent import keyword_alignment_rule
class rule_006(rule.rule):
class rule_006(keyword_alignment_rule):
'''
Concurrent rule 006 ensures the alignment of the "<=" keyword over multiple lines.
'''
def __init__(self):
rule.rule.__init__(self, 'concurrent', '006')
keyword_alignment_rule.__init__(self, 'concurrent', '006')
self.solution = 'Inconsistent alignment of "<=" in group of lines.'
self.phase = 5
def analyze(self, oFile):
lGroup = []
fGroupFound = False
iStartGroupIndex = None
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isConcurrentBegin and not fGroupFound:
fGroupFound = True
iStartGroupIndex = iLineNumber
if not oLine.insideConcurrent and fGroupFound:
fGroupFound = False
check.keyword_alignment(self, iStartGroupIndex, '<=', lGroup)
lGroup = []
iStartGroupIndex = None
if fGroupFound:
lGroup.append(oLine)
def _fix_violations(self, oFile):
fix.keyword_alignment(self, oFile)
self.sKeyword = '<='
self.sStartGroupTrigger = 'isConcurrentBegin'
self.sEndGroupTrigger = 'insideConcurrent'

View File

@ -1,36 +1,15 @@
from vsg import rule
from vsg import check
from vsg import fix
from vsg.rules.concurrent import keyword_alignment_rule
class rule_008(rule.rule):
class rule_008(keyword_alignment_rule):
'''
Concurrent rule 008 ensures the alignment of comments in sequential conccurent statements.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'concurrent'
self.identifier = '008'
keyword_alignment_rule.__init__(self, 'concurrent', '008')
self.solution = 'Inconsistent alignment of comments in group of lines.'
self.phase = 5
def analyze(self, oFile):
lGroup = []
fGroupFound = False
iStartGroupIndex = None
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.isConcurrentBegin and not fGroupFound:
fGroupFound = True
iStartGroupIndex = iLineNumber
if not oLine.insideConcurrent and fGroupFound:
fGroupFound = False
check.keyword_alignment(self, iStartGroupIndex, '--', lGroup)
lGroup = []
iStartGroupIndex = None
if fGroupFound:
lGroup.append(oLine)
def _fix_violations(self, oFile):
fix.keyword_alignment(self, oFile)
self.sKeyword = '--'
self.sStartGroupTrigger = 'isConcurrentBegin'
self.sEndGroupTrigger = 'insideConcurrent'

View File

@ -7,7 +7,31 @@ from vsg import line
class keyword_alignment_rule(rule.rule):
'''
Instantiation rule 015 ensures the alignment of the => operator for every generic in the instantiation.
Checks for keyword alignment in consecutive concurrent statements.
Parameters
----------
name : string
The group the rule belongs to.
identifier : string
unique identifier. Usually in the form of 00N.
Attributes
----------
sKeyword : string
The keyword to align.
sStartGroupTrigger: string
The line attribute which marks the start of a group to align.
sEndGroupTrigger: string
The line attribute which ends the group to align.
sLineTrigger : string
Stores lines in a group which match this attribute.
'''
def __init__(self, name=None, identifier=None):