]> git.saurik.com Git - bison.git/blame_incremental - src/complain.c
Don't apply the default %destructor or %printer to the error token,
[bison.git] / src / complain.c
... / ...
CommitLineData
1/* Declaration for error-reporting function for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006
4 Free Software Foundation, Inc.
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
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 USA. */
20
21/* Based on error.c and error.h,
22 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
23
24#include <config.h>
25#include "system.h"
26
27#include <stdarg.h>
28
29#include "complain.h"
30#include "files.h"
31
32/* The calling program should define program_name and set it to the
33 name of the executing program. */
34extern char *program_name;
35
36bool complaint_issued;
37
38\f
39
40/** Report an error message.
41 *
42 * \param loc the location, defaulting to the current file,
43 * or the program name.
44 * \param prefix put before the message (e.g., "warning").
45 * \param message the error message, a printf format string.
46 * \param args the arguments of the format string.
47 */
48static
49void
50error_message (location *loc,
51 const char *prefix,
52 const char *message, va_list args)
53{
54 if (loc)
55 location_print (stderr, *loc);
56 else
57 fputs (current_file ? current_file : program_name, stderr);
58 fputs (": ", stderr);
59
60 if (prefix)
61 fprintf (stderr, "%s: ", prefix);
62
63 vfprintf (stderr, message, args);
64 va_end (args);
65 putc ('\n', stderr);
66 fflush (stderr);
67}
68
69/** Wrap error_message() with varargs handling. */
70#define ERROR_MESSAGE(Loc, Prefix, Message) \
71{ \
72 va_list args; \
73 va_start (args, Message); \
74 error_message (Loc, Prefix, Message, args); \
75}
76
77
78/*--------------------------------.
79| Report a warning, and proceed. |
80`--------------------------------*/
81
82void
83warn_at (location loc, const char *message, ...)
84{
85 ERROR_MESSAGE (&loc, _("warning"), message);
86}
87
88void
89warn (const char *message, ...)
90{
91 ERROR_MESSAGE (NULL, _("warning"), message);
92}
93
94
95/*-----------------------------------------------------------.
96| An error has occurred, but we can proceed, and die later. |
97`-----------------------------------------------------------*/
98
99void
100complain_at (location loc, const char *message, ...)
101{
102 ERROR_MESSAGE (&loc, NULL, message);
103 complaint_issued = true;
104}
105
106void
107complain (const char *message, ...)
108{
109 ERROR_MESSAGE (NULL, NULL, message);
110 complaint_issued = true;
111}
112
113
114/*-------------------------------------------------.
115| A severe error has occurred, we cannot proceed. |
116`-------------------------------------------------*/
117
118void
119fatal_at (location loc, const char *message, ...)
120{
121 ERROR_MESSAGE (&loc, _("fatal error"), message);
122 exit (EXIT_FAILURE);
123}
124
125void
126fatal (const char *message, ...)
127{
128 ERROR_MESSAGE (NULL, _("fatal error"), message);
129 exit (EXIT_FAILURE);
130}