summaryrefslogtreecommitdiff
path: root/gcc/cpperror.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-04-14 18:42:47 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-04-14 18:42:47 +0000
commitebef4e8ca795b46b1f51a82d4b93c35f1eacd54c (patch)
tree75fa26f503af564c85d2a564dac4f51a833dca58 /gcc/cpperror.c
parentc19a385911ad926bd88713535b5a93c947d9f1bd (diff)
downloadgcc-ebef4e8ca795b46b1f51a82d4b93c35f1eacd54c.tar.gz
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
Diffstat (limited to 'gcc/cpperror.c')
-rw-r--r--gcc/cpperror.c228
1 files changed, 57 insertions, 171 deletions
diff --git a/gcc/cpperror.c b/gcc/cpperror.c
index 375dc2ba5b3..7d74b2ea684 100644
--- a/gcc/cpperror.c
+++ b/gcc/cpperror.c
@@ -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,226 +64,123 @@ 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))
- return 0;
- is_warning = 1;
- }
+ else if (CPP_OPTION (pfile, inhibit_warnings))
+ return 0;
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;
}
-/* 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);
+/* 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)
- VA_CLOSE (ap);
-}
+/* Exported interface. */
/* 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 (_cpp_begin_message (pfile, ERROR, 0, 0))
- v_message (msgid, ap);
-
- VA_CLOSE (ap);
-}
-
-/* Print an error at a specific location. */
-void
-cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
- 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, int, line);
- VA_FIXEDARG (ap, int, column);
- VA_FIXEDARG (ap, const char *, msgid);
-
- if (_cpp_begin_message (pfile, ERROR, line, column))
- v_message (msgid, ap);
+ unsigned int line, column;
- VA_CLOSE (ap);
-}
-
-/* Error including a message from `errno'. */
-void
-cpp_error_from_errno (pfile, name)
- 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, ...))
-{
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, 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 (pfile->buffer)
+ {
+ line = pfile->cur_token[-1].line;
+ column = pfile->cur_token[-1].col;
+ }
+ else
+ line = column = 0;
- if (_cpp_begin_message (pfile, PEDWARN, 0, 0))
+ if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
}
-/* Pedwarn at a specific location. */
+/* Print an error at a specific location. */
void
-cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
- const char *msgid, ...))
+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, PEDWARN, line, column))
+ if (_cpp_begin_message (pfile, level, 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_errno (pfile, level, msgid)
cpp_reader *pfile;
- const char *name;
+ int level;
+ const char *msgid;
{
- if (name[0] == '\0')
- name = "stdout";
- cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
+ if (msgid[0] == '\0')
+ msgid = _("stdout");
+
+ cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
}