OSDN Git Service

Workaround for Itanium A/B step errata
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
index 0ba2561..d598fbd 100644 (file)
@@ -32,10 +32,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 static void print_containing_files     PARAMS ((cpp_reader *, cpp_buffer *));
 static void print_file_and_line                PARAMS ((const char *, unsigned int,
                                                 unsigned int));
-static void v_message                  PARAMS ((cpp_reader *, int,
-                                                const char *,
-                                                unsigned int, unsigned int,
-                                                const char *, va_list));
+
+#define v_message(msgid, ap) \
+do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
 
 /* Print the file names and line numbers of the #include
    commands which led to the current file.  */
@@ -58,6 +57,8 @@ print_containing_files (pfile, ip)
       if (first)
        {
          first = 0;
+         /* The current line in each outer source file is now the
+            same as the line of the #include.  */
          fprintf (stderr,  _("In file included from %s:%u"),
                   ip->nominal_fname, CPP_BUF_LINE (ip));
        }
@@ -66,15 +67,16 @@ print_containing_files (pfile, ip)
           with "In file included from %s:%ld" and some other
           tricks.  We want something like this:
 
-          In file included from sys/select.h:123,
-                           from sys/types.h:234,
-                           from userfile.c:31:
-          bits/select.h:45: <error message here>
+          In file included from sys/select.h:123,
+                           from sys/types.h:234,
+                           from userfile.c:31:
+          bits/select.h:45: <error message here>
 
+          with all the "from"s lined up.
           The trailing comma is at the beginning of this message,
           and the trailing colon is not translated.  */
        fprintf (stderr, _(",\n                 from %s:%u"),
-                ip->nominal_fname, CPP_BUF_LINE (ip));
+                ip->nominal_fname, CPP_BUF_LINE (ip) - 1);
     }
   if (first == 0)
     fputs (":\n", stderr);
@@ -90,67 +92,102 @@ print_file_and_line (filename, line, column)
 {
   if (filename == 0 || *filename == '\0')
     filename = "<stdin>";
-  if (line == 0)
-    fputs (_("<command line>: "), stderr);
+
+  if (line == (unsigned int)-1)
+    fprintf (stderr, "%s: ", filename);
   else if (column > 0)
     fprintf (stderr, "%s:%u:%u: ", filename, line, column);
   else
     fprintf (stderr, "%s:%u: ", filename, line);
 }
 
-/* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
-   1 for error, 0 for warning.  */
+/* Set up for an error message: print the file and line, bump the error
+   counter, etc.
+   If it returns 0, this error has been suppressed.  */
 
-static void
-v_message (pfile, is_error, file, line, col, msg, ap)
+int
+_cpp_begin_message (pfile, code, file, pos)
      cpp_reader *pfile;
-     int is_error;
+     enum error_type code;
      const char *file;
-     unsigned int line;
-     unsigned int col;
-     const char *msg;
-     va_list ap;
+     const cpp_lexer_pos *pos;
 {
-  cpp_buffer *ip = cpp_file_buffer (pfile);
+  cpp_buffer *ip = CPP_BUFFER (pfile);
+  int is_warning = 0;
 
-  if (ip)
+  switch (code)
     {
-      if (file == NULL)
-       file = ip->nominal_fname;
-      if (line == 0)
+    case WARNING:
+      if (CPP_IN_SYSTEM_HEADER (pfile)
+         && ! CPP_OPTION (pfile, warn_system_headers))
+       return 0;
+      if (! CPP_OPTION (pfile, warnings_are_errors))
        {
-         line = CPP_BUF_LINE (ip);
-         col = CPP_BUF_COL (ip);
+          if (CPP_OPTION (pfile, inhibit_warnings))
+           return 0;
+         is_warning = 1;
        }
-      print_containing_files (pfile, ip);
-      print_file_and_line (file, line,
-                          CPP_OPTION (pfile, show_column) ? col : 0);
-    }
-  else
-    fprintf (stderr, "%s: ", progname);
+      else
+       {
+         if (CPP_OPTION (pfile, inhibit_errors))
+           return 0;
+         if (pfile->errors < CPP_FATAL_LIMIT)
+           pfile->errors++;
+       }
+      break;
 
-  switch (is_error)
-    {
-    case 0:
-      fprintf (stderr, _("warning: "));
+    case PEDWARN:
+      if (CPP_IN_SYSTEM_HEADER (pfile)
+         && ! CPP_OPTION (pfile, warn_system_headers))
+       return 0;
+      if (! CPP_OPTION (pfile, pedantic_errors))
+       {
+          if (CPP_OPTION (pfile, inhibit_warnings))
+           return 0;
+         is_warning = 1;
+       }
+      else
+       {
+         if (CPP_OPTION (pfile, inhibit_errors))
+           return 0;
+         if (pfile->errors < CPP_FATAL_LIMIT)
+           pfile->errors++;
+       }
       break;
-    case 1:
+       
+    case ERROR:
+      if (CPP_OPTION (pfile, inhibit_errors))
+       return 0;
       if (pfile->errors < CPP_FATAL_LIMIT)
        pfile->errors++;
       break;
-    case 2:
+      /* Fatal errors cannot be inhibited.  */
+    case FATAL:
       pfile->errors = CPP_FATAL_LIMIT;
       break;
-    case 3:
+    case ICE:
       fprintf (stderr, _("internal error: "));
       pfile->errors = CPP_FATAL_LIMIT;
       break;
-    default:
-      cpp_ice (pfile, "bad is_error(%d) in v_message", is_error);
     }
 
-  vfprintf (stderr, _(msg), ap);
-  putc ('\n', stderr);
+  if (ip)
+    {
+      if (file == NULL)
+       file = ip->nominal_fname;
+      if (pos == 0)
+       pos = cpp_get_line (pfile);
+      print_containing_files (pfile, ip);
+      print_file_and_line (file, pos->line,
+                          CPP_OPTION (pfile, show_column) ? pos->col : 0);
+    }
+  else
+    fprintf (stderr, "%s: ", progname);
+
+  if (is_warning)
+    fputs (_("warning: "), stderr);
+
+  return 1;
 }
 
 /* Exported interface.  */
@@ -174,7 +211,8 @@ cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
   msgid = va_arg (ap, const char *);
 #endif
 
-  v_message (pfile, 3, NULL, 0, 0, msgid, ap);
+  if (_cpp_begin_message (pfile, ICE, NULL, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -200,7 +238,8 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
   msgid = va_arg (ap, const char *);
 #endif
 
-  v_message (pfile, 2, NULL, 0, 0, msgid, ap);
+  if (_cpp_begin_message (pfile, FATAL, NULL, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -220,10 +259,8 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, inhibit_errors))
-    return;
-
-  v_message (pfile, 1, NULL, 0, 0, msgid, ap);
+  if (_cpp_begin_message (pfile, ERROR, NULL, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -238,6 +275,7 @@ cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
   const char *msgid;
 #endif
   va_list ap;
+  cpp_lexer_pos pos;
   
   VA_START (ap, msgid);
   
@@ -248,10 +286,10 @@ cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, inhibit_errors))
-    return;
-
-  v_message (pfile, 1, NULL, line, column, msgid, ap);
+  pos.line = line;
+  pos.col = column;
+  if (_cpp_begin_message (pfile, ERROR, NULL, &pos))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -280,10 +318,8 @@ cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, inhibit_warnings))
-    return;
-
-  v_message (pfile, 0, NULL, 0, 0, msgid, ap);
+  if (_cpp_begin_message (pfile, WARNING, NULL, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -298,6 +334,7 @@ cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
   const char *msgid;
 #endif
   va_list ap;
+  cpp_lexer_pos pos;
   
   VA_START (ap, msgid);
   
@@ -308,10 +345,10 @@ cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, inhibit_warnings))
-    return;
-
-  v_message (pfile, 0, NULL, line, column, msgid, ap);
+  pos.line = line;
+  pos.col = column;
+  if (_cpp_begin_message (pfile, WARNING, NULL, &pos))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -331,13 +368,8 @@ cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, pedantic_errors)
-      ? CPP_OPTION (pfile, inhibit_errors)
-      : CPP_OPTION (pfile, inhibit_warnings))
-    return;
-
-  v_message (pfile, CPP_OPTION (pfile, pedantic_errors),
-                NULL, 0, 0, msgid, ap);
+  if (_cpp_begin_message (pfile, PEDWARN, NULL, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -352,6 +384,7 @@ cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
   const char *msgid;
 #endif
   va_list ap;
+  cpp_lexer_pos pos;
   
   VA_START (ap, msgid);
   
@@ -362,13 +395,10 @@ cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, pedantic_errors)
-      ? CPP_OPTION (pfile, inhibit_errors)
-      : CPP_OPTION (pfile, inhibit_warnings))
-    return;
-
-  v_message (pfile, CPP_OPTION (pfile, pedantic_errors),
-                NULL, line, column, msgid, ap);
+  pos.line = line;
+  pos.col = column;
+  if (_cpp_begin_message (pfile, PEDWARN, NULL, &pos))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -388,6 +418,7 @@ cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile,
   const char *msgid;
 #endif
   va_list ap;
+  cpp_lexer_pos pos;
   
   VA_START (ap, msgid);
 
@@ -399,13 +430,10 @@ cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile,
   msgid = va_arg (ap, const char *);
 #endif
 
-  if (CPP_OPTION (pfile, pedantic_errors)
-      ? CPP_OPTION (pfile, inhibit_errors)
-      : CPP_OPTION (pfile, inhibit_warnings))
-    return;
-
-  v_message (pfile, CPP_OPTION (pfile, pedantic_errors),
-                file, line, col, msgid, ap);
+  pos.line = line;
+  pos.col = col;
+  if (_cpp_begin_message (pfile, PEDWARN, file, &pos))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -440,5 +468,7 @@ cpp_notice_from_errno (pfile, name)
      cpp_reader *pfile;
      const char *name;
 {
+  if (name[0] == '\0')
+    name = "stdout";
   cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
 }