1 /* Declaration for error-reporting function for Bison.
3 Copyright (C) 2000-2002, 2004-2006, 2009-2013 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>. */
33 warnings warnings_flag
=
34 Wconflicts_sr
| Wconflicts_rr
| Wdeprecated
| Wother
;
38 err_status complaint_status
= status_none
;
39 static unsigned *indent_ptr
= 0;
42 warnings_print_categories (warnings warn_flags
)
44 if (! (warn_flags
& silent
))
46 char const *warn_names
[] =
59 for (i
= 0; i
< ARRAY_CARDINALITY (warn_names
); ++i
)
60 if (warn_flags
& 1 << i
)
62 bool err
= warn_flags
& errors_flag
;
63 fprintf (stderr
, "%s-W", any
? ", " : " [");
64 fprintf (stderr
, "%s%s", err
? "error=" : "" , warn_names
[i
]);
68 fprintf (stderr
, "]");
72 /** Report an error message.
74 * \param loc the location, defaulting to the current file,
75 * or the program name.
76 * \param flags the category for this message.
77 * \param prefix put before the message (e.g., "warning").
78 * \param message the error message, a printf format string. Iff it
79 * ends with ": ", then no trailing newline is printed,
80 * and the caller should print the remaining
81 * newline-terminated message to stderr.
82 * \param args the arguments of the format string.
86 error_message (const location
*loc
, warnings flags
, const char *prefix
,
87 const char *message
, va_list args
)
92 pos
+= location_print (*loc
, stderr
);
94 pos
+= fprintf (stderr
, "%s", current_file
? current_file
: program_name
);
95 pos
+= fprintf (stderr
, ": ");
103 else if (*indent_ptr
> pos
)
104 fprintf (stderr
, "%*s", *indent_ptr
- pos
, "");
109 fprintf (stderr
, "%s: ", prefix
);
111 vfprintf (stderr
, message
, args
);
112 warnings_print_categories (flags
);
114 size_t l
= strlen (message
);
115 if (l
< 2 || message
[l
- 2] != ':' || message
[l
- 1] != ' ')
119 if (loc
&& feature_flag
& feature_caret
&& !(flags
& no_caret
))
120 location_caret (*loc
, stderr
);
126 /** Raise a complaint. That can be a fatal error, a complaint or just a
129 complains (const location
*loc
, warnings flags
, const char *message
,
133 flags
& fatal
? _("fatal error")
134 : flags
& (errors_flag
| complaint
) ? _("error")
137 if ((flags
& complaint
) && complaint_status
< status_complaint
)
138 complaint_status
= status_complaint
;
139 else if ((flags
& (warnings_flag
& errors_flag
)) && ! complaint_status
)
140 complaint_status
= status_warning_as_error
;
141 if (flags
& (warnings_flag
| fatal
| complaint
))
142 error_message (loc
, flags
, prefix
, message
, args
);
148 complain (location
const *loc
, warnings flags
, const char *message
, ...)
151 va_start (args
, message
);
152 complains (loc
, flags
, message
, args
);
157 complain_indent (location
const *loc
, warnings flags
, unsigned *indent
,
158 const char *message
, ...)
162 va_start (args
, message
);
163 complains (loc
, flags
, message
, args
);
168 complain_args (location
const *loc
, warnings w
, unsigned *indent
,
169 int argc
, char *argv
[])
174 complain_indent (loc
, w
, indent
, "%s", _(argv
[0]));
177 complain_indent (loc
, w
, indent
, _(argv
[0]), argv
[1]);
180 complain_indent (loc
, w
, indent
, _(argv
[0]), argv
[1], argv
[2]);
183 complain_indent (loc
, w
, indent
, _(argv
[0]), argv
[1], argv
[2], argv
[3]);
186 complain_indent (loc
, w
, indent
, _(argv
[0]), argv
[1], argv
[2], argv
[3],
190 complain (loc
, fatal
, "too many arguments for complains");
197 deprecated_directive (location
const *loc
, char const *old
, char const *upd
)
199 if (feature_flag
& feature_caret
)
200 complain (loc
, Wdeprecated
,
201 _("deprecated directive, use %s"),
204 complain (loc
, Wdeprecated
,
205 _("deprecated directive: %s, use %s"),
206 quote (old
), quote_n (1, upd
));