On 10/31/24 6:43 AM, Paul Iannetta wrote:
gcc/c-family/ChangeLog:
* c-pragma.cc (struct pragma_pp_data): Use (struct
internal_pragma_handler);
(c_register_pragma_1): Always register name and space for all pragmas.
If we're using the _pp data structure for all pragmas now, I'd think we
should rename it to remove _pp?
(c_invoke_pragma_handler): Adapt.
(c_invoke_early_pragma_handler): Likewise.
(c_pp_invoke_early_pragma_handler): Likewise.
---
gcc/c-family/c-pragma.cc | 54 +++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 31 deletions(-)
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index de7c378965d..81c785ce6ed 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1488,16 +1488,14 @@ handle_pragma_float_const_decimal64 (cpp_reader *)
/* A vector of registered pragma callbacks, which is never freed. */
-static vec<internal_pragma_handler> registered_pragmas;
struct pragma_pp_data
{
const char *space;
const char *name;
- pragma_handler_1arg early_handler;
+ struct internal_pragma_handler ihandler;
};
-
static vec<pragma_pp_data> registered_pp_pragmas;
struct omp_pragma_def { const char *name; unsigned int id; };
@@ -1613,31 +1611,24 @@ c_register_pragma_1 (const char *space, const char
*name,
{
unsigned id;
- if (flag_preprocess_only)
- {
- if (cpp_get_options (parse_in)->directives_only
- || !(allow_expansion || ihandler.early_handler.handler_1arg))
- return;
+ pragma_pp_data pp_data;
+ pp_data.space = space;
+ pp_data.name = name;
- pragma_pp_data pp_data;
- pp_data.space = space;
- pp_data.name = name;
- pp_data.early_handler = ihandler.early_handler.handler_1arg;
- registered_pp_pragmas.safe_push (pp_data);
- id = registered_pp_pragmas.length ();
- id += PRAGMA_FIRST_EXTERNAL - 1;
- }
- else
- {
- registered_pragmas.safe_push (ihandler);
- id = registered_pragmas.length ();
- id += PRAGMA_FIRST_EXTERNAL - 1;
-
- /* The C front end allocates 8 bits in c_token. The C++ front end
- keeps the pragma kind in the form of INTEGER_CST, so no small
- limit applies. At present this is sufficient. */
- gcc_assert (id < 256);
- }
+ if (flag_preprocess_only
+ && (cpp_get_options (parse_in)->directives_only
+ || !(allow_expansion || ihandler.early_handler.handler_1arg)))
+ return;
+
+ pp_data.ihandler = ihandler;
+ registered_pp_pragmas.safe_push (pp_data);
+ id = registered_pp_pragmas.length ();
+ id += PRAGMA_FIRST_EXTERNAL - 1;
+
+ /* The C front end allocates 8 bits in c_token. The C++ front end
+ keeps the pragma kind in the form of INTEGER_CST, so no small
+ limit applies. At present this is sufficient. */
+ gcc_assert (id < 256);
cpp_register_deferred_pragma (parse_in, space, name, id,
allow_expansion, false);
@@ -1731,7 +1722,7 @@ c_invoke_pragma_handler (unsigned int id)
pragma_handler_2arg handler_2arg;
id -= PRAGMA_FIRST_EXTERNAL;
- ihandler = ®istered_pragmas[id];
+ ihandler = ®istered_pp_pragmas[id].ihandler;
if (ihandler->extra_data)
{
handler_2arg = ihandler->handler.handler_2arg;
@@ -1753,7 +1744,7 @@ c_invoke_early_pragma_handler (unsigned int id)
pragma_handler_2arg handler_2arg;
id -= PRAGMA_FIRST_EXTERNAL;
- ihandler = ®istered_pragmas[id];
+ ihandler = ®istered_pp_pragmas[id].ihandler;
if (ihandler->extra_data)
{
handler_2arg = ihandler->early_handler.handler_2arg;
@@ -1772,9 +1763,10 @@ void
c_pp_invoke_early_pragma_handler (unsigned int id)
{
const auto data = ®istered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL];
- if (data->early_handler)
+ pragma_handler_1arg handler = data->ihandler.early_handler.handler_1arg;
+ if (handler)
{
- data->early_handler (parse_in);
+ handler (parse_in);
pragma_lex_discard_to_eol ();
}
}