Issue#976: Added prefix and suffix rules for function designators. (#987)
This commit is contained in:
parent
3697765cb0
commit
1430bcbd5d
|
|
@ -56,6 +56,8 @@ Rules Enforcing Prefixes and Suffixes
|
|||
+-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
|
||||
| Constant Identifier | `constant_015 <constant_rules.html#constant-015>`_ | `constant_600 <constant_rules.html#constant-600>`_ |
|
||||
+-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
|
||||
| Function Designator | `function_600 <function_rules.html#function-600>`_ | `function_601 <function_rules.html#function-601>`_ |
|
||||
+-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
|
||||
| Generate Label | `generate_017 <generate_rules.html#generate-017>`_ | `generate_600 <generate_rules.html#generate-600>`_ |
|
||||
+-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
|
||||
| Generic Identifier | `generic_020 <generic_rules.html#generic-020>`_ | `generic_600 <generic_rules.html#generic-600>`_ |
|
||||
|
|
|
|||
|
|
@ -541,3 +541,47 @@ This rule checks the function designator has proper case on the end function dec
|
|||
|
||||
end function overflow;
|
||||
|
||||
function_600
|
||||
############
|
||||
|
||||
|phase_7| |disabled| |error| |naming|
|
||||
|
||||
This rule checks for valid prefixes on function designators.
|
||||
Default signal prefix is *f\_*.
|
||||
|
||||
|configuring_prefix_and_suffix_rules_link|
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function f_read_data
|
||||
|
||||
function_601
|
||||
############
|
||||
|
||||
|phase_7| |disabled| |error| |naming|
|
||||
|
||||
This rule checks for valid suffixes on function designators.
|
||||
Default signal suffix is *\_f*.
|
||||
|
||||
|configuring_prefix_and_suffix_rules_link|
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data_f
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ Rules Enforcing Naming Rule Group
|
|||
* `block_601 <../block_rules.html#block-601>`_
|
||||
* `constant_015 <../constant_rules.html#constant-015>`_
|
||||
* `constant_600 <../constant_rules.html#constant-600>`_
|
||||
* `function_600 <../function_rules.html#function-600>`_
|
||||
* `function_601 <../function_rules.html#function-601>`_
|
||||
* `generate_017 <../generate_rules.html#generate-017>`_
|
||||
* `generate_600 <../generate_rules.html#generate-600>`_
|
||||
* `generic_020 <../generic_rules.html#generic-020>`_
|
||||
|
|
|
|||
|
|
@ -31,3 +31,6 @@ from .rule_300 import rule_300
|
|||
from .rule_502 import rule_502
|
||||
from .rule_506 import rule_506
|
||||
|
||||
from .rule_600 import rule_600
|
||||
from .rule_601 import rule_601
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
from vsg.rules import token_prefix
|
||||
|
||||
from vsg import token
|
||||
|
||||
lTokens = []
|
||||
lTokens.append(token.function_specification.designator)
|
||||
|
||||
|
||||
class rule_600(token_prefix):
|
||||
'''
|
||||
This rule checks for valid prefixes on function designators.
|
||||
Default signal prefix is *f\_*.
|
||||
|
||||
|configuring_prefix_and_suffix_rules_link|
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function f_read_data
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
token_prefix.__init__(self, 'function', '600', lTokens)
|
||||
self.prefixes = ['f_']
|
||||
self.solution = 'Function designator'
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
from vsg.rules import token_suffix
|
||||
|
||||
from vsg import token
|
||||
|
||||
lTokens = []
|
||||
lTokens.append(token.function_specification.designator)
|
||||
|
||||
|
||||
class rule_601(token_suffix):
|
||||
'''
|
||||
This rule checks for valid suffixes on function designators.
|
||||
Default signal suffix is *\_f*.
|
||||
|
||||
|configuring_prefix_and_suffix_rules_link|
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
function read_data_f
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
token_suffix.__init__(self, 'function', '601', lTokens)
|
||||
self.suffixes = ['_f']
|
||||
self.solution = 'Function designator'
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
architecture RTL of FIFO is
|
||||
|
||||
function f_func1 return integer;
|
||||
|
||||
pure function f_func1 return integer;
|
||||
|
||||
impure function f_func1 return integer;
|
||||
|
||||
function f_func1 return integer is
|
||||
|
||||
begin
|
||||
|
||||
end function func1;
|
||||
|
||||
-- Violations follow
|
||||
|
||||
function func1 return integer;
|
||||
|
||||
function func1 return integer;
|
||||
|
||||
pure function func1 return integer;
|
||||
pure function func1 return integer;
|
||||
|
||||
impure function func1 return integer;
|
||||
impure function func1 return integer;
|
||||
|
||||
begin
|
||||
|
||||
end architecture RTL;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
architecture RTL of FIFO is
|
||||
|
||||
function func1_f return integer;
|
||||
|
||||
pure function func1_f return integer;
|
||||
|
||||
impure function func1_f return integer;
|
||||
|
||||
function func1_f return integer is
|
||||
|
||||
begin
|
||||
|
||||
end function func1;
|
||||
|
||||
-- Violations follow
|
||||
|
||||
function func1 return integer;
|
||||
|
||||
function func1 return integer;
|
||||
|
||||
pure function func1 return integer;
|
||||
pure function func1 return integer;
|
||||
|
||||
impure function func1 return integer;
|
||||
impure function func1 return integer;
|
||||
|
||||
begin
|
||||
|
||||
end architecture RTL;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from vsg.rules import function
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
sTestDir = os.path.dirname(__file__)
|
||||
|
||||
lFile, eError =vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir,'rule_600_test_input.vhd'))
|
||||
|
||||
|
||||
class test_function_rule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.oFile = vhdlFile.vhdlFile(lFile)
|
||||
self.assertIsNone(eError)
|
||||
|
||||
def test_rule_600(self):
|
||||
oRule = function.rule_600()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'function')
|
||||
self.assertEqual(oRule.identifier, '600')
|
||||
|
||||
lExpected = [18, 20, 22, 23, 25, 26]
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from vsg.rules import function
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
sTestDir = os.path.dirname(__file__)
|
||||
|
||||
lFile, eError =vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir,'rule_601_test_input.vhd'))
|
||||
|
||||
|
||||
class test_function_rule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.oFile = vhdlFile.vhdlFile(lFile)
|
||||
self.assertIsNone(eError)
|
||||
|
||||
def test_rule_601(self):
|
||||
oRule = function.rule_601()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'function')
|
||||
self.assertEqual(oRule.identifier, '601')
|
||||
|
||||
lExpected = [18, 20, 22, 23, 25, 26]
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
Loading…
Reference in New Issue