OSDN Git Service

PR middle-end/40500
[pf3gnuchains/gcc-fork.git] / gcc / fortran / error.c
index c119bca..88c2883 100644 (file)
@@ -30,13 +30,35 @@ along with GCC; see the file COPYING3.  If not see
 #include "flags.h"
 #include "gfortran.h"
 
-int gfc_suppress_error = 0;
+static int suppress_errors = 0;
+
+static int warnings_not_errors = 0; 
 
 static int terminal_width, buffer_flag, errors, warnings;
 
 static gfc_error_buf error_buffer, warning_buffer, *cur_error_buffer;
 
 
+/* Go one level deeper suppressing errors.  */
+
+void
+gfc_push_suppress_errors (void)
+{
+  gcc_assert (suppress_errors >= 0);
+  ++suppress_errors;
+}
+
+
+/* Leave one level of error suppressing.  */
+
+void
+gfc_pop_suppress_errors (void)
+{
+  gcc_assert (suppress_errors > 0);
+  --suppress_errors;
+}
+
+
 /* Per-file error initialization.  */
 
 void
@@ -70,8 +92,8 @@ error_char (char c)
        {
          cur_error_buffer->allocated = cur_error_buffer->allocated
                                      ? cur_error_buffer->allocated * 2 : 1000;
-         cur_error_buffer->message = xrealloc (cur_error_buffer->message,
-                                               cur_error_buffer->allocated);
+         cur_error_buffer->message = XRESIZEVEC (char, cur_error_buffer->message,
+                                                 cur_error_buffer->allocated);
        }
       cur_error_buffer->message[cur_error_buffer->index++] = c;
     }
@@ -87,7 +109,7 @@ error_char (char c)
          if (index + 1 >= allocated)
            {
              allocated = allocated ? allocated * 2 : 1000;
-             line = xrealloc (line, allocated);
+             line = XRESIZEVEC (char, line, allocated);
            }
          line[index++] = c;
          if (c == '\n')
@@ -152,48 +174,48 @@ error_integer (long int i)
 }
 
 
-/* Show the file, where it was included, and the source line, give a
-   locus.  Calls error_printf() recursively, but the recursion is at
-   most one level deep.  */
-
 static void
-print_wide_char (gfc_char_t c)
+print_wide_char_into_buffer (gfc_char_t c, char *buf)
 {
   static const char xdigit[16] = { '0', '1', '2', '3', '4', '5', '6',
     '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-  char buf[9];
 
   if (gfc_wide_is_printable (c))
-    error_char (c);
+    {
+      buf[1] = '\0';
+      buf[0] = (unsigned char) c;
+    }
   else if (c < ((gfc_char_t) 1 << 8))
     {
-      buf[2] = '\0';
-      buf[1] = xdigit[c & 0x0F];
+      buf[4] = '\0';
+      buf[3] = xdigit[c & 0x0F];
       c = c >> 4;
-      buf[0] = xdigit[c & 0x0F];
+      buf[2] = xdigit[c & 0x0F];
 
-      error_char ('\\');
-      error_char ('x');
-      error_string (buf);
+      buf[1] = 'x';
+      buf[0] = '\\';
     }
   else if (c < ((gfc_char_t) 1 << 16))
     {
-      buf[4] = '\0';
-      buf[3] = xdigit[c & 0x0F];
+      buf[6] = '\0';
+      buf[5] = xdigit[c & 0x0F];
       c = c >> 4;
-      buf[2] = xdigit[c & 0x0F];
+      buf[4] = xdigit[c & 0x0F];
       c = c >> 4;
-      buf[1] = xdigit[c & 0x0F];
+      buf[3] = xdigit[c & 0x0F];
       c = c >> 4;
-      buf[0] = xdigit[c & 0x0F];
+      buf[2] = xdigit[c & 0x0F];
 
-      error_char ('\\');
-      error_char ('u');
-      error_string (buf);
+      buf[1] = 'u';
+      buf[0] = '\\';
     }
   else
     {
-      buf[8] = '\0';
+      buf[10] = '\0';
+      buf[9] = xdigit[c & 0x0F];
+      c = c >> 4;
+      buf[8] = xdigit[c & 0x0F];
+      c = c >> 4;
       buf[7] = xdigit[c & 0x0F];
       c = c >> 4;
       buf[6] = xdigit[c & 0x0F];
@@ -205,17 +227,26 @@ print_wide_char (gfc_char_t c)
       buf[3] = xdigit[c & 0x0F];
       c = c >> 4;
       buf[2] = xdigit[c & 0x0F];
-      c = c >> 4;
-      buf[1] = xdigit[c & 0x0F];
-      c = c >> 4;
-      buf[0] = xdigit[c & 0x0F];
 
-      error_char ('\\');
-      error_char ('U');
-      error_string (buf);
+      buf[1] = 'U';
+      buf[0] = '\\';
     }
 }
 
+static char wide_char_print_buffer[11];
+
+const char *
+gfc_print_wide_char (gfc_char_t c)
+{
+  print_wide_char_into_buffer (c, wide_char_print_buffer);
+  return wide_char_print_buffer;
+}
+
+
+/* Show the file, where it was included, and the source line, give a
+   locus.  Calls error_printf() recursively, but the recursion is at
+   most one level deep.  */
+
 static void error_printf (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
 
 static void
@@ -278,14 +309,6 @@ show_locus (locus *loc, int c1, int c2)
 
   offset = 0;
 
-  /* When the loci is not associated with a column, it will have a
-     value of zero.  We adjust this to 1 so that it will appear.  */
-     
-  if (c1 == 0)
-    c1 = 1;
-  if (c2 == 0)
-    c2 = 1;
-
   /* If the two loci would appear in the same column, we shift
      '2' one column to the right, so as to print '12' rather than
      just '1'.  We do this here so it will be accounted for in the
@@ -313,11 +336,14 @@ show_locus (locus *loc, int c1, int c2)
 
   for (; i > 0; i--)
     {
+      static char buffer[11];
+
       c = *p++;
       if (c == '\t')
        c = ' ';
 
-      print_wide_char (c);
+      print_wide_char_into_buffer (c, buffer);
+      error_string (buffer);
     }
 
   error_char ('\n');
@@ -329,7 +355,7 @@ show_locus (locus *loc, int c1, int c2)
   c1 -= offset;
   c2 -= offset;
 
-  for (i = 1; i <= cmax; i++)
+  for (i = 0; i <= cmax; i++)
     {
       if (i == c1)
        error_char ('1');
@@ -509,6 +535,7 @@ error_print (const char *type, const char *format0, va_list argp)
 
          case 'u':
            arg[pos].type = TYPE_UINTEGER;
+           break;
 
          case 'l':
            c = *format++;
@@ -742,7 +769,7 @@ gfc_notification_std (int std)
    standard does not contain the requested bits.  Return FAILURE if
    an error is generated.  */
 
-try
+gfc_try
 gfc_notify_std (int std, const char *nocmsgid, ...)
 {
   va_list argp;
@@ -752,7 +779,7 @@ gfc_notify_std (int std, const char *nocmsgid, ...)
   if ((gfc_option.allow_std & std) != 0 && !warning)
     return SUCCESS;
 
-  if (gfc_suppress_error)
+  if (suppress_errors)
     return warning ? SUCCESS : FAILURE;
 
   cur_error_buffer = warning ? &warning_buffer : &error_buffer;
@@ -794,14 +821,16 @@ gfc_warning_now (const char *nocmsgid, ...)
   i = buffer_flag;
   buffer_flag = 0;
   warnings++;
-  if (warnings_are_errors)
-    gfc_increment_error_count();
 
   va_start (argp, nocmsgid);
   error_print (_("Warning:"), _(nocmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
+
+  if (warnings_are_errors)
+    gfc_increment_error_count();
+
   buffer_flag = i;
 }
 
@@ -838,7 +867,10 @@ gfc_error (const char *nocmsgid, ...)
 {
   va_list argp;
 
-  if (gfc_suppress_error)
+  if (warnings_not_errors)
+    goto warning;
+
+  if (suppress_errors)
     return;
 
   error_buffer.flag = 1;
@@ -853,6 +885,30 @@ gfc_error (const char *nocmsgid, ...)
 
   if (buffer_flag == 0)
     gfc_increment_error_count();
+
+  return;
+
+warning:
+
+  if (inhibit_warnings)
+    return;
+
+  warning_buffer.flag = 1;
+  warning_buffer.index = 0;
+  cur_error_buffer = &warning_buffer;
+
+  va_start (argp, nocmsgid);
+  error_print (_("Warning:"), _(nocmsgid), argp);
+  va_end (argp);
+
+  error_char ('\0');
+
+  if (buffer_flag == 0)
+  {
+    warnings++;
+    if (warnings_are_errors)
+      gfc_increment_error_count();
+  }
 }
 
 
@@ -930,6 +986,7 @@ void
 gfc_clear_error (void)
 {
   error_buffer.flag = 0;
+  warnings_not_errors = 0;
 }
 
 
@@ -1017,3 +1074,12 @@ gfc_get_errors (int *w, int *e)
   if (e != NULL)
     *e = errors;
 }
+
+
+/* Switch errors into warnings.  */
+
+void
+gfc_errors_to_warnings (int f)
+{
+  warnings_not_errors = (f == 1) ? 1 : 0;
+}