diff --git a/docs/configuring_prefix_and_suffix_rules.rst b/docs/configuring_prefix_and_suffix_rules.rst index ebb6479c..1f425871 100644 --- a/docs/configuring_prefix_and_suffix_rules.rst +++ b/docs/configuring_prefix_and_suffix_rules.rst @@ -56,6 +56,8 @@ Rules Enforcing Prefixes and Suffixes +-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ | Constant Identifier | `constant_015 `_ | `constant_600 `_ | +-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ +| Function Designator | `function_600 `_ | `function_601 `_ | ++-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ | Generate Label | `generate_017 `_ | `generate_600 `_ | +-------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ | Generic Identifier | `generic_020 `_ | `generic_600 `_ | diff --git a/docs/function_rules.rst b/docs/function_rules.rst index 860f68eb..11ab18d6 100644 --- a/docs/function_rules.rst +++ b/docs/function_rules.rst @@ -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 + diff --git a/docs/rule_groups/naming_rule_group.rst b/docs/rule_groups/naming_rule_group.rst index 05da4218..e639bb20 100644 --- a/docs/rule_groups/naming_rule_group.rst +++ b/docs/rule_groups/naming_rule_group.rst @@ -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>`_ diff --git a/vsg/rules/function/__init__.py b/vsg/rules/function/__init__.py index 0e047ca8..766cc160 100644 --- a/vsg/rules/function/__init__.py +++ b/vsg/rules/function/__init__.py @@ -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 + diff --git a/vsg/rules/function/rule_600.py b/vsg/rules/function/rule_600.py new file mode 100644 index 00000000..3ef374ae --- /dev/null +++ b/vsg/rules/function/rule_600.py @@ -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' diff --git a/vsg/rules/function/rule_601.py b/vsg/rules/function/rule_601.py new file mode 100644 index 00000000..44bae47c --- /dev/null +++ b/vsg/rules/function/rule_601.py @@ -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' diff --git a/vsg/tests/function/rule_600_test_input.vhd b/vsg/tests/function/rule_600_test_input.vhd new file mode 100644 index 00000000..8aecbc3e --- /dev/null +++ b/vsg/tests/function/rule_600_test_input.vhd @@ -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; diff --git a/vsg/tests/function/rule_601_test_input.vhd b/vsg/tests/function/rule_601_test_input.vhd new file mode 100644 index 00000000..d8e1d541 --- /dev/null +++ b/vsg/tests/function/rule_601_test_input.vhd @@ -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; diff --git a/vsg/tests/function/test_rule_600.py b/vsg/tests/function/test_rule_600.py new file mode 100644 index 00000000..d96c6d8b --- /dev/null +++ b/vsg/tests/function/test_rule_600.py @@ -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)) diff --git a/vsg/tests/function/test_rule_601.py b/vsg/tests/function/test_rule_601.py new file mode 100644 index 00000000..ee2b5790 --- /dev/null +++ b/vsg/tests/function/test_rule_601.py @@ -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))