diff --git a/vsg/tests/file_declaration/classification_results.txt b/vsg/tests/file_declaration/classification_results.txt new file mode 100644 index 00000000..65c485ba --- /dev/null +++ b/vsg/tests/file_declaration/classification_results.txt @@ -0,0 +1,78 @@ +-------------------------------------------------------------------------------- +0 | None | +-------------------------------------------------------------------------------- +1 | None | architecture RTL of FIFO is + + + + + +-------------------------------------------------------------------------------- +2 | None | + +-------------------------------------------------------------------------------- +3 | None | file F1 : IntegerFile; + + + + + +-------------------------------------------------------------------------------- +4 | None | + +-------------------------------------------------------------------------------- +5 | None | file F2 : IntegerFile is "test.dat"; + + + + + + + +-------------------------------------------------------------------------------- +6 | None | + +-------------------------------------------------------------------------------- +7 | None | file F3 : IntegerFile open WRITE_MODEW is "test.dat"; + + + + + + + + + +-------------------------------------------------------------------------------- +8 | None | + +-------------------------------------------------------------------------------- +9 | None | file F1, F2, F3 : IntegerFile open WRITE_MODEW is "test.dat"; + + + + + + + + + + + + + +-------------------------------------------------------------------------------- +10 | None | + +-------------------------------------------------------------------------------- +11 | None | begin + +-------------------------------------------------------------------------------- +12 | None | + +-------------------------------------------------------------------------------- +13 | None | end architecture RTL; + + + + diff --git a/vsg/tests/file_declaration/classification_test_input.vhd b/vsg/tests/file_declaration/classification_test_input.vhd new file mode 100644 index 00000000..21c9c2f4 --- /dev/null +++ b/vsg/tests/file_declaration/classification_test_input.vhd @@ -0,0 +1,13 @@ +architecture RTL of FIFO is + + file F1 : IntegerFile; + + file F2 : IntegerFile is "test.dat"; + + file F3 : IntegerFile open WRITE_MODEW is "test.dat"; + + file F1, F2, F3 : IntegerFile open WRITE_MODEW is "test.dat"; + +begin + +end architecture RTL; diff --git a/vsg/tests/vhdlFile_new/test_file_declaration.py b/vsg/tests/vhdlFile_new/test_file_declaration.py new file mode 100644 index 00000000..009f48a0 --- /dev/null +++ b/vsg/tests/vhdlFile_new/test_file_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/file_declaration.py b/vsg/token/file_declaration.py index 3d7403cc..b589a394 100644 --- a/vsg/token/file_declaration.py +++ b/vsg/token/file_declaration.py @@ -1,9 +1,24 @@ from vsg import parser -############################################################################### -# File objects -############################################################################### + +class file_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class colon(parser.colon): + + def __init__(self, sString=':'): + parser.colon.__init__(self) + + +class semicolon(parser.semicolon): + + def __init__(self, sString=';'): + parser.semicolon.__init__(self) + class keyword(parser.keyword): @@ -20,11 +35,6 @@ class comma(parser.comma): def __init__(self): parser.comma.__init__(self) -class colon(parser.colon): - - def __init__(self): - parser.colon.__init__(self) - class subtype_indication(parser.subtype_indication): def __init__(self, sString): @@ -52,5 +62,5 @@ class logical_name(parser.logical_name): class semicolon(parser.semicolon): - def __init__(self): + def __init__(self, sString=';'): parser.semicolon.__init__(self) diff --git a/vsg/token/file_open_information.py b/vsg/token/file_open_information.py new file mode 100644 index 00000000..cb0afc59 --- /dev/null +++ b/vsg/token/file_open_information.py @@ -0,0 +1,27 @@ + +from vsg import parser + + +class open_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class file_open_kind_expression(parser.expression): + + def __init__(self, sString): + parser.expression.__init__(self, sString) + + +class is_keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + + +class file_logical_name(parser.expression): + + def __init__(self, sString): + parser.expression.__init__(self, sString) + diff --git a/vsg/vhdlFile/classify_new/block_declarative_item.py b/vsg/vhdlFile/classify_new/block_declarative_item.py index 877c3aae..2b006cd9 100644 --- a/vsg/vhdlFile/classify_new/block_declarative_item.py +++ b/vsg/vhdlFile/classify_new/block_declarative_item.py @@ -9,6 +9,7 @@ from vsg.vhdlFile.classify_new import subtype_declaration from vsg.vhdlFile.classify_new import constant_declaration from vsg.vhdlFile.classify_new import signal_declaration from vsg.vhdlFile.classify_new import variable_declaration +from vsg.vhdlFile.classify_new import file_declaration from vsg.vhdlFile.classify_new import use_clause @@ -24,7 +25,7 @@ from vsg.vhdlFile.classify_new import use_clause | subtype_declaration | constant_declaration | signal_declaration - | shared_variable_declaration + | *shared*_variable_declaration | file_declaration | alias_declaration | component_declaration @@ -75,6 +76,10 @@ def detect(iToken, lObjects): if iReturn != iToken: return iReturn + iReturn = file_declaration.detect(iToken, lObjects) + if iReturn != iToken: + return iReturn + iReturn = use_clause.detect(iToken, lObjects) diff --git a/vsg/vhdlFile/classify_new/file_declaration.py b/vsg/vhdlFile/classify_new/file_declaration.py new file mode 100644 index 00000000..77cf6876 --- /dev/null +++ b/vsg/vhdlFile/classify_new/file_declaration.py @@ -0,0 +1,33 @@ + +from vsg.token import file_declaration as token + +from vsg.vhdlFile import utils + +from vsg.vhdlFile.classify_new import file_open_information +from vsg.vhdlFile.classify_new import identifier_list +from vsg.vhdlFile.classify_new import subtype_indication + + +''' + file_declaration ::= + file identifier_list : subtype_indication [ file_open_information ] ; +''' + + +def detect(iToken, lObjects): + + if utils.is_next_token('file', iToken, lObjects): + return classify(iToken, lObjects) + + return iToken + + +def classify(iToken, lObjects): + iCurrent = utils.assign_next_token_required('file', token.file_keyword, iToken, lObjects) + iCurrent = identifier_list.classify(iCurrent, lObjects) + iCurrent = utils.assign_next_token_required(':', token.colon, iCurrent, lObjects) + sEnd = utils.find_earliest_occurance([';', ':=', 'open', 'is'], iCurrent, lObjects) + iCurrent = utils.classify_subelement_until(sEnd, subtype_indication, iCurrent, lObjects) + iCurrent = file_open_information.detect(iCurrent, lObjects) + iCurrent = utils.assign_next_token_required(';', token.semicolon, iCurrent, lObjects) + return iCurrent diff --git a/vsg/vhdlFile/classify_new/file_open_information.py b/vsg/vhdlFile/classify_new/file_open_information.py new file mode 100644 index 00000000..cc93f7d3 --- /dev/null +++ b/vsg/vhdlFile/classify_new/file_open_information.py @@ -0,0 +1,30 @@ + +from vsg.token import file_open_information as token + +from vsg.vhdlFile import utils + + +''' + file_open_information ::= + [ open *file_open_kind*_expression ] is file_logical_name +''' + + +def detect(iToken, lObjects): + + if utils.is_next_token('open', iToken, lObjects): + return classify(iToken, lObjects) + elif utils.is_next_token('is', iToken, lObjects): + return classify(iToken, lObjects) + + return iToken + + +def classify(iToken, lObjects): + iCurrent = iToken + if utils.is_next_token('open', iCurrent, lObjects): + iCurrent = utils.assign_next_token_required('open', token.open_keyword, iCurrent, lObjects) + iCurrent = utils.assign_next_token(token.file_open_kind_expression, iCurrent, lObjects) + iCurrent = utils.assign_next_token_required('is', token.is_keyword, iCurrent, lObjects) + iCurrent = utils.assign_next_token(token.file_logical_name, iCurrent, lObjects) + return iCurrent