]>
git.saurik.com Git - bison.git/blob - src/complain.c
f7900af45fb8e2ece805d32c4057ce041c0941bb
1 /* Declaration for error-reporting function for Bison.
3 Copyright (C) 2000-2002, 2004-2006, 2009-2010 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.
42 * \param args the arguments of the format string.
46 error_message (location
*loc
,
48 const char *message
, va_list args
)
53 pos
+= location_print (stderr
, *loc
);
55 pos
+= fprintf(stderr
, "%s", current_file
? current_file
: program_name
);
56 pos
+= fprintf(stderr
, ": ");
62 else if (*indent_ptr
> pos
)
63 fprintf (stderr
, "%*s", *indent_ptr
- pos
, "");
68 fprintf (stderr
, "%s: ", prefix
);
70 vfprintf (stderr
, message
, args
);
75 /** Wrap error_message() with varargs handling. */
76 #define ERROR_MESSAGE(Loc, Prefix, Message) \
79 va_start (args, Message); \
80 error_message (Loc, Prefix, Message, args); \
85 /*--------------------------------.
86 | Report a warning, and proceed. |
87 `--------------------------------*/
90 set_warning_issued (void)
92 static bool warning_issued
= false;
93 if (!warning_issued
&& (warnings_flag
& warnings_error
))
95 fprintf (stderr
, "%s: warnings being treated as errors\n", program_name
);
96 complaint_issued
= true;
98 warning_issued
= true;
102 warn_at (location loc
, const char *message
, ...)
104 set_warning_issued ();
105 ERROR_MESSAGE (&loc
, _("warning"), message
);
109 warn_at_indent (location loc
, unsigned *indent
,
110 const char *message
, ...)
112 set_warning_issued ();
114 ERROR_MESSAGE (&loc
, _("warning"), message
);
118 warn (const char *message
, ...)
120 set_warning_issued ();
121 ERROR_MESSAGE (NULL
, _("warning"), message
);
125 /*-----------------------------------------------------------.
126 | An error has occurred, but we can proceed, and die later. |
127 `-----------------------------------------------------------*/
130 complain_at (location loc
, const char *message
, ...)
132 ERROR_MESSAGE (&loc
, NULL
, message
);
133 complaint_issued
= true;
137 complain_at_indent (location loc
, unsigned *indent
,
138 const char *message
, ...)
141 ERROR_MESSAGE (&loc
, NULL
, message
);
142 complaint_issued
= true;
146 complain (const char *message
, ...)
148 ERROR_MESSAGE (NULL
, NULL
, message
);
149 complaint_issued
= true;
153 /*--------------------------------------------------------------.
154 | An incompatibility with POSIX Yacc: mapped either to warn* or |
155 | complain* depending on yacc_flag. |
156 `--------------------------------------------------------------*/
159 yacc_at (location loc
, const char *message
, ...)
163 ERROR_MESSAGE (&loc
, NULL
, message
);
164 complaint_issued
= true;
166 else if (warnings_flag
& warnings_yacc
)
168 set_warning_issued ();
169 ERROR_MESSAGE (&loc
, _("warning"), message
);
174 /*-------------------------------------------------.
175 | A severe error has occurred, we cannot proceed. |
176 `-------------------------------------------------*/
179 fatal_at (location loc
, const char *message
, ...)
181 ERROR_MESSAGE (&loc
, _("fatal error"), message
);
186 fatal (const char *message
, ...)
188 ERROR_MESSAGE (NULL
, _("fatal error"), message
);