From 3075c5301586419e21de478c46030ba2b5e27f88 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 30 Dec 2023 12:41:14 +0000 Subject: [PATCH] More fixes for 2019 improved type generics --- src/bounds.c | 15 +++++++-------- src/common.c | 5 ++++- src/parse.c | 3 ++- src/sem.c | 4 +--- test/regress/gentype7.vhd | 24 ++++++++++++++++++++++++ test/sem/lcs2016_59.vhd | 25 +++++++++++++++++++++++++ test/test_sem.c | 3 +++ 7 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/bounds.c b/src/bounds.c index 14e4458c..de7dc782 100644 --- a/src/bounds.c +++ b/src/bounds.c @@ -705,13 +705,10 @@ static void bounds_check_aggregate(tree_t t) static void bounds_check_subtype(type_t type) { - const bool is_constrained_array_subtype = - type_is_array(type) - && !type_is_unconstrained(type) - && type_kind(type) == T_SUBTYPE; - - if (!is_constrained_array_subtype) - return; + if (type_kind(type) != T_SUBTYPE || type_has_ident(type)) + return; // Not an anonymous subtype + else if (!type_is_array(type) || type_is_unconstrained(type)) + return; // Not a fully constrained array // Check folded range does not violate index constraints of base type @@ -722,8 +719,10 @@ static void bounds_check_subtype(type_t type) tree_t dim = range_of(type, i); type_t cons = index_type_of(base, i); - type_t cons_base = type_base_recur(cons); + if (type_kind(cons) == T_GENERIC) + continue; // Cannot check + type_t cons_base = type_base_recur(cons); const bool is_enum = (type_kind(cons_base) == T_ENUM); tree_t bounds = range_of(cons, 0); diff --git a/src/common.c b/src/common.c index 74acaf28..a39a3158 100644 --- a/src/common.c +++ b/src/common.c @@ -765,8 +765,11 @@ tree_t aliased_type_decl(tree_t decl) case T_ALIAS: { tree_t value = tree_value(decl); - if (tree_kind(value) == T_REF && tree_has_ref(value)) + const tree_kind_t kind = tree_kind(value); + if (kind == T_REF && tree_has_ref(value)) return aliased_type_decl(tree_ref(value)); + else if (kind == T_ATTR_REF && is_type_attribute(tree_subkind(value))) + return value; else return NULL; } diff --git a/src/parse.c b/src/parse.c index b569f58c..b283b29d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -8411,9 +8411,10 @@ static tree_t p_package_declaration(tree_t unit) tree_set_ident(pack, name); tree_set_loc(pack, CURRENT_LOC); - push_scope(nametab); insert_name(nametab, pack, NULL); + push_scope(nametab); + consume(tIS); push_scope(nametab); diff --git a/src/sem.c b/src/sem.c index 87806486..68bdd4e4 100644 --- a/src/sem.c +++ b/src/sem.c @@ -5805,9 +5805,7 @@ static bool sem_check_file_decl(tree_t t, nametab_t *tab) { // Rules for file declarations are in LRM 93 section 4.3.1.4 - type_t type = tree_type(t); - - if (type_kind(type) != T_FILE) + if (!type_is_file(tree_type(t))) sem_error(t, "file declarations must have file type"); if (tree_has_value(t)) { diff --git a/test/regress/gentype7.vhd b/test/regress/gentype7.vhd index 9fa0c04a..95306c31 100644 --- a/test/regress/gentype7.vhd +++ b/test/regress/gentype7.vhd @@ -4,6 +4,7 @@ end entity; architecture test of gentype7 is signal i : integer; signal a : bit_vector(1 to 3); + signal v : integer_vector(1 to 5); begin b1: block is @@ -28,11 +29,34 @@ begin s <= "101"; end block; + b3: block is + package gp is + generic ( + type element_type is private; + type index_type is (<>); + type array_type is array (index_type range <>) of element_type; + left_index, right_index : index_type ); + signal s : array_type(left_index to right_index); + end package; + + package p is new gp + generic map ( + element_type => integer, + index_type => natural, + array_type => integer_vector, + left_index => 1, + right_index => 5 ); + begin + p.s <= (1, 2, 3, 4, 5); + v <= p.s; + end block; + check: process is begin wait for 1 ns; assert i = 42; assert a = "101"; + assert v = (1, 2, 3, 4, 5); wait; end process; diff --git a/test/sem/lcs2016_59.vhd b/test/sem/lcs2016_59.vhd index 6d80fb28..601824f2 100644 --- a/test/sem/lcs2016_59.vhd +++ b/test/sem/lcs2016_59.vhd @@ -243,4 +243,29 @@ begin begin end block; + b5: block is + generic ( type ft is file of type is private ); + generic map ( ft => t8 ); + file f : ft; -- OK + begin + end block; + + b7: block is + package gp is + generic ( + type array_type is array (type is (<>)) of type is private ); + alias index_type is array_type'INDEX; + alias element_type is array_type'ELEMENT; + end package; + + package p is new gp + generic map ( array_type => bit_vector ); + + signal x : p.array_type(1 to 3); -- OK + signal y : p.index_type := 5; -- OK (TODO) + signal z : p.element_type := '1'; -- OK (TODO) + begin + + end block; + end architecture; diff --git a/test/test_sem.c b/test/test_sem.c index 051525c3..9c364c4c 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -3414,6 +3414,9 @@ START_TEST(test_lcs2016_59) "2 dimensions but the incomplete type definition has 1" }, { 227, "declaration of variable V2 without an initial value cannot have " "unconstrained type T6" }, + { 265, "type of initial value universal_integer does not match type of " + "declaration (an anonymous type)" }, // TODO: wrong + { 266, "ambiguous use of enumeration literal '1'" }, // TODO: wrong { -1, NULL } }; expect_errors(expect); -- 2.39.2