Updates for issue #226
Refactoring the following rules for code coverage: architecture_024 instantiation_010 port_011 process_018 process_031 sequential_004
This commit is contained in:
parent
dabedaa26f
commit
016f65d6b0
|
|
@ -14,20 +14,20 @@ class rule_024(rule.rule):
|
|||
self.solution = 'Add architecture name keyword.'
|
||||
self.phase = 1
|
||||
|
||||
def analyze(self, oFile):
|
||||
def _pre_analyze(self):
|
||||
self.dFix['label'] = {}
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if self._is_vsg_off(oLine):
|
||||
continue
|
||||
if oLine.isArchitectureKeyword:
|
||||
sLabel = oLine.line.split()[1]
|
||||
if oLine.isEndArchitecture and not re.match('^\s*end\s+architecture\s+\w+', oLine.line, re.IGNORECASE):
|
||||
if re.match('^\s*end\s+architecture', oLine.line, re.IGNORECASE):
|
||||
self.add_violation(iLineNumber)
|
||||
self.dFix['label'][iLineNumber] = sLabel
|
||||
elif not re.match('^\s*end\s+\w+', oLine.line, re.IGNORECASE):
|
||||
self.add_violation(iLineNumber)
|
||||
self.dFix['label'][iLineNumber] = sLabel
|
||||
self.sLabel = ""
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isArchitectureKeyword:
|
||||
self.sLabel = oLine.line.split()[1]
|
||||
if oLine.isEndArchitecture and not re.match('^\s*end\s+architecture\s+\w+', oLine.line, re.IGNORECASE):
|
||||
if re.match('^\s*end\s+architecture', oLine.line, re.IGNORECASE):
|
||||
self.add_violation(iLineNumber)
|
||||
self.dFix['label'][iLineNumber] = self.sLabel
|
||||
elif not re.match('^\s*end\s+\w+', oLine.line, re.IGNORECASE):
|
||||
self.add_violation(iLineNumber)
|
||||
self.dFix['label'][iLineNumber] = self.sLabel
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
|
|
|
|||
|
|
@ -17,27 +17,26 @@ class rule_010(rule.rule):
|
|||
self.solution = 'Inconsistent alignment of "=>" in port assignments of instantiation.'
|
||||
self.phase = 5
|
||||
|
||||
def analyze(self, oFile):
|
||||
lGroup = []
|
||||
fGroupFound = False
|
||||
iStartGroupIndex = None
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if self._is_vsg_off(oLine):
|
||||
continue
|
||||
if oLine.isInstantiationPortKeyword and not fGroupFound:
|
||||
fGroupFound = True
|
||||
iStartGroupIndex = iLineNumber
|
||||
if oLine.isInstantiationPortEnd and fGroupFound:
|
||||
lGroup.append(oLine)
|
||||
fGroupFound = False
|
||||
check.keyword_alignment(self, iStartGroupIndex, '=>', lGroup)
|
||||
lGroup = []
|
||||
iStartGroupIndex = None
|
||||
if fGroupFound:
|
||||
if oLine.isInstantiationPortAssignment and not oLine.isInstantiationPortKeyword:
|
||||
lGroup.append(oLine)
|
||||
else:
|
||||
lGroup.append(line.line('Removed line'))
|
||||
def _pre_analyze(self):
|
||||
self.lGroup = []
|
||||
self.fGroupFound = False
|
||||
self.iStartGroupIndex = None
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isInstantiationPortKeyword and not self.fGroupFound:
|
||||
self.fGroupFound = True
|
||||
self.iStartGroupIndex = iLineNumber
|
||||
if oLine.isInstantiationPortEnd and self.fGroupFound:
|
||||
self.lGroup.append(oLine)
|
||||
self.fGroupFound = False
|
||||
check.keyword_alignment(self, self.iStartGroupIndex, '=>', self.lGroup)
|
||||
self.lGroup = []
|
||||
self.iStartGroupIndex = None
|
||||
if self.fGroupFound:
|
||||
if oLine.isInstantiationPortAssignment and not oLine.isInstantiationPortKeyword:
|
||||
self.lGroup.append(oLine)
|
||||
else:
|
||||
self.lGroup.append(line.line('Removed line'))
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
fix.keyword_alignment(self, oFile)
|
||||
|
|
|
|||
|
|
@ -20,16 +20,14 @@ class rule_011(rule.rule):
|
|||
self.fixable = False # This requires the user to fix as this could cover multiple files.
|
||||
self.configuration.append('port_direction')
|
||||
|
||||
def analyze(self, oFile):
|
||||
def _pre_analyze(self):
|
||||
select_solution(self)
|
||||
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if self._is_vsg_off(oLine):
|
||||
continue
|
||||
if oLine.isPortDeclaration and oLine.insideEntity:
|
||||
lLine = oLine.lineLower.split()
|
||||
check_for_prefix(self, lLine, iLineNumber)
|
||||
check_for_suffix(self, lLine, iLineNumber)
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isPortDeclaration and oLine.insideEntity:
|
||||
lLine = oLine.lineLower.split()
|
||||
check_for_prefix(self, lLine, iLineNumber)
|
||||
check_for_suffix(self, lLine, iLineNumber)
|
||||
|
||||
|
||||
def select_solution(self):
|
||||
|
|
|
|||
|
|
@ -14,27 +14,29 @@ class rule_018(rule.rule):
|
|||
self.solution = 'Add a label for the "end process".'
|
||||
self.phase = 1
|
||||
|
||||
def _pre_analyze(self):
|
||||
self.dFix['processLabel'] = {}
|
||||
self.labelStack = ''
|
||||
self.iProcStartLine = 0
|
||||
self.iProcLabelLine = 0
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isProcessKeyword:
|
||||
self.iProcStartLine = iLineNumber
|
||||
oMatch = re.match('^\s*(\S+)\s*:\s*process', oLine.lineLower)
|
||||
if oMatch:
|
||||
self.iProcLabelLine = iLineNumber
|
||||
self.labelStack = oMatch.group(1)
|
||||
if oLine.isEndProcess:
|
||||
if not re.match('^\s*\S+\s+\S+\s+\S+', oLine.line):
|
||||
self.add_violation(iLineNumber)
|
||||
if self.labelStack and self.iProcStartLine == self.iProcLabelLine:
|
||||
self.dFix['processLabel'][iLineNumber] = self.labelStack
|
||||
self.labelStack = ''
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.isEndProcess and not re.match('^\s*\S+\s+\S+\s+\S+', oLine.line):
|
||||
if iLineNumber in self.dFix['processLabel']:
|
||||
oMatch = re.search(r'^(\s*)\S+\s+\S+', oLine.line)
|
||||
oLine.line = oMatch.group(1) + 'end process ' + self.dFix['processLabel'][iLineNumber] + ';'
|
||||
|
||||
def analyze(self, oFile):
|
||||
self.dFix['processLabel'] = {}
|
||||
labelStack = ''
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if not self._is_vsg_off(oLine):
|
||||
if oLine.isProcessKeyword:
|
||||
iProcStartLine = iLineNumber
|
||||
oMatch = re.match('^\s*(\S+)\s*:\s*process', oLine.lineLower)
|
||||
if oMatch:
|
||||
iProcLabelLine = iLineNumber
|
||||
labelStack = oMatch.group(1)
|
||||
if oLine.isEndProcess:
|
||||
if not re.match('^\s*\S+\s+\S+\s+\S+', oLine.line):
|
||||
self.add_violation(iLineNumber)
|
||||
if labelStack and iProcStartLine == iProcLabelLine:
|
||||
self.dFix['processLabel'][iLineNumber] = labelStack
|
||||
labelStack = ''
|
||||
|
|
|
|||
|
|
@ -15,26 +15,26 @@ class rule_031(rule.rule):
|
|||
self.phase = 5
|
||||
self.solution = 'Align the first character of each identifier and align colons.'
|
||||
|
||||
def analyze(self, oFile):
|
||||
lGroup = []
|
||||
fGroupFound = False
|
||||
iStartGroupIndex = None
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if not self._is_vsg_off(oLine):
|
||||
if oLine.isProcessKeyword and not fGroupFound:
|
||||
fGroupFound = True
|
||||
iStartGroupIndex = iLineNumber
|
||||
if fGroupFound:
|
||||
if oLine.isConstant or oLine.isVariable or oLine.isFileKeyword:
|
||||
lGroup.append(oLine)
|
||||
else:
|
||||
lGroup.append(line.blank_line())
|
||||
if oLine.isProcessBegin and fGroupFound:
|
||||
fGroupFound = False
|
||||
check.identifier_alignment(self, iStartGroupIndex, lGroup)
|
||||
check.keyword_alignment(self, iStartGroupIndex, ':', lGroup)
|
||||
lGroup = []
|
||||
iStartGroupIndex = None
|
||||
def _pre_analyze(self):
|
||||
self.lGroup = []
|
||||
self.fGroupFound = False
|
||||
self.iStartGroupIndex = None
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isProcessKeyword and not self.fGroupFound:
|
||||
self.fGroupFound = True
|
||||
self.iStartGroupIndex = iLineNumber
|
||||
if self.fGroupFound:
|
||||
if oLine.isConstant or oLine.isVariable or oLine.isFileKeyword:
|
||||
self.lGroup.append(oLine)
|
||||
else:
|
||||
self.lGroup.append(line.blank_line())
|
||||
if oLine.isProcessBegin and self.fGroupFound:
|
||||
self.fGroupFound = False
|
||||
check.identifier_alignment(self, self.iStartGroupIndex, self.lGroup)
|
||||
check.keyword_alignment(self, self.iStartGroupIndex, ':', self.lGroup)
|
||||
self.lGroup = []
|
||||
self.iStartGroupIndex = None
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
fix.identifier_alignment(self, oFile)
|
||||
|
|
|
|||
|
|
@ -15,16 +15,15 @@ class rule_004(rule.rule):
|
|||
self.solution = 'Align with space after the "<=" keyword.'
|
||||
self.phase = 5
|
||||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if self._is_vsg_off(oLine):
|
||||
continue
|
||||
if oLine.isSequential and oLine.isSequentialEnd:
|
||||
continue
|
||||
if oLine.isSequential:
|
||||
iAlignmentColumn = oLine.line.find('<=') + len('<= ')
|
||||
if oLine.insideSequential and not oLine.isComment and not oLine.isSequential:
|
||||
check.multiline_alignment(self, iAlignmentColumn, oLine, iLineNumber)
|
||||
def _pre_analyze(self):
|
||||
self.iAlignmentColumn = 0
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isSequential:
|
||||
if not oLine.isSequentialEnd:
|
||||
self.iAlignmentColumn = oLine.line.find('<=') + len('<= ')
|
||||
if oLine.insideSequential and not oLine.isComment and not oLine.isSequential:
|
||||
check.multiline_alignment(self, self.iAlignmentColumn, oLine, iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.dFix['violations']:
|
||||
|
|
|
|||
Loading…
Reference in New Issue