/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
- 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
cpp_macro *macro = node->value.macro;
if (!macro->used
- && MAIN_FILE_P (linemap_lookup (&pfile->line_maps, macro->line)))
- cpp_error_with_line (pfile, DL_WARNING, macro->line, 0,
+ && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line)))
+ cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0,
"macro \"%s\" is not used", NODE_NAME (node));
}
const uchar *
_cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
{
+ const struct line_map *map;
const uchar *result = NULL;
unsigned int number = 1;
switch (node->value.builtin)
{
default:
- cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+ cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
NODE_NAME (node));
break;
unsigned int len;
const char *name;
uchar *buf;
- const struct line_map *map = pfile->map;
+ map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
if (node->value.builtin == BT_BASE_FILE)
while (! MAIN_FILE_P (map))
- map = INCLUDED_FROM (&pfile->line_maps, map);
+ map = INCLUDED_FROM (pfile->line_table, map);
name = map->to_file;
len = strlen (name);
/* The line map depth counts the primary source as level 1, but
historically __INCLUDE_DEPTH__ has called the primary source
level 0. */
- number = pfile->line_maps.depth - 1;
+ number = pfile->line_table->depth - 1;
break;
case BT_SPECLINE:
+ map = &pfile->line_table->maps[pfile->line_table->used-1];
/* If __LINE__ is embedded in a macro, it must expand to the
line of the macro's invocation, not its definition.
Otherwise things like assert() will not work properly. */
if (CPP_OPTION (pfile, traditional))
- number = pfile->line;
+ number = pfile->line_table->highest_line;
else
- number = pfile->cur_token[-1].line;
- number = SOURCE_LINE (pfile->map, number);
+ number = pfile->cur_token[-1].src_loc;
+ number = SOURCE_LINE (map, number);
break;
/* __STDC__ has the value 1 under normal circumstances.
value 0. */
case BT_STDC:
{
- if (CPP_IN_SYSTEM_HEADER (pfile)
+ if (cpp_in_system_header (pfile)
&& CPP_OPTION (pfile, stdc_0_in_system_headers)
&& !CPP_OPTION (pfile,std))
number = 0;
}
else
{
- cpp_errno (pfile, DL_WARNING,
+ cpp_errno (pfile, CPP_DL_WARNING,
"could not determine date and time");
pfile->date = U"\"??? ?? ????\"";
pfile->cur_token = _cpp_temp_token (pfile);
push_token_context (pfile, NULL, _cpp_lex_direct (pfile), 1);
if (pfile->buffer->cur != pfile->buffer->rlimit)
- cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+ cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
NODE_NAME (node));
_cpp_pop_buffer (pfile);
/* Ignore the final \ of invalid string literals. */
if (backslash_count & 1)
{
- cpp_error (pfile, DL_WARNING,
+ cpp_error (pfile, CPP_DL_WARNING,
"invalid string literal, ignoring final '\\'");
dest--;
}
/* Mandatory error for all apart from assembler. */
if (CPP_OPTION (pfile, lang) != CLK_ASM)
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
cpp_token_as_text (pfile, lhs),
cpp_token_as_text (pfile, rhs));
if (argc + 1 == macro->paramc && macro->variadic)
{
if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
- cpp_error (pfile, DL_PEDWARN,
+ cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C99 requires rest arguments to be used");
return true;
}
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"macro \"%s\" requires %u arguments, but only %u given",
NODE_NAME (node), macro->paramc, argc);
}
else
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"macro \"%s\" passed %u arguments, but takes just %u",
NODE_NAME (node), argc, macro->paramc);
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, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"unterminated argument list invoking macro \"%s\"",
NODE_NAME (node));
}
if (buff == NULL)
{
if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
- cpp_error (pfile, DL_WARNING,
+ cpp_error (pfile, CPP_DL_WARNING,
"function-like macro \"%s\" must be used with arguments in traditional C",
NODE_NAME (node));
void
cpp_scan_nooutput (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;
+
if (CPP_OPTION (pfile, traditional))
while (_cpp_read_logical_line_trad (pfile))
;
/* Constraint 6.10.3.6 - duplicate parameter names. */
if (node->flags & NODE_MACRO_ARG)
{
- cpp_error (pfile, DL_ERROR, "duplicate macro parameter \"%s\"",
+ cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"",
NODE_NAME (node));
return true;
}
&& ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
continue;
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"\"%s\" may not appear in macro parameter list",
cpp_token_as_text (pfile, token));
return false;
case CPP_NAME:
if (prev_ident)
{
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"macro parameters must be comma-separated");
return false;
}
case CPP_COMMA:
if (!prev_ident)
{
- cpp_error (pfile, DL_ERROR, "parameter name missing");
+ cpp_error (pfile, CPP_DL_ERROR, "parameter name missing");
return false;
}
prev_ident = 0;
_cpp_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_error (pfile, DL_PEDWARN,
+ if (! CPP_OPTION (pfile, c99)
+ && CPP_OPTION (pfile, pedantic)
+ && CPP_OPTION (pfile, warn_variadic_macros))
+ cpp_error (pfile, CPP_DL_PEDWARN,
"anonymous variadic macros were introduced in C99");
}
- else if (CPP_OPTION (pfile, pedantic))
- cpp_error (pfile, DL_PEDWARN,
+ else if (CPP_OPTION (pfile, pedantic)
+ && CPP_OPTION (pfile, warn_variadic_macros))
+ cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C does not permit named variadic macros");
/* We're at the end, and just expect a closing parenthesis. */
/* Fall through. */
case CPP_EOF:
- cpp_error (pfile, DL_ERROR, "missing ')' in macro parameter list");
+ cpp_error (pfile, CPP_DL_ERROR, "missing ')' in macro parameter list");
return false;
}
}
macro->fun_like = 1;
}
else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
- cpp_error (pfile, DL_PEDWARN,
+ cpp_error (pfile, CPP_DL_PEDWARN,
"ISO C requires whitespace after the macro name");
if (macro->fun_like)
/* Let assembler get away with murder. */
else if (CPP_OPTION (pfile, lang) != CLK_ASM)
{
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"'#' is not followed by a macro parameter");
return false;
}
if (macro->count == 0 || token->type == CPP_EOF)
{
- cpp_error (pfile, DL_ERROR,
+ cpp_error (pfile, CPP_DL_ERROR,
"'##' cannot appear at either end of a macro expansion");
return false;
}
macro->count = 0;
macro->fun_like = 0;
/* To suppress some diagnostics. */
- macro->syshdr = pfile->map->sysp != 0;
+ macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0;
if (CPP_OPTION (pfile, traditional))
ok = _cpp_create_trad_definition (pfile, macro);
if (warn_of_redefinition (pfile, node, macro))
{
- cpp_error_with_line (pfile, DL_PEDWARN, pfile->directive_line, 0,
+ cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->directive_line, 0,
"\"%s\" redefined", NODE_NAME (node));
if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
- cpp_error_with_line (pfile, DL_PEDWARN,
+ cpp_error_with_line (pfile, CPP_DL_PEDWARN,
node->value.macro->line, 0,
"this is the location of the previous definition");
}
if (NODE_LEN (node) == len
&& !memcmp (p, NODE_NAME (node), len))
{
- cpp_error (pfile, DL_WARNING,
+ cpp_error (pfile, CPP_DL_WARNING,
"macro argument \"%s\" would be stringified in traditional C",
NODE_NAME (node));
break;
if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
{
- cpp_error (pfile, DL_ICE,
+ cpp_error (pfile, CPP_DL_ICE,
"invalid hash type %d in cpp_macro_definition", node->type);
return 0;
}