Use -static when testing --gc-sections on native targets
[official-gcc.git] / gcc / cp / errfn.c
blobff2fb31e3e5162e2f45afd48a9efeb8cac957989
1 /* Provide a call-back mechanism for handling error output.
2 Copyright (C) 1993, 94, 95, 96, 97, 98, 99, 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)
11 any later version.
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. */
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "cp-tree.h"
27 #include "toplev.h"
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. */
40 int cp_silent = 0;
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
49 codes. */
51 static void
52 cp_thing (errfn, atarg1, format, ap)
53 errorfn *errfn;
54 int atarg1;
55 const char *format;
56 va_list ap;
58 static char *buf;
59 static long buflen;
60 int nargs = 0;
61 long len;
62 long offset;
63 const char *f;
64 tree atarg = 0;
66 len = strlen (format) + 1;
67 if (len > buflen)
69 buflen = len;
70 buf = xrealloc (buf, buflen);
72 offset = 0;
74 for (f = format; *f; ++f)
76 cp_printer * function;
77 int alternate;
78 int maybe_here;
80 /* ignore text */
81 if (*f != '%')
83 buf[offset++] = *f;
84 continue;
87 ++f;
89 alternate = 0;
90 maybe_here = 0;
92 /* Check for '+' and '#' (in that order). */
93 if (*f == '+')
95 maybe_here = 1;
96 ++f;
98 if (*f == '#')
100 alternate = 1;
101 ++f;
104 /* no field width or precision */
106 function = cp_printers[(int)*f];
108 if (function || *f == 's')
110 const char *p;
111 int plen;
113 if (*f == 's')
115 p = va_arg (ap, char *);
116 nargs++;
118 else
120 tree t = va_arg (ap, tree);
121 nargs++;
123 /* This indicates that ATARG comes from a different
124 location than normal. */
125 if (maybe_here && atarg1)
126 atarg = t;
128 /* If atarg1 is set and this is the first argument, then
129 set ATARG appropriately. */
130 if (atarg1 && nargs == 1)
131 atarg = t;
133 p = (*function) (t, alternate);
136 plen = strlen (p);
137 len += plen;
138 if (len > buflen)
140 buflen = len;
141 buf = xrealloc (buf, len);
143 strcpy (buf + offset, p);
144 offset += plen;
146 else if (*f == '%')
148 /* A `%%' has occurred in the input string. Replace it with
149 a `%' in the formatted message buf. */
151 if (++len > buflen)
153 buflen = len;
154 buf = xrealloc (buf, len);
156 buf[offset++] = '%';
158 else
160 if (*f != 'd')
161 abort ();
162 len += HOST_BITS_PER_INT / 2;
163 if (len > buflen)
165 buflen = len;
166 buf = xrealloc (buf, len);
168 sprintf (buf + offset, "%d", va_arg (ap, int));
169 nargs++;
170 offset += strlen (buf + offset);
171 /* With an ANSI C library one could write
172 out += sprintf (...); */
175 buf[offset] = '\0';
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);
182 if (atarg)
184 const char *file = cp_file_of (atarg);
185 int line = cp_line_of (atarg);
186 (*errfn) (file, line, "%s", buf);
188 else
189 (*errfn) ("%s", buf);
193 void
194 cp_error VPARAMS ((const char *format, ...))
196 #ifndef ANSI_PROTOTYPES
197 char *format;
198 #endif
199 va_list ap;
201 VA_START (ap, format);
203 #ifndef ANSI_PROTOTYPES
204 format = va_arg (ap, char *);
205 #endif
207 if (! cp_silent)
208 cp_thing ((errorfn *) error, 0, format, ap);
209 va_end (ap);
212 void
213 cp_warning VPARAMS ((const char *format, ...))
215 #ifndef ANSI_PROTOTYPES
216 char *format;
217 #endif
218 va_list ap;
220 VA_START (ap, format);
222 #ifndef ANSI_PROTOTYPES
223 format = va_arg (ap, char *);
224 #endif
226 if (! cp_silent)
227 cp_thing ((errorfn *) warning, 0, format, ap);
228 va_end (ap);
231 void
232 cp_pedwarn VPARAMS ((const char *format, ...))
234 #ifndef ANSI_PROTOTYPES
235 char *format;
236 #endif
237 va_list ap;
239 VA_START (ap, format);
241 #ifndef ANSI_PROTOTYPES
242 format = va_arg (ap, char *);
243 #endif
245 if (! cp_silent)
246 cp_thing ((errorfn *) pedwarn, 0, format, ap);
247 va_end (ap);
250 void
251 cp_compiler_error VPARAMS ((const char *format, ...))
253 #ifndef ANSI_PROTOTYPES
254 char *format;
255 #endif
256 va_list ap;
258 VA_START (ap, format);
260 #ifndef ANSI_PROTOTYPES
261 format = va_arg (ap, char *);
262 #endif
264 if (! cp_silent)
265 cp_thing ((errorfn *) compiler_error, 0, format, ap);
266 va_end (ap);
269 void
270 cp_deprecated (msg)
271 const char *msg;
273 extern int warn_deprecated;
274 if (!warn_deprecated)
275 return;
276 cp_warning ("%s is deprecated.", msg);
277 cp_warning ("Please see the documentation for details.");
280 void
281 cp_sprintf VPARAMS ((const char *format, ...))
283 #ifndef ANSI_PROTOTYPES
284 char *format;
285 #endif
286 va_list ap;
288 VA_START (ap, format);
290 #ifndef ANSI_PROTOTYPES
291 format = va_arg (ap, char *);
292 #endif
294 cp_thing ((errorfn *) sprintf, 0, format, ap);
295 va_end (ap);
298 void
299 cp_error_at VPARAMS ((const char *format, ...))
301 #ifndef ANSI_PROTOTYPES
302 char *format;
303 #endif
304 va_list ap;
306 VA_START (ap, format);
308 #ifndef ANSI_PROTOTYPES
309 format = va_arg (ap, char *);
310 #endif
312 if (! cp_silent)
313 cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
314 va_end (ap);
317 void
318 cp_warning_at VPARAMS ((const char *format, ...))
320 #ifndef ANSI_PROTOTYPES
321 char *format;
322 #endif
323 va_list ap;
325 VA_START (ap, format);
327 #ifndef ANSI_PROTOTYPES
328 format = va_arg (ap, char *);
329 #endif
331 if (! cp_silent)
332 cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
333 va_end (ap);
336 void
337 cp_pedwarn_at VPARAMS ((const char *format, ...))
339 #ifndef ANSI_PROTOTYPES
340 char *format;
341 #endif
342 va_list ap;
344 VA_START (ap, format);
346 #ifndef ANSI_PROTOTYPES
347 format = va_arg (ap, char *);
348 #endif
350 if (! cp_silent)
351 cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);
352 va_end (ap);