]> git.saurik.com Git - bison.git/blame - src/complain.c
Finish implementing --warnings=error, which should not be implied by
[bison.git] / src / complain.c
CommitLineData
a0f6b076 1/* Declaration for error-reporting function for Bison.
2cec9080 2
23eb2a69
AD
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
4 Free Software Foundation, Inc.
a0f6b076
AD
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
0fb669f9 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
a0f6b076
AD
19 USA. */
20
21/* Based on error.c and error.h,
22 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
23
2cec9080 24#include <config.h>
342b8b6e 25#include "system.h"
a0f6b076 26
21184140 27#include <stdarg.h>
a0f6b076 28
a0f6b076 29#include "complain.h"
4b68955b 30#include "files.h"
89eb3c76 31#include "getargs.h"
a0f6b076 32
a0f6b076
AD
33/* The calling program should define program_name and set it to the
34 name of the executing program. */
35extern char *program_name;
8f13fe33 36
0ae6073a 37bool complaint_issued;
a0f6b076 38
a0f6b076 39\f
a0f6b076 40
23eb2a69
AD
41/** Report an error message.
42 *
43 * \param loc the location, defaulting to the current file,
44 * or the program name.
45 * \param prefix put before the message (e.g., "warning").
46 * \param message the error message, a printf format string.
47 * \param args the arguments of the format string.
48 */
49static
e9955c83 50void
23eb2a69
AD
51error_message (location *loc,
52 const char *prefix,
53 const char *message, va_list args)
e9955c83 54{
23eb2a69
AD
55 if (loc)
56 location_print (stderr, *loc);
57 else
58 fputs (current_file ? current_file : program_name, stderr);
ee000ba4 59 fputs (": ", stderr);
e9955c83 60
23eb2a69
AD
61 if (prefix)
62 fprintf (stderr, "%s: ", prefix);
63
52489d44
AD
64 vfprintf (stderr, message, args);
65 va_end (args);
52489d44 66 putc ('\n', stderr);
23eb2a69
AD
67 fflush (stderr);
68}
69
70/** Wrap error_message() with varargs handling. */
71#define ERROR_MESSAGE(Loc, Prefix, Message) \
72{ \
73 va_list args; \
74 va_start (args, Message); \
75 error_message (Loc, Prefix, Message, args); \
76}
77
78
79/*--------------------------------.
80| Report a warning, and proceed. |
81`--------------------------------*/
82
89eb3c76
JD
83static void
84set_warning_issued (void)
85{
86 static bool warning_issued = false;
87 if (!warning_issued && (warnings_flag & warnings_error))
88 {
89 fprintf (stderr, "%s: warnings being treated as errors\n", program_name);
90 complaint_issued = true;
91 }
92 warning_issued = true;
93}
94
23eb2a69
AD
95void
96warn_at (location loc, const char *message, ...)
97{
89eb3c76 98 set_warning_issued ();
23eb2a69 99 ERROR_MESSAGE (&loc, _("warning"), message);
52489d44
AD
100}
101
102void
52489d44 103warn (const char *message, ...)
52489d44 104{
89eb3c76 105 set_warning_issued ();
23eb2a69
AD
106 ERROR_MESSAGE (NULL, _("warning"), message);
107}
52489d44 108
e9955c83 109
a0f6b076
AD
110/*-----------------------------------------------------------.
111| An error has occurred, but we can proceed, and die later. |
112`-----------------------------------------------------------*/
113
e9955c83 114void
41f83caf 115complain_at (location loc, const char *message, ...)
e9955c83 116{
23eb2a69 117 ERROR_MESSAGE (&loc, NULL, message);
0ae6073a 118 complaint_issued = true;
52489d44
AD
119}
120
121void
52489d44 122complain (const char *message, ...)
52489d44 123{
23eb2a69 124 ERROR_MESSAGE (NULL, NULL, message);
0ae6073a 125 complaint_issued = true;
e9955c83 126}
23eb2a69
AD
127
128
a0f6b076
AD
129/*-------------------------------------------------.
130| A severe error has occurred, we cannot proceed. |
131`-------------------------------------------------*/
132
e9955c83 133void
41f83caf 134fatal_at (location loc, const char *message, ...)
e9955c83 135{
23eb2a69 136 ERROR_MESSAGE (&loc, _("fatal error"), message);
0ae6073a 137 exit (EXIT_FAILURE);
e9955c83
AD
138}
139
a0f6b076 140void
a0f6b076 141fatal (const char *message, ...)
a0f6b076 142{
23eb2a69 143 ERROR_MESSAGE (NULL, _("fatal error"), message);
0ae6073a 144 exit (EXIT_FAILURE);
a0f6b076 145}