mksysinfo.sh: always define CLONE_NEWNET
[gcc.git] / libcpp / errors.c
index b7783f54d31ef09ff41db98aab88897dda35f139..f7d411226eeec215c4f685ca1aa0dbbcfc2cb882 100644 (file)
@@ -1,6 +1,5 @@
 /* Default error handlers for CPP Library.
-   Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000,
-   2001, 2002, 2004, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1986-2016 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
@@ -28,6 +27,24 @@ 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 (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)
@@ -36,7 +53,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))
     {
@@ -49,21 +65,13 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
      current run -- that is invalid.  */
   else if (pfile->cur_token == pfile->cur_run->base)
     {
-      if (pfile->cur_run->prev != NULL)
-       src_loc = pfile->cur_run->prev->limit->src_loc;
-      else
-       src_loc = 0;
+      src_loc = 0;
     }
   else
     {
       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;
+  return cpp_diagnostic_at (pfile, level, reason, src_loc, msgid, ap);
 }
 
 /* Print a warning or error, depending on the value of LEVEL.  */
@@ -143,7 +151,10 @@ cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
   
   if (!pfile->cb.error)
     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.error (pfile, level, reason, &richloc, _(msgid), ap);
 
   return ret;
 }
@@ -225,14 +236,45 @@ 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;
+}
+
 /* 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)
 {
-  if (msgid[0] == '\0')
-    msgid = _("stdout");
+  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, int level, const char *filename,
+                   source_location loc)
+{
+  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));
 }