OSDN Git Service

In include:
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
index 0e8afc4..a6c7b2d 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,23 +57,27 @@ print_containing_files (pfile, ip)
       if (first)
        {
          first = 0;
+         /* N.B. The current line in each outer source file is one
+            greater than the line of the #include, so we must
+            subtract one to correct for that.  */
          fprintf (stderr,  _("In file included from %s:%u"),
-                  ip->nominal_fname, CPP_BUF_LINE (ip));
+                  ip->nominal_fname, CPP_BUF_LINE (ip) - 1);
        }
       else
        /* Translators note: this message is used in conjunction
           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 +93,97 @@ 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, line, col)
      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;
 {
-  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_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_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 (line == 0)
+       line = _cpp_get_line (pfile, &col);
+      print_containing_files (pfile, ip);
+      print_file_and_line (file, line,
+                          CPP_OPTION (pfile, show_column) ? col : 0);
+    }
+  else
+    fprintf (stderr, "%s: ", progname);
+
+  if (is_warning)
+    fputs (_("warning: "), stderr);
+
+  return 1;
 }
 
 /* Exported interface.  */
@@ -174,7 +207,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, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -200,7 +234,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, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -220,10 +255,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, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -248,10 +281,8 @@ 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);
+  if (_cpp_begin_message (pfile, ERROR, NULL, line, column))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -280,10 +311,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, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -308,10 +337,8 @@ 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);
+  if (_cpp_begin_message (pfile, WARNING, NULL, line, column))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -331,13 +358,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, 0))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -362,13 +384,8 @@ 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);
+  if (_cpp_begin_message (pfile, PEDWARN, NULL, line, column))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -399,13 +416,8 @@ 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);
+  if (_cpp_begin_message (pfile, PEDWARN, file, line, col))
+    v_message (msgid, ap);
   va_end(ap);
 }
 
@@ -444,3 +456,11 @@ cpp_notice_from_errno (pfile, name)
     name = "stdout";
   cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
 }
+
+const char *
+cpp_type2name (type)
+     enum cpp_ttype type;
+{
+  return (const char *) _cpp_token_spellings[type].name;
+}
+