From c52e6c3544450988da6eaffd80e6e61db9b65c6f Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 30 Dec 2023 11:38:15 +0000 Subject: [PATCH] Allow alias of type attribute --- src/sem.c | 3 +++ test/sem/attr.vhd | 1 + test/sem/lcs2016_59.vhd | 10 ++++++++++ test/test_sem.c | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/sem.c b/src/sem.c index ac30e41e..87806486 100644 --- a/src/sem.c +++ b/src/sem.c @@ -1406,6 +1406,8 @@ static bool sem_check_alias(tree_t t, nametab_t *tab) else if (tree_kind(decl) == T_VIEW_DECL) return true; // Alias of view declaration } + else if (value_kind == T_ATTR_REF && is_type_attribute(tree_subkind(value))) + return true; // Alias of type // Alias of object if (!sem_check(value, tab)) @@ -4184,6 +4186,7 @@ static bool sem_check_attr_ref(tree_t t, bool allow_range, nametab_t *tab) case ATTR_ELEMENT: case ATTR_SUBTYPE: + case ATTR_INDEX: sem_error(t, "%s attribute is only allowed in a type mark", istr(attr)); case ATTR_CONVERSE: diff --git a/test/sem/attr.vhd b/test/sem/attr.vhd index 9421f895..414408e6 100644 --- a/test/sem/attr.vhd +++ b/test/sem/attr.vhd @@ -216,6 +216,7 @@ begin subtype my_int is integer range 1 to 20; subtype my_bool is boolean range true to true; variable x : integer; + alias my_int_base is my_int'base; -- OK begin assert my_int'base'left = 1; -- OK assert x'base'left = 2; -- Error diff --git a/test/sem/lcs2016_59.vhd b/test/sem/lcs2016_59.vhd index a7a467a5..6d80fb28 100644 --- a/test/sem/lcs2016_59.vhd +++ b/test/sem/lcs2016_59.vhd @@ -233,4 +233,14 @@ begin end block; + b4: block is + generic ( + type array_type is array(type is (<>)) of type is private ); + generic map ( array_type => integer_vector ); + + alias index_type is array_type'INDEX; -- OK + alias element_type is array_type'ELEMENT; -- OK + begin + end block; + end architecture; diff --git a/test/test_sem.c b/test/test_sem.c index a71f92dc..051525c3 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -713,17 +713,17 @@ START_TEST(test_attr) { 160, "prefix does not have a range" }, { 204, "prefix does not have LENGTH attribute" }, { 212, "cannot use attribute IMAGE with non-scalar type INT2_" }, - { 221, "prefix of 'BASE attribute must be a type or subtype declara" }, - { 222, "BASE attribute is allowed only as the prefix of the name" }, - { 228, "no visible declaration for NOT_HERE" }, - { 251, "parameter of attribute VAL must have an integer type but " + { 222, "prefix of 'BASE attribute must be a type or subtype declara" }, + { 223, "BASE attribute is allowed only as the prefix of the name" }, + { 229, "no visible declaration for NOT_HERE" }, + { 252, "parameter of attribute VAL must have an integer type but " "found universal_real" }, - { 252, "attribute VAL requires a parameter" }, - { 260, "cannot use attribute VALUE with non-scalar type BIT2D" }, - { 303, "expression must be a BOOLEAN literal" }, - { 305, "NEVER_WAITS attribute can only be applied to procedures" }, - { 309, "failed to parse FOREIGN attribute" }, - { 310, "FOREIGN attribute must have string literal value" }, + { 253, "attribute VAL requires a parameter" }, + { 261, "cannot use attribute VALUE with non-scalar type BIT2D" }, + { 304, "expression must be a BOOLEAN literal" }, + { 306, "NEVER_WAITS attribute can only be applied to procedures" }, + { 310, "failed to parse FOREIGN attribute" }, + { 311, "FOREIGN attribute must have string literal value" }, { -1, NULL } }; expect_errors(expect); -- 2.39.2