static cpp_macro *
create_iso_definition (cpp_reader *pfile)
{
- cpp_macro *macro = _cpp_new_macro (pfile, cmk_macro);
bool following_paste_op = false;
const char *paste_op_error_msg =
N_("'##' cannot appear at either end of a macro expansion");
unsigned int num_extra_tokens = 0;
unsigned nparms = 0;
+ cpp_hashnode **params = NULL;
+ bool varadic = false;
bool ok = false;
+ cpp_macro *macro = NULL;
/* Look at the first token, to see if this is a function-like
macro. */
- cpp_token *token = lex_expansion_token (pfile, macro);
+ cpp_token first;
+ cpp_token *saved_cur_token = pfile->cur_token;
+ pfile->cur_token = &first;
+ cpp_token *token = _cpp_lex_direct (pfile);
+ pfile->cur_token = saved_cur_token;
+
if (token->flags & PREV_WHITE)
/* Preceeded by space, must be part of expansion. */;
else if (token->type == CPP_OPEN_PAREN)
{
/* An open-paren, get a parameter list. */
- bool varadic = false;
-
- /* Drop the '(' token. */
- macro->count = 0;
if (!parse_params (pfile, &nparms, &varadic))
goto out;
- macro->parm.params = (cpp_hashnode **)_cpp_commit_buff
+ params = (cpp_hashnode **)_cpp_commit_buff
(pfile, sizeof (cpp_hashnode *) * nparms);
- macro->variadic = varadic;
- macro->paramc = nparms;
- macro->fun_like = 1;
-
token = NULL;
}
else if (token->type != CPP_EOF
}
}
+ macro = _cpp_new_macro (pfile, cmk_macro);
+ if (!token)
+ {
+ macro->variadic = varadic;
+ macro->paramc = nparms;
+ macro->parm.params = params;
+ macro->fun_like = true;
+ }
+ else
+ {
+ /* Preserve the token we peeked. */
+ void *base = _cpp_reserve_room (pfile, 0, sizeof (cpp_token));
+ *(cpp_token *)base = *token;
+ token = (cpp_token *)base;
+ macro->count = 1;
+ }
+
for (vaopt_state vaopt_tracker (pfile, macro->variadic, true);; token = NULL)
{
if (!token)
cpp_macro *
_cpp_create_trad_definition (cpp_reader *pfile)
{
- cpp_macro *macro = _cpp_new_macro (pfile, cmk_traditional);
const uchar *cur;
uchar *limit;
cpp_context *context = pfile->context;
unsigned nparms = 0;
+ int fun_like = 0;
+ cpp_hashnode **params = NULL;
/* The context has not been set up for command line defines, and CUR
has not been updated for the macro name for in-file defines. */
/* Is this a function-like macro? */
if (* CUR (context) == '(')
{
+ fun_like = +1;
if (scan_parameters (pfile, &nparms))
- {
- macro->paramc = nparms;
- macro->parm.params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
- BUFF_FRONT (pfile->a_buff)
- = (uchar *) ¯o->parm.params[macro->paramc];
- macro->fun_like = 1;
- }
+ params = (cpp_hashnode **)_cpp_commit_buff
+ (pfile, sizeof (cpp_hashnode *) * nparms);
else
- macro = NULL;
+ fun_like = -1;
+ }
+
+ cpp_macro *macro = NULL;
+
+ if (fun_like >= 0)
+ {
+ macro = _cpp_new_macro (pfile, cmk_traditional);
+ macro->parm.params = params;
+ macro->paramc = nparms;
+ macro->fun_like = fun_like != 0;
}
/* Skip leading whitespace in the replacement text. */