2018-07-11 Nathan Sidwell <nathan@acm.org>
+ 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.
(*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);
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;
*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);
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);
}
/* 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
/* 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. */
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;
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))
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);
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))
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. */
*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__)
{
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);
}
}
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);
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. */
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;
}
}