diff libcpp/errors.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
line wrap: on
line diff
--- a/libcpp/errors.c	Sun Aug 21 07:07:55 2011 +0900
+++ b/libcpp/errors.c	Fri Oct 27 22:46:09 2017 +0900
@@ -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, 2010 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
@@ -28,6 +27,41 @@
 #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)
@@ -36,7 +70,6 @@
                 const char *msgid, va_list *ap)
 {
   source_location src_loc;
-  bool ret;
 
   if (CPP_OPTION (pfile, traditional))
     {
@@ -49,21 +82,13 @@
      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 +168,10 @@
   
   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 +253,64 @@
   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.  */
 
 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".  */
 
-  return cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
+bool
+cpp_errno_filename (cpp_reader *pfile, int level, const char *filename,
+		    source_location loc)
+{
+  if (filename[0] == '\0')
+    filename = _("stdout");
+
+  return cpp_error_at (pfile, level, loc, "%s: %s", filename,
+		       xstrerror (errno));
 }