/* Default error handlers for CPP Library.
- Copyright (C) 1986-2014 Free Software Foundation, Inc.
+ Copyright (C) 1986-2020 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
#include "cpplib.h"
#include "internal.h"
+/* Print a diagnostic at the given location. */
+
+ATTRIBUTE_FPTR_PRINTF(5,0)
+static bool
+cpp_diagnostic_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason, rich_location *richloc,
+ const char *msgid, va_list *ap)
+{
+ bool ret;
+
+ if (!pfile->cb.diagnostic)
+ abort ();
+ ret = pfile->cb.diagnostic (pfile, level, reason, richloc, _(msgid), ap);
+
+ return ret;
+}
+
/* Print a diagnostic at the location of the previously lexed token. */
ATTRIBUTE_FPTR_PRINTF(4,0)
static bool
-cpp_diagnostic (cpp_reader * pfile, int level, int reason,
- const char *msgid, va_list *ap)
+cpp_diagnostic (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason,
+ const char *msgid, va_list *ap)
{
- source_location src_loc;
- bool ret;
+ location_t src_loc;
if (CPP_OPTION (pfile, traditional))
{
{
src_loc = pfile->cur_token[-1].src_loc;
}
-
- if (!pfile->cb.error)
- abort ();
- ret = pfile->cb.error (pfile, level, reason, src_loc, 0, _(msgid), ap);
-
- return ret;
+ rich_location richloc (pfile->line_table, src_loc);
+ return cpp_diagnostic_at (pfile, level, reason, &richloc, msgid, ap);
}
/* Print a warning or error, depending on the value of LEVEL. */
bool
-cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
+cpp_error (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
/* Print a warning. The warning reason may be given in REASON. */
bool
-cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_warning (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
-cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_pedwarning (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
given in REASON. */
bool
-cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_warning_syshdr (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
ATTRIBUTE_FPTR_PRINTF(6,0)
static bool
-cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, va_list *ap)
+cpp_diagnostic_with_line (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason,
+ location_t src_loc, unsigned int column,
+ const char *msgid, va_list *ap)
{
bool ret;
- if (!pfile->cb.error)
+ if (!pfile->cb.diagnostic)
abort ();
- ret = pfile->cb.error (pfile, level, reason, src_loc, column, _(msgid), ap);
+ rich_location richloc (pfile->line_table, src_loc);
+ if (column)
+ richloc.override_column (column);
+ ret = pfile->cb.diagnostic (pfile, level, reason, &richloc, _(msgid), ap);
return ret;
}
/* Print a warning or error, depending on the value of LEVEL. */
bool
-cpp_error_with_line (cpp_reader *pfile, int level,
- source_location src_loc, unsigned int column,
+cpp_error_with_line (cpp_reader *pfile, enum cpp_diagnostic_level level,
+ location_t src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
/* Print a warning. The warning reason may be given in REASON. */
bool
-cpp_warning_with_line (cpp_reader *pfile, int reason,
- source_location src_loc, unsigned int column,
+cpp_warning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason,
+ location_t src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
-cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, ...)
+cpp_pedwarning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason,
+ location_t src_loc, unsigned int column,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
given in REASON. */
bool
-cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, ...)
+cpp_warning_with_line_syshdr (cpp_reader *pfile, enum cpp_warning_reason reason,
+ location_t src_loc, unsigned int column,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
return ret;
}
+/* As cpp_error, but use SRC_LOC as the location of the error, without
+ a column override. */
+
+bool
+cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ location_t src_loc, const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ rich_location richloc (pfile->line_table, src_loc);
+ ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, &richloc,
+ msgid, &ap);
+
+ va_end (ap);
+ return ret;
+}
+
+/* As cpp_error, but use RICHLOC as the location of the error, without
+ a column override. */
+
+bool
+cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ rich_location *richloc, const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, richloc,
+ msgid, &ap);
+
+ va_end (ap);
+ return ret;
+}
+
/* Print a warning or error, depending on the value of LEVEL. Include
information from errno. */
bool
-cpp_errno (cpp_reader *pfile, int level, const char *msgid)
+cpp_errno (cpp_reader *pfile, enum cpp_diagnostic_level level,
+ const char *msgid)
+{
+ return cpp_error (pfile, level, "%s: %s", _(msgid), xstrerror (errno));
+}
+
+/* Print a warning or error, depending on the value of LEVEL. Include
+ information from errno. Unlike cpp_errno, the argument is a filename
+ that is not localized, but "" is replaced with localized "stdout". */
+
+bool
+cpp_errno_filename (cpp_reader *pfile, enum cpp_diagnostic_level level,
+ const char *filename,
+ location_t loc)
{
- if (msgid[0] == '\0')
- msgid = _("stdout");
+ if (filename[0] == '\0')
+ filename = _("stdout");
- return cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
+ return cpp_error_at (pfile, level, loc, "%s: %s", filename,
+ xstrerror (errno));
}