From 016f65d6b044dba4dbbb96f84f1d7e4b54b2aec4 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Wed, 10 Apr 2019 20:21:11 -0500 Subject: [PATCH] Updates for issue #226 Refactoring the following rules for code coverage: architecture_024 instantiation_010 port_011 process_018 process_031 sequential_004 --- vsg/rules/architecture/rule_024.py | 26 +++++++++--------- vsg/rules/instantiation/rule_010.py | 41 ++++++++++++++--------------- vsg/rules/port/rule_011.py | 14 +++++----- vsg/rules/process/rule_018.py | 38 +++++++++++++------------- vsg/rules/process/rule_031.py | 40 ++++++++++++++-------------- vsg/rules/sequential/rule_004.py | 19 +++++++------ 6 files changed, 88 insertions(+), 90 deletions(-) diff --git a/vsg/rules/architecture/rule_024.py b/vsg/rules/architecture/rule_024.py index a9db3e5a..77a7ff43 100644 --- a/vsg/rules/architecture/rule_024.py +++ b/vsg/rules/architecture/rule_024.py @@ -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): diff --git a/vsg/rules/instantiation/rule_010.py b/vsg/rules/instantiation/rule_010.py index e24b622e..e72d9313 100644 --- a/vsg/rules/instantiation/rule_010.py +++ b/vsg/rules/instantiation/rule_010.py @@ -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) diff --git a/vsg/rules/port/rule_011.py b/vsg/rules/port/rule_011.py index a403c398..763eb24f 100644 --- a/vsg/rules/port/rule_011.py +++ b/vsg/rules/port/rule_011.py @@ -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): diff --git a/vsg/rules/process/rule_018.py b/vsg/rules/process/rule_018.py index e10981dc..955a7d40 100644 --- a/vsg/rules/process/rule_018.py +++ b/vsg/rules/process/rule_018.py @@ -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 = '' diff --git a/vsg/rules/process/rule_031.py b/vsg/rules/process/rule_031.py index dfdba747..4fbd6483 100644 --- a/vsg/rules/process/rule_031.py +++ b/vsg/rules/process/rule_031.py @@ -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) diff --git a/vsg/rules/sequential/rule_004.py b/vsg/rules/sequential/rule_004.py index 7c104ca0..45d50728 100644 --- a/vsg/rules/sequential/rule_004.py +++ b/vsg/rules/sequential/rule_004.py @@ -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']: