From 2f3d4d7e233366fca75ebde33cee907dec6b6c2c Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Thu, 10 Sep 2020 08:02:23 -0500 Subject: [PATCH] Adding parsing of subprogram_instantiation_declaration. --- .../classification_results.txt | 249 ++++++++++++++++++ .../classification_test_input.vhd | 44 ++++ ...st_subprogram_instantiation_declaration.py | 30 +++ .../subprogram_instantiation_declaration.py | 31 +++ vsg/token/subprogram_kind.py | 13 + .../classify_new/block_declarative_item.py | 5 + .../classify_new/function_specification.py | 9 +- .../classify_new/procedure_specification.py | 3 +- .../subprogram_instantiation_declaration.py | 36 +++ vsg/vhdlFile/classify_new/subprogram_kind.py | 24 ++ 10 files changed, 440 insertions(+), 4 deletions(-) create mode 100644 vsg/tests/subprogram_instantiation_declaration/classification_results.txt create mode 100644 vsg/tests/subprogram_instantiation_declaration/classification_test_input.vhd create mode 100644 vsg/tests/vhdlFile_new/test_subprogram_instantiation_declaration.py create mode 100644 vsg/token/subprogram_instantiation_declaration.py create mode 100644 vsg/token/subprogram_kind.py create mode 100644 vsg/vhdlFile/classify_new/subprogram_instantiation_declaration.py create mode 100644 vsg/vhdlFile/classify_new/subprogram_kind.py diff --git a/vsg/tests/subprogram_instantiation_declaration/classification_results.txt b/vsg/tests/subprogram_instantiation_declaration/classification_results.txt new file mode 100644 index 00000000..addcb34d --- /dev/null +++ b/vsg/tests/subprogram_instantiation_declaration/classification_results.txt @@ -0,0 +1,249 @@ +-------------------------------------------------------------------------------- +0 | None | +-------------------------------------------------------------------------------- +1 | None | + +-------------------------------------------------------------------------------- +2 | None | architecture RTL of FIFO is + + + + + +-------------------------------------------------------------------------------- +3 | None | + +-------------------------------------------------------------------------------- +4 | None | function PARITY is new uninstantiated_subprogram_name [name1, name2 return integer] + + + + + + + + + + + + +-------------------------------------------------------------------------------- +5 | None | generic map ( + + + +-------------------------------------------------------------------------------- +6 | None | GEN1 => 3, + + + + +-------------------------------------------------------------------------------- +7 | None | GEN2 => 4, + + + + +-------------------------------------------------------------------------------- +8 | None | GEN5 => 6 + + + +-------------------------------------------------------------------------------- +9 | None | ); + + +-------------------------------------------------------------------------------- +10 | None | + +-------------------------------------------------------------------------------- +11 | None | function PARITY is new uninstantiated_subprogram_name + + + + + +-------------------------------------------------------------------------------- +12 | None | generic map ( + + + +-------------------------------------------------------------------------------- +13 | None | GEN1 => 3, + + + + +-------------------------------------------------------------------------------- +14 | None | GEN2 => 4, + + + + +-------------------------------------------------------------------------------- +15 | None | GEN5 => 6 + + + +-------------------------------------------------------------------------------- +16 | None | ); + + +-------------------------------------------------------------------------------- +17 | None | + +-------------------------------------------------------------------------------- +18 | None | function PARITY is new uninstantiated_subprogram_name [name1, name2 return integer]; + + + + + + + + + + + + + +-------------------------------------------------------------------------------- +19 | None | + +-------------------------------------------------------------------------------- +20 | None | function PARITY is new uninstantiated_subprogram_name; + + + + + + +-------------------------------------------------------------------------------- +21 | None | + +-------------------------------------------------------------------------------- +22 | None | + +-------------------------------------------------------------------------------- +23 | None | procedure PARITY is new uninstantiated_subprogram_name [name1, name2 return integer] + + + + + + + + + + + + +-------------------------------------------------------------------------------- +24 | None | generic map ( + + + +-------------------------------------------------------------------------------- +25 | None | GEN1 => 3, + + + + +-------------------------------------------------------------------------------- +26 | None | GEN2 => 4, + + + + +-------------------------------------------------------------------------------- +27 | None | GEN5 => 6 + + + +-------------------------------------------------------------------------------- +28 | None | ); + + +-------------------------------------------------------------------------------- +29 | None | + +-------------------------------------------------------------------------------- +30 | None | procedure PARITY is new uninstantiated_subprogram_name + + + + + +-------------------------------------------------------------------------------- +31 | None | generic map ( + + + +-------------------------------------------------------------------------------- +32 | None | GEN1 => 3, + + + + +-------------------------------------------------------------------------------- +33 | None | GEN2 => 4, + + + + +-------------------------------------------------------------------------------- +34 | None | GEN5 => 6 + + + +-------------------------------------------------------------------------------- +35 | None | ); + + +-------------------------------------------------------------------------------- +36 | None | + +-------------------------------------------------------------------------------- +37 | None | procedure PARITY is new uninstantiated_subprogram_name [name1, name2 return integer]; + + + + + + + + + + + + + +-------------------------------------------------------------------------------- +38 | None | + +-------------------------------------------------------------------------------- +39 | None | procedure PARITY is new uninstantiated_subprogram_name; + + + + + + +-------------------------------------------------------------------------------- +40 | None | + +-------------------------------------------------------------------------------- +41 | None | begin + +-------------------------------------------------------------------------------- +42 | None | + +-------------------------------------------------------------------------------- +43 | None | + +-------------------------------------------------------------------------------- +44 | None | end architecture RTL; + + + + diff --git a/vsg/tests/subprogram_instantiation_declaration/classification_test_input.vhd b/vsg/tests/subprogram_instantiation_declaration/classification_test_input.vhd new file mode 100644 index 00000000..6eb15ab8 --- /dev/null +++ b/vsg/tests/subprogram_instantiation_declaration/classification_test_input.vhd @@ -0,0 +1,44 @@ + +architecture RTL of FIFO is + + function PARITY is new uninstantiated_subprogram_name [name1, name2 return integer] + generic map ( + GEN1 => 3, + GEN2 => 4, + GEN5 => 6 + ); + + function PARITY is new uninstantiated_subprogram_name + generic map ( + GEN1 => 3, + GEN2 => 4, + GEN5 => 6 + ); + + function PARITY is new uninstantiated_subprogram_name [name1, name2 return integer]; + + function PARITY is new uninstantiated_subprogram_name; + + + procedure PARITY is new uninstantiated_subprogram_name [name1, name2 return integer] + generic map ( + GEN1 => 3, + GEN2 => 4, + GEN5 => 6 + ); + + procedure PARITY is new uninstantiated_subprogram_name + generic map ( + GEN1 => 3, + GEN2 => 4, + GEN5 => 6 + ); + + procedure PARITY is new uninstantiated_subprogram_name [name1, name2 return integer]; + + procedure PARITY is new uninstantiated_subprogram_name; + +begin + + +end architecture RTL; diff --git a/vsg/tests/vhdlFile_new/test_subprogram_instantiation_declaration.py b/vsg/tests/vhdlFile_new/test_subprogram_instantiation_declaration.py new file mode 100644 index 00000000..009f48a0 --- /dev/null +++ b/vsg/tests/vhdlFile_new/test_subprogram_instantiation_declaration.py @@ -0,0 +1,30 @@ +import os + +import unittest + +from vsg.tests import utils +from vsg.vhdlFile import vhdlFile_new + +sLrmUnit = utils.extract_lrm_unit_name(__name__) + +lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..',sLrmUnit,'classification_test_input.vhd')) +oFile = vhdlFile_new.vhdlFile(lFile) + + +class test_token(unittest.TestCase): + + def test_classification(self): + sTestDir = os.path.join(os.path.dirname(__file__),'..',sLrmUnit) + + lExpected = [] + utils.read_file(os.path.join(sTestDir, 'classification_results.txt'), lExpected, False) + + lActual = [] + + for oObject in utils.extract_objects(oFile, True): + lActual.append(str(oObject)) + + self.assertEqual(lExpected, lActual) + +# def test_debug(self): +# utils.print_objects(oFile,True) diff --git a/vsg/token/subprogram_instantiation_declaration.py b/vsg/token/subprogram_instantiation_declaration.py new file mode 100644 index 00000000..d9566df9 --- /dev/null +++ b/vsg/token/subprogram_instantiation_declaration.py @@ -0,0 +1,31 @@ +from vsg import parser + + +class identifier(parser.identifier): + + def __init__(self, sString): + parser.identifier.__init__(self, sString) + + +class is_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class new_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class uninstantiated_subprogram_name(parser.name): + + def __init__(self, sString): + parser.name.__init__(self, sString) + + +class semicolon(parser.semicolon): + + def __init__(self, sString=';'): + parser.semicolon.__init__(self) diff --git a/vsg/token/subprogram_kind.py b/vsg/token/subprogram_kind.py new file mode 100644 index 00000000..7cf09c73 --- /dev/null +++ b/vsg/token/subprogram_kind.py @@ -0,0 +1,13 @@ +from vsg import parser + + +class procedure_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class function_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) diff --git a/vsg/vhdlFile/classify_new/block_declarative_item.py b/vsg/vhdlFile/classify_new/block_declarative_item.py index 2ce1d5e3..d6ce9a5c 100644 --- a/vsg/vhdlFile/classify_new/block_declarative_item.py +++ b/vsg/vhdlFile/classify_new/block_declarative_item.py @@ -1,5 +1,6 @@ from vsg.vhdlFile.classify_new import subprogram_declaration +from vsg.vhdlFile.classify_new import subprogram_instantiation_declaration from vsg.vhdlFile.classify_new import package_declaration from vsg.vhdlFile.classify_new import package_body @@ -52,6 +53,10 @@ def detect(iToken, lObjects): if iReturn != iToken: return iReturn + iReturn = subprogram_instantiation_declaration.detect(iToken, lObjects) + if iReturn != iToken: + return iReturn + iReturn = package_declaration.detect(iToken, lObjects) if iReturn != iToken: return iReturn diff --git a/vsg/vhdlFile/classify_new/function_specification.py b/vsg/vhdlFile/classify_new/function_specification.py index ef174cb9..41667a94 100644 --- a/vsg/vhdlFile/classify_new/function_specification.py +++ b/vsg/vhdlFile/classify_new/function_specification.py @@ -16,11 +16,14 @@ from vsg.vhdlFile.classify_new import type_mark def detect(iToken, lObjects): if utils.is_next_token('pure', iToken, lObjects): - return classify(iToken, lObjects) + if not utils.find_in_next_n_tokens('is', 4, iToken, lObjects): + return classify(iToken, lObjects) elif utils.is_next_token('impure', iToken, lObjects): - return classify(iToken, lObjects) + if not utils.find_in_next_n_tokens('is', 4, iToken, lObjects): + return classify(iToken, lObjects) elif utils.is_next_token('function', iToken, lObjects): - return classify(iToken, lObjects) + if not utils.find_in_next_n_tokens('is', 3, iToken, lObjects): + return classify(iToken, lObjects) return iToken diff --git a/vsg/vhdlFile/classify_new/procedure_specification.py b/vsg/vhdlFile/classify_new/procedure_specification.py index 5e21f492..dc8ab55b 100644 --- a/vsg/vhdlFile/classify_new/procedure_specification.py +++ b/vsg/vhdlFile/classify_new/procedure_specification.py @@ -15,7 +15,8 @@ from vsg.vhdlFile.classify_new import subprogram_header def detect(iToken, lObjects): if utils.is_next_token('procedure', iToken, lObjects): - return classify(iToken, lObjects) + if not utils.find_in_next_n_tokens('is', 3, iToken, lObjects): + return classify(iToken, lObjects) return iToken diff --git a/vsg/vhdlFile/classify_new/subprogram_instantiation_declaration.py b/vsg/vhdlFile/classify_new/subprogram_instantiation_declaration.py new file mode 100644 index 00000000..20f81f3b --- /dev/null +++ b/vsg/vhdlFile/classify_new/subprogram_instantiation_declaration.py @@ -0,0 +1,36 @@ + +from vsg.token import subprogram_instantiation_declaration as token + +from vsg.vhdlFile import utils + +from vsg.vhdlFile.classify_new import signature +from vsg.vhdlFile.classify_new import subprogram_kind +from vsg.vhdlFile.classify_new import generic_map_aspect + + +''' + subprogram_instantiation_declaration ::= + subprogram_kind identifier is new uninstantiated_subprogram_name [ signature ] + [ generic_map_aspect ] ; +''' + + +def detect(iToken, lObjects): + if subprogram_kind.detect(iToken, lObjects): + if utils.find_in_next_n_tokens('is', 3, iToken, lObjects): + return classify(iToken, lObjects) + else: + return iToken + return iToken + + +def classify(iToken, lObjects): + iCurrent = subprogram_kind.classify(iToken, lObjects) + iCurrent = utils.assign_next_token(token.identifier, iCurrent, lObjects) + iCurrent = utils.assign_next_token_required('is', token.is_keyword, iCurrent, lObjects) + iCurrent = utils.assign_next_token_required('new', token.new_keyword, iCurrent, lObjects) + iCurrent = utils.assign_next_token(token.uninstantiated_subprogram_name, iCurrent, lObjects) + iCurrent = signature.detect(iCurrent, lObjects) + iCurrent = generic_map_aspect.detect(iCurrent, lObjects) + iCurrent = utils.assign_next_token_required(';', token.semicolon, iCurrent, lObjects) + return iCurrent diff --git a/vsg/vhdlFile/classify_new/subprogram_kind.py b/vsg/vhdlFile/classify_new/subprogram_kind.py new file mode 100644 index 00000000..94bcaa8c --- /dev/null +++ b/vsg/vhdlFile/classify_new/subprogram_kind.py @@ -0,0 +1,24 @@ + +from vsg.token import subprogram_kind as token + +from vsg.vhdlFile import utils + + +''' + subprogram_kind ::= + procedure | function +''' + + +def detect(iToken, lObjects): + if utils.is_next_token('procedure', iToken, lObjects): + return True + if utils.is_next_token('function', iToken, lObjects): + return True + return False + + +def classify(iToken, lObjects): + iCurrent = utils.assign_next_token_if('procedure', token.procedure_keyword, iToken, lObjects) + iCurrent = utils.assign_next_token_if('function', token.function_keyword, iToken, lObjects) + return iCurrent