From d2caa0054d4d5c13a70553e726fa8cd3646292a9 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 11 Jul 2018 16:14:14 +0000 Subject: [PATCH] Add cmk_assert structures Add cmk_assert structures libcpp/ * include/cpp-id-data.h (enum cpp_macro_kind): Add cmk_assert. (struct cpp_macro): Place parms in union. * macro.c (warn_of_redefinition): Adjust param field access. (create_iso_definiton, _cpp_create_definition): Likewise. (check_trad_stringification, cpp_macro_definition): Likewise. * traditional.c (_cpp_replacement_text_len): Likewise. (_cpp_copy_replacement_text, _cpp_create_trad_definition): Likewise. gcc/c-family/ * c-ada-spec.c (macro_length, dump_ada_macros): Adjust param field access. From-SVN: r262558 --- ChangeLog.name-lookup | 13 +++++++++++++ gcc/c-family/c-ada-spec.c | 8 ++++---- libcpp/include/cpp-id-data.h | 20 ++++++++++++++------ libcpp/macro.c | 19 ++++++++++--------- libcpp/traditional.c | 9 +++++---- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index 06e100379d21..daf4fb7cf33b 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,5 +1,18 @@ 2018-07-11 Nathan Sidwell + Add cmk_assert structures + libcpp/ + * include/cpp-id-data.h (enum cpp_macro_kind): Add cmk_assert. + (struct cpp_macro): Place parms in union. + * macro.c (warn_of_redefinition): Adjust param field access. + (create_iso_definiton, _cpp_create_definition): Likewise. + (check_trad_stringification, cpp_macro_definition): Likewise. + * traditional.c (_cpp_replacement_text_len): Likewise. + (_cpp_copy_replacement_text, _cpp_create_trad_definition): Likewise. + gcc/c-family/ + * c-ada-spec.c (macro_length, dump_ada_macros): Adjust param field + access. + Add cpp_macro_kind libcpp/ * include/cpp-id-data.h (enum cpp_macro_kind): New. diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 99b6f0581431..f1b02d8f2fc1 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -70,7 +70,7 @@ macro_length (const cpp_macro *macro, int *supported, int *buffer_len, (*param_len)++; for (i = 0; i < macro->paramc; i++) { - cpp_hashnode *param = macro->params[i]; + cpp_hashnode *param = macro->parm.params[i]; *param_len += NODE_LEN (param); @@ -102,7 +102,7 @@ macro_length (const cpp_macro *macro, int *supported, int *buffer_len, if (token->type == CPP_MACRO_ARG) *buffer_len += - NODE_LEN (macro->params[token->val.macro_arg.arg_no - 1]); + NODE_LEN (macro->parm.params[token->val.macro_arg.arg_no - 1]); else /* Include enough extra space to handle e.g. special characters. */ *buffer_len += (cpp_token_len (token) + 1) * 8; @@ -253,7 +253,7 @@ dump_ada_macros (pretty_printer *pp, const char* file) *buf_param++ = '('; for (i = 0; i < macro->paramc; i++) { - cpp_hashnode *param = macro->params[i]; + cpp_hashnode *param = macro->parm.params[i]; memcpy (buf_param, NODE_NAME (param), NODE_LEN (param)); buf_param += NODE_LEN (param); @@ -292,7 +292,7 @@ dump_ada_macros (pretty_printer *pp, const char* file) case CPP_MACRO_ARG: { cpp_hashnode *param = - macro->params[token->val.macro_arg.arg_no - 1]; + macro->parm.params[token->val.macro_arg.arg_no - 1]; memcpy (buffer, NODE_NAME (param), NODE_LEN (param)); buffer += NODE_LEN (param); } diff --git a/libcpp/include/cpp-id-data.h b/libcpp/include/cpp-id-data.h index f4596b69dc41..8117a8893de5 100644 --- a/libcpp/include/cpp-id-data.h +++ b/libcpp/include/cpp-id-data.h @@ -33,24 +33,32 @@ struct GTY(()) answer { /* The kind of the cpp_macro. */ enum cpp_macro_kind { cmk_macro, /* An ISO macro (token expansion). */ + cmk_assert, /* An assertion. */ cmk_traditional, /* A traditional macro (text expansion). */ }; /* Each macro definition is recorded in a cpp_macro structure. Variadic macros cannot occur with traditional cpp. */ struct GTY(()) cpp_macro { - /* Parameters, if any. If parameter names use extended identifiers, - the original spelling of those identifiers, not the canonical - UTF-8 spelling, goes here. */ - cpp_hashnode ** GTY ((nested_ptr (union tree_node, + union cpp_parm_u + { + /* Parameters, if any. If parameter names use extended identifiers, + the original spelling of those identifiers, not the canonical + UTF-8 spelling, goes here. */ + cpp_hashnode ** GTY ((tag ("false"), + nested_ptr (union tree_node, "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), - length ("%h.paramc"))) params; + length ("%1.paramc"))) params; + + /* If this is an assertion, the next one in the chain. */ + cpp_macro *GTY ((tag ("true"))) next; + } GTY ((desc ("%1.kind == cmk_assert"))) parm; union cpp_exp_u { /* Replacement tokens (ISO), or assertion body value. */ - cpp_token * GTY ((tag ("false"), length ("%0.count"))) tokens; + cpp_token * GTY ((tag ("false"), length ("%1.count"))) tokens; /* Replacement text (traditional). See comment at top of cpptrad.c for how traditional function-like macros are diff --git a/libcpp/macro.c b/libcpp/macro.c index d8ea69230c1d..0d798fdc4ca2 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -3032,7 +3032,7 @@ warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node, /* Check parameter spellings. */ for (i = 0; i < macro1->paramc; i++) - if (macro1->params[i] != macro2->params[i]) + if (macro1->parm.params[i] != macro2->parm.params[i]) return true; /* Check the replacement text or tokens. */ @@ -3257,7 +3257,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro) if (ctoken->type == CPP_OPEN_PAREN && !(ctoken->flags & PREV_WHITE)) { bool ok = parse_params (pfile, macro); - macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); + macro->parm.params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); if (!ok) return false; @@ -3267,12 +3267,13 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro) cpp_hashnode **params = (cpp_hashnode **) pfile->hash_table->alloc_subobject (sizeof (cpp_hashnode *) * macro->paramc); - memcpy (params, macro->params, + memcpy (params, macro->parm.params, sizeof (cpp_hashnode *) * macro->paramc); - macro->params = params; + macro->parm.params = params; } else - BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->params[macro->paramc]; + BUFF_FRONT (pfile->a_buff) + = (uchar *) ¯o->parm.params[macro->paramc]; macro->fun_like = 1; } else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE)) @@ -3464,7 +3465,7 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) else macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro)); macro->line = pfile->directive_line; - macro->params = 0; + macro->parm.params = 0; macro->paramc = 0; macro->variadic = 0; macro->used = !CPP_OPTION (pfile, warn_unused_macros); @@ -3576,7 +3577,7 @@ check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro, identifier inside the string matches one of them. */ for (i = 0; i < macro->paramc; i++) { - const cpp_hashnode *node = macro->params[i]; + const cpp_hashnode *node = macro->parm.params[i]; if (NODE_LEN (node) == len && !memcmp (p, NODE_NAME (node), len)) @@ -3630,7 +3631,7 @@ cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node) len += 4; /* "()" plus possible final ".." of named varargs (we have + 1 below). */ for (i = 0; i < macro->paramc; i++) - len += NODE_LEN (macro->params[i]) + 1; /* "," */ + len += NODE_LEN (macro->parm.params[i]) + 1; /* "," */ } /* This should match below where we fill in the buffer. */ @@ -3674,7 +3675,7 @@ cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node) *buffer++ = '('; for (i = 0; i < macro->paramc; i++) { - cpp_hashnode *param = macro->params[i]; + cpp_hashnode *param = macro->parm.params[i]; if (param != pfile->spec_nodes.n__VA_ARGS__) { diff --git a/libcpp/traditional.c b/libcpp/traditional.c index 3cb967371437..795fb277ac47 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -919,7 +919,7 @@ _cpp_replacement_text_len (const cpp_macro *macro) len += b->text_len; if (b->arg_index == 0) break; - len += NODE_LEN (macro->params[b->arg_index - 1]); + len += NODE_LEN (macro->parm.params[b->arg_index - 1]); exp += BLOCK_LEN (b->text_len); } } @@ -948,7 +948,7 @@ _cpp_copy_replacement_text (const cpp_macro *macro, uchar *dest) dest += b->text_len; if (b->arg_index == 0) break; - param = macro->params[b->arg_index - 1]; + param = macro->parm.params[b->arg_index - 1]; memcpy (dest, NODE_NAME (param), NODE_LEN (param)); dest += NODE_LEN (param); exp += BLOCK_LEN (b->text_len); @@ -1195,7 +1195,7 @@ _cpp_create_trad_definition (cpp_reader *pfile, cpp_macro *macro) bool ok = scan_parameters (pfile, macro); /* Remember the params so we can clear NODE_MACRO_ARG flags. */ - macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); + macro->parm.params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); /* Setting macro to NULL indicates an error occurred, and prevents unnecessary work in _cpp_scan_out_logical_line. */ @@ -1203,7 +1203,8 @@ _cpp_create_trad_definition (cpp_reader *pfile, cpp_macro *macro) macro = NULL; else { - BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->params[macro->paramc]; + BUFF_FRONT (pfile->a_buff) + = (uchar *) ¯o->parm.params[macro->paramc]; macro->fun_like = 1; } } -- 2.47.2