OSDN Git Service

* Makefile.in: Remove pointless setting of CXXFLAGS for dejagnu
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.c
index 54f4911..a192229 100644 (file)
@@ -27,6 +27,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #undef FLOAT /* This is for hpux. They should change hpux.  */
 #undef FFS  /* Some systems define this in param.h.  */
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "tm_p.h"
 #include "flags.h"
@@ -37,17 +39,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "langhooks.h"
 #include "langhooks-def.h"
 
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free  free
-
-#define output_formatted_integer(BUFFER, FORMAT, INTEGER)      \
-  do                                                           \
-    {                                                          \
-      sprintf ((BUFFER)->digit_buffer, FORMAT, INTEGER);       \
-      output_add_string (BUFFER, (BUFFER)->digit_buffer);      \
-    }                                                          \
-  while (0)
-
 #define output_text_length(BUFFER) (BUFFER)->line_length
 #define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
 #define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
@@ -89,6 +80,7 @@ static void default_diagnostic_finalizer PARAMS ((diagnostic_context *,
                                                   diagnostic_info *));
 
 static void error_recursion PARAMS ((diagnostic_context *)) ATTRIBUTE_NORETURN;
+static bool text_specifies_location PARAMS ((text_info *, location_t *));
 
 extern int rtl_dump_and_exit;
 extern int warnings_are_errors;
@@ -311,7 +303,7 @@ output_decimal (buffer, i)
      output_buffer *buffer;
      int i;
 {
-  output_formatted_integer (buffer, "%d", i);
+  output_formatted_scalar (buffer, "%d", i);
 }
 
 static void
@@ -319,7 +311,7 @@ output_long_decimal (buffer, i)
      output_buffer *buffer;
      long int i;
 {
-  output_formatted_integer (buffer, "%ld", i);
+  output_formatted_scalar (buffer, "%ld", i);
 }
 
 static void
@@ -327,7 +319,7 @@ output_unsigned_decimal (buffer, i)
      output_buffer *buffer;
      unsigned int i;
 {
-  output_formatted_integer (buffer, "%u", i);
+  output_formatted_scalar (buffer, "%u", i);
 }
 
 static void
@@ -335,7 +327,7 @@ output_long_unsigned_decimal (buffer, i)
      output_buffer *buffer;
      long unsigned int i;
 {
-  output_formatted_integer (buffer, "%lu", i);
+  output_formatted_scalar (buffer, "%lu", i);
 }
 
 static void
@@ -343,7 +335,7 @@ output_octal (buffer, i)
      output_buffer *buffer;
      unsigned int i;
 {
-  output_formatted_integer (buffer, "%o", i);
+  output_formatted_scalar (buffer, "%o", i);
 }
 
 static void
@@ -351,7 +343,7 @@ output_long_octal (buffer, i)
      output_buffer *buffer;
      unsigned long int i;
 {
-  output_formatted_integer (buffer, "%lo", i);
+  output_formatted_scalar (buffer, "%lo", i);
 }
 
 static void
@@ -359,7 +351,7 @@ output_hexadecimal (buffer, i)
      output_buffer *buffer;
      unsigned int i;
 {
-  output_formatted_integer (buffer, "%x", i);
+  output_formatted_scalar (buffer, "%x", i);
 }
 
 static void
@@ -367,7 +359,7 @@ output_long_hexadecimal (buffer, i)
      output_buffer *buffer;
      unsigned long int i;
 {
-  output_formatted_integer (buffer, "%lx", i);
+  output_formatted_scalar (buffer, "%lx", i);
 }
 
 /* Append to BUFFER a string specified by its STARTING character
@@ -473,6 +465,16 @@ output_add_string (buffer, str)
   maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
 }
 
+/* Append an identifier ID to BUFFER.  */
+void
+output_add_identifier (buffer, id)
+     output_buffer *buffer;
+     tree id;
+{
+  output_append (buffer, IDENTIFIER_POINTER (id),
+                IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
+}
+
 /* Flush the content of BUFFER onto the attached stream,
    and reinitialize.  */
 
@@ -495,7 +497,8 @@ output_buffer_to_stream (buffer)
    %c: character.
    %s: string.
    %%: `%'.
-   %*.s: a substring the length of which is specified by an integer.  */
+   %*.s: a substring the length of which is specified by an integer.
+   %H: location_t.  */
 static void
 output_format (buffer, text)
      output_buffer *buffer;
@@ -576,6 +579,16 @@ output_format (buffer, text)
          output_add_character (buffer, '%');
          break;
 
+        case 'H':
+          {
+            const location_t *locus = va_arg (*text->args_ptr, location_t *);
+            output_add_string (buffer, "file '");
+            output_add_string (buffer, locus->file);
+            output_add_string (buffer, "', line ");
+            output_decimal (buffer, locus->line);
+          }
+          break;
+
        case '.':
          {
            int n;
@@ -631,7 +644,7 @@ build_message_string VPARAMS ((const char *msg, ...))
   return str;
 }
 
-/* Same as diagnsotic_build_prefix, but only the source FILE is given.  */
+/* Same as diagnostic_build_prefix, but only the source FILE is given.  */
 char *
 file_name_as_prefix (f)
      const char *f;
@@ -766,6 +779,31 @@ diagnostic_initialize (context)
 
   diagnostic_starter (context) = default_diagnostic_starter;
   diagnostic_finalizer (context) = default_diagnostic_finalizer;
+  context->warnings_are_errors_message = warnings_are_errors;
+}
+
+/* Returns true if the next format specifier in TEXT is a format specifier
+   for a location_t.  If so, update the object pointed by LOCUS to reflect
+   the specified location in *TEXT->args_ptr.  */
+static bool
+text_specifies_location (text, locus)
+     text_info *text;
+     location_t *locus;
+{
+  const char *p;
+  /* Skip any leading text.  */
+  for (p = text->format_spec; *p && *p != '%'; ++p)
+    ;
+
+  /* Extract the location information if any.  */
+  if (*p == '%' && *++p == 'H')
+    {
+      *locus = *va_arg (*text->args_ptr, location_t *);
+      text->format_spec = p + 1;
+      return true;
+    }
+
+  return false;
 }
 
 void
@@ -779,8 +817,13 @@ diagnostic_set_info (diagnostic, msgid, args, file, line, kind)
 {
   diagnostic->message.format_spec = msgid;
   diagnostic->message.args_ptr = args;
-  diagnostic->location.file = file;
-  diagnostic->location.line = line;
+  /* If the diagnostic message doesn't specify a location,
+     use FILE and LINE.  */
+  if (!text_specifies_location (&diagnostic->message, &diagnostic->location))
+    {
+      diagnostic->location.file = file;
+      diagnostic->location.line = line;
+    }
   diagnostic->kind = kind;
 }
 
@@ -790,8 +833,8 @@ char *
 diagnostic_build_prefix (diagnostic)
      diagnostic_info *diagnostic;
 {
-  static const char *diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T) _(T),
+  static const char *const diagnostic_kind_text[] = {
+#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
 #include "diagnostic.def"
 #undef DEFINE_DIAGNOSTIC_KIND
     "must-not-happen"
@@ -803,9 +846,9 @@ diagnostic_build_prefix (diagnostic)
     ? build_message_string ("%s:%d: %s",
                             diagnostic->location.file,
                             diagnostic->location.line,
-                            diagnostic_kind_text[diagnostic->kind])
+                            _(diagnostic_kind_text[diagnostic->kind]))
     : build_message_string ("%s: %s", progname,
-                            diagnostic_kind_text[diagnostic->kind]);
+                            _(diagnostic_kind_text[diagnostic->kind]));
 }
 
 /* Report a diagnostic MESSAGE at the declaration DECL.
@@ -819,7 +862,7 @@ diagnostic_for_decl (diagnostic, decl)
   if (global_dc->lock++)
     error_recursion (global_dc);
 
-  if (diagnostic_count_error (global_dc, diagnostic->kind))
+  if (diagnostic_count_diagnostic (global_dc, diagnostic->kind))
     {
       diagnostic_report_current_function (global_dc);
       output_set_prefix
@@ -839,29 +882,42 @@ diagnostic_flush_buffer (context)
   fflush (output_buffer_attached_stream (&context->buffer));
 }
 
-/* Count an error or warning.  Return true if the message should be
-   printed.  */
+/* Count a diagnostic.  Return true if the message should be printed.  */
 bool
-diagnostic_count_error (context, kind)
+diagnostic_count_diagnostic (context, kind)
     diagnostic_context *context;
     diagnostic_t kind;
 {
-  if (kind == DK_WARNING && !diagnostic_report_warnings_p ())
-    return false;
-
-  if (kind == DK_WARNING && !warnings_are_errors)
-    ++diagnostic_kind_count (context, DK_WARNING);
-  else
+  switch (kind)
     {
-      static bool warning_message = false;
-
-      if (kind == DK_WARNING && !warning_message)
-       {
+    default:
+      abort();
+      break;
+
+    case DK_FATAL: case DK_ICE: case DK_SORRY:
+    case DK_ANACHRONISM: case DK_NOTE:
+      ++diagnostic_kind_count (context, kind);
+      break;
+
+    case DK_WARNING:
+      if (!diagnostic_report_warnings_p ())
+        return false;
+      else if (!warnings_are_errors)
+        {
+          ++diagnostic_kind_count (context, DK_WARNING);
+          break;
+        }
+      /* else fall through.  */
+
+    case DK_ERROR:
+      if (kind == DK_WARNING && context->warnings_are_errors_message)
+        {
          output_verbatim (&context->buffer,
                            "%s: warnings being treated as errors\n", progname);
-         warning_message = true;
-       }
+          context->warnings_are_errors_message = false;
+        }
       ++diagnostic_kind_count (context, DK_ERROR);
+      break;
     }
 
   return true;
@@ -969,7 +1025,6 @@ sorry VPARAMS ((const char *msgid, ...))
 
   output_set_prefix
     (&global_dc->buffer, diagnostic_build_prefix (&diagnostic));
-  output_printf (&global_dc->buffer, "sorry, not implemented: ");
   output_format (&global_dc->buffer, &diagnostic.message);
   output_flush (&global_dc->buffer);
   VA_CLOSE (ap);
@@ -1140,7 +1195,7 @@ internal_error VPARAMS ((const char *msgid, ...))
   fnotice (stderr,
 "Please submit a full bug report,\n\
 with preprocessed source if appropriate.\n\
-See %s for instructions.\n", GCCBUGURL);
+See %s for instructions.\n", bug_report_url);
   exit (FATAL_EXIT_CODE);
 }
 
@@ -1220,7 +1275,7 @@ diagnostic_report_diagnostic (context, diagnostic)
   if (context->lock++)
     error_recursion (context);
 
-  if (diagnostic_count_error (context, diagnostic->kind))
+  if (diagnostic_count_diagnostic (context, diagnostic->kind))
     {
       (*diagnostic_starter (context)) (context, diagnostic);
       output_format (&context->buffer, &diagnostic->message);
@@ -1248,7 +1303,7 @@ error_recursion (context)
   fnotice (stderr,
 "Please submit a full bug report,\n\
 with preprocessed source if appropriate.\n\
-See %s for instructions.\n", GCCBUGURL);
+See %s for instructions.\n", bug_report_url);
   exit (FATAL_EXIT_CODE);
 }
 
@@ -1306,8 +1361,7 @@ fancy_abort (file, line, function)
      int line;
      const char *function;
 {
-  internal_error ("Internal compiler error in %s, at %s:%d",
-                 function, trim_filename (file), line);
+  internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
 }
 
 void
@@ -1355,6 +1409,20 @@ default_diagnostic_finalizer (context, diagnostic)
 }
 
 void
+inform VPARAMS ((const char *msgid, ...))
+{
+  diagnostic_info diagnostic;
+
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
+
+  diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, lineno,
+                       DK_NOTE);
+  report_diagnostic (&diagnostic);
+  VA_CLOSE (ap);
+}
+
+void
 warn_deprecated_use (node)
      tree node;
 {