[Ada] Consistently use explicit Entity_Id type instead of alias
[gcc.git] / libcpp / errors.c
index bc857f0b81d5d3d4acf624be0adff409fd267462..275e4afd0035b7eb8fcdd0f6f05765c0c8153856 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -27,15 +27,32 @@ 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, 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))
     {
@@ -54,18 +71,15 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
     {
       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;
@@ -81,7 +95,8 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
 /* 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;
@@ -97,7 +112,8 @@ cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
 /* 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;
@@ -114,7 +130,8 @@ cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
    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;
@@ -131,15 +148,19 @@ cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
 
 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;
 }
@@ -147,8 +168,8 @@ cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
 /* 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;
@@ -166,8 +187,8 @@ cpp_error_with_line (cpp_reader *pfile, int level,
 /* 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;
@@ -185,9 +206,9 @@ cpp_warning_with_line (cpp_reader *pfile, int reason,
 /* 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;
@@ -205,9 +226,9 @@ cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
    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;
@@ -221,14 +242,67 @@ 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, 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));
 }