cpperror.c (print_location): Don't print include chain if line == 0.

* cpperror.c (print_location): Don't print include chain
	if line == 0.
	(cpp_begin_message): Update to use DL_ macros.
	(cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning,
	cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line,
	cpp_notice, cpp_notice_from_errno): Remove.
	(cpp_error, cpp_error_with_line): Update to take a diagnostic
	level.
	(cpp_errno): New.
	* cppexp.c (CPP_ICE): Remove.
	(SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined,
	lex, integer_overflow, _cpp_parse_expr): Update.
	* cppfiles.c (read_include_file, find_include_file,
	handle_missing_header, _cpp_read_file, remap_filename): Update.
	* cpphash.h (enum error_type): Remove.
	(_cpp_begin_message): Update.
	* cppinit.c (append_include_chain, remove_dup_dirs, output_deps,
	cpp_handle_option, cpp_post_options): Update.
	* cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment,
	skip_whitespace, parse_identifier, parse_slow, parse_string,
	_cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape,
	cpp_interpret_charconst): Update.
	* cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive,
	lex_macro_node, do_undef, glue_header_name, parse_include,
	do_include_common, read_flag, do_line, do_linemarker, do_ident,
	cpp_register_pragma, do_pragma_once, do_pragma_system_header,
	do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else,
	do_elif, do_endif, parse_answer, parse_assertion, do_assert,
	_cpp_pop_buffer, do_diagnostic): Update.
	* cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR,
	DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New.
	(cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning,
	cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line,
	cpp_notice, cpp_notice_from_errno): Remove.
	(cpp_error, cpp_error_with_line): Update to take a diagnostic
	level.
	(cpp_errno): New.
	* cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens,
	collect_args, enter_macro_context, save_parameter, parse_params,
	_cpp_create_definition, check_trad_stringification,
	cpp_macro_definition): Update.
	* cppmain.c (cpp_preprocess_file): Update.
	* fix-header.c (read_scan_file): Update.

From-SVN: r52302
This commit is contained in:
Neil Booth 2002-04-14 18:42:47 +00:00 committed by Neil Booth
parent c19a385911
commit ebef4e8ca7
12 changed files with 387 additions and 391 deletions

View File

@ -1,3 +1,49 @@
2002-04-14 Neil Booth <neil@daikokuya.demon.co.uk>
* cpperror.c (print_location): Don't print include chain
if line == 0.
(cpp_begin_message): Update to use DL_ macros.
(cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning,
cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line,
cpp_notice, cpp_notice_from_errno): Remove.
(cpp_error, cpp_error_with_line): Update to take a diagnostic
level.
(cpp_errno): New.
* cppexp.c (CPP_ICE): Remove.
(SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined,
lex, integer_overflow, _cpp_parse_expr): Update.
* cppfiles.c (read_include_file, find_include_file,
handle_missing_header, _cpp_read_file, remap_filename): Update.
* cpphash.h (enum error_type): Remove.
(_cpp_begin_message): Update.
* cppinit.c (append_include_chain, remove_dup_dirs, output_deps,
cpp_handle_option, cpp_post_options): Update.
* cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment,
skip_whitespace, parse_identifier, parse_slow, parse_string,
_cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape,
cpp_interpret_charconst): Update.
* cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive,
lex_macro_node, do_undef, glue_header_name, parse_include,
do_include_common, read_flag, do_line, do_linemarker, do_ident,
cpp_register_pragma, do_pragma_once, do_pragma_system_header,
do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else,
do_elif, do_endif, parse_answer, parse_assertion, do_assert,
_cpp_pop_buffer, do_diagnostic): Update.
* cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR,
DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New.
(cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning,
cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line,
cpp_notice, cpp_notice_from_errno): Remove.
(cpp_error, cpp_error_with_line): Update to take a diagnostic
level.
(cpp_errno): New.
* cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens,
collect_args, enter_macro_context, save_parameter, parse_params,
_cpp_create_definition, check_trad_stringification,
cpp_macro_definition): Update.
* cppmain.c (cpp_preprocess_file): Update.
* fix-header.c (read_scan_file): Update.
2002-04-14 Andreas Schwab <schwab@suse.de> 2002-04-14 Andreas Schwab <schwab@suse.de>
* config/ia64/linux.h (CPP_PREDEFINES): Fix missing backslash. * config/ia64/linux.h (CPP_PREDEFINES): Fix missing backslash.

View File

@ -31,32 +31,21 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int)); static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
/* Don't remove the blank before do, as otherwise the exgettext
script will mistake this as a function definition */
#define v_message(msgid, ap) \
do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
/* Print the logical file location (LINE, COL) in preparation for a /* Print the logical file location (LINE, COL) in preparation for a
diagnostic. Outputs the #include chain if it has changed. */ diagnostic. Outputs the #include chain if it has changed. A line
of zero suppresses the include stack, and outputs the program name
instead. */
static void static void
print_location (pfile, line, col) print_location (pfile, line, col)
cpp_reader *pfile; cpp_reader *pfile;
unsigned int line, col; unsigned int line, col;
{ {
cpp_buffer *buffer = pfile->buffer; if (!pfile->buffer || line == 0)
if (!buffer)
fprintf (stderr, "%s: ", progname); fprintf (stderr, "%s: ", progname);
else else
{ {
const struct line_map *map; const struct line_map *map;
if (line == 0)
{
line = pfile->cur_token[-1].line;
col = pfile->cur_token[-1].col;
}
map = lookup_line (&pfile->line_maps, line); map = lookup_line (&pfile->line_maps, line);
print_containing_files (&pfile->line_maps, map); print_containing_files (&pfile->line_maps, map);
@ -75,109 +64,91 @@ print_location (pfile, line, col)
} }
} }
/* Set up for an error message: print the file and line, bump the error /* Set up for a diagnostic: print the file and line, bump the error
counter, etc. LINE is the logical line number; zero means to print counter, etc. LINE is the logical line number; zero means to print
at the location of the previously lexed token, which tends to be the at the location of the previously lexed token, which tends to be
correct place by default. Returns 0 if the error has been suppressed. */ the correct place by default. Returns 0 if the error has been
suppressed. */
int int
_cpp_begin_message (pfile, code, line, column) _cpp_begin_message (pfile, code, line, column)
cpp_reader *pfile; cpp_reader *pfile;
enum error_type code; int code;
unsigned int line, column; unsigned int line, column;
{ {
int is_warning = 0; int level = DL_EXTRACT (code);
switch (code) switch (level)
{ {
case PEDWARN: case DL_WARNING:
case WARNING: case DL_PEDWARN:
if (CPP_IN_SYSTEM_HEADER (pfile) if (CPP_IN_SYSTEM_HEADER (pfile)
&& ! CPP_OPTION (pfile, warn_system_headers)) && ! CPP_OPTION (pfile, warn_system_headers))
return 0; return 0;
case WARNING_SYSHDR: /* Fall through. */
case DL_WARNING_SYSHDR:
if (CPP_OPTION (pfile, warnings_are_errors) if (CPP_OPTION (pfile, warnings_are_errors)
|| (code == PEDWARN && CPP_OPTION (pfile, pedantic_errors))) || (level == DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
{ {
if (CPP_OPTION (pfile, inhibit_errors)) if (CPP_OPTION (pfile, inhibit_errors))
return 0; return 0;
if (pfile->errors < CPP_FATAL_LIMIT) if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++; pfile->errors++;
} }
else else if (CPP_OPTION (pfile, inhibit_warnings))
{
if (CPP_OPTION (pfile, inhibit_warnings))
return 0; return 0;
is_warning = 1;
}
break; break;
case ERROR: case DL_ERROR:
if (CPP_OPTION (pfile, inhibit_errors)) if (CPP_OPTION (pfile, inhibit_errors))
return 0; return 0;
if (pfile->errors < CPP_FATAL_LIMIT) if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++; pfile->errors++;
break; break;
/* Fatal errors cannot be inhibited. */ /* Fatal errors cannot be inhibited. */
case FATAL: case DL_FATAL:
pfile->errors = CPP_FATAL_LIMIT; case DL_ICE:
break;
case ICE:
fprintf (stderr, _("internal error: "));
pfile->errors = CPP_FATAL_LIMIT; pfile->errors = CPP_FATAL_LIMIT;
break; break;
} }
print_location (pfile, line, column); print_location (pfile, line, column);
if (is_warning) if (DL_WARNING_P (level))
fputs (_("warning: "), stderr); fputs (_("warning: "), stderr);
else if (level == DL_ICE)
fputs (_("internal error: "), stderr);
return 1; return 1;
} }
/* Don't remove the blank before do, as otherwise the exgettext
script will mistake this as a function definition */
#define v_message(msgid, ap) \
do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
/* Exported interface. */ /* Exported interface. */
/* For reporting internal errors. Prints "internal error: " for you,
otherwise identical to cpp_fatal. */
void
cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, ICE, 0, 0))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Same as cpp_error, except we consider the error to be "fatal",
such as inconsistent options. I.e. there is little point in continuing.
(We do not exit, to support use of cpplib as a library.
Instead, it is the caller's responsibility to check
CPP_FATAL_ERRORS. */
void
cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, FATAL, 0, 0))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Print an error at the location of the previously lexed token. */ /* Print an error at the location of the previously lexed token. */
void void
cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) cpp_error VPARAMS ((cpp_reader * pfile, int level, const char *msgid, ...))
{ {
unsigned int line, column;
VA_OPEN (ap, msgid); VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, level);
VA_FIXEDARG (ap, const char *, msgid); VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, ERROR, 0, 0)) if (pfile->buffer)
{
line = pfile->cur_token[-1].line;
column = pfile->cur_token[-1].col;
}
else
line = column = 0;
if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
@ -185,116 +156,31 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
/* Print an error at a specific location. */ /* Print an error at a specific location. */
void void
cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column, cpp_error_with_line VPARAMS ((cpp_reader *pfile, int level,
unsigned int line, unsigned int column,
const char *msgid, ...)) const char *msgid, ...))
{ {
VA_OPEN (ap, msgid); VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line); VA_FIXEDARG (ap, int, level);
VA_FIXEDARG (ap, int, column); VA_FIXEDARG (ap, unsigned int, line);
VA_FIXEDARG (ap, unsigned int, column);
VA_FIXEDARG (ap, const char *, msgid); VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, ERROR, line, column)) if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
} }
/* Error including a message from `errno'. */
void void
cpp_error_from_errno (pfile, name) cpp_errno (pfile, level, msgid)
cpp_reader *pfile; cpp_reader *pfile;
const char *name; int level;
const char *msgid;
{ {
cpp_error (pfile, "%s: %s", name, xstrerror (errno)); if (msgid[0] == '\0')
} msgid = _("stdout");
/* Print a warning at the location of the previously lexed token. */ cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
void
cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, WARNING, 0, 0))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Print a warning at a specific location. */
void
cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, WARNING, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Pedwarn at the location of the previously lexed token. */
void
cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, PEDWARN, 0, 0))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Pedwarn at a specific location. */
void
cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, PEDWARN, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Print an error message not associated with the translation unit. */
void
cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid);
if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++;
v_message (msgid, ap);
VA_CLOSE (ap);
}
/* Print an error message originating from ERRNO and not associated
with the translation unit. */
void
cpp_notice_from_errno (pfile, name)
cpp_reader *pfile;
const char *name;
{
if (name[0] == '\0')
name = "stdout";
cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
} }

View File

@ -54,12 +54,10 @@ struct op
/* With -O2, gcc appears to produce nice code, moving the error /* With -O2, gcc appears to produce nice code, moving the error
message load and subsequent jump completely out of the main path. */ message load and subsequent jump completely out of the main path. */
#define CPP_ICE(msgid) \
do { cpp_ice (pfile, msgid); goto syntax_error; } while(0)
#define SYNTAX_ERROR(msgid) \ #define SYNTAX_ERROR(msgid) \
do { cpp_error (pfile, msgid); goto syntax_error; } while(0) do { cpp_error (pfile, DL_ERROR, msgid); goto syntax_error; } while(0)
#define SYNTAX_ERROR2(msgid, arg) \ #define SYNTAX_ERROR2(msgid, arg) \
do { cpp_error (pfile, msgid, arg); goto syntax_error; } while(0) do { cpp_error (pfile, DL_ERROR, msgid, arg); goto syntax_error; } while(0)
struct suffix struct suffix
{ {
@ -172,23 +170,26 @@ parse_number (pfile, tok)
if (CPP_WTRADITIONAL (pfile) if (CPP_WTRADITIONAL (pfile)
&& sufftab[i].u && sufftab[i].u
&& ! cpp_sys_macro_p (pfile)) && ! cpp_sys_macro_p (pfile))
cpp_warning (pfile, "traditional C rejects the `U' suffix"); cpp_error (pfile, DL_WARNING, "traditional C rejects the `U' suffix");
if (sufftab[i].l == 2 && CPP_OPTION (pfile, pedantic) if (sufftab[i].l == 2 && CPP_OPTION (pfile, pedantic)
&& ! CPP_OPTION (pfile, c99)) && ! CPP_OPTION (pfile, c99))
cpp_pedwarn (pfile, "too many 'l' suffixes in integer constant"); cpp_error (pfile, DL_PEDWARN,
"too many 'l' suffixes in integer constant");
} }
if (base <= largest_digit) if (base <= largest_digit)
cpp_pedwarn (pfile, "integer constant contains digits beyond the radix"); cpp_error (pfile, DL_PEDWARN,
"integer constant contains digits beyond the radix");
if (overflow) if (overflow)
cpp_pedwarn (pfile, "integer constant out of range"); cpp_error (pfile, DL_PEDWARN, "integer constant out of range");
/* If too big to be signed, consider it unsigned. */ /* If too big to be signed, consider it unsigned. */
else if ((HOST_WIDEST_INT) n < 0 && ! op.unsignedp) else if ((HOST_WIDEST_INT) n < 0 && ! op.unsignedp)
{ {
if (base == 10) if (base == 10)
cpp_warning (pfile, "integer constant is so large that it is unsigned"); cpp_error (pfile, DL_WARNING,
"integer constant is so large that it is unsigned");
op.unsignedp = 1; op.unsignedp = 1;
} }
@ -197,7 +198,7 @@ parse_number (pfile, tok)
return op; return op;
invalid_suffix: invalid_suffix:
cpp_error (pfile, "invalid suffix '%.*s' on integer constant", cpp_error (pfile, DL_ERROR, "invalid suffix '%.*s' on integer constant",
(int) (end - p), p); (int) (end - p), p);
syntax_error: syntax_error:
op.op = CPP_ERROR; op.op = CPP_ERROR;
@ -230,20 +231,21 @@ parse_defined (pfile)
node = token->val.node; node = token->val.node;
if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN) if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
{ {
cpp_error (pfile, "missing ')' after \"defined\""); cpp_error (pfile, DL_ERROR, "missing ')' after \"defined\"");
node = 0; node = 0;
} }
} }
else else
{ {
cpp_error (pfile, "operator \"defined\" requires an identifier"); cpp_error (pfile, DL_ERROR,
"operator \"defined\" requires an identifier");
if (token->flags & NAMED_OP) if (token->flags & NAMED_OP)
{ {
cpp_token op; cpp_token op;
op.flags = 0; op.flags = 0;
op.type = token->type; op.type = token->type;
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"(\"%s\" is an alternative token for \"%s\" in C++)", "(\"%s\" is an alternative token for \"%s\" in C++)",
cpp_token_as_text (pfile, token), cpp_token_as_text (pfile, token),
cpp_token_as_text (pfile, &op)); cpp_token_as_text (pfile, &op));
@ -255,7 +257,8 @@ parse_defined (pfile)
else else
{ {
if (pfile->context != initial_context) if (pfile->context != initial_context)
cpp_warning (pfile, "this use of \"defined\" may not be portable"); cpp_error (pfile, DL_WARNING,
"this use of \"defined\" may not be portable");
op.value = node->type == NT_MACRO; op.value = node->type == NT_MACRO;
op.unsignedp = 0; op.unsignedp = 0;
@ -326,7 +329,8 @@ lex (pfile, skip_evaluation)
and stdbool.h has not been included. */ and stdbool.h has not been included. */
if (CPP_PEDANTIC (pfile) if (CPP_PEDANTIC (pfile)
&& ! cpp_defined (pfile, DSC("__bool_true_false_are_defined"))) && ! cpp_defined (pfile, DSC("__bool_true_false_are_defined")))
cpp_pedwarn (pfile, "ISO C++ does not permit \"%s\" in #if", cpp_error (pfile, DL_PEDWARN,
"ISO C++ does not permit \"%s\" in #if",
NODE_NAME (token->val.node)); NODE_NAME (token->val.node));
return op; return op;
} }
@ -337,7 +341,7 @@ lex (pfile, skip_evaluation)
op.value = 0; op.value = 0;
if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation) if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
cpp_warning (pfile, "\"%s\" is not defined", cpp_error (pfile, DL_WARNING, "\"%s\" is not defined",
NODE_NAME (token->val.node)); NODE_NAME (token->val.node));
return op; return op;
} }
@ -378,7 +382,8 @@ integer_overflow (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "integer overflow in preprocessor expression"); cpp_error (pfile, DL_PEDWARN,
"integer overflow in preprocessor expression");
} }
/* Handle shifting A left by B bits. UNSIGNEDP is non-zero if A is /* Handle shifting A left by B bits. UNSIGNEDP is non-zero if A is
@ -657,7 +662,7 @@ _cpp_parse_expr (pfile)
switch (top[1].op) switch (top[1].op)
{ {
default: default:
cpp_ice (pfile, "impossible operator '%s'", cpp_error (pfile, DL_ICE, "impossible operator '%s'",
op_as_text (pfile, top[1].op)); op_as_text (pfile, top[1].op));
goto syntax_error; goto syntax_error;
@ -688,7 +693,7 @@ _cpp_parse_expr (pfile)
top->flags |= HAVE_VALUE; top->flags |= HAVE_VALUE;
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
"traditional C rejects the unary plus operator"); "traditional C rejects the unary plus operator");
} }
else else
@ -767,7 +772,8 @@ _cpp_parse_expr (pfile)
break; break;
case CPP_COMMA: case CPP_COMMA:
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "comma operator in operand of #if"); cpp_error (pfile, DL_PEDWARN,
"comma operator in operand of #if");
top->value = v2; top->value = v2;
top->unsignedp = unsigned2; top->unsignedp = unsigned2;
break; break;
@ -860,7 +866,10 @@ _cpp_parse_expr (pfile)
result = (top[1].value != 0); result = (top[1].value != 0);
if (top != stack) if (top != stack)
CPP_ICE ("unbalanced stack in #if"); {
cpp_error (pfile, DL_ICE, "unbalanced stack in #if");
goto syntax_error;
}
else if (!(top[1].flags & HAVE_VALUE)) else if (!(top[1].flags & HAVE_VALUE))
{ {
SYNTAX_ERROR ("#if with no expression"); SYNTAX_ERROR ("#if with no expression");

View File

@ -392,7 +392,7 @@ read_include_file (pfile, inc)
does not bite us. */ does not bite us. */
if (inc->st.st_size > INTTYPE_MAXIMUM (ssize_t)) if (inc->st.st_size > INTTYPE_MAXIMUM (ssize_t))
{ {
cpp_error (pfile, "%s is too large", inc->name); cpp_error (pfile, DL_ERROR, "%s is too large", inc->name);
goto fail; goto fail;
} }
size = inc->st.st_size; size = inc->st.st_size;
@ -422,8 +422,8 @@ read_include_file (pfile, inc)
if (count == 0) if (count == 0)
{ {
if (!STAT_SIZE_TOO_BIG (inc->st)) if (!STAT_SIZE_TOO_BIG (inc->st))
cpp_warning cpp_error (pfile, DL_WARNING,
(pfile, "%s is shorter than expected", inc->name); "%s is shorter than expected", inc->name);
size = offset; size = offset;
buf = xrealloc (buf, size + 1); buf = xrealloc (buf, size + 1);
inc->st.st_size = size; inc->st.st_size = size;
@ -437,7 +437,7 @@ read_include_file (pfile, inc)
} }
else if (S_ISBLK (inc->st.st_mode)) else if (S_ISBLK (inc->st.st_mode))
{ {
cpp_error (pfile, "%s is a block device", inc->name); cpp_error (pfile, DL_ERROR, "%s is a block device", inc->name);
goto fail; goto fail;
} }
else else
@ -473,7 +473,7 @@ read_include_file (pfile, inc)
return 0; return 0;
perror_fail: perror_fail:
cpp_error_from_errno (pfile, inc->name); cpp_errno (pfile, DL_ERROR, inc->name);
fail: fail:
return 1; return 1;
} }
@ -563,7 +563,8 @@ find_include_file (pfile, header, type)
if (path == NULL) if (path == NULL)
{ {
cpp_error (pfile, "no include path in which to find %s", fname); cpp_error (pfile, DL_ERROR, "no include path in which to find %s",
fname);
return NO_INCLUDE_PATH; return NO_INCLUDE_PATH;
} }
@ -685,12 +686,10 @@ handle_missing_header (pfile, fname, angle_brackets)
we can still produce correct output. Otherwise, we can't produce we can still produce correct output. Otherwise, we can't produce
correct output, because there may be dependencies we need inside correct output, because there may be dependencies we need inside
the missing file, and we don't know what directory this missing the missing file, and we don't know what directory this missing
file exists in. FIXME: Use a future cpp_diagnostic_with_errno () file exists in. */
for both of these cases. */
else if (CPP_PRINT_DEPS (pfile) && ! print_dep)
cpp_warning (pfile, "%s: %s", fname, xstrerror (errno));
else else
cpp_error_from_errno (pfile, fname); cpp_errno (pfile, CPP_PRINT_DEPS (pfile) && ! print_dep
? DL_WARNING: DL_ERROR, fname);
} }
/* Handles #include-family directives (distinguished by TYPE), /* Handles #include-family directives (distinguished by TYPE),
@ -754,7 +753,7 @@ _cpp_read_file (pfile, fname)
if (f == NULL) if (f == NULL)
{ {
cpp_error_from_errno (pfile, fname); cpp_errno (pfile, DL_ERROR, fname);
return false; return false;
} }
@ -1026,7 +1025,7 @@ remap_filename (pfile, name, loc)
/* We know p != name as absolute paths don't call remap_filename. */ /* We know p != name as absolute paths don't call remap_filename. */
if (p == name) if (p == name)
cpp_ice (pfile, "absolute file name in remap_filename"); cpp_error (pfile, DL_ICE, "absolute file name in remap_filename");
dir = (char *) alloca (p - name + 1); dir = (char *) alloca (p - name + 1);
memcpy (dir, name, p - name); memcpy (dir, name, p - name);

View File

@ -356,8 +356,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional) #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
/* In cpperror.c */ /* In cpperror.c */
enum error_type { WARNING = 0, WARNING_SYSHDR, PEDWARN, ERROR, FATAL, ICE }; extern int _cpp_begin_message PARAMS ((cpp_reader *, int,
extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
unsigned int, unsigned int)); unsigned int, unsigned int));
/* In cppmacro.c */ /* In cppmacro.c */

View File

@ -225,7 +225,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
{ {
/* Dirs that don't exist are silently ignored. */ /* Dirs that don't exist are silently ignored. */
if (errno != ENOENT) if (errno != ENOENT)
cpp_notice_from_errno (pfile, dir); cpp_errno (pfile, DL_ERROR, dir);
else if (CPP_OPTION (pfile, verbose)) else if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir); fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
free (dir); free (dir);
@ -234,7 +234,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
if (!S_ISDIR (st.st_mode)) if (!S_ISDIR (st.st_mode))
{ {
cpp_notice (pfile, "%s: Not a directory", dir); cpp_error_with_line (pfile, DL_ERROR, 0, 0, "%s: Not a directory", dir);
free (dir); free (dir);
return; return;
} }
@ -308,15 +308,15 @@ remove_dup_dirs (pfile, head)
{ {
if (cur->sysp && !other->sysp) if (cur->sysp && !other->sysp)
{ {
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
"changing search order for system directory \"%s\"", "changing search order for system directory \"%s\"",
cur->name); cur->name);
if (strcmp (cur->name, other->name)) if (strcmp (cur->name, other->name))
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
" as it is the same as non-system directory \"%s\"", " as it is the same as non-system directory \"%s\"",
other->name); other->name);
else else
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
" as it has already been specified as a non-system directory"); " as it has already been specified as a non-system directory");
} }
cur = remove_dup_dir (pfile, prev); cur = remove_dup_dir (pfile, prev);
@ -1092,7 +1092,7 @@ output_deps (pfile)
deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode); deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode);
if (deps_stream == 0) if (deps_stream == 0)
{ {
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, deps_file)); cpp_errno (pfile, DL_ERROR, CPP_OPTION (pfile, deps_file));
return; return;
} }
} }
@ -1106,7 +1106,7 @@ output_deps (pfile)
if (deps_stream != stdout) if (deps_stream != stdout)
{ {
if (ferror (deps_stream) || fclose (deps_stream) != 0) if (ferror (deps_stream) || fclose (deps_stream) != 0)
cpp_fatal (pfile, "I/O error on output"); cpp_error (pfile, DL_FATAL, "I/O error on output");
} }
} }
@ -1350,7 +1350,8 @@ cpp_handle_option (pfile, argc, argv, ignore)
else if (CPP_OPTION (pfile, out_fname) == NULL) else if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = argv[i]; CPP_OPTION (pfile, out_fname) = argv[i];
else else
cpp_fatal (pfile, "too many filenames. Type %s --help for usage info", cpp_error (pfile, DL_FATAL,
"too many filenames. Type %s --help for usage info",
progname); progname);
} }
else else
@ -1377,7 +1378,8 @@ cpp_handle_option (pfile, argc, argv, ignore)
arg = argv[++i]; arg = argv[++i];
if (!arg) if (!arg)
{ {
cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]); cpp_error (pfile, DL_FATAL,
cl_options[opt_index].msg, argv[i - 1]);
return argc; return argc;
} }
} }
@ -1545,7 +1547,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
CPP_OPTION (pfile, out_fname) = arg; CPP_OPTION (pfile, out_fname) = arg;
else else
{ {
cpp_fatal (pfile, "output filename specified twice"); cpp_error (pfile, DL_FATAL, "output filename specified twice");
return argc; return argc;
} }
break; break;
@ -1657,7 +1659,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
} }
else else
{ {
cpp_fatal (pfile, "-I- specified twice"); cpp_error (pfile, DL_FATAL, "-I- specified twice");
return argc; return argc;
} }
} }
@ -1843,7 +1845,8 @@ cpp_post_options (pfile)
(CPP_OPTION (pfile, print_deps_missing_files) (CPP_OPTION (pfile, print_deps_missing_files)
|| CPP_OPTION (pfile, deps_file) || CPP_OPTION (pfile, deps_file)
|| CPP_OPTION (pfile, deps_phony_targets))) || CPP_OPTION (pfile, deps_phony_targets)))
cpp_fatal (pfile, "you must additionally specify either -M or -MM"); cpp_error (pfile, DL_FATAL,
"you must additionally specify either -M or -MM");
} }
/* Set up dependency-file output. On exit, if print_deps is non-zero /* Set up dependency-file output. On exit, if print_deps is non-zero

View File

@ -150,15 +150,16 @@ trigraph_p (pfile)
if (CPP_OPTION (pfile, warn_trigraphs) && !pfile->state.lexing_comment) if (CPP_OPTION (pfile, warn_trigraphs) && !pfile->state.lexing_comment)
{ {
if (accept) if (accept)
cpp_warning_with_line (pfile, pfile->line, CPP_BUF_COL (buffer) - 1, cpp_error_with_line (pfile, DL_WARNING,
pfile->line, CPP_BUF_COL (buffer) - 1,
"trigraph ??%c converted to %c", "trigraph ??%c converted to %c",
(int) from_char, (int) from_char,
(int) _cpp_trigraph_map[from_char]); (int) _cpp_trigraph_map[from_char]);
else if (buffer->cur != buffer->last_Wtrigraphs) else if (buffer->cur != buffer->last_Wtrigraphs)
{ {
buffer->last_Wtrigraphs = buffer->cur; buffer->last_Wtrigraphs = buffer->cur;
cpp_warning_with_line (pfile, pfile->line, cpp_error_with_line (pfile, DL_WARNING,
CPP_BUF_COL (buffer) - 1, pfile->line, CPP_BUF_COL (buffer) - 1,
"trigraph ??%c ignored", (int) from_char); "trigraph ??%c ignored", (int) from_char);
} }
} }
@ -215,13 +216,15 @@ skip_escaped_newlines (pfile)
if (saved_cur != buffer->cur - 1 if (saved_cur != buffer->cur - 1
&& !pfile->state.lexing_comment) && !pfile->state.lexing_comment)
cpp_warning (pfile, "backslash and newline separated by space"); cpp_error (pfile, DL_WARNING,
"backslash and newline separated by space");
handle_newline (pfile); handle_newline (pfile);
buffer->backup_to = buffer->cur; buffer->backup_to = buffer->cur;
if (buffer->cur == buffer->rlimit) if (buffer->cur == buffer->rlimit)
{ {
cpp_pedwarn (pfile, "backslash-newline at end of file"); cpp_error (pfile, DL_PEDWARN,
"backslash-newline at end of file");
next = EOF; next = EOF;
} }
else else
@ -285,7 +288,7 @@ skip_block_comment (pfile)
Don't bother to get it right across escaped newlines. */ Don't bother to get it right across escaped newlines. */
if (CPP_OPTION (pfile, warn_comments) if (CPP_OPTION (pfile, warn_comments)
&& buffer->cur[0] == '*' && buffer->cur[1] != '/') && buffer->cur[0] == '*' && buffer->cur[1] != '/')
cpp_warning_with_line (pfile, cpp_error_with_line (pfile, DL_WARNING,
pfile->line, CPP_BUF_COL (buffer), pfile->line, CPP_BUF_COL (buffer),
"\"/*\" within comment"); "\"/*\" within comment");
} }
@ -370,12 +373,12 @@ skip_whitespace (pfile, c)
return 0; return 0;
if (!warned) if (!warned)
{ {
cpp_warning (pfile, "null character(s) ignored"); cpp_error (pfile, DL_WARNING, "null character(s) ignored");
warned = 1; warned = 1;
} }
} }
else if (pfile->state.in_directive && CPP_PEDANTIC (pfile)) else if (pfile->state.in_directive && CPP_PEDANTIC (pfile))
cpp_pedwarn_with_line (pfile, pfile->line, cpp_error_with_line (pfile, DL_PEDWARN, pfile->line,
CPP_BUF_COL (buffer), CPP_BUF_COL (buffer),
"%s in preprocessing directive", "%s in preprocessing directive",
c == '\f' ? "form feed" : "vertical tab"); c == '\f' ? "form feed" : "vertical tab");
@ -450,14 +453,14 @@ parse_identifier (pfile)
{ {
/* It is allowed to poison the same identifier twice. */ /* It is allowed to poison the same identifier twice. */
if ((result->flags & NODE_POISONED) && !pfile->state.poisoned_ok) if ((result->flags & NODE_POISONED) && !pfile->state.poisoned_ok)
cpp_error (pfile, "attempt to use poisoned \"%s\"", cpp_error (pfile, DL_ERROR, "attempt to use poisoned \"%s\"",
NODE_NAME (result)); NODE_NAME (result));
/* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the /* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the
replacement list of a variadic macro. */ replacement list of a variadic macro. */
if (result == pfile->spec_nodes.n__VA_ARGS__ if (result == pfile->spec_nodes.n__VA_ARGS__
&& !pfile->state.va_args_ok) && !pfile->state.va_args_ok)
cpp_pedwarn (pfile, cpp_error (pfile, DL_PEDWARN,
"__VA_ARGS__ can only appear in the expansion of a C99 variadic macro"); "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro");
} }
@ -530,7 +533,7 @@ parse_slow (pfile, cur, number_p, plen)
accepted as an extension. Don't warn about it in skipped accepted as an extension. Don't warn about it in skipped
conditional blocks. */ conditional blocks. */
if (saw_dollar && CPP_PEDANTIC (pfile) && ! pfile->state.skipping) if (saw_dollar && CPP_PEDANTIC (pfile) && ! pfile->state.skipping)
cpp_pedwarn (pfile, "'$' character(s) in identifier or number"); cpp_error (pfile, DL_PEDWARN, "'$' character(s) in identifier or number");
/* Identifiers and numbers are null-terminated. */ /* Identifiers and numbers are null-terminated. */
*plen = obstack_object_size (stack); *plen = obstack_object_size (stack);
@ -647,7 +650,8 @@ parse_string (pfile, token, terminator)
comments are. */ comments are. */
unterminated: unterminated:
if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>') if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>')
cpp_error (pfile, "missing terminating %c character", terminator); cpp_error (pfile, DL_ERROR, "missing terminating %c character",
terminator);
buffer->cur--; buffer->cur--;
break; break;
} }
@ -658,7 +662,8 @@ parse_string (pfile, token, terminator)
if (!warned_nulls) if (!warned_nulls)
{ {
warned_nulls = true; warned_nulls = true;
cpp_warning (pfile, "null character(s) preserved in literal"); cpp_error (pfile, DL_WARNING,
"null character(s) preserved in literal");
} }
} }
@ -881,7 +886,7 @@ _cpp_lex_direct (pfile)
/* Non-empty files should end in a newline. Don't warn /* Non-empty files should end in a newline. Don't warn
for command line and _Pragma buffers. */ for command line and _Pragma buffers. */
if (!buffer->from_stage3) if (!buffer->from_stage3)
cpp_pedwarn (pfile, "no newline at end of file"); cpp_error (pfile, DL_PEDWARN, "no newline at end of file");
handle_newline (pfile); handle_newline (pfile);
} }
@ -1001,7 +1006,7 @@ _cpp_lex_direct (pfile)
if (c == '*') if (c == '*')
{ {
if (skip_block_comment (pfile)) if (skip_block_comment (pfile))
cpp_error (pfile, "unterminated comment"); cpp_error (pfile, DL_ERROR, "unterminated comment");
} }
else if (c == '/' && (CPP_OPTION (pfile, cplusplus_comments) else if (c == '/' && (CPP_OPTION (pfile, cplusplus_comments)
|| CPP_IN_SYSTEM_HEADER (pfile))) || CPP_IN_SYSTEM_HEADER (pfile)))
@ -1011,15 +1016,15 @@ _cpp_lex_direct (pfile)
if (CPP_OPTION (pfile, lang) == CLK_GNUC89 && CPP_PEDANTIC (pfile) if (CPP_OPTION (pfile, lang) == CLK_GNUC89 && CPP_PEDANTIC (pfile)
&& ! buffer->warned_cplusplus_comments) && ! buffer->warned_cplusplus_comments)
{ {
cpp_pedwarn (pfile, cpp_error (pfile, DL_PEDWARN,
"C++ style comments are not allowed in ISO C89"); "C++ style comments are not allowed in ISO C89");
cpp_pedwarn (pfile, cpp_error (pfile, DL_PEDWARN,
"(this will be reported only once per input file)"); "(this will be reported only once per input file)");
buffer->warned_cplusplus_comments = 1; buffer->warned_cplusplus_comments = 1;
} }
if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments)) if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
cpp_warning (pfile, "multi-line comment"); cpp_error (pfile, DL_WARNING, "multi-line comment");
} }
else if (c == '=') else if (c == '=')
{ {
@ -1334,7 +1339,8 @@ cpp_spell_token (pfile, token, buffer)
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break; case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break; case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default: default:
cpp_ice (pfile, "unknown string token %s\n", TOKEN_NAME (token)); cpp_error (pfile, DL_ICE, "unknown string token %s\n",
TOKEN_NAME (token));
return buffer; return buffer;
} }
if (tag) *buffer++ = tag; if (tag) *buffer++ = tag;
@ -1346,7 +1352,7 @@ cpp_spell_token (pfile, token, buffer)
break; break;
case SPELL_NONE: case SPELL_NONE:
cpp_ice (pfile, "unspellable token %s", TOKEN_NAME (token)); cpp_error (pfile, DL_ICE, "unspellable token %s", TOKEN_NAME (token));
break; break;
} }
@ -1602,13 +1608,14 @@ maybe_read_ucs (pfile, pstr, limit, pc)
return 1; return 1;
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "the meaning of '\\%c' is different in traditional C", c); cpp_error (pfile, DL_WARNING,
"the meaning of '\\%c' is different in traditional C", c);
length = (c == 'u' ? 4: 8); length = (c == 'u' ? 4: 8);
if ((size_t) (limit - p) < length) if ((size_t) (limit - p) < length)
{ {
cpp_error (pfile, "incomplete universal-character-name"); cpp_error (pfile, DL_ERROR, "incomplete universal-character-name");
/* Skip to the end to avoid more diagnostics. */ /* Skip to the end to avoid more diagnostics. */
p = limit; p = limit;
} }
@ -1621,7 +1628,7 @@ maybe_read_ucs (pfile, pstr, limit, pc)
code = (code << 4) + hex_digit_value (c); code = (code << 4) + hex_digit_value (c);
else else
{ {
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"non-hex digit '%c' in universal-character-name", c); "non-hex digit '%c' in universal-character-name", c);
/* We shouldn't skip in case there are multibyte chars. */ /* We shouldn't skip in case there are multibyte chars. */
break; break;
@ -1630,7 +1637,7 @@ maybe_read_ucs (pfile, pstr, limit, pc)
} }
#ifdef TARGET_EBCDIC #ifdef TARGET_EBCDIC
cpp_error (pfile, "universal-character-name on EBCDIC target"); cpp_error (pfile, DL_ERROR, "universal-character-name on EBCDIC target");
code = 0x3f; /* EBCDIC invalid character */ code = 0x3f; /* EBCDIC invalid character */
#else #else
/* True extended characters are OK. */ /* True extended characters are OK. */
@ -1644,7 +1651,7 @@ maybe_read_ucs (pfile, pstr, limit, pc)
; ;
/* Don't give another error if one occurred above. */ /* Don't give another error if one occurred above. */
else if (length == 0) else if (length == 0)
cpp_error (pfile, "universal-character-name out of range"); cpp_error (pfile, DL_ERROR, "universal-character-name out of range");
#endif #endif
*pstr = p; *pstr = p;
@ -1687,13 +1694,15 @@ cpp_parse_escape (pfile, pstr, limit, mask)
case 'a': case 'a':
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "the meaning of '\\a' is different in traditional C"); cpp_error (pfile, DL_WARNING,
"the meaning of '\\a' is different in traditional C");
c = TARGET_BELL; c = TARGET_BELL;
break; break;
case 'e': case 'E': case 'e': case 'E':
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "non-ISO-standard escape sequence, '\\%c'", c); cpp_error (pfile, DL_PEDWARN,
"non-ISO-standard escape sequence, '\\%c'", c);
c = TARGET_ESC; c = TARGET_ESC;
break; break;
@ -1703,7 +1712,8 @@ cpp_parse_escape (pfile, pstr, limit, mask)
case 'x': case 'x':
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "the meaning of '\\x' is different in traditional C"); cpp_error (pfile, DL_WARNING,
"the meaning of '\\x' is different in traditional C");
{ {
unsigned int i = 0, overflow = 0; unsigned int i = 0, overflow = 0;
@ -1721,11 +1731,13 @@ cpp_parse_escape (pfile, pstr, limit, mask)
} }
if (!digits_found) if (!digits_found)
cpp_error (pfile, "\\x used with no following hex digits"); cpp_error (pfile, DL_ERROR,
"\\x used with no following hex digits");
if (overflow | (i != (i & mask))) if (overflow | (i != (i & mask)))
{ {
cpp_pedwarn (pfile, "hex escape sequence out of range"); cpp_error (pfile, DL_PEDWARN,
"hex escape sequence out of range");
i &= mask; i &= mask;
} }
c = i; c = i;
@ -1749,7 +1761,8 @@ cpp_parse_escape (pfile, pstr, limit, mask)
if (i != (i & mask)) if (i != (i & mask))
{ {
cpp_pedwarn (pfile, "octal escape sequence out of range"); cpp_error (pfile, DL_PEDWARN,
"octal escape sequence out of range");
i &= mask; i &= mask;
} }
c = i; c = i;
@ -1764,13 +1777,13 @@ cpp_parse_escape (pfile, pstr, limit, mask)
if (unknown) if (unknown)
{ {
if (ISGRAPH (c)) if (ISGRAPH (c))
cpp_pedwarn (pfile, "unknown escape sequence '\\%c'", c); cpp_error (pfile, DL_PEDWARN, "unknown escape sequence '\\%c'", c);
else else
cpp_pedwarn (pfile, "unknown escape sequence: '\\%03o'", c); cpp_error (pfile, DL_PEDWARN, "unknown escape sequence: '\\%03o'", c);
} }
if (c > mask) if (c > mask)
cpp_pedwarn (pfile, "escape sequence out of range for character"); cpp_error (pfile, DL_PEDWARN, "escape sequence out of range for type");
*pstr = str; *pstr = str;
return c; return c;
@ -1833,7 +1846,8 @@ cpp_interpret_charconst (pfile, token, warn_multi, pchars_seen)
char_len = local_mbtowc (&wc, str, limit - str); char_len = local_mbtowc (&wc, str, limit - str);
if (char_len == -1) if (char_len == -1)
{ {
cpp_warning (pfile, "ignoring invalid multibyte character"); cpp_error (pfile, DL_WARNING,
"ignoring invalid multibyte character");
c = *str++; c = *str++;
} }
else else
@ -1864,14 +1878,14 @@ cpp_interpret_charconst (pfile, token, warn_multi, pchars_seen)
} }
if (chars_seen == 0) if (chars_seen == 0)
cpp_error (pfile, "empty character constant"); cpp_error (pfile, DL_ERROR, "empty character constant");
else if (chars_seen > max_chars) else if (chars_seen > max_chars)
{ {
chars_seen = max_chars; chars_seen = max_chars;
cpp_warning (pfile, "character constant too long"); cpp_error (pfile, DL_WARNING, "character constant too long");
} }
else if (chars_seen > 1 && warn_multi) else if (chars_seen > 1 && warn_multi)
cpp_warning (pfile, "multi-character character constant"); cpp_error (pfile, DL_WARNING, "multi-character character constant");
/* If relevant type is signed, sign-extend the constant. */ /* If relevant type is signed, sign-extend the constant. */
if (chars_seen) if (chars_seen)

View File

@ -107,7 +107,7 @@ static U_CHAR *dequote_string PARAMS ((cpp_reader *, const U_CHAR *,
unsigned int)); unsigned int));
static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int, static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int,
unsigned long *)); unsigned long *));
static void do_diagnostic PARAMS ((cpp_reader *, enum error_type, int)); static void do_diagnostic PARAMS ((cpp_reader *, int, int));
static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *)); static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *));
static void do_include_common PARAMS ((cpp_reader *, enum include_type)); static void do_include_common PARAMS ((cpp_reader *, enum include_type));
static struct pragma_entry *lookup_pragma_entry static struct pragma_entry *lookup_pragma_entry
@ -225,7 +225,7 @@ check_eol (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF) if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF)
cpp_pedwarn (pfile, "extra tokens at end of #%s directive", cpp_error (pfile, DL_PEDWARN, "extra tokens at end of #%s directive",
pfile->directive->name); pfile->directive->name);
} }
@ -278,7 +278,7 @@ directive_diagnostics (pfile, dir, indented)
if (CPP_PEDANTIC (pfile) if (CPP_PEDANTIC (pfile)
&& ! pfile->state.skipping && ! pfile->state.skipping
&& dir->origin == EXTENSION) && dir->origin == EXTENSION)
cpp_pedwarn (pfile, "#%s is a GCC extension", dir->name); cpp_error (pfile, DL_PEDWARN, "#%s is a GCC extension", dir->name);
/* Traditionally, a directive is ignored unless its # is in /* Traditionally, a directive is ignored unless its # is in
column 1. Therefore in code intended to work with K+R column 1. Therefore in code intended to work with K+R
@ -289,13 +289,14 @@ directive_diagnostics (pfile, dir, indented)
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
{ {
if (dir == &dtable[T_ELIF]) if (dir == &dtable[T_ELIF])
cpp_warning (pfile, "suggest not using #elif in traditional C"); cpp_error (pfile, DL_WARNING,
"suggest not using #elif in traditional C");
else if (indented && dir->origin == KANDR) else if (indented && dir->origin == KANDR)
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
"traditional C ignores #%s with the # indented", "traditional C ignores #%s with the # indented",
dir->name); dir->name);
else if (!indented && dir->origin != KANDR) else if (!indented && dir->origin != KANDR)
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
"suggest hiding #%s from traditional C with an indented #", "suggest hiding #%s from traditional C with an indented #",
dir->name); dir->name);
} }
@ -319,7 +320,7 @@ _cpp_handle_directive (pfile, indented)
if (was_parsing_args) if (was_parsing_args)
{ {
if (CPP_OPTION (pfile, pedantic)) if (CPP_OPTION (pfile, pedantic))
cpp_pedwarn (pfile, cpp_error (pfile, DL_PEDWARN,
"embedding a directive within macro arguments is not portable"); "embedding a directive within macro arguments is not portable");
pfile->state.parsing_args = 0; pfile->state.parsing_args = 0;
pfile->state.prevent_expansion = 0; pfile->state.prevent_expansion = 0;
@ -339,7 +340,8 @@ _cpp_handle_directive (pfile, indented)
dir = &linemarker_dir; dir = &linemarker_dir;
if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed) if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed)
&& ! pfile->state.skipping) && ! pfile->state.skipping)
cpp_pedwarn (pfile, "style of line directive is a GCC extension"); cpp_error (pfile, DL_PEDWARN,
"style of line directive is a GCC extension");
} }
if (dir) if (dir)
@ -388,7 +390,7 @@ _cpp_handle_directive (pfile, indented)
if (CPP_OPTION (pfile, lang) == CLK_ASM) if (CPP_OPTION (pfile, lang) == CLK_ASM)
skip = 0; skip = 0;
else if (!pfile->state.skipping) else if (!pfile->state.skipping)
cpp_error (pfile, "invalid preprocessing directive #%s", cpp_error (pfile, DL_ERROR, "invalid preprocessing directive #%s",
cpp_token_as_text (pfile, dname)); cpp_token_as_text (pfile, dname));
} }
@ -466,14 +468,14 @@ lex_macro_node (pfile)
if (token->type != CPP_NAME) if (token->type != CPP_NAME)
{ {
if (token->type == CPP_EOF) if (token->type == CPP_EOF)
cpp_error (pfile, "no macro name given in #%s directive", cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive",
pfile->directive->name); pfile->directive->name);
else if (token->flags & NAMED_OP) else if (token->flags & NAMED_OP)
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"\"%s\" cannot be used as a macro name as it is an operator in C++", "\"%s\" cannot be used as a macro name as it is an operator in C++",
NODE_NAME (token->val.node)); NODE_NAME (token->val.node));
else else
cpp_error (pfile, "macro names must be identifiers"); cpp_error (pfile, DL_ERROR, "macro names must be identifiers");
return 0; return 0;
} }
@ -484,7 +486,7 @@ lex_macro_node (pfile)
if (node == pfile->spec_nodes.n_defined) if (node == pfile->spec_nodes.n_defined)
{ {
cpp_error (pfile, "\"%s\" cannot be used as a macro name", cpp_error (pfile, DL_ERROR, "\"%s\" cannot be used as a macro name",
NODE_NAME (node)); NODE_NAME (node));
return 0; return 0;
} }
@ -522,7 +524,7 @@ do_undef (pfile)
(*pfile->cb.undef) (pfile, pfile->directive_line, node); (*pfile->cb.undef) (pfile, pfile->directive_line, node);
if (node->flags & NODE_WARN) if (node->flags & NODE_WARN)
cpp_warning (pfile, "undefining \"%s\"", NODE_NAME (node)); cpp_error (pfile, DL_WARNING, "undefining \"%s\"", NODE_NAME (node));
_cpp_free_definition (node); _cpp_free_definition (node);
} }
@ -565,7 +567,7 @@ glue_header_name (pfile)
} }
if (token->type == CPP_EOF) if (token->type == CPP_EOF)
cpp_error (pfile, "missing terminating > character"); cpp_error (pfile, DL_ERROR, "missing terminating > character");
else else
{ {
unsigned char *token_mem = _cpp_unaligned_alloc (pfile, total_len + 1); unsigned char *token_mem = _cpp_unaligned_alloc (pfile, total_len + 1);
@ -603,7 +605,8 @@ parse_include (pfile)
{ {
if (header->type != CPP_LESS) if (header->type != CPP_LESS)
{ {
cpp_error (pfile, "#%s expects \"FILENAME\" or <FILENAME>", dir); cpp_error (pfile, DL_ERROR,
"#%s expects \"FILENAME\" or <FILENAME>", dir);
return NULL; return NULL;
} }
@ -614,7 +617,7 @@ parse_include (pfile)
if (header->val.str.len == 0) if (header->val.str.len == 0)
{ {
cpp_error (pfile, "empty file name in #%s", dir); cpp_error (pfile, DL_ERROR, "empty file name in #%s", dir);
return NULL; return NULL;
} }
@ -633,13 +636,13 @@ do_include_common (pfile, type)
use the normal search logic. */ use the normal search logic. */
if (type == IT_INCLUDE_NEXT && ! pfile->buffer->prev) if (type == IT_INCLUDE_NEXT && ! pfile->buffer->prev)
{ {
cpp_warning (pfile, "#include_next in primary source file"); cpp_error (pfile, DL_WARNING, "#include_next in primary source file");
type = IT_INCLUDE; type = IT_INCLUDE;
} }
else if (type == IT_IMPORT && CPP_OPTION (pfile, warn_import)) else if (type == IT_IMPORT && CPP_OPTION (pfile, warn_import))
{ {
CPP_OPTION (pfile, warn_import) = 0; CPP_OPTION (pfile, warn_import) = 0;
cpp_warning (pfile, cpp_error (pfile, DL_WARNING,
"#import is obsolete, use an #ifndef wrapper in the header file"); "#import is obsolete, use an #ifndef wrapper in the header file");
} }
@ -648,7 +651,7 @@ do_include_common (pfile, type)
{ {
/* Prevent #include recursion. */ /* Prevent #include recursion. */
if (pfile->line_maps.depth >= CPP_STACK_MAX) if (pfile->line_maps.depth >= CPP_STACK_MAX)
cpp_fatal (pfile, "#include nested too deeply"); cpp_error (pfile, DL_FATAL, "#include nested too deeply");
else else
{ {
check_eol (pfile); check_eol (pfile);
@ -706,7 +709,7 @@ read_flag (pfile, last)
} }
if (token->type != CPP_EOF) if (token->type != CPP_EOF)
cpp_error (pfile, "invalid flag \"%s\" in line directive", cpp_error (pfile, DL_ERROR, "invalid flag \"%s\" in line directive",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return 0; return 0;
} }
@ -788,13 +791,14 @@ do_line (pfile)
|| strtoul_for_line (token->val.str.text, token->val.str.len, || strtoul_for_line (token->val.str.text, token->val.str.len,
&new_lineno)) &new_lineno))
{ {
cpp_error (pfile, "\"%s\" after #line is not a positive integer", cpp_error (pfile, DL_ERROR,
"\"%s\" after #line is not a positive integer",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return; return;
} }
if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap)) if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
cpp_pedwarn (pfile, "line number out of range"); cpp_error (pfile, DL_PEDWARN, "line number out of range");
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if (token->type == CPP_STRING) if (token->type == CPP_STRING)
@ -805,7 +809,7 @@ do_line (pfile)
} }
else if (token->type != CPP_EOF) else if (token->type != CPP_EOF)
{ {
cpp_error (pfile, "\"%s\" is not a valid filename", cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return; return;
} }
@ -840,7 +844,7 @@ do_linemarker (pfile)
|| strtoul_for_line (token->val.str.text, token->val.str.len, || strtoul_for_line (token->val.str.text, token->val.str.len,
&new_lineno)) &new_lineno))
{ {
cpp_error (pfile, "\"%s\" after # is not a positive integer", cpp_error (pfile, DL_ERROR, "\"%s\" after # is not a positive integer",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return; return;
} }
@ -876,7 +880,7 @@ do_linemarker (pfile)
} }
else if (token->type != CPP_EOF) else if (token->type != CPP_EOF)
{ {
cpp_error (pfile, "\"%s\" is not a valid filename", cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return; return;
} }
@ -909,10 +913,12 @@ _cpp_do_file_change (pfile, reason, to_file, file_line, sysp)
static void static void
do_diagnostic (pfile, code, print_dir) do_diagnostic (pfile, code, print_dir)
cpp_reader *pfile; cpp_reader *pfile;
enum error_type code; int code;
int print_dir; int print_dir;
{ {
if (_cpp_begin_message (pfile, code, 0, 0)) if (_cpp_begin_message (pfile, code,
pfile->cur_token[-1].line,
pfile->cur_token[-1].col))
{ {
if (print_dir) if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name); fprintf (stderr, "#%s ", pfile->directive->name);
@ -926,7 +932,7 @@ static void
do_error (pfile) do_error (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
do_diagnostic (pfile, ERROR, 1); do_diagnostic (pfile, DL_ERROR, 1);
} }
static void static void
@ -934,7 +940,7 @@ do_warning (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
/* We want #warning diagnostics to be emitted in system headers too. */ /* We want #warning diagnostics to be emitted in system headers too. */
do_diagnostic (pfile, WARNING_SYSHDR, 1); do_diagnostic (pfile, DL_WARNING_SYSHDR, 1);
} }
/* Report program identification. */ /* Report program identification. */
@ -945,7 +951,7 @@ do_ident (pfile)
const cpp_token *str = cpp_get_token (pfile); const cpp_token *str = cpp_get_token (pfile);
if (str->type != CPP_STRING) if (str->type != CPP_STRING)
cpp_error (pfile, "invalid #ident directive"); cpp_error (pfile, DL_ERROR, "invalid #ident directive");
else if (pfile->cb.ident) else if (pfile->cb.ident)
(*pfile->cb.ident) (pfile, pfile->directive_line, &str->val.str); (*pfile->cb.ident) (pfile, pfile->directive_line, &str->val.str);
@ -1032,13 +1038,14 @@ cpp_register_pragma (pfile, space, name, handler)
{ {
if (entry->is_nspace) if (entry->is_nspace)
clash: clash:
cpp_ice (pfile, cpp_error (pfile, DL_ICE,
"registering \"%s\" as both a pragma and a pragma namespace", "registering \"%s\" as both a pragma and a pragma namespace",
NODE_NAME (node)); NODE_NAME (node));
else if (space) else if (space)
cpp_ice (pfile, "#pragma %s %s is already registered", space, name); cpp_error (pfile, DL_ICE, "#pragma %s %s is already registered",
space, name);
else else
cpp_ice (pfile, "#pragma %s is already registered", name); cpp_error (pfile, DL_ICE, "#pragma %s is already registered", name);
} }
else else
insert_pragma_entry (pfile, chain, node, handler); insert_pragma_entry (pfile, chain, node, handler);
@ -1113,10 +1120,10 @@ static void
do_pragma_once (pfile) do_pragma_once (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_warning (pfile, "#pragma once is obsolete"); cpp_error (pfile, DL_WARNING, "#pragma once is obsolete");
if (pfile->buffer->prev == NULL) if (pfile->buffer->prev == NULL)
cpp_warning (pfile, "#pragma once in main file"); cpp_error (pfile, DL_WARNING, "#pragma once in main file");
else else
_cpp_never_reread (pfile->buffer->inc); _cpp_never_reread (pfile->buffer->inc);
@ -1140,7 +1147,7 @@ do_pragma_poison (pfile)
break; break;
if (tok->type != CPP_NAME) if (tok->type != CPP_NAME)
{ {
cpp_error (pfile, "invalid #pragma GCC poison directive"); cpp_error (pfile, DL_ERROR, "invalid #pragma GCC poison directive");
break; break;
} }
@ -1149,7 +1156,8 @@ do_pragma_poison (pfile)
continue; continue;
if (hp->type == NT_MACRO) if (hp->type == NT_MACRO)
cpp_warning (pfile, "poisoning existing macro \"%s\"", NODE_NAME (hp)); cpp_error (pfile, DL_WARNING, "poisoning existing macro \"%s\"",
NODE_NAME (hp));
_cpp_free_definition (hp); _cpp_free_definition (hp);
hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC; hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC;
} }
@ -1169,7 +1177,8 @@ do_pragma_system_header (pfile)
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
if (buffer->prev == 0) if (buffer->prev == 0)
cpp_warning (pfile, "#pragma system_header ignored outside include file"); cpp_error (pfile, DL_WARNING,
"#pragma system_header ignored outside include file");
else else
{ {
check_eol (pfile); check_eol (pfile);
@ -1194,16 +1203,16 @@ do_pragma_dependency (pfile)
ordering = _cpp_compare_file_date (pfile, header); ordering = _cpp_compare_file_date (pfile, header);
if (ordering < 0) if (ordering < 0)
cpp_warning (pfile, "cannot find source %s", cpp_error (pfile, DL_WARNING, "cannot find source %s",
cpp_token_as_text (pfile, header)); cpp_token_as_text (pfile, header));
else if (ordering > 0) else if (ordering > 0)
{ {
cpp_warning (pfile, "current file is older than %s", cpp_error (pfile, DL_WARNING, "current file is older than %s",
cpp_token_as_text (pfile, header)); cpp_token_as_text (pfile, header));
if (cpp_get_token (pfile)->type != CPP_EOF) if (cpp_get_token (pfile)->type != CPP_EOF)
{ {
_cpp_backup_tokens (pfile, 1); _cpp_backup_tokens (pfile, 1);
do_diagnostic (pfile, WARNING, 0); do_diagnostic (pfile, DL_WARNING, 0);
} }
} }
} }
@ -1273,7 +1282,8 @@ _cpp_do__Pragma (pfile)
const cpp_token *string = get__Pragma_string (pfile); const cpp_token *string = get__Pragma_string (pfile);
if (!string) if (!string)
cpp_error (pfile, "_Pragma takes a parenthesized string literal"); cpp_error (pfile, DL_ERROR,
"_Pragma takes a parenthesized string literal");
else else
{ {
/* Ideally, we'd like /* Ideally, we'd like
@ -1372,13 +1382,13 @@ do_else (pfile)
struct if_stack *ifs = buffer->if_stack; struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL) if (ifs == NULL)
cpp_error (pfile, "#else without #if"); cpp_error (pfile, DL_ERROR, "#else without #if");
else else
{ {
if (ifs->type == T_ELSE) if (ifs->type == T_ELSE)
{ {
cpp_error (pfile, "#else after #else"); cpp_error (pfile, DL_ERROR, "#else after #else");
cpp_error_with_line (pfile, ifs->line, 0, cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"the conditional began here"); "the conditional began here");
} }
ifs->type = T_ELSE; ifs->type = T_ELSE;
@ -1406,13 +1416,13 @@ do_elif (pfile)
struct if_stack *ifs = buffer->if_stack; struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL) if (ifs == NULL)
cpp_error (pfile, "#elif without #if"); cpp_error (pfile, DL_ERROR, "#elif without #if");
else else
{ {
if (ifs->type == T_ELSE) if (ifs->type == T_ELSE)
{ {
cpp_error (pfile, "#elif after #else"); cpp_error (pfile, DL_ERROR, "#elif after #else");
cpp_error_with_line (pfile, ifs->line, 0, cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"the conditional began here"); "the conditional began here");
} }
ifs->type = T_ELIF; ifs->type = T_ELIF;
@ -1442,7 +1452,7 @@ do_endif (pfile)
struct if_stack *ifs = buffer->if_stack; struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL) if (ifs == NULL)
cpp_error (pfile, "#endif without #if"); cpp_error (pfile, DL_ERROR, "#endif without #if");
else else
{ {
/* Only check EOL if was not originally skipping. */ /* Only check EOL if was not originally skipping. */
@ -1525,7 +1535,7 @@ parse_answer (pfile, answerp, type)
if (type == T_UNASSERT && paren->type == CPP_EOF) if (type == T_UNASSERT && paren->type == CPP_EOF)
return 0; return 0;
cpp_error (pfile, "missing '(' after predicate"); cpp_error (pfile, DL_ERROR, "missing '(' after predicate");
return 1; return 1;
} }
@ -1540,7 +1550,7 @@ parse_answer (pfile, answerp, type)
if (token->type == CPP_EOF) if (token->type == CPP_EOF)
{ {
cpp_error (pfile, "missing ')' to complete answer"); cpp_error (pfile, DL_ERROR, "missing ')' to complete answer");
return 1; return 1;
} }
@ -1560,7 +1570,7 @@ parse_answer (pfile, answerp, type)
if (acount == 0) if (acount == 0)
{ {
cpp_error (pfile, "predicate's answer is empty"); cpp_error (pfile, DL_ERROR, "predicate's answer is empty");
return 1; return 1;
} }
@ -1590,9 +1600,9 @@ parse_assertion (pfile, answerp, type)
*answerp = 0; *answerp = 0;
predicate = cpp_get_token (pfile); predicate = cpp_get_token (pfile);
if (predicate->type == CPP_EOF) if (predicate->type == CPP_EOF)
cpp_error (pfile, "assertion without predicate"); cpp_error (pfile, DL_ERROR, "assertion without predicate");
else if (predicate->type != CPP_NAME) else if (predicate->type != CPP_NAME)
cpp_error (pfile, "predicate must be an identifier"); cpp_error (pfile, DL_ERROR, "predicate must be an identifier");
else if (parse_answer (pfile, answerp, type) == 0) else if (parse_answer (pfile, answerp, type) == 0)
{ {
unsigned int len = NODE_LEN (predicate->val.node); unsigned int len = NODE_LEN (predicate->val.node);
@ -1674,7 +1684,8 @@ do_assert (pfile)
{ {
if (*find_answer (node, new_answer)) if (*find_answer (node, new_answer))
{ {
cpp_warning (pfile, "\"%s\" re-asserted", NODE_NAME (node) + 1); cpp_error (pfile, DL_WARNING, "\"%s\" re-asserted",
NODE_NAME (node) + 1);
return; return;
} }
new_answer->next = node->value.answers; new_answer->next = node->value.answers;
@ -1903,7 +1914,7 @@ _cpp_pop_buffer (pfile)
/* Walk back up the conditional stack till we reach its level at /* Walk back up the conditional stack till we reach its level at
entry to this file, issuing error messages. */ entry to this file, issuing error messages. */
for (ifs = buffer->if_stack; ifs; ifs = ifs->next) for (ifs = buffer->if_stack; ifs; ifs = ifs->next)
cpp_error_with_line (pfile, ifs->line, 0, cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"unterminated #%s", dtable[ifs->type].name); "unterminated #%s", dtable[ifs->type].name);
/* In case of a missing #endif. */ /* In case of a missing #endif. */

View File

@ -546,32 +546,50 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
int, int)); int, int));
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int)); extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
/* Diagnostic levels. To get a dianostic without associating a
position in the translation unit with it, use cpp_error_with_line
with a line number of zero. */
/* Warning, an error with -Werror. */
#define DL_WARNING 0x00
/* Same as DL_WARNING, except it is not suppressed in system headers. */
#define DL_WARNING_SYSHDR 0x01
/* Warning, an error with -pedantic-errors or -Werror. */
#define DL_PEDWARN 0x02
/* An error. */
#define DL_ERROR 0x03
/* A fatal error. We do not exit, to support use of cpplib as a
library, but may only return CPP_EOF tokens thereon. It is the
caller's responsibility to check CPP_FATAL_ERRORS. */
#define DL_FATAL 0x04
/* An internal consistency check failed. Prints "internal error: ",
otherwise the same as DL_FATAL. */
#define DL_ICE 0x05
/* Extracts a diagnostic level from an int. */
#define DL_EXTRACT(l) (l & 0xf)
/* Non-zero if a diagnostic level is one of the warnings. */
#define DL_WARNING_P(l) (DL_EXTRACT (l) >= DL_WARNING \
&& DL_EXTRACT (l) <= DL_PEDWARN)
/* N.B. The error-message-printer prototypes have not been nicely /* N.B. The error-message-printer prototypes have not been nicely
formatted because exgettext needs to see 'msgid' on the same line formatted because exgettext needs to see 'msgid' on the same line
as the name of the function in order to work properly. Only the as the name of the function in order to work properly. Only the
string argument gets a name in an effort to keep the lines from string argument gets a name in an effort to keep the lines from
getting ridiculously oversized. */ getting ridiculously oversized. */
extern void cpp_ice PARAMS ((cpp_reader *, const char *msgid, ...)) /* Output a diagnostic of some kind. */
ATTRIBUTE_PRINTF_2; extern void cpp_error PARAMS ((cpp_reader *, int, const char *msgid, ...))
extern void cpp_fatal PARAMS ((cpp_reader *, const char *msgid, ...)) ATTRIBUTE_PRINTF_3;
ATTRIBUTE_PRINTF_2;
extern void cpp_error PARAMS ((cpp_reader *, const char *msgid, ...)) /* Output a diagnostic of severity LEVEL, with "MSG: " preceding the
ATTRIBUTE_PRINTF_2; error string of errno. No location is printed. */
extern void cpp_warning PARAMS ((cpp_reader *, const char *msgid, ...)) extern void cpp_errno PARAMS ((cpp_reader *, int level, const char *msg));
ATTRIBUTE_PRINTF_2;
extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *msgid, ...)) /* Same as cpp_error, except additionally specifies a position as a
ATTRIBUTE_PRINTF_2; (translation unit) physical line and physical column. If the line is
extern void cpp_notice PARAMS ((cpp_reader *, const char *msgid, ...)) zero, then no location is printed. */
ATTRIBUTE_PRINTF_2; extern void cpp_error_with_line PARAMS ((cpp_reader *, int, unsigned, unsigned, const char *msgid, ...))
extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...)) ATTRIBUTE_PRINTF_5;
ATTRIBUTE_PRINTF_4;
extern void cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
/* In cpplex.c */ /* In cpplex.c */
extern int cpp_ideq PARAMS ((const cpp_token *, extern int cpp_ideq PARAMS ((const cpp_token *,

View File

@ -143,7 +143,8 @@ builtin_macro (pfile, node)
switch (node->value.builtin) switch (node->value.builtin)
{ {
default: 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; return 0;
case BT_FILE: case BT_FILE:
@ -344,7 +345,8 @@ stringify_arg (pfile, arg)
/* Ignore the final \ of invalid string literals. */ /* Ignore the final \ of invalid string literals. */
if (backslash_count & 1) if (backslash_count & 1)
{ {
cpp_warning (pfile, "invalid string literal, ignoring final '\\'"); cpp_error (pfile, DL_WARNING,
"invalid string literal, ignoring final '\\'");
dest--; dest--;
} }
@ -435,7 +437,7 @@ paste_all_tokens (pfile, lhs)
/* Mandatory warning for all apart from assembler. */ /* Mandatory warning for all apart from assembler. */
if (CPP_OPTION (pfile, lang) != CLK_ASM) 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", "pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
cpp_token_as_text (pfile, lhs), cpp_token_as_text (pfile, lhs),
cpp_token_as_text (pfile, rhs)); cpp_token_as_text (pfile, rhs));
@ -555,7 +557,8 @@ collect_args (pfile, node)
callers at the end of an -include-d file. */ callers at the end of an -include-d file. */
if (pfile->context->prev || pfile->state.in_directive) if (pfile->context->prev || pfile->state.in_directive)
_cpp_backup_tokens (pfile, 1); _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)); NODE_NAME (node));
error = true; error = true;
} }
@ -572,11 +575,12 @@ collect_args (pfile, node)
if (argc + 1 == macro->paramc && macro->variadic) if (argc + 1 == macro->paramc && macro->variadic)
{ {
if (CPP_PEDANTIC (pfile) && ! macro->syshdr) 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 else
{ {
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"macro \"%s\" requires %u arguments, but only %u given", "macro \"%s\" requires %u arguments, but only %u given",
NODE_NAME (node), macro->paramc, argc); NODE_NAME (node), macro->paramc, argc);
error = true; error = true;
@ -587,7 +591,7 @@ collect_args (pfile, node)
/* Empty argument to a macro taking no arguments is OK. */ /* Empty argument to a macro taking no arguments is OK. */
if (argc != 1 || arg->count) if (argc != 1 || arg->count)
{ {
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"macro \"%s\" passed %u arguments, but takes just %u", "macro \"%s\" passed %u arguments, but takes just %u",
NODE_NAME (node), argc, macro->paramc); NODE_NAME (node), argc, macro->paramc);
error = true; error = true;
@ -670,7 +674,7 @@ enter_macro_context (pfile, node)
if (buff == NULL) if (buff == NULL)
{ {
if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr) 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", "function-like macro \"%s\" must be used with arguments in traditional C",
NODE_NAME (node)); NODE_NAME (node));
@ -1169,7 +1173,8 @@ save_parameter (pfile, macro, node)
/* Constraint 6.10.3.6 - duplicate parameter names. */ /* Constraint 6.10.3.6 - duplicate parameter names. */
if (node->arg_index) 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; return 1;
} }
@ -1203,14 +1208,16 @@ parse_params (pfile, macro)
&& ! CPP_OPTION (pfile, discard_comments_in_macro_exp)) && ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
continue; continue;
cpp_error (pfile, "\"%s\" may not appear in macro parameter list", cpp_error (pfile, DL_ERROR,
"\"%s\" may not appear in macro parameter list",
cpp_token_as_text (pfile, token)); cpp_token_as_text (pfile, token));
return 0; return 0;
case CPP_NAME: case CPP_NAME:
if (prev_ident) 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; return 0;
} }
prev_ident = 1; prev_ident = 1;
@ -1227,7 +1234,7 @@ parse_params (pfile, macro)
case CPP_COMMA: case CPP_COMMA:
if (!prev_ident) if (!prev_ident)
{ {
cpp_error (pfile, "parameter name missing"); cpp_error (pfile, DL_ERROR, "parameter name missing");
return 0; return 0;
} }
prev_ident = 0; prev_ident = 0;
@ -1240,11 +1247,12 @@ parse_params (pfile, macro)
save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__); save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__);
pfile->state.va_args_ok = 1; pfile->state.va_args_ok = 1;
if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic)) if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic))
cpp_pedwarn (pfile, cpp_error (pfile, DL_PEDWARN,
"anonymous variadic macros were introduced in C99"); "anonymous variadic macros were introduced in C99");
} }
else if (CPP_OPTION (pfile, pedantic)) 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. */ /* We're at the end, and just expect a closing parenthesis. */
token = _cpp_lex_token (pfile); token = _cpp_lex_token (pfile);
@ -1253,7 +1261,7 @@ parse_params (pfile, macro)
/* Fall through. */ /* Fall through. */
case CPP_EOF: case CPP_EOF:
cpp_error (pfile, "missing ')' in macro parameter list"); cpp_error (pfile, DL_ERROR, "missing ')' in macro parameter list");
return 0; return 0;
} }
} }
@ -1331,7 +1339,8 @@ _cpp_create_definition (pfile, node)
macro->fun_like = 1; macro->fun_like = 1;
} }
else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE)) 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; saved_cur_token = pfile->cur_token;
@ -1361,7 +1370,8 @@ _cpp_create_definition (pfile, node)
else if (CPP_OPTION (pfile, lang) != CLK_ASM) else if (CPP_OPTION (pfile, lang) != CLK_ASM)
{ {
ok = 0; 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; goto cleanup1;
} }
} }
@ -1380,7 +1390,7 @@ _cpp_create_definition (pfile, node)
if (macro->count == 0 || token->type == CPP_EOF) if (macro->count == 0 || token->type == CPP_EOF)
{ {
ok = 0; ok = 0;
cpp_error (pfile, cpp_error (pfile, DL_ERROR,
"'##' cannot appear at either end of a macro expansion"); "'##' cannot appear at either end of a macro expansion");
goto cleanup1; goto cleanup1;
} }
@ -1416,11 +1426,11 @@ _cpp_create_definition (pfile, node)
{ {
if (warn_of_redefinition (node, macro)) if (warn_of_redefinition (node, macro))
{ {
cpp_pedwarn_with_line (pfile, pfile->directive_line, 0, cpp_error_with_line (pfile, DL_PEDWARN, pfile->directive_line, 0,
"\"%s\" redefined", NODE_NAME (node)); "\"%s\" redefined", NODE_NAME (node));
if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) 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"); "this is the location of the previous definition");
} }
_cpp_free_definition (node); _cpp_free_definition (node);
@ -1484,7 +1494,7 @@ check_trad_stringification (pfile, macro, string)
if (NODE_LEN (node) == len if (NODE_LEN (node) == len
&& !memcmp (p, NODE_NAME (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", "macro argument \"%s\" would be stringified in traditional C",
NODE_NAME (node)); NODE_NAME (node));
break; break;
@ -1509,7 +1519,8 @@ cpp_macro_definition (pfile, node)
if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN)) 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; return 0;
} }

View File

@ -89,7 +89,7 @@ cpp_preprocess_file (pfile)
print.outf = fopen (options->out_fname, "w"); print.outf = fopen (options->out_fname, "w");
if (print.outf == NULL) if (print.outf == NULL)
{ {
cpp_notice_from_errno (pfile, options->out_fname); cpp_errno (pfile, DL_ERROR, options->out_fname);
return; return;
} }
} }
@ -120,7 +120,7 @@ cpp_preprocess_file (pfile)
if (print.outf != stdout) if (print.outf != stdout)
{ {
if (ferror (print.outf) || fclose (print.outf)) if (ferror (print.outf) || fclose (print.outf))
cpp_notice_from_errno (pfile, options->out_fname); cpp_errno (pfile, DL_ERROR, options->out_fname);
} }
} }

View File

@ -633,7 +633,7 @@ read_scan_file (in_fname, argc, argv)
i = cpp_handle_options (scan_in, argc, argv); i = cpp_handle_options (scan_in, argc, argv);
if (i < argc && ! CPP_FATAL_ERRORS (scan_in)) if (i < argc && ! CPP_FATAL_ERRORS (scan_in))
cpp_fatal (scan_in, "Invalid option `%s'", argv[i]); cpp_error (scan_in, DL_FATAL, "invalid option `%s'", argv[i]);
cpp_post_options (scan_in); cpp_post_options (scan_in);
if (CPP_FATAL_ERRORS (scan_in)) if (CPP_FATAL_ERRORS (scan_in))
exit (FATAL_EXIT_CODE); exit (FATAL_EXIT_CODE);