From aba181c2acae1187b0950326c5a2d7f6a54ce0bc Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 28 Sep 2023 21:59:26 +0100 Subject: [PATCH] Tweak handling of pragmas outside of design units --- src/parse.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/parse.c b/src/parse.c index 6387a205..6a4a734d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -198,11 +198,15 @@ static void _push_state(const state_t *s) static void skip_pragma(pragma_kind_t kind) { - tree_t p = tree_new(T_PRAGMA); - tree_set_loc(p, &yylloc); - tree_set_subkind(p, kind); + if (nametab == NULL) + warn_at(&yylloc, "ignoring pragma outside of design unit"); + else { + tree_t p = tree_new(T_PRAGMA); + tree_set_loc(p, &yylloc); + tree_set_subkind(p, kind); - APUSH(pragmas, p); + APUSH(pragmas, p); + } } static token_t wrapped_yylex(void) @@ -12726,14 +12730,6 @@ static void flush_pragmas(tree_t unit) "translate_on$$ directive seen before end of design unit"); ACLEAR(pragmas); - - (void)peek(); // Skips over all pragmas until next token - - if (pragmas.count > 0) { - warn_at(tree_loc(pragmas.items[0]), "ignoring pragma outside of " - "design unit"); - ACLEAR(pragmas); - } } tree_t parse(void) -- 2.39.2