static const cpp_token *padding_token
PARAMS ((cpp_reader *, const cpp_token *));
static void expand_arg PARAMS ((cpp_reader *, macro_arg *));
-static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *,
+static const cpp_token *new_string_token PARAMS ((cpp_reader *, uchar *,
unsigned int));
static const cpp_token *new_number_token PARAMS ((cpp_reader *, unsigned int));
static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *));
switch (node->value.builtin)
{
default:
- cpp_ice (pfile, "invalid built-in macro \"%s\"", NODE_NAME (node));
+ cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+ NODE_NAME (node));
return 0;
case BT_FILE:
{
unsigned int len;
const char *name;
- U_CHAR *buf;
+ uchar *buf;
const struct line_map *map = pfile->map;
if (node->value.builtin == BT_BASE_FILE)
backslashes and double quotes. Non-printable characters are
converted to octal. DEST must be of sufficient size. Returns
a pointer to the end of the string. */
-U_CHAR *
+uchar *
cpp_quote_string (dest, src, len)
- U_CHAR *dest;
- const U_CHAR *src;
+ uchar *dest;
+ const uchar *src;
unsigned int len;
{
while (len--)
{
- U_CHAR c = *src++;
+ uchar c = *src++;
if (c == '\\' || c == '"')
{
/* Ignore the final \ of invalid string literals. */
if (backslash_count & 1)
{
- cpp_warning (pfile, "invalid string literal, ignoring final '\\'");
+ cpp_error (pfile, DL_WARNING,
+ "invalid string literal, ignoring final '\\'");
dest--;
}
/* Mandatory warning for all apart from assembler. */
if (CPP_OPTION (pfile, lang) != CLK_ASM)
- cpp_warning (pfile,
+ cpp_error (pfile, DL_WARNING,
"pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
- cpp_token_as_text (pfile, lhs),
- cpp_token_as_text (pfile, rhs));
+ cpp_token_as_text (pfile, lhs),
+ cpp_token_as_text (pfile, rhs));
break;
}
}
callers at the end of an -include-d file. */
if (pfile->context->prev || pfile->state.in_directive)
_cpp_backup_tokens (pfile, 1);
- cpp_error (pfile, "unterminated argument list invoking macro \"%s\"",
+ cpp_error (pfile, DL_ERROR,
+ "unterminated argument list invoking macro \"%s\"",
NODE_NAME (node));
error = true;
}
if (argc + 1 == macro->paramc && macro->variadic)
{
if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
- cpp_pedwarn (pfile, "ISO C99 requires rest arguments to be used");
+ cpp_error (pfile, DL_PEDWARN,
+ "ISO C99 requires rest arguments to be used");
}
else
{
- cpp_error (pfile,
+ cpp_error (pfile, DL_ERROR,
"macro \"%s\" requires %u arguments, but only %u given",
NODE_NAME (node), macro->paramc, argc);
error = true;
/* Empty argument to a macro taking no arguments is OK. */
if (argc != 1 || arg->count)
{
- cpp_error (pfile,
+ cpp_error (pfile, DL_ERROR,
"macro \"%s\" passed %u arguments, but takes just %u",
NODE_NAME (node), argc, macro->paramc);
error = true;
return collect_args (pfile, node);
}
- /* Back up. We may have skipped padding, in which case backing up
- more than one token when expanding macros is in general too
- difficult. We re-insert it in its own context. */
- _cpp_backup_tokens (pfile, 1);
- if (padding)
- push_token_context (pfile, NULL, padding, 1);
+ /* CPP_EOF can be the end of macro arguments, or the end of the
+ file. We mustn't back up over the latter. Ugh. */
+ if (token->type != CPP_EOF || token == &pfile->eof)
+ {
+ /* Back up. We may have skipped padding, in which case backing
+ up more than one token when expanding macros is in general
+ too difficult. We re-insert it in its own context. */
+ _cpp_backup_tokens (pfile, 1);
+ if (padding)
+ push_token_context (pfile, NULL, padding, 1);
+ }
return NULL;
}
if (buff == NULL)
{
if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
- cpp_warning (pfile,
+ cpp_error (pfile, DL_WARNING,
"function-like macro \"%s\" must be used with arguments in traditional C",
- NODE_NAME (node));
+ NODE_NAME (node));
return 0;
}
return &pfile->avoid_paste;
}
+ if (pfile->state.in_directive && result->type == CPP_COMMENT)
+ continue;
+
if (result->type != CPP_NAME)
break;
return node && node->value.macro && node->value.macro->syshdr;
}
-/* Read each token in, until EOF. Directives are transparently
- processed. */
+/* Read each token in, until end of the current file. Directives are
+ transparently processed. */
void
cpp_scan_nooutput (pfile)
cpp_reader *pfile;
{
+ /* Request a CPP_EOF token at the end of this file, rather than
+ transparently continuing with the including file. */
+ pfile->buffer->return_at_eof = true;
+
while (cpp_get_token (pfile)->type != CPP_EOF)
;
}
/* Constraint 6.10.3.6 - duplicate parameter names. */
if (node->arg_index)
{
- cpp_error (pfile, "duplicate macro parameter \"%s\"", NODE_NAME (node));
+ cpp_error (pfile, DL_ERROR, "duplicate macro parameter \"%s\"",
+ NODE_NAME (node));
return 1;
}
switch (token->type)
{
default:
- cpp_error (pfile, "\"%s\" may not appear in macro parameter list",
+ /* Allow/ignore comments in parameter lists if we are
+ preserving comments in macro expansions. */
+ if (token->type == CPP_COMMENT
+ && ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
+ continue;
+
+ cpp_error (pfile, DL_ERROR,
+ "\"%s\" may not appear in macro parameter list",
cpp_token_as_text (pfile, token));
return 0;
case CPP_NAME:
if (prev_ident)
{
- cpp_error (pfile, "macro parameters must be comma-separated");
+ cpp_error (pfile, DL_ERROR,
+ "macro parameters must be comma-separated");
return 0;
}
prev_ident = 1;
case CPP_COMMA:
if (!prev_ident)
{
- cpp_error (pfile, "parameter name missing");
+ cpp_error (pfile, DL_ERROR, "parameter name missing");
return 0;
}
prev_ident = 0;
save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__);
pfile->state.va_args_ok = 1;
if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic))
- cpp_pedwarn (pfile,
- "anonymous variadic macros were introduced in C99");
+ cpp_error (pfile, DL_PEDWARN,
+ "anonymous variadic macros were introduced in C99");
}
else if (CPP_OPTION (pfile, pedantic))
- cpp_pedwarn (pfile, "ISO C does not permit named variadic macros");
+ cpp_error (pfile, DL_PEDWARN,
+ "ISO C does not permit named variadic macros");
/* We're at the end, and just expect a closing parenthesis. */
token = _cpp_lex_token (pfile);
/* Fall through. */
case CPP_EOF:
- cpp_error (pfile, "missing ')' in macro parameter list");
+ cpp_error (pfile, DL_ERROR, "missing ')' in macro parameter list");
return 0;
}
}
goto cleanup2;
/* Success. Commit the parameter array. */
- BUFF_FRONT (pfile->a_buff) = (U_CHAR *) ¯o->params[macro->paramc];
+ BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->params[macro->paramc];
macro->fun_like = 1;
}
else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
- cpp_pedwarn (pfile, "ISO C requires whitespace after the macro name");
+ cpp_error (pfile, DL_PEDWARN,
+ "ISO C requires whitespace after the macro name");
saved_cur_token = pfile->cur_token;
else if (CPP_OPTION (pfile, lang) != CLK_ASM)
{
ok = 0;
- cpp_error (pfile, "'#' is not followed by a macro parameter");
+ cpp_error (pfile, DL_ERROR,
+ "'#' is not followed by a macro parameter");
goto cleanup1;
}
}
if (macro->count == 0 || token->type == CPP_EOF)
{
ok = 0;
- cpp_error (pfile,
+ cpp_error (pfile, DL_ERROR,
"'##' cannot appear at either end of a macro expansion");
goto cleanup1;
}
macro->expansion[0].flags &= ~PREV_WHITE;
/* Commit the memory. */
- BUFF_FRONT (pfile->a_buff) = (U_CHAR *) ¯o->expansion[macro->count];
+ BUFF_FRONT (pfile->a_buff) = (uchar *) ¯o->expansion[macro->count];
/* Implement the macro-defined-to-itself optimisation. */
if (macro->count == 1 && !macro->fun_like
{
if (warn_of_redefinition (node, macro))
{
- cpp_pedwarn_with_line (pfile, pfile->directive_line, 0,
- "\"%s\" redefined", NODE_NAME (node));
+ cpp_error_with_line (pfile, DL_PEDWARN, pfile->directive_line, 0,
+ "\"%s\" redefined", NODE_NAME (node));
if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
- cpp_pedwarn_with_line (pfile, node->value.macro->line, 0,
+ cpp_error_with_line (pfile, DL_PEDWARN, node->value.macro->line, 0,
"this is the location of the previous definition");
}
_cpp_free_definition (node);
const cpp_string *string;
{
unsigned int i, len;
- const U_CHAR *p, *q, *limit = string->text + string->len;
+ const uchar *p, *q, *limit = string->text + string->len;
/* Loop over the string. */
for (p = string->text; p < limit; p = q)
if (NODE_LEN (node) == len
&& !memcmp (p, NODE_NAME (node), len))
{
- cpp_warning (pfile,
+ cpp_error (pfile, DL_WARNING,
"macro argument \"%s\" would be stringified in traditional C",
- NODE_NAME (node));
+ NODE_NAME (node));
break;
}
}
if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
{
- cpp_ice (pfile, "invalid hash type %d in cpp_macro_definition", node->type);
+ cpp_error (pfile, DL_ICE,
+ "invalid hash type %d in cpp_macro_definition", node->type);
return 0;
}
len = NODE_LEN (node) + 1; /* ' ' */
if (macro->fun_like)
{
- len += 3; /* "()" plus possible final "." of named
- varargs (we have + 2 below). */
+ 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]) + 2; /* ", " */
+ len += NODE_LEN (macro->params[i]) + 1; /* "," */
}
for (i = 0; i < macro->count; i++)
if (len > pfile->macro_buffer_len)
{
- pfile->macro_buffer = (U_CHAR *) xrealloc (pfile->macro_buffer, len);
+ pfile->macro_buffer = (uchar *) xrealloc (pfile->macro_buffer, len);
pfile->macro_buffer_len = len;
}
}
if (i + 1 < macro->paramc)
- *buffer++ = ',', *buffer++ = ' ';
+ /* Don't emit a space after the comma here; we're trying
+ to emit a Dwarf-friendly definition, and the Dwarf spec
+ forbids spaces in the argument list. */
+ *buffer++ = ',';
else if (macro->variadic)
*buffer++ = '.', *buffer++ = '.', *buffer++ = '.';
}
*buffer++ = ')';
}
+ /* The Dwarf spec requires a space after the macro name, even if the
+ definition is the empty string. */
+ *buffer++ = ' ';
+
/* Expansion tokens. */
if (macro->count)
{
- *buffer++ = ' ';
for (i = 0; i < macro->count; i++)
{
cpp_token *token = ¯o->expansion[i];