1 /* Provide a call-back mechanism for handling error output.
2 Copyright (C) 1993, 94-98, 1999 Free Software Foundation, Inc.
3 Contributed by Jason Merrill (jason@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 /* cp_printer is the type of a function which converts an argument into
29 a string for digestion by printf. The cp_printer function should deal
30 with all memory management; the functions in this file will not free
31 the char*s returned. See error.c for an example use of this code. */
33 typedef char* cp_printer PROTO((tree, int));
34 extern cp_printer * cp_printers[256];
36 /* Whether or not we should try to be quiet for errors and warnings; this is
37 used to avoid being too talkative about problems with tentative choices
38 when we're computing the conversion costs for a method call. */
41 typedef void errorfn (); /* deliberately vague */
43 static void cp_thing PROTO ((errorfn *, int, const char *, va_list));
45 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
47 /* This function supports only `%s', `%d', `%%', and the C++ print
51 cp_thing (errfn, atarg1, format, ap)
65 len = strlen (format) + 1;
69 buf = xrealloc (buf, buflen);
73 for (f = format; *f; ++f)
75 cp_printer * function;
91 /* Check for '+' and '#' (in that order). */
103 /* no field width or precision */
105 function = cp_printers[(int)*f];
107 if (function || *f == 's')
114 p = va_arg (ap, char *);
119 tree t = va_arg (ap, tree);
122 /* This indicates that ATARG comes from a different
123 location than normal. */
124 if (maybe_here && atarg1)
127 /* If atarg1 is set and this is the first argument, then
128 set ATARG appropriately. */
129 if (atarg1 && nargs == 1)
132 p = (*function) (t, alternate);
140 buf = xrealloc (buf, len);
142 strcpy (buf + offset, p);
147 /* A `%%' has occurred in the input string. Replace it with
148 a `%' in the formatted message buf. */
153 buf = xrealloc (buf, len);
161 len += HOST_BITS_PER_INT / 2;
165 buf = xrealloc (buf, len);
167 sprintf (buf + offset, "%d", va_arg (ap, int));
169 offset += strlen (buf + offset);
170 /* With an ANSI C library one could write
171 out += sprintf (...); */
176 /* If ATARG1 is set, but we haven't extracted any arguments, then
177 extract one tree argument for ATARG. */
178 if (nargs == 0 && atarg1)
179 atarg = va_arg (ap, tree);
183 char *file = cp_file_of (atarg);
184 int line = cp_line_of (atarg);
185 (*errfn) (file, line, "%s", buf);
188 (*errfn) ("%s", buf);
193 cp_error VPROTO((const char *format, ...))
195 #ifndef ANSI_PROTOTYPES
200 VA_START (ap, format);
202 #ifndef ANSI_PROTOTYPES
203 format = va_arg (ap, char *);
207 cp_thing ((errorfn *) error, 0, format, ap);
212 cp_warning VPROTO((const char *format, ...))
214 #ifndef ANSI_PROTOTYPES
219 VA_START (ap, format);
221 #ifndef ANSI_PROTOTYPES
222 format = va_arg (ap, char *);
226 cp_thing ((errorfn *) warning, 0, format, ap);
231 cp_pedwarn VPROTO((const char *format, ...))
233 #ifndef ANSI_PROTOTYPES
238 VA_START (ap, format);
240 #ifndef ANSI_PROTOTYPES
241 format = va_arg (ap, char *);
245 cp_thing ((errorfn *) pedwarn, 0, format, ap);
250 cp_compiler_error VPROTO((const char *format, ...))
252 #ifndef ANSI_PROTOTYPES
257 VA_START (ap, format);
259 #ifndef ANSI_PROTOTYPES
260 format = va_arg (ap, char *);
264 cp_thing ((errorfn *) compiler_error, 0, format, ap);
272 extern int warn_deprecated;
273 if (!warn_deprecated)
275 cp_warning ("%s is deprecated.", msg);
276 cp_warning ("Please see the documentation for details.");
280 cp_sprintf VPROTO((const char *format, ...))
282 #ifndef ANSI_PROTOTYPES
287 VA_START (ap, format);
289 #ifndef ANSI_PROTOTYPES
290 format = va_arg (ap, char *);
293 cp_thing ((errorfn *) sprintf, 0, format, ap);
298 cp_error_at VPROTO((const char *format, ...))
300 #ifndef ANSI_PROTOTYPES
305 VA_START (ap, format);
307 #ifndef ANSI_PROTOTYPES
308 format = va_arg (ap, char *);
312 cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
317 cp_warning_at VPROTO((const char *format, ...))
319 #ifndef ANSI_PROTOTYPES
324 VA_START (ap, format);
326 #ifndef ANSI_PROTOTYPES
327 format = va_arg (ap, char *);
331 cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
336 cp_pedwarn_at VPROTO((const char *format, ...))
338 #ifndef ANSI_PROTOTYPES
343 VA_START (ap, format);
345 #ifndef ANSI_PROTOTYPES
346 format = va_arg (ap, char *);
350 cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);