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 /* Whether or not we should try to be quiet for errors and warnings; this is
30 used to avoid being too talkative about problems with tentative choices
31 when we're computing the conversion costs for a method call. */
34 typedef void errorfn (); /* deliberately vague */
36 static void cp_thing
PARAMS ((errorfn
*, int, const char *, va_list));
38 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
40 /* This function supports only `%s', `%d', `%%', and the C++ print
44 cp_thing (errfn
, atarg1
, format
, ap
)
58 len
= strlen (format
) + 1;
62 buf
= xrealloc (buf
, buflen
);
66 for (f
= format
; *f
; ++f
)
68 cp_printer
* function
;
84 /* Check for '+' and '#' (in that order). */
96 /* no field width or precision */
98 function
= cp_printers
[(int)*f
];
100 if (function
|| *f
== 's')
107 p
= va_arg (ap
, char *);
112 tree t
= va_arg (ap
, tree
);
115 /* This indicates that ATARG comes from a different
116 location than normal. */
117 if (maybe_here
&& atarg1
)
120 /* If atarg1 is set and this is the first argument, then
121 set ATARG appropriately. */
122 if (atarg1
&& nargs
== 1)
125 p
= (*function
) (t
, alternate
);
133 buf
= xrealloc (buf
, len
);
135 strcpy (buf
+ offset
, p
);
140 /* A `%%' has occurred in the input string. Replace it with
141 a `%' in the formatted message buf. */
146 buf
= xrealloc (buf
, len
);
154 len
+= HOST_BITS_PER_INT
/ 2;
158 buf
= xrealloc (buf
, len
);
160 sprintf (buf
+ offset
, "%d", va_arg (ap
, int));
162 offset
+= strlen (buf
+ offset
);
163 /* With an ANSI C library one could write
164 out += sprintf (...); */
169 /* If ATARG1 is set, but we haven't extracted any arguments, then
170 extract one tree argument for ATARG. */
171 if (nargs
== 0 && atarg1
)
172 atarg
= va_arg (ap
, tree
);
176 const char *file
= cp_file_of (atarg
);
177 int line
= cp_line_of (atarg
);
178 (*errfn
) (file
, line
, "%s", buf
);
181 (*errfn
) ("%s", buf
);
186 cp_error
VPARAMS ((const char *format
, ...))
188 #ifndef ANSI_PROTOTYPES
193 VA_START (ap
, format
);
195 #ifndef ANSI_PROTOTYPES
196 format
= va_arg (ap
, char *);
200 cp_thing ((errorfn
*) error
, 0, format
, ap
);
205 cp_warning
VPARAMS ((const char *format
, ...))
207 #ifndef ANSI_PROTOTYPES
212 VA_START (ap
, format
);
214 #ifndef ANSI_PROTOTYPES
215 format
= va_arg (ap
, char *);
219 cp_thing ((errorfn
*) warning
, 0, format
, ap
);
224 cp_pedwarn
VPARAMS ((const char *format
, ...))
226 #ifndef ANSI_PROTOTYPES
231 VA_START (ap
, format
);
233 #ifndef ANSI_PROTOTYPES
234 format
= va_arg (ap
, char *);
238 cp_thing ((errorfn
*) pedwarn
, 0, format
, ap
);
243 cp_compiler_error
VPARAMS ((const char *format
, ...))
245 #ifndef ANSI_PROTOTYPES
250 VA_START (ap
, format
);
252 #ifndef ANSI_PROTOTYPES
253 format
= va_arg (ap
, char *);
257 cp_thing ((errorfn
*) compiler_error
, 0, format
, ap
);
265 extern int warn_deprecated
;
266 if (!warn_deprecated
)
268 cp_warning ("%s is deprecated, please see the documentation for details", msg
);
272 cp_sprintf
VPARAMS ((const char *format
, ...))
274 #ifndef ANSI_PROTOTYPES
279 VA_START (ap
, format
);
281 #ifndef ANSI_PROTOTYPES
282 format
= va_arg (ap
, char *);
285 cp_thing ((errorfn
*) sprintf
, 0, format
, ap
);
290 cp_error_at
VPARAMS ((const char *format
, ...))
292 #ifndef ANSI_PROTOTYPES
297 VA_START (ap
, format
);
299 #ifndef ANSI_PROTOTYPES
300 format
= va_arg (ap
, char *);
304 cp_thing ((errorfn
*) error_with_file_and_line
, 1, format
, ap
);
309 cp_warning_at
VPARAMS ((const char *format
, ...))
311 #ifndef ANSI_PROTOTYPES
316 VA_START (ap
, format
);
318 #ifndef ANSI_PROTOTYPES
319 format
= va_arg (ap
, char *);
323 cp_thing ((errorfn
*) warning_with_file_and_line
, 1, format
, ap
);
328 cp_pedwarn_at
VPARAMS ((const char *format
, ...))
330 #ifndef ANSI_PROTOTYPES
335 VA_START (ap
, format
);
337 #ifndef ANSI_PROTOTYPES
338 format
= va_arg (ap
, char *);
342 cp_thing ((errorfn
*) pedwarn_with_file_and_line
, 1, format
, ap
);