diff --git a/docs/rule_groups/structure_rule_group.rst b/docs/rule_groups/structure_rule_group.rst index 08c4ebed..00661e2a 100644 --- a/docs/rule_groups/structure_rule_group.rst +++ b/docs/rule_groups/structure_rule_group.rst @@ -173,6 +173,11 @@ Rules Enforcing Structure Rule Group * `signal_015 <../signal_rules.html#signal-015>`_ * `signal_017 <../signal_rules.html#signal-017>`_ * `source_file_001 <../source_file_rules.html#source-file-001>`_ +* `subprogram_instantiation_001 <../subprogram_instantiation_rules.html#subprogram-instantiation-001>`_ +* `subprogram_instantiation_002 <../subprogram_instantiation_rules.html#subprogram-instantiation-002>`_ +* `subprogram_instantiation_003 <../subprogram_instantiation_rules.html#subprogram-instantiation-003>`_ +* `subprogram_instantiation_004 <../subprogram_instantiation_rules.html#subprogram-instantiation-004>`_ +* `subprogram_instantiation_005 <../subprogram_instantiation_rules.html#subprogram-instantiation-005>`_ * `subtype_005 <../subtype_rules.html#subtype-005>`_ * `subtype_006 <../subtype_rules.html#subtype-006>`_ * `type_008 <../type_rules.html#type-008>`_ diff --git a/docs/subprogram_instantiation_rules.rst b/docs/subprogram_instantiation_rules.rst index 765b1634..b2f4197b 100644 --- a/docs/subprogram_instantiation_rules.rst +++ b/docs/subprogram_instantiation_rules.rst @@ -3,6 +3,106 @@ Subprogram Instantiation Rules ------------------------------ +subprogram_instantiation_001 +############################ + +|phase_1| |error| |structure| + +This rule checks the new subprogram identifier is on the same line as the **procedure** keyword. + +**Violation** + +.. code-block:: vhdl + + procedure + my_proc is new my_generic_proc + +**Fix** + +.. code-block:: vhdl + + procedure my_proc is new my_generic_proc + +subprogram_instantiation_002 +############################ + +|phase_1| |error| |structure| + +This rule checks the new subprogram identifier is on the same line as the **function** keyword. + +**Violation** + +.. code-block:: vhdl + + function + my_func is new my_generic_func + +**Fix** + +.. code-block:: vhdl + + function my_func is new my_generic_func + +subprogram_instantiation_003 +############################ + +|phase_1| |error| |structure| + +This rule checks the **is** keyword is on the same line as the new subprogram identifier. + +**Violation** + +.. code-block:: vhdl + + procedure my_proc + is new my_generic_proc + +**Fix** + +.. code-block:: vhdl + + procedure my_proc is new my_generic_proc + +subprogram_instantiation_004 +############################ + +|phase_1| |error| |structure| + +This rule checks the **new** keyword is on the same line as the **is** keyword. + +**Violation** + +.. code-block:: vhdl + + procedure my_proc is + new my_generic_proc + +**Fix** + +.. code-block:: vhdl + + procedure my_proc is new my_generic_proc + +subprogram_instantiation_005 +############################ + +|phase_1| |error| |structure| + +This rule checks the uninstantiated subprogram name is on the same line as the **new** keyword. + +**Violation** + +.. code-block:: vhdl + + procedure my_proc is new + my_generic_proc + +**Fix** + +.. code-block:: vhdl + + procedure my_proc is new my_generic_proc + subprogram_instantiation_100 ############################ diff --git a/tests/subprogram_instantiation/rule_001_test_input.fixed.vhd b/tests/subprogram_instantiation/rule_001_test_input.fixed.vhd new file mode 100644 index 00000000..1fbbc613 --- /dev/null +++ b/tests/subprogram_instantiation/rule_001_test_input.fixed.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function + my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc + is new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_001_test_input.vhd b/tests/subprogram_instantiation/rule_001_test_input.vhd new file mode 100644 index 00000000..12b97518 --- /dev/null +++ b/tests/subprogram_instantiation/rule_001_test_input.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function + my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure + my_proc is new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_002_test_input.fixed.vhd b/tests/subprogram_instantiation/rule_002_test_input.fixed.vhd new file mode 100644 index 00000000..995c289b --- /dev/null +++ b/tests/subprogram_instantiation/rule_002_test_input.fixed.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func + is new my_generic_func + generic map ( + test => 2 + ); + + procedure + my_proc is new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_002_test_input.vhd b/tests/subprogram_instantiation/rule_002_test_input.vhd new file mode 100644 index 00000000..12b97518 --- /dev/null +++ b/tests/subprogram_instantiation/rule_002_test_input.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function + my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure + my_proc is new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_003_test_input.fixed.vhd b/tests/subprogram_instantiation/rule_003_test_input.fixed.vhd new file mode 100644 index 00000000..d06df044 --- /dev/null +++ b/tests/subprogram_instantiation/rule_003_test_input.fixed.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func is + new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is + new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_003_test_input.vhd b/tests/subprogram_instantiation/rule_003_test_input.vhd new file mode 100644 index 00000000..704f8dbf --- /dev/null +++ b/tests/subprogram_instantiation/rule_003_test_input.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func + is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc + is new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_004_test_input.fixed.vhd b/tests/subprogram_instantiation/rule_004_test_input.fixed.vhd new file mode 100644 index 00000000..f4c0a910 --- /dev/null +++ b/tests/subprogram_instantiation/rule_004_test_input.fixed.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func is new + my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new + my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_004_test_input.vhd b/tests/subprogram_instantiation/rule_004_test_input.vhd new file mode 100644 index 00000000..d06df044 --- /dev/null +++ b/tests/subprogram_instantiation/rule_004_test_input.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func is + new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is + new my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_005_test_input.fixed.vhd b/tests/subprogram_instantiation/rule_005_test_input.fixed.vhd new file mode 100644 index 00000000..8d641475 --- /dev/null +++ b/tests/subprogram_instantiation/rule_005_test_input.fixed.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func is new my_generic_func + + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/rule_005_test_input.vhd b/tests/subprogram_instantiation/rule_005_test_input.vhd new file mode 100644 index 00000000..f4c0a910 --- /dev/null +++ b/tests/subprogram_instantiation/rule_005_test_input.vhd @@ -0,0 +1,26 @@ + +package test is + + function my_func is new my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new my_generic_proc + generic map ( + test => 2 + ); + + function my_func is new + my_generic_func + generic map ( + test => 2 + ); + + procedure my_proc is new + my_generic_proc + generic map ( + test => 2 + ); + +end package test; diff --git a/tests/subprogram_instantiation/test_rule_001.py b/tests/subprogram_instantiation/test_rule_001.py new file mode 100644 index 00000000..8b5749a3 --- /dev/null +++ b/tests/subprogram_instantiation/test_rule_001.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import subprogram_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_001_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_001_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_001(self): + oRule = subprogram_instantiation.rule_001() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "subprogram_instantiation") + self.assertEqual(oRule.identifier, "001") + + lExpected = [20] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_001(self): + oRule = subprogram_instantiation.rule_001() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/subprogram_instantiation/test_rule_002.py b/tests/subprogram_instantiation/test_rule_002.py new file mode 100644 index 00000000..27b1cf7d --- /dev/null +++ b/tests/subprogram_instantiation/test_rule_002.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import subprogram_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_002_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_002_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_002(self): + oRule = subprogram_instantiation.rule_002() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "subprogram_instantiation") + self.assertEqual(oRule.identifier, "002") + + lExpected = [14] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_002(self): + oRule = subprogram_instantiation.rule_002() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/subprogram_instantiation/test_rule_003.py b/tests/subprogram_instantiation/test_rule_003.py new file mode 100644 index 00000000..deab8fcb --- /dev/null +++ b/tests/subprogram_instantiation/test_rule_003.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import subprogram_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_003_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_003_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_003(self): + oRule = subprogram_instantiation.rule_003() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "subprogram_instantiation") + self.assertEqual(oRule.identifier, "003") + + lExpected = [14, 20] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_003(self): + oRule = subprogram_instantiation.rule_003() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/subprogram_instantiation/test_rule_004.py b/tests/subprogram_instantiation/test_rule_004.py new file mode 100644 index 00000000..23ce0e43 --- /dev/null +++ b/tests/subprogram_instantiation/test_rule_004.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import subprogram_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_004_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_004_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_004(self): + oRule = subprogram_instantiation.rule_004() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "subprogram_instantiation") + self.assertEqual(oRule.identifier, "004") + + lExpected = [14, 20] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_004(self): + oRule = subprogram_instantiation.rule_004() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/subprogram_instantiation/test_rule_005.py b/tests/subprogram_instantiation/test_rule_005.py new file mode 100644 index 00000000..e31bd553 --- /dev/null +++ b/tests/subprogram_instantiation/test_rule_005.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import subprogram_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_005_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_005_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_005(self): + oRule = subprogram_instantiation.rule_005() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "subprogram_instantiation") + self.assertEqual(oRule.identifier, "005") + + lExpected = [14, 20] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_005(self): + oRule = subprogram_instantiation.rule_005() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/subprogram_instantiation/__init__.py b/vsg/rules/subprogram_instantiation/__init__.py index 944a4209..03761c33 100644 --- a/vsg/rules/subprogram_instantiation/__init__.py +++ b/vsg/rules/subprogram_instantiation/__init__.py @@ -1,5 +1,10 @@ # -*- coding: utf-8 -*- +from .rule_001 import rule_001 +from .rule_002 import rule_002 +from .rule_003 import rule_003 +from .rule_004 import rule_004 +from .rule_005 import rule_005 from .rule_100 import rule_100 from .rule_101 import rule_101 from .rule_102 import rule_102 diff --git a/vsg/rules/subprogram_instantiation/rule_001.py b/vsg/rules/subprogram_instantiation/rule_001.py new file mode 100644 index 00000000..2d9db569 --- /dev/null +++ b/vsg/rules/subprogram_instantiation/rule_001.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import move_token_next_to_another_token + + +class rule_001(move_token_next_to_another_token): + """ + This rule checks the new subprogram identifier is on the same line as the **procedure** keyword. + + **Violation** + + .. code-block:: vhdl + + procedure + my_proc is new my_generic_proc + + **Fix** + + .. code-block:: vhdl + + procedure my_proc is new my_generic_proc + """ + + def __init__(self): + super().__init__(token.subprogram_kind.procedure_keyword, token.subprogram_instantiation_declaration.identifier) + self.solution = "Ensure the *procedure* keyword is on the same line as the new package identifier." diff --git a/vsg/rules/subprogram_instantiation/rule_002.py b/vsg/rules/subprogram_instantiation/rule_002.py new file mode 100644 index 00000000..dd7d1d50 --- /dev/null +++ b/vsg/rules/subprogram_instantiation/rule_002.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import move_token_next_to_another_token + + +class rule_002(move_token_next_to_another_token): + """ + This rule checks the new subprogram identifier is on the same line as the **function** keyword. + + **Violation** + + .. code-block:: vhdl + + function + my_func is new my_generic_func + + **Fix** + + .. code-block:: vhdl + + function my_func is new my_generic_func + """ + + def __init__(self): + super().__init__(token.subprogram_kind.function_keyword, token.subprogram_instantiation_declaration.identifier) + self.solution = "Ensure the *function* keyword is on the same line as the new package identifier." diff --git a/vsg/rules/subprogram_instantiation/rule_003.py b/vsg/rules/subprogram_instantiation/rule_003.py new file mode 100644 index 00000000..e334cf56 --- /dev/null +++ b/vsg/rules/subprogram_instantiation/rule_003.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import move_token_next_to_another_token + + +class rule_003(move_token_next_to_another_token): + """ + This rule checks the **is** keyword is on the same line as the new subprogram identifier. + + **Violation** + + .. code-block:: vhdl + + procedure my_proc + is new my_generic_proc + + **Fix** + + .. code-block:: vhdl + + procedure my_proc is new my_generic_proc + """ + + def __init__(self): + super().__init__(token.subprogram_instantiation_declaration.identifier, token.subprogram_instantiation_declaration.is_keyword) + self.solution = "Ensure the *is* keyword is on the same line as the new subprogram identifier." diff --git a/vsg/rules/subprogram_instantiation/rule_004.py b/vsg/rules/subprogram_instantiation/rule_004.py new file mode 100644 index 00000000..dd184395 --- /dev/null +++ b/vsg/rules/subprogram_instantiation/rule_004.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from vsg.rules import move_token_next_to_another_token +from vsg.token import subprogram_instantiation_declaration as token + + +class rule_004(move_token_next_to_another_token): + """ + This rule checks the **new** keyword is on the same line as the **is** keyword. + + **Violation** + + .. code-block:: vhdl + + procedure my_proc is + new my_generic_proc + + **Fix** + + .. code-block:: vhdl + + procedure my_proc is new my_generic_proc + """ + + def __init__(self): + super().__init__(token.is_keyword, token.new_keyword) + self.solution = "Ensure the *new* keyword is on the same line as the *is* keyword." diff --git a/vsg/rules/subprogram_instantiation/rule_005.py b/vsg/rules/subprogram_instantiation/rule_005.py new file mode 100644 index 00000000..f9c96d16 --- /dev/null +++ b/vsg/rules/subprogram_instantiation/rule_005.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from vsg.rules import move_token_next_to_another_token +from vsg.token import subprogram_instantiation_declaration as token + + +class rule_005(move_token_next_to_another_token): + """ + This rule checks the uninstantiated subprogram name is on the same line as the **new** keyword. + + **Violation** + + .. code-block:: vhdl + + procedure my_proc is new + my_generic_proc + + **Fix** + + .. code-block:: vhdl + + procedure my_proc is new my_generic_proc + """ + + def __init__(self): + super().__init__(token.new_keyword, token.uninstantiated_subprogram_name) + self.solution = "Ensure the uninstantiated subprogram name is on the same line as the *new* keyword."