1 /* Provide a call-back mechanism for handling error output.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Jason Merrill (jason@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 /* cp_printer is the type of a function which converts an argument into
30 a string for digestion by printf. The cp_printer function should deal
31 with all memory management; the functions in this file will not free
32 the char*s returned. See error.c for an example use of this code. */
34 typedef const char *cp_printer
PARAMS ((tree
, int));
35 extern cp_printer
* cp_printers
[256];
37 /* Whether or not we should try to be quiet for errors and warnings; this is
38 used to avoid being too talkative about problems with tentative choices
39 when we're computing the conversion costs for a method call. */
42 typedef void errorfn (); /* deliberately vague */
44 static void cp_thing
PARAMS ((errorfn
*, int, const char *, va_list));
46 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
48 /* This function supports only `%s', `%d', `%%', and the C++ print
52 cp_thing (errfn
, atarg1
, format
, ap
)
66 len
= strlen (format
) + 1;
70 buf
= xrealloc (buf
, buflen
);
74 for (f
= format
; *f
; ++f
)
76 cp_printer
* function
;
92 /* Check for '+' and '#' (in that order). */
104 /* no field width or precision */
106 function
= cp_printers
[(int)*f
];
108 if (function
|| *f
== 's')
115 p
= va_arg (ap
, char *);
120 tree t
= va_arg (ap
, tree
);
123 /* This indicates that ATARG comes from a different
124 location than normal. */
125 if (maybe_here
&& atarg1
)
128 /* If atarg1 is set and this is the first argument, then
129 set ATARG appropriately. */
130 if (atarg1
&& nargs
== 1)
133 p
= (*function
) (t
, alternate
);
141 buf
= xrealloc (buf
, len
);
143 strcpy (buf
+ offset
, p
);
148 /* A `%%' has occurred in the input string. Replace it with
149 a `%' in the formatted message buf. */
154 buf
= xrealloc (buf
, len
);
162 len
+= HOST_BITS_PER_INT
/ 2;
166 buf
= xrealloc (buf
, len
);
168 sprintf (buf
+ offset
, "%d", va_arg (ap
, int));
170 offset
+= strlen (buf
+ offset
);
171 /* With an ANSI C library one could write
172 out += sprintf (...); */
177 /* If ATARG1 is set, but we haven't extracted any arguments, then
178 extract one tree argument for ATARG. */
179 if (nargs
== 0 && atarg1
)
180 atarg
= va_arg (ap
, tree
);
184 const char *file
= cp_file_of (atarg
);
185 int line
= cp_line_of (atarg
);
186 (*errfn
) (file
, line
, "%s", buf
);
189 (*errfn
) ("%s", buf
);
194 cp_error
VPARAMS ((const char *format
, ...))
196 #ifndef ANSI_PROTOTYPES
201 VA_START (ap
, format
);
203 #ifndef ANSI_PROTOTYPES
204 format
= va_arg (ap
, char *);
208 cp_thing ((errorfn
*) error
, 0, format
, ap
);
213 cp_warning
VPARAMS ((const char *format
, ...))
215 #ifndef ANSI_PROTOTYPES
220 VA_START (ap
, format
);
222 #ifndef ANSI_PROTOTYPES
223 format
= va_arg (ap
, char *);
227 cp_thing ((errorfn
*) warning
, 0, format
, ap
);
232 cp_pedwarn
VPARAMS ((const char *format
, ...))
234 #ifndef ANSI_PROTOTYPES
239 VA_START (ap
, format
);
241 #ifndef ANSI_PROTOTYPES
242 format
= va_arg (ap
, char *);
246 cp_thing ((errorfn
*) pedwarn
, 0, format
, ap
);
251 cp_compiler_error
VPARAMS ((const char *format
, ...))
253 #ifndef ANSI_PROTOTYPES
258 VA_START (ap
, format
);
260 #ifndef ANSI_PROTOTYPES
261 format
= va_arg (ap
, char *);
265 cp_thing ((errorfn
*) compiler_error
, 0, format
, ap
);
273 extern int warn_deprecated
;
274 if (!warn_deprecated
)
276 cp_warning ("%s is deprecated.", msg
);
277 cp_warning ("Please see the documentation for details.");
281 cp_sprintf
VPARAMS ((const char *format
, ...))
283 #ifndef ANSI_PROTOTYPES
288 VA_START (ap
, format
);
290 #ifndef ANSI_PROTOTYPES
291 format
= va_arg (ap
, char *);
294 cp_thing ((errorfn
*) sprintf
, 0, format
, ap
);
299 cp_error_at
VPARAMS ((const char *format
, ...))
301 #ifndef ANSI_PROTOTYPES
306 VA_START (ap
, format
);
308 #ifndef ANSI_PROTOTYPES
309 format
= va_arg (ap
, char *);
313 cp_thing ((errorfn
*) error_with_file_and_line
, 1, format
, ap
);
318 cp_warning_at
VPARAMS ((const char *format
, ...))
320 #ifndef ANSI_PROTOTYPES
325 VA_START (ap
, format
);
327 #ifndef ANSI_PROTOTYPES
328 format
= va_arg (ap
, char *);
332 cp_thing ((errorfn
*) warning_with_file_and_line
, 1, format
, ap
);
337 cp_pedwarn_at
VPARAMS ((const char *format
, ...))
339 #ifndef ANSI_PROTOTYPES
344 VA_START (ap
, format
);
346 #ifndef ANSI_PROTOTYPES
347 format
= va_arg (ap
, char *);
351 cp_thing ((errorfn
*) pedwarn_with_file_and_line
, 1, format
, ap
);