OSDN Git Service

2010-05-28 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / fortran / error.c
index 4ef22d0..b05e669 100644 (file)
@@ -1,5 +1,6 @@
 /* Handle errors.
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+   2010
    Free Software Foundation, Inc.
    Contributed by Andy Vaught & Niels Kristian Bech Jensen
 
@@ -30,13 +31,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
@@ -287,14 +310,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
@@ -341,7 +356,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');
@@ -521,6 +536,7 @@ error_print (const char *type, const char *format0, va_list argp)
 
          case 'u':
            arg[pos].type = TYPE_UINTEGER;
+           break;
 
          case 'l':
            c = *format++;
@@ -682,12 +698,12 @@ error_print (const char *type, const char *format0, va_list argp)
 /* Wrapper for error_print().  */
 
 static void
-error_printf (const char *nocmsgid, ...)
+error_printf (const char *gmsgid, ...)
 {
   va_list argp;
 
-  va_start (argp, nocmsgid);
-  error_print ("", _(nocmsgid), argp);
+  va_start (argp, gmsgid);
+  error_print ("", _(gmsgid), argp);
   va_end (argp);
 }
 
@@ -707,7 +723,7 @@ gfc_increment_error_count (void)
 /* Issue a warning.  */
 
 void
-gfc_warning (const char *nocmsgid, ...)
+gfc_warning (const char *gmsgid, ...)
 {
   va_list argp;
 
@@ -718,8 +734,8 @@ gfc_warning (const char *nocmsgid, ...)
   warning_buffer.index = 0;
   cur_error_buffer = &warning_buffer;
 
-  va_start (argp, nocmsgid);
-  error_print (_("Warning:"), _(nocmsgid), argp);
+  va_start (argp, gmsgid);
+  error_print (_("Warning:"), _(gmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
@@ -754,8 +770,8 @@ gfc_notification_std (int std)
    standard does not contain the requested bits.  Return FAILURE if
    an error is generated.  */
 
-try
-gfc_notify_std (int std, const char *nocmsgid, ...)
+gfc_try
+gfc_notify_std (int std, const char *gmsgid, ...)
 {
   va_list argp;
   bool warning;
@@ -764,18 +780,18 @@ 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;
   cur_error_buffer->flag = 1;
   cur_error_buffer->index = 0;
 
-  va_start (argp, nocmsgid);
+  va_start (argp, gmsgid);
   if (warning)
-    error_print (_("Warning:"), _(nocmsgid), argp);
+    error_print (_("Warning:"), _(gmsgid), argp);
   else
-    error_print (_("Error:"), _(nocmsgid), argp);
+    error_print (_("Error:"), _(gmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
@@ -795,7 +811,7 @@ gfc_notify_std (int std, const char *nocmsgid, ...)
 /* Immediate warning (i.e. do not buffer the warning).  */
 
 void
-gfc_warning_now (const char *nocmsgid, ...)
+gfc_warning_now (const char *gmsgid, ...)
 {
   va_list argp;
   int i;
@@ -806,14 +822,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_start (argp, gmsgid);
+  error_print (_("Warning:"), _(gmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
+
+  if (warnings_are_errors)
+    gfc_increment_error_count();
+
   buffer_flag = i;
 }
 
@@ -846,32 +864,59 @@ gfc_warning_check (void)
 /* Issue an error.  */
 
 void
-gfc_error (const char *nocmsgid, ...)
+gfc_error (const char *gmsgid, ...)
 {
   va_list argp;
 
-  if (gfc_suppress_error)
+  if (warnings_not_errors)
+    goto warning;
+
+  if (suppress_errors)
     return;
 
   error_buffer.flag = 1;
   error_buffer.index = 0;
   cur_error_buffer = &error_buffer;
 
-  va_start (argp, nocmsgid);
-  error_print (_("Error:"), _(nocmsgid), argp);
+  va_start (argp, gmsgid);
+  error_print (_("Error:"), _(gmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
 
   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, gmsgid);
+  error_print (_("Warning:"), _(gmsgid), argp);
+  va_end (argp);
+
+  error_char ('\0');
+
+  if (buffer_flag == 0)
+  {
+    warnings++;
+    if (warnings_are_errors)
+      gfc_increment_error_count();
+  }
 }
 
 
 /* Immediate error.  */
 
 void
-gfc_error_now (const char *nocmsgid, ...)
+gfc_error_now (const char *gmsgid, ...)
 {
   va_list argp;
   int i;
@@ -883,8 +928,8 @@ gfc_error_now (const char *nocmsgid, ...)
   i = buffer_flag;
   buffer_flag = 0;
 
-  va_start (argp, nocmsgid);
-  error_print (_("Error:"), _(nocmsgid), argp);
+  va_start (argp, gmsgid);
+  error_print (_("Error:"), _(gmsgid), argp);
   va_end (argp);
 
   error_char ('\0');
@@ -901,14 +946,14 @@ gfc_error_now (const char *nocmsgid, ...)
 /* Fatal error, never returns.  */
 
 void
-gfc_fatal_error (const char *nocmsgid, ...)
+gfc_fatal_error (const char *gmsgid, ...)
 {
   va_list argp;
 
   buffer_flag = 0;
 
-  va_start (argp, nocmsgid);
-  error_print (_("Fatal Error:"), _(nocmsgid), argp);
+  va_start (argp, gmsgid);
+  error_print (_("Fatal Error:"), _(gmsgid), argp);
   va_end (argp);
 
   exit (3);
@@ -942,6 +987,7 @@ void
 gfc_clear_error (void)
 {
   error_buffer.flag = 0;
+  warnings_not_errors = 0;
 }
 
 
@@ -1029,3 +1075,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;
+}