]>
git.saurik.com Git - bison.git/blob - src/complain.c
7428a4af2f50c95493116348e7d83930f5a94c7b
1 /* Declaration for error-reporting function for Bison.
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
4 Free Software Foundation, Inc.
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
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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 /* Based on error.c and error.h,
22 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
33 /* The calling program should define program_name and set it to the
34 name of the executing program. */
35 extern char *program_name
;
37 bool complaint_issued
;
41 /** Report an error message.
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.
51 error_message (location
*loc
,
53 const char *message
, va_list args
)
56 location_print (stderr
, *loc
);
58 fputs (current_file
? current_file
: program_name
, stderr
);
62 fprintf (stderr
, "%s: ", prefix
);
64 vfprintf (stderr
, message
, args
);
70 /** Wrap error_message() with varargs handling. */
71 #define ERROR_MESSAGE(Loc, Prefix, Message) \
74 va_start (args, Message); \
75 error_message (Loc, Prefix, Message, args); \
79 /*--------------------------------.
80 | Report a warning, and proceed. |
81 `--------------------------------*/
84 set_warning_issued (void)
86 static bool warning_issued
= false;
87 if (!warning_issued
&& (warnings_flag
& warnings_error
))
89 fprintf (stderr
, "%s: warnings being treated as errors\n", program_name
);
90 complaint_issued
= true;
92 warning_issued
= true;
96 warn_at (location loc
, const char *message
, ...)
98 set_warning_issued ();
99 ERROR_MESSAGE (&loc
, _("warning"), message
);
103 warn (const char *message
, ...)
105 set_warning_issued ();
106 ERROR_MESSAGE (NULL
, _("warning"), message
);
110 /*-----------------------------------------------------------.
111 | An error has occurred, but we can proceed, and die later. |
112 `-----------------------------------------------------------*/
115 complain_at (location loc
, const char *message
, ...)
117 ERROR_MESSAGE (&loc
, NULL
, message
);
118 complaint_issued
= true;
122 complain (const char *message
, ...)
124 ERROR_MESSAGE (NULL
, NULL
, message
);
125 complaint_issued
= true;
129 /*-------------------------------------------------.
130 | A severe error has occurred, we cannot proceed. |
131 `-------------------------------------------------*/
134 fatal_at (location loc
, const char *message
, ...)
136 ERROR_MESSAGE (&loc
, _("fatal error"), message
);
141 fatal (const char *message
, ...)
143 ERROR_MESSAGE (NULL
, _("fatal error"), message
);