summaryrefslogtreecommitdiff
path: root/libcpp/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp/errors.c')
-rw-r--r--libcpp/errors.c90
1 files changed, 79 insertions, 11 deletions
diff --git a/libcpp/errors.c b/libcpp/errors.c
index 984737877b..7fdee3c625 100644
--- a/libcpp/errors.c
+++ b/libcpp/errors.c
@@ -1,5 +1,5 @@
/* Default error handlers for CPP Library.
- Copyright (C) 1986-2016 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 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
@@ -27,6 +27,41 @@ along with this program; see the file COPYING3. If not see
#include "cpplib.h"
#include "internal.h"
+/* Print a diagnostic at the given location. */
+
+ATTRIBUTE_FPTR_PRINTF(5,0)
+static bool
+cpp_diagnostic_at_richloc (cpp_reader * pfile, int level, int reason,
+ rich_location *richloc,
+ const char *msgid, va_list *ap)
+{
+ bool ret;
+
+ if (!pfile->cb.error)
+ abort ();
+ ret = pfile->cb.error (pfile, level, reason, richloc, _(msgid), ap);
+
+ return ret;
+}
+
+/* Print a diagnostic at the given location. */
+
+ATTRIBUTE_FPTR_PRINTF(5,0)
+static bool
+cpp_diagnostic_at (cpp_reader * pfile, int level, int reason,
+ source_location src_loc,
+ const char *msgid, va_list *ap)
+{
+ bool ret;
+
+ if (!pfile->cb.error)
+ abort ();
+ rich_location richloc (pfile->line_table, src_loc);
+ ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap);
+
+ return ret;
+}
+
/* Print a diagnostic at the location of the previously lexed token. */
ATTRIBUTE_FPTR_PRINTF(4,0)
@@ -35,7 +70,6 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
const char *msgid, va_list *ap)
{
source_location src_loc;
- bool ret;
if (CPP_OPTION (pfile, traditional))
{
@@ -54,13 +88,7 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
{
src_loc = pfile->cur_token[-1].src_loc;
}
-
- if (!pfile->cb.error)
- abort ();
- rich_location richloc (pfile->line_table, src_loc);
- ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap);
-
- return ret;
+ return cpp_diagnostic_at (pfile, level, reason, src_loc, msgid, ap);
}
/* Print a warning or error, depending on the value of LEVEL. */
@@ -225,6 +253,44 @@ cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
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, int level, source_location src_loc,
+ const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, src_loc,
+ 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_richloc (cpp_reader * pfile, int level, rich_location *richloc,
+ const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ ret = cpp_diagnostic_at_richloc (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. */
@@ -239,10 +305,12 @@ cpp_errno (cpp_reader *pfile, int level, const char *msgid)
that is not localized, but "" is replaced with localized "stdout". */
bool
-cpp_errno_filename (cpp_reader *pfile, int level, const char *filename)
+cpp_errno_filename (cpp_reader *pfile, int level, const char *filename,
+ source_location loc)
{
if (filename[0] == '\0')
filename = _("stdout");
- return cpp_error (pfile, level, "%s: %s", filename, xstrerror (errno));
+ return cpp_error_at (pfile, level, loc, "%s: %s", filename,
+ xstrerror (errno));
}