1 /* Provide a call-back mechanism for handling error output.
2 Copyright (C) 1993, 1994, 1995 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. */
33 /* cp_printer is the type of a function which converts an argument into
34 a string for digestion by printf. The cp_printer function should deal
35 with all memory management; the functions in this file will not free
36 the char*s returned. See error.c for an example use of this code. */
38 typedef char* cp_printer PROTO((tree, int));
39 extern cp_printer * cp_printers[256];
41 /* Whether or not we should try to be quiet for errors and warnings; this is
42 used to avoid being too talkative about problems with tentative choices
43 when we're computing the conversion costs for a method call. */
46 typedef void errorfn (); /* deliberately vague */
48 extern char* cp_file_of PROTO((tree));
49 extern int cp_line_of PROTO((tree));
51 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
53 /* This function supports only `%s', `%d', `%%', and the C++ print
58 cp_thing (errorfn *errfn, int atarg1, const char *format, va_list ap)
61 cp_thing (errfn, atarg1, format, ap)
76 len = strlen (format) + 1;
80 buf = xrealloc (buf, buflen);
84 for (f = format; *f; ++f)
86 cp_printer * function;
102 /* Check for '+' and '#' (in that order). */
114 /* no field width or precision */
116 function = cp_printers[(int)*f];
118 if (function || *f == 's')
125 p = va_arg (ap, char *);
130 tree t = va_arg (ap, tree);
133 /* This indicates that ATARG comes from a different
134 location than normal. */
135 if (maybe_here && atarg1)
138 /* If atarg1 is set and this is the first argument, then
139 set ATARG appropriately. */
140 if (atarg1 && nargs == 1)
143 p = (*function) (t, alternate);
151 buf = xrealloc (buf, len);
153 strcpy (buf + offset, p);
158 /* A `%%' has occurred in the input string. Since the
159 string we produce here will be passed to vprintf we must
160 preserve both `%' characters. */
166 buf = xrealloc (buf, len);
168 strcpy (buf + offset, "%%");
175 len += HOST_BITS_PER_INT / 2;
179 buf = xrealloc (buf, len);
181 sprintf (buf + offset, "%d", va_arg (ap, int));
183 offset += strlen (buf + offset);
184 /* With an ANSI C library one could write
185 out += sprintf (...); */
190 /* If ATARG1 is set, but we haven't extracted any arguments, then
191 extract one tree argument for ATARG. */
192 if (nargs == 0 && atarg1)
193 atarg = va_arg (ap, tree);
197 char *file = cp_file_of (atarg);
198 int line = cp_line_of (atarg);
199 (*errfn) (file, line, buf);
207 #define DECLARE(name) void name (const char *format, ...)
208 #define INIT va_start (ap, format)
210 #define DECLARE(name) void name (format, va_alist) char *format; va_dcl
211 #define INIT va_start (ap)
219 cp_thing ((errorfn *) error, 0, format, ap);
228 cp_thing ((errorfn *) warning, 0, format, ap);
237 cp_thing ((errorfn *) pedwarn, 0, format, ap);
241 DECLARE (cp_compiler_error)
243 extern errorfn compiler_error;
247 cp_thing (compiler_error, 0, format, ap);
255 cp_thing ((errorfn *) sprintf, 0, format, ap);
259 DECLARE (cp_error_at)
264 cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
268 DECLARE (cp_warning_at)
273 cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
277 DECLARE (cp_pedwarn_at)
282 cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);