Commit ebef4e8c by Neil Booth Committed by Neil Booth

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
parent c19a3859
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>
* config/ia64/linux.h (CPP_PREDEFINES): Fix missing backslash.
......
......@@ -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));
/* 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
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
print_location (pfile, line, col)
cpp_reader *pfile;
unsigned int line, col;
{
cpp_buffer *buffer = pfile->buffer;
if (!buffer)
if (!pfile->buffer || line == 0)
fprintf (stderr, "%s: ", progname);
else
{
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);
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
at the location of the previously lexed token, which tends to be the
correct place by default. Returns 0 if the error has been suppressed. */
at the location of the previously lexed token, which tends to be
the correct place by default. Returns 0 if the error has been
suppressed. */
int
_cpp_begin_message (pfile, code, line, column)
cpp_reader *pfile;
enum error_type code;
int code;
unsigned int line, column;
{
int is_warning = 0;
int level = DL_EXTRACT (code);
switch (code)
switch (level)
{
case PEDWARN:
case WARNING:
case DL_WARNING:
case DL_PEDWARN:
if (CPP_IN_SYSTEM_HEADER (pfile)
&& ! CPP_OPTION (pfile, warn_system_headers))
return 0;
case WARNING_SYSHDR:
/* Fall through. */
case DL_WARNING_SYSHDR:
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))
return 0;
if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++;
}
else
{
if (CPP_OPTION (pfile, inhibit_warnings))
else if (CPP_OPTION (pfile, inhibit_warnings))
return 0;
is_warning = 1;
}
break;
case ERROR:
case DL_ERROR:
if (CPP_OPTION (pfile, inhibit_errors))
return 0;
if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++;
break;
/* Fatal errors cannot be inhibited. */
case FATAL:
pfile->errors = CPP_FATAL_LIMIT;
break;
case ICE:
fprintf (stderr, _("internal error: "));
case DL_FATAL:
case DL_ICE:
pfile->errors = CPP_FATAL_LIMIT;
break;
}
print_location (pfile, line, column);
if (is_warning)
if (DL_WARNING_P (level))
fputs (_("warning: "), stderr);
else if (level == DL_ICE)
fputs (_("internal error: "), stderr);
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. */
/* For reporting internal errors. Prints "internal error: " for you,
otherwise identical to cpp_fatal. */
/* Print an error at the location of the previously lexed token. */
void
cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
cpp_error VPARAMS ((cpp_reader * pfile, int level, 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);
}
unsigned int line, column;
/* 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, int, level);
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. */
void
cpp_error 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->buffer)
{
line = pfile->cur_token[-1].line;
column = pfile->cur_token[-1].col;
}
else
line = column = 0;
if (_cpp_begin_message (pfile, ERROR, 0, 0))
if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
......@@ -185,116 +156,31 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
/* Print an error at a specific location. */
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, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, int, level);
VA_FIXEDARG (ap, unsigned int, line);
VA_FIXEDARG (ap, unsigned int, column);
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);
VA_CLOSE (ap);
}
/* Error including a message from `errno'. */
void
cpp_error_from_errno (pfile, name)
cpp_errno (pfile, level, msgid)
cpp_reader *pfile;
const char *name;
{
cpp_error (pfile, "%s: %s", name, xstrerror (errno));
}
/* Print a warning at the location of the previously lexed token. */
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, ...))
int level;
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 (msgid[0] == '\0')
msgid = _("stdout");
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));
cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
}
......@@ -54,12 +54,10 @@ struct op
/* With -O2, gcc appears to produce nice code, moving the error
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) \
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) \
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
{
......@@ -172,23 +170,26 @@ parse_number (pfile, tok)
if (CPP_WTRADITIONAL (pfile)
&& sufftab[i].u
&& ! 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)
&& ! 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)
cpp_pedwarn (pfile, "integer constant contains digits beyond the radix");
cpp_error (pfile, DL_PEDWARN,
"integer constant contains digits beyond the radix");
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. */
else if ((HOST_WIDEST_INT) n < 0 && ! op.unsignedp)
{
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;
}
......@@ -197,7 +198,7 @@ parse_number (pfile, tok)
return op;
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);
syntax_error:
op.op = CPP_ERROR;
......@@ -230,20 +231,21 @@ parse_defined (pfile)
node = token->val.node;
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;
}
}
else
{
cpp_error (pfile, "operator \"defined\" requires an identifier");
cpp_error (pfile, DL_ERROR,
"operator \"defined\" requires an identifier");
if (token->flags & NAMED_OP)
{
cpp_token op;
op.flags = 0;
op.type = token->type;
cpp_error (pfile,
cpp_error (pfile, DL_ERROR,
"(\"%s\" is an alternative token for \"%s\" in C++)",
cpp_token_as_text (pfile, token),
cpp_token_as_text (pfile, &op));
......@@ -255,7 +257,8 @@ parse_defined (pfile)
else
{
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.unsignedp = 0;
......@@ -326,7 +329,8 @@ lex (pfile, skip_evaluation)
and stdbool.h has not been included. */
if (CPP_PEDANTIC (pfile)
&& ! 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));
return op;
}
......@@ -337,7 +341,7 @@ lex (pfile, skip_evaluation)
op.value = 0;
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));
return op;
}
......@@ -378,7 +382,8 @@ integer_overflow (pfile)
cpp_reader *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
......@@ -657,7 +662,7 @@ _cpp_parse_expr (pfile)
switch (top[1].op)
{
default:
cpp_ice (pfile, "impossible operator '%s'",
cpp_error (pfile, DL_ICE, "impossible operator '%s'",
op_as_text (pfile, top[1].op));
goto syntax_error;
......@@ -688,7 +693,7 @@ _cpp_parse_expr (pfile)
top->flags |= HAVE_VALUE;
if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile,
cpp_error (pfile, DL_WARNING,
"traditional C rejects the unary plus operator");
}
else
......@@ -767,7 +772,8 @@ _cpp_parse_expr (pfile)
break;
case CPP_COMMA:
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->unsignedp = unsigned2;
break;
......@@ -860,7 +866,10 @@ _cpp_parse_expr (pfile)
result = (top[1].value != 0);
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))
{
SYNTAX_ERROR ("#if with no expression");
......
......@@ -392,7 +392,7 @@ read_include_file (pfile, inc)
does not bite us. */
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;
}
size = inc->st.st_size;
......@@ -422,8 +422,8 @@ read_include_file (pfile, inc)
if (count == 0)
{
if (!STAT_SIZE_TOO_BIG (inc->st))
cpp_warning
(pfile, "%s is shorter than expected", inc->name);
cpp_error (pfile, DL_WARNING,
"%s is shorter than expected", inc->name);
size = offset;
buf = xrealloc (buf, size + 1);
inc->st.st_size = size;
......@@ -437,7 +437,7 @@ read_include_file (pfile, inc)
}
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;
}
else
......@@ -473,7 +473,7 @@ read_include_file (pfile, inc)
return 0;
perror_fail:
cpp_error_from_errno (pfile, inc->name);
cpp_errno (pfile, DL_ERROR, inc->name);
fail:
return 1;
}
......@@ -563,7 +563,8 @@ find_include_file (pfile, header, type)
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;
}
......@@ -685,12 +686,10 @@ handle_missing_header (pfile, fname, angle_brackets)
we can still produce correct output. Otherwise, we can't produce
correct output, because there may be dependencies we need inside
the missing file, and we don't know what directory this missing
file exists in. FIXME: Use a future cpp_diagnostic_with_errno ()
for both of these cases. */
else if (CPP_PRINT_DEPS (pfile) && ! print_dep)
cpp_warning (pfile, "%s: %s", fname, xstrerror (errno));
file exists in. */
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),
......@@ -754,7 +753,7 @@ _cpp_read_file (pfile, fname)
if (f == NULL)
{
cpp_error_from_errno (pfile, fname);
cpp_errno (pfile, DL_ERROR, fname);
return false;
}
......@@ -1026,7 +1025,7 @@ remap_filename (pfile, name, loc)
/* We know p != name as absolute paths don't call remap_filename. */
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);
memcpy (dir, name, p - name);
......
......@@ -356,8 +356,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
/* In cpperror.c */
enum error_type { WARNING = 0, WARNING_SYSHDR, PEDWARN, ERROR, FATAL, ICE };
extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
extern int _cpp_begin_message PARAMS ((cpp_reader *, int,
unsigned int, unsigned int));
/* In cppmacro.c */
......
......@@ -225,7 +225,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
{
/* Dirs that don't exist are silently ignored. */
if (errno != ENOENT)
cpp_notice_from_errno (pfile, dir);
cpp_errno (pfile, DL_ERROR, dir);
else if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
free (dir);
......@@ -234,7 +234,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
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);
return;
}
......@@ -308,15 +308,15 @@ remove_dup_dirs (pfile, head)
{
if (cur->sysp && !other->sysp)
{
cpp_warning (pfile,
cpp_error (pfile, DL_WARNING,
"changing search order for system directory \"%s\"",
cur->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\"",
other->name);
else
cpp_warning (pfile,
cpp_error (pfile, DL_WARNING,
" as it has already been specified as a non-system directory");
}
cur = remove_dup_dir (pfile, prev);
......@@ -1092,7 +1092,7 @@ output_deps (pfile)
deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode);
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;
}
}
......@@ -1106,7 +1106,7 @@ output_deps (pfile)
if (deps_stream != stdout)
{
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)
CPP_OPTION (pfile, out_fname) = argv[i];
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);
}
else
......@@ -1377,7 +1378,8 @@ cpp_handle_option (pfile, argc, argv, ignore)
arg = argv[++i];
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;
}
}
......@@ -1545,7 +1547,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
CPP_OPTION (pfile, out_fname) = arg;
else
{
cpp_fatal (pfile, "output filename specified twice");
cpp_error (pfile, DL_FATAL, "output filename specified twice");
return argc;
}
break;
......@@ -1657,7 +1659,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
}
else
{
cpp_fatal (pfile, "-I- specified twice");
cpp_error (pfile, DL_FATAL, "-I- specified twice");
return argc;
}
}
......@@ -1843,7 +1845,8 @@ cpp_post_options (pfile)
(CPP_OPTION (pfile, print_deps_missing_files)
|| CPP_OPTION (pfile, deps_file)
|| 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
......
......@@ -546,32 +546,50 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
int, 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
formatted because exgettext needs to see 'msgid' on the same line
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
getting ridiculously oversized. */
extern void cpp_ice PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_fatal PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_error PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_warning PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_notice PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
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 *));
/* Output a diagnostic of some kind. */
extern void cpp_error PARAMS ((cpp_reader *, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_3;
/* Output a diagnostic of severity LEVEL, with "MSG: " preceding the
error string of errno. No location is printed. */
extern void cpp_errno PARAMS ((cpp_reader *, int level, const char *msg));
/* Same as cpp_error, except additionally specifies a position as a
(translation unit) physical line and physical column. If the line is
zero, then no location is printed. */
extern void cpp_error_with_line PARAMS ((cpp_reader *, int, unsigned, unsigned, const char *msgid, ...))
ATTRIBUTE_PRINTF_5;
/* In cpplex.c */
extern int cpp_ideq PARAMS ((const cpp_token *,
......
......@@ -143,7 +143,8 @@ builtin_macro (pfile, node)
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:
......@@ -344,7 +345,8 @@ stringify_arg (pfile, arg)
/* 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--;
}
......@@ -435,7 +437,7 @@ paste_all_tokens (pfile, lhs)
/* 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));
......@@ -555,7 +557,8 @@ collect_args (pfile, node)
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;
}
......@@ -572,11 +575,12 @@ collect_args (pfile, node)
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;
......@@ -587,7 +591,7 @@ collect_args (pfile, node)
/* 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;
......@@ -670,7 +674,7 @@ enter_macro_context (pfile, node)
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));
......@@ -1169,7 +1173,8 @@ save_parameter (pfile, macro, node)
/* 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;
}
......@@ -1203,14 +1208,16 @@ parse_params (pfile, macro)
&& ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
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));
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;
......@@ -1227,7 +1234,7 @@ parse_params (pfile, macro)
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;
......@@ -1240,11 +1247,12 @@ parse_params (pfile, macro)
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,
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);
......@@ -1253,7 +1261,7 @@ parse_params (pfile, macro)
/* 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;
}
}
......@@ -1331,7 +1339,8 @@ _cpp_create_definition (pfile, node)
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;
......@@ -1361,7 +1370,8 @@ _cpp_create_definition (pfile, node)
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;
}
}
......@@ -1380,7 +1390,7 @@ _cpp_create_definition (pfile, node)
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;
}
......@@ -1416,11 +1426,11 @@ _cpp_create_definition (pfile, node)
{
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));
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);
......@@ -1484,7 +1494,7 @@ check_trad_stringification (pfile, macro, string)
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));
break;
......@@ -1509,7 +1519,8 @@ cpp_macro_definition (pfile, node)
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;
}
......
......@@ -89,7 +89,7 @@ cpp_preprocess_file (pfile)
print.outf = fopen (options->out_fname, "w");
if (print.outf == NULL)
{
cpp_notice_from_errno (pfile, options->out_fname);
cpp_errno (pfile, DL_ERROR, options->out_fname);
return;
}
}
......@@ -120,7 +120,7 @@ cpp_preprocess_file (pfile)
if (print.outf != stdout)
{
if (ferror (print.outf) || fclose (print.outf))
cpp_notice_from_errno (pfile, options->out_fname);
cpp_errno (pfile, DL_ERROR, options->out_fname);
}
}
......
......@@ -633,7 +633,7 @@ read_scan_file (in_fname, argc, argv)
i = cpp_handle_options (scan_in, argc, argv);
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);
if (CPP_FATAL_ERRORS (scan_in))
exit (FATAL_EXIT_CODE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment