diff --git a/tests/vhdlFile/full_type_declaration/classification_results.txt b/tests/vhdlFile/full_type_declaration/classification_results.txt index 9e1b434b..3904c1d0 100644 --- a/tests/vhdlFile/full_type_declaration/classification_results.txt +++ b/tests/vhdlFile/full_type_declaration/classification_results.txt @@ -289,13 +289,39 @@ 62 | -------------------------------------------------------------------------------- -63 | begin - +63 | type EXAMPLE_T is record + + + + -------------------------------------------------------------------------------- -64 | +64 | axis : m_axis_o(0)'SUBTYPE; + + + + + + + + + +-------------------------------------------------------------------------------- +65 | end record EXAMPLE_T; + + + + +-------------------------------------------------------------------------------- +66 | -------------------------------------------------------------------------------- -65 | end architecture RTL; +67 | begin + +-------------------------------------------------------------------------------- +68 | + +-------------------------------------------------------------------------------- +69 | end architecture RTL; diff --git a/tests/vhdlFile/full_type_declaration/classification_test_input.vhd b/tests/vhdlFile/full_type_declaration/classification_test_input.vhd index 8dbbef25..b6d35323 100644 --- a/tests/vhdlFile/full_type_declaration/classification_test_input.vhd +++ b/tests/vhdlFile/full_type_declaration/classification_test_input.vhd @@ -60,6 +60,10 @@ architecture RTL of ENTITY_NAME is sud3 = 10 sud2; end units physical_type_simple_name; + type EXAMPLE_T is record + axis : m_axis_o(0)'SUBTYPE; + end record EXAMPLE_T; + begin end architecture RTL; diff --git a/tests/vhdlFile/signal_declaration/classification_results.txt b/tests/vhdlFile/signal_declaration/classification_results.txt index 6d25ff0b..06c9c4e1 100644 --- a/tests/vhdlFile/signal_declaration/classification_results.txt +++ b/tests/vhdlFile/signal_declaration/classification_results.txt @@ -76,9 +76,9 @@ - - - + + + -------------------------------------------------------------------------------- 13 | diff --git a/vsg/token/attribute_name.py b/vsg/token/attribute_name.py new file mode 100644 index 00000000..d9034d2b --- /dev/null +++ b/vsg/token/attribute_name.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from vsg import parser + + +class name(parser.name): + """ + unique_id = attribute_name : name + """ + + def __init__(self, sString): + super().__init__(sString) + + +class tic(parser.tic): + """ + unique_id = attribute_name : tic + """ + + def __init__(self, sString): + super().__init__(sString) + + +class attribute(parser.attribute): + """ + unique_id = attribute_name : attribute + """ + + def __init__(self, sString): + super().__init__(sString) diff --git a/vsg/token/type_mark.py b/vsg/token/type_mark.py index ba02aa07..27287df6 100644 --- a/vsg/token/type_mark.py +++ b/vsg/token/type_mark.py @@ -9,21 +9,3 @@ class name(parser.name): def __init__(self, sString): super().__init__(sString) - - -class tic(parser.tic): - """ - unique_id = type_mark : tic - """ - - def __init__(self, sString): - super().__init__(sString) - - -class attribute(parser.attribute): - """ - unique_id = type_mark : attribute - """ - - def __init__(self, sString): - super().__init__(sString) diff --git a/vsg/vhdlFile/classify/attribute_name.py b/vsg/vhdlFile/classify/attribute_name.py new file mode 100644 index 00000000..792c74fa --- /dev/null +++ b/vsg/vhdlFile/classify/attribute_name.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from vsg import parser +from vsg.token import attribute_name as token +from vsg.vhdlFile import utils +from vsg.vhdlFile.classify import expression, signature + + +def detect(iToken, lObjects): + """ + attribute_name ::= + prefix [ signature ] ' attribute_designator [ ( expression ) ] + """ + + # Skip over prefix + iCurrent = utils.find_next_token(iToken, lObjects) + iCurrent = utils.find_next_token(iCurrent + 1, lObjects) + + if utils.token_is_open_parenthesis(iCurrent, lObjects): + iCurrent += 1 + iCurrent = utils.skip_tokens_until_matching_closing_paren(iCurrent, lObjects) + iCurrent += 1 + + # Check for signature + if utils.is_next_token("[", iCurrent, lObjects): + return True + + # Check for tic + if utils.is_next_token("'", iCurrent, lObjects): + return True + + return False + + +def classify(iToken, lObjects): + iCurrent = utils.assign_next_token(token.name, iToken, lObjects) + iCurrent = utils.find_next_token(iCurrent, lObjects) + + if utils.token_is_open_parenthesis(iCurrent, lObjects): + iCurrent = utils.assign_token(lObjects, iCurrent, parser.open_parenthesis) + iCurrent = utils.assign_tokens_until_matching_closing_paren(parser.todo, iCurrent, lObjects) + iCurrent = utils.assign_token(lObjects, iCurrent, parser.close_parenthesis) + + signature.detect(iCurrent, lObjects) + + iCurrent = utils.assign_next_token_required("'", token.tic, iCurrent, lObjects) + iCurrent = utils.assign_next_token(token.attribute, iCurrent, lObjects) + + return iCurrent diff --git a/vsg/vhdlFile/classify/type_mark.py b/vsg/vhdlFile/classify/type_mark.py index 9c26dfe1..6104ad89 100644 --- a/vsg/vhdlFile/classify/type_mark.py +++ b/vsg/vhdlFile/classify/type_mark.py @@ -3,6 +3,7 @@ from vsg import parser from vsg.token import type_mark as token from vsg.vhdlFile import utils +from vsg.vhdlFile.classify import attribute_name def classify(iToken, lObjects): @@ -11,10 +12,10 @@ def classify(iToken, lObjects): *type*_name | *subtype*_name """ + + if attribute_name.detect(iToken, lObjects): + return attribute_name.classify(iToken, lObjects) + iCurrent = utils.assign_next_token(token.name, iToken, lObjects) - if utils.is_next_token("'", iCurrent, lObjects): - iCurrent = utils.assign_next_token(token.tic, iCurrent, lObjects) - iCurrent = utils.assign_next_token(token.attribute, iCurrent, lObjects) - return iCurrent diff --git a/vsg/vhdlFile/utils.py b/vsg/vhdlFile/utils.py index f6adf88c..33cd6673 100644 --- a/vsg/vhdlFile/utils.py +++ b/vsg/vhdlFile/utils.py @@ -1017,3 +1017,14 @@ def extract_line_with_token_index_of(iToken, lObjects): for oObject in lObjects[iStart:iEnd]: sReturn += oObject.get_value() return sReturn + + +def skip_tokens_until_matching_closing_paren(iToken, lObjects): + iCounter = 1 + iCurrent = iToken + while iCurrent < len(lObjects): + iCurrent = find_next_token(iCurrent, lObjects) + iCounter = update_paren_counter(iCurrent, lObjects, iCounter) + if token_is_close_parenthesis(iCurrent, lObjects) and iCounter == 0: + return iCurrent + iCurrent += 1 diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index 023b4a88..8fd10907 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -4,6 +4,7 @@ from vsg import config, exceptions, parser, token, tokens from vsg.token import ( adding_operator, aggregate, + attribute_name, choices, direction, exponent, @@ -448,7 +449,12 @@ def post_token_assignments(lTokens): iParenId = 0 lParenId = [] for iToken, oToken in enumerate(lTokens): - if isinstance(oToken, resolution_indication.resolution_function_name) or isinstance(oToken, type_mark.name) or isinstance(oToken, todo.name): + if ( + isinstance(oToken, resolution_indication.resolution_function_name) + or isinstance(oToken, type_mark.name) + or isinstance(oToken, attribute_name.name) + or isinstance(oToken, todo.name) + ): sValue = oToken.get_value() sLowerValue = oToken.get_lower_value() ### IEEE values @@ -476,7 +482,7 @@ def post_token_assignments(lTokens): elif sValue.lower() == "unsigned": lTokens[iToken] = types.unsigned(sValue) - elif isinstance(oToken, type_mark.attribute): + elif isinstance(oToken, attribute_name.attribute): sValue = oToken.get_value() if sValue.lower() in predefined_attribute.values: lTokens[iToken] = predefined_attribute.keyword(sValue)