From 31e2a9a2cf358fce778748ef636ab420582cc817 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 3 Jul 2022 11:29:22 +0100 Subject: [PATCH] Fix parsing error with nested array/record constraints --- src/parse.c | 12 +++++++++++- src/sem.c | 7 ++++++- test/sem/record2008.vhd | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/parse.c b/src/parse.c index 717d54f2..422d8dcc 100644 --- a/src/parse.c +++ b/src/parse.c @@ -164,6 +164,7 @@ static tree_t p_record_constraint(type_t base); static tree_t p_qualified_expression(tree_t prefix); static tree_t p_concurrent_procedure_call_statement(ident_t label, tree_t name); static tree_t p_subprogram_instantiation_declaration(void); +static tree_t p_record_element_constraint(type_t base); static bool consume(token_t tok); static bool optional(token_t tok); @@ -3679,8 +3680,17 @@ static void p_array_constraint(type_t type, type_t base) type_add_constraint(type, c); } - else + else if (type_is_record(base)) { + type_add_constraint(type, p_record_constraint(base)); + break; + } + else { type_add_constraint(type, p_index_constraint(base)); + + // Base type may not actually be an array due to earlier errors + if (base != NULL && type_is_array(base)) + base = type_elem(base); + } } while (peek() == tLPAREN); } diff --git a/src/sem.c b/src/sem.c index ec618775..e50b207b 100644 --- a/src/sem.c +++ b/src/sem.c @@ -403,10 +403,15 @@ static bool sem_check_subtype(tree_t decl, type_t type, nametab_t *tab) if (type_is_protected(base)) sem_error(decl, "subtypes may not have protected base types"); + type_t elem = base; const int ncon = type_constraints(type); for (int i = 0; i < ncon; i++) { - if (!sem_check_constraint(type_constraint(type, i), base, tab)) + tree_t cons = type_constraint(type, i); + if (!sem_check_constraint(cons, elem, tab)) return false; + + if (i + 1 < ncon && tree_subkind(cons) == C_INDEX) + elem = type_elem(type); } if (type_freedom(type) < 0) diff --git a/test/sem/record2008.vhd b/test/sem/record2008.vhd index 5b4d4a8f..bdff9106 100644 --- a/test/sem/record2008.vhd +++ b/test/sem/record2008.vhd @@ -63,4 +63,11 @@ begin begin end process; + p3: process is + type rec1_vec is array (natural range <>) of rec1; + constant c1 : rec1_vec(0 to 0)(x(1 to 3)) := ( -- OK + 0 => (x => "111") ); + begin + end process; + end architecture; -- 2.39.2