Skip to content

Commit

Permalink
Issue#882: Moving rule concurrent_007 to conditional_waveforms_001. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiah-c-leary authored Dec 9, 2023
1 parent e5ca972 commit 0096b7d
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 165 deletions.
45 changes: 1 addition & 44 deletions docs/concurrent_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,50 +156,7 @@ This rule checks the alignment of the **<=** operator over multiple consecutive
concurrent_007
##############

|phase_1| |error| |structure|

This rule checks for code after the **else** keyword.

.. NOTE:: There is a configuration option :code:`allow_single_line` which allows single line concurrent statements.

:code:`allow_single_line` set to :code:`no` (Default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Violation**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else
'1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
:code:`allow_single_line` set to :code:`yes`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Violation**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
This rule has been renamed to `conditional_waveforms_001 <conditional_waveforms_rules.html#conditional-waveforms-001>`_.

concurrent_008
##############
Expand Down
48 changes: 48 additions & 0 deletions docs/conditional_waveforms_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,54 @@
Conditional Waveforms Rules
---------------------------

conditional_waveforms_001
#########################

|phase_1| |error| |structure|

This rule checks for code after the **else** keyword.

.. NOTE:: There is a configuration option :code:`allow_single_line` which allows single line concurrent statements.

:code:`allow_single_line` set to :code:`no` (Default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Violation**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else
'1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
:code:`allow_single_line` set to :code:`yes`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Violation**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**

.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
conditional_waveforms_100
#########################

Expand Down
2 changes: 1 addition & 1 deletion docs/rule_groups/structure_rule_group.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Rules Enforcing Structure Rule Group
* `component_019 <../component_rules.html#component-019>`_
* `component_021 <../component_rules.html#component-021>`_
* `concurrent_005 <../concurrent_rules.html#concurrent-005>`_
* `concurrent_007 <../concurrent_rules.html#concurrent-007>`_
* `concurrent_011 <../concurrent_rules.html#concurrent-011>`_
* `concurrent_012 <../concurrent_rules.html#concurrent-012>`_
* `conditional_waveforms_001 <../conditional_waveforms_rules.html#conditional-waveforms-001>`_
* `constant_007 <../constant_rules.html#constant-007>`_
* `constant_016 <../constant_rules.html#constant-016>`_
* `constant_017 <../constant_rules.html#constant-017>`_
Expand Down
108 changes: 5 additions & 103 deletions vsg/rules/concurrent/rule_007.py
Original file line number Diff line number Diff line change
@@ -1,110 +1,12 @@

from vsg import parser
from vsg import token
from vsg import violation
from vsg import deprecated_rule

from vsg.vhdlFile import utils
from vsg.rule_group import structure

lSplitTokens = []
lSplitTokens.append(token.conditional_waveforms.else_keyword)

lTokenPairs = []
lTokenPairs.append([token.concurrent_conditional_signal_assignment.assignment, token.concurrent_conditional_signal_assignment.semicolon])


class rule_007(structure.Rule):
class rule_007(deprecated_rule.Rule):
'''
This rule checks for code after the **else** keyword.
.. NOTE:: There is a configuration option :code:`allow_single_line` which allows single line concurrent statements.
:code:`allow_single_line` set to :code:`no` (Default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Violation**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else
'1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
:code:`allow_single_line` set to :code:`yes`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Violation**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
This rule has been renamed to `conditional_waveforms_001 <conditional_waveforms_rules.html#conditional-waveforms-001>`_.
'''

def __init__(self):
structure.Rule.__init__(self, 'concurrent', '007')
self.solution = 'move code after else to next line.'
self.subphase = 2
self.lSplitTokens = lSplitTokens
self.lTokenPairs = lTokenPairs
self.allow_single_line = 'no'
self.configuration.append('allow_single_line')
self.configuration_documentation_link = None

def _get_tokens_of_interest(self, oFile):
lToi = []
for lTokenPair in lTokenPairs:
aToi = oFile.get_tokens_bounded_by(lTokenPair[0], lTokenPair[1])
lToi = utils.combine_two_token_class_lists(lToi, aToi)
return lToi

def _analyze(self, lToi):
self.allow_single_line = utils.convert_yes_no_option_to_boolean(self.allow_single_line)

for oToi in lToi:
lTokens = oToi.get_tokens()

if utils.find_carriage_return(lTokens) is None and self.allow_single_line:
for oSplitToken in self.lSplitTokens:
if utils.count_token_types_in_list_of_tokens(oSplitToken, lTokens) > 1:
break
else:
continue

iLine = oToi.get_line_number()
for iToken, oToken in enumerate(lTokens):
iLine = utils.increment_line_number(iLine, oToken)
for oSplitToken in self.lSplitTokens:
if isinstance(oToken, oSplitToken):
if utils.are_next_consecutive_token_types([parser.whitespace, parser.comment], iToken + 1, lTokens):
continue
if utils.are_next_consecutive_token_types([parser.comment], iToken + 1, lTokens):
continue
if utils.are_next_consecutive_token_types([parser.carriage_return], iToken + 1, lTokens):
continue
oViolation = violation.New(iLine, oToi.extract_tokens(iToken, iToken), self.solution)
self.add_violation(oViolation)
break

def _fix_violation(self, oViolation):
lTokens = oViolation.get_tokens()
lTokens.append(parser.carriage_return())
oViolation.set_tokens(lTokens)
deprecated_rule.Rule.__init__(self, 'concurrent', '007')
self.message.append('Rule ' + self.unique_id + ' has been renamed to conditional_waveforms_001.')
2 changes: 2 additions & 0 deletions vsg/rules/conditional_waveforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from .rule_001 import rule_001

from .rule_100 import rule_100
from .rule_101 import rule_101
from .rule_102 import rule_102
Expand Down
110 changes: 110 additions & 0 deletions vsg/rules/conditional_waveforms/rule_001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

from vsg import parser
from vsg import token
from vsg import violation

from vsg.vhdlFile import utils
from vsg.rule_group import structure

lSplitTokens = []
lSplitTokens.append(token.conditional_waveforms.else_keyword)

lTokenPairs = []
lTokenPairs.append([token.concurrent_conditional_signal_assignment.assignment, token.concurrent_conditional_signal_assignment.semicolon])


class rule_001(structure.Rule):
'''
This rule checks for code after the **else** keyword.
.. NOTE:: There is a configuration option :code:`allow_single_line` which allows single line concurrent statements.
:code:`allow_single_line` set to :code:`no` (Default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Violation**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else
'1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
:code:`allow_single_line` set to :code:`yes`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Violation**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else '1' when underflow = '1' else sig_a;
**Fix**
.. code-block:: vhdl
wr_en <= '0' when overflow = '0' else '1';
wr_en <= '0' when overflow = '0' else
'1' when underflow = '1' else
sig_a;
'''

def __init__(self):
structure.Rule.__init__(self, 'conditional_waveforms', '001')
self.solution = 'move code after else to next line.'
self.subphase = 2
self.lSplitTokens = lSplitTokens
self.lTokenPairs = lTokenPairs
self.allow_single_line = 'no'
self.configuration.append('allow_single_line')
self.configuration_documentation_link = None

def _get_tokens_of_interest(self, oFile):
lToi = []
for lTokenPair in lTokenPairs:
aToi = oFile.get_tokens_bounded_by(lTokenPair[0], lTokenPair[1])
lToi = utils.combine_two_token_class_lists(lToi, aToi)
return lToi

def _analyze(self, lToi):
self.allow_single_line = utils.convert_yes_no_option_to_boolean(self.allow_single_line)

for oToi in lToi:
lTokens = oToi.get_tokens()

if utils.find_carriage_return(lTokens) is None and self.allow_single_line:
for oSplitToken in self.lSplitTokens:
if utils.count_token_types_in_list_of_tokens(oSplitToken, lTokens) > 1:
break
else:
continue

iLine = oToi.get_line_number()
for iToken, oToken in enumerate(lTokens):
iLine = utils.increment_line_number(iLine, oToken)
for oSplitToken in self.lSplitTokens:
if isinstance(oToken, oSplitToken):
if utils.are_next_consecutive_token_types([parser.whitespace, parser.comment], iToken + 1, lTokens):
continue
if utils.are_next_consecutive_token_types([parser.comment], iToken + 1, lTokens):
continue
if utils.are_next_consecutive_token_types([parser.carriage_return], iToken + 1, lTokens):
continue
oViolation = violation.New(iLine, oToi.extract_tokens(iToken, iToken), self.solution)
self.add_violation(oViolation)
break

def _fix_violation(self, oViolation):
lTokens = oViolation.get_tokens()
lTokens.append(parser.carriage_return())
oViolation.set_tokens(lTokens)
Loading

0 comments on commit 0096b7d

Please sign in to comment.