]>
git.saurik.com Git - bison.git/blob - src/complain.c
   1 /* Declaration for error-reporting function for Bison. 
   3    Copyright (C) 2000-2002, 2004-2006, 2009-2012 Free Software 
   6    This program is free software: you can redistribute it and/or modify 
   7    it under the terms of the GNU General Public License as published by 
   8    the Free Software Foundation, either version 3 of the License, or 
   9    (at your option) any later version. 
  11    This program is distributed in the hope that it will be useful, 
  12    but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  14    GNU General Public License for more details. 
  16    You should have received a copy of the GNU General Public License 
  17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */ 
  19 /* Based on error.c and error.h, 
  20    written by David MacKenzie <djm@gnu.ai.mit.edu>.  */ 
  31 bool complaint_issued
; 
  32 static unsigned *indent_ptr 
= 0; 
  36 /** Report an error message. 
  38  * \param loc     the location, defaulting to the current file, 
  39  *                or the program name. 
  40  * \param prefix  put before the message (e.g., "warning"). 
  41  * \param message the error message, a printf format string.  Iff it 
  42  *                ends with ": ", then no trailing newline is printed, 
  43  *                and the caller should print the remaining 
  44  *                newline-terminated message to stderr. 
  45  * \param args    the arguments of the format string. 
  49 error_message (location 
*loc
, 
  51                const char *message
, va_list args
) 
  56     pos 
+= location_print (stderr
, *loc
); 
  58     pos 
+= fprintf(stderr
, "%s", current_file 
? current_file 
: program_name
); 
  59   pos 
+= fprintf(stderr
, ": "); 
  65       else if (*indent_ptr 
> pos
) 
  66         fprintf (stderr
, "%*s", *indent_ptr 
- pos
, ""); 
  71     fprintf (stderr
, "%s: ", prefix
); 
  73   vfprintf (stderr
, message
, args
); 
  75     size_t l 
= strlen (message
); 
  76     if (l 
< 2 || message
[l
-2] != ':' || message
[l
-1] != ' ') { 
  83 /** Wrap error_message() with varargs handling. */ 
  84 #define ERROR_MESSAGE(Loc, Prefix, Message)     \ 
  87   va_start (args, Message);                     \ 
  88   error_message (Loc, Prefix, Message, args);   \ 
  93 /*--------------------------------. 
  94 | Report a warning, and proceed.  | 
  95 `--------------------------------*/ 
  98 set_warning_issued (void) 
 100   static bool warning_issued 
= false; 
 101   if (!warning_issued 
&& (warnings_flag 
& warnings_error
)) 
 103       fprintf (stderr
, "%s: warnings being treated as errors\n", program_name
); 
 104       complaint_issued 
= true; 
 106   warning_issued 
= true; 
 110 warn_at (location loc
, const char *message
, ...) 
 112   if (!(warnings_flag 
& warnings_other
)) 
 114   set_warning_issued (); 
 115   ERROR_MESSAGE (&loc
, _("warning"), message
); 
 119 warn_at_indent (location loc
, unsigned *indent
, 
 120                 const char *message
, ...) 
 122   if (!(warnings_flag 
& warnings_other
)) 
 124   set_warning_issued (); 
 126   ERROR_MESSAGE (&loc
, _("warning"), message
); 
 130 warn (const char *message
, ...) 
 132   if (!(warnings_flag 
& warnings_other
)) 
 134   set_warning_issued (); 
 135   ERROR_MESSAGE (NULL
, _("warning"), message
); 
 139 /*-----------------------------------------------------------. 
 140 | An error has occurred, but we can proceed, and die later.  | 
 141 `-----------------------------------------------------------*/ 
 144 complain_at (location loc
, const char *message
, ...) 
 146   ERROR_MESSAGE (&loc
, NULL
, message
); 
 147   complaint_issued 
= true; 
 151 complain_at_indent (location loc
, unsigned *indent
, 
 152                     const char *message
, ...) 
 155   ERROR_MESSAGE (&loc
, NULL
, message
); 
 156   complaint_issued 
= true; 
 160 complain (const char *message
, ...) 
 162   ERROR_MESSAGE (NULL
, NULL
, message
); 
 163   complaint_issued 
= true; 
 167 /*--------------------------------------------------------------. 
 168 | An incompatibility with POSIX Yacc: mapped either to warn* or | 
 169 | complain* depending on yacc_flag.                             | 
 170 `--------------------------------------------------------------*/ 
 173 yacc_at (location loc
, const char *message
, ...) 
 177       ERROR_MESSAGE (&loc
, NULL
, message
); 
 178       complaint_issued 
= true; 
 180   else if (warnings_flag 
& warnings_yacc
) 
 182       set_warning_issued (); 
 183       ERROR_MESSAGE (&loc
, _("warning"), message
); 
 188 midrule_value_at (location loc
, const char *message
, ...) 
 190   if (!(warnings_flag 
& warnings_midrule_values
)) 
 192   set_warning_issued (); 
 193   ERROR_MESSAGE (&loc
, _("warning"), message
); 
 196 /*-------------------------------------------------. 
 197 | A severe error has occurred, we cannot proceed.  | 
 198 `-------------------------------------------------*/ 
 201 fatal_at (location loc
, const char *message
, ...) 
 203   ERROR_MESSAGE (&loc
, _("fatal error"), message
); 
 208 fatal (const char *message
, ...) 
 210   ERROR_MESSAGE (NULL
, _("fatal error"), message
);