OSDN Git Service

* class.c (dfs_accumulate_vtbl_inits): Just point to the base we're
[pf3gnuchains/gcc-fork.git] / gcc / cp / errfn.c
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)
5
6    This file is part of GNU CC.
7
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.
12
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.
17
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.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "cp-tree.h"
27 #include "toplev.h"
28
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.  */
32 int cp_silent = 0;
33
34 typedef void errorfn ();        /* deliberately vague */
35
36 static void cp_thing PARAMS ((errorfn *, int, const char *, va_list));
37
38 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
39
40 /* This function supports only `%s', `%d', `%%', and the C++ print
41    codes.  */
42
43 static void
44 cp_thing (errfn, atarg1, format, ap)
45      errorfn *errfn;
46      int atarg1;
47      const char *format;
48      va_list ap;
49 {
50   static char *buf;
51   static long buflen;
52   int nargs = 0;
53   long len;
54   long offset;
55   const char *f;
56   tree atarg = 0;
57
58   len = strlen (format) + 1;
59   if (len > buflen)
60     {
61       buflen = len;
62       buf = xrealloc (buf, buflen);
63     }
64   offset = 0;
65
66   for (f = format; *f; ++f)
67     {
68       cp_printer * function;
69       int alternate;
70       int maybe_here;
71
72       /* ignore text */
73       if (*f != '%')
74         {
75           buf[offset++] = *f;
76           continue;
77         }
78
79       ++f;
80
81       alternate = 0;
82       maybe_here = 0;
83
84       /* Check for '+' and '#' (in that order). */
85       if (*f == '+')
86         {
87           maybe_here = 1;
88           ++f;
89         }
90       if (*f == '#')
91         {
92           alternate = 1;
93           ++f;
94         }
95
96       /* no field width or precision */
97
98       function = cp_printers[(int)*f];
99
100       if (function || *f == 's')
101         {
102           const char *p;
103           int plen;
104
105           if (*f == 's')
106             {
107               p = va_arg (ap, char *);
108               nargs++;
109             }
110           else
111             {
112               tree t = va_arg (ap, tree);
113               nargs++;
114
115               /* This indicates that ATARG comes from a different
116                  location than normal.  */
117               if (maybe_here && atarg1)
118                 atarg = t;
119
120               /* If atarg1 is set and this is the first argument, then
121                  set ATARG appropriately.  */
122               if (atarg1 && nargs == 1)
123                 atarg = t;
124
125               p = (*function) (t, alternate);
126             }
127
128           plen = strlen (p);
129           len += plen;
130           if (len > buflen)
131             {
132               buflen = len;
133               buf = xrealloc (buf, len);
134             }
135           strcpy (buf + offset, p);
136           offset += plen;
137         }
138       else if (*f == '%')
139         {
140           /* A `%%' has occurred in the input string. Replace it with
141              a `%' in the formatted message buf. */
142
143           if (++len > buflen)
144             {
145               buflen = len;
146               buf = xrealloc (buf, len);
147             }
148           buf[offset++] = '%';
149         }
150       else
151         {
152           if (*f != 'd')
153             abort ();
154           len += HOST_BITS_PER_INT / 2;
155           if (len > buflen)
156             {
157               buflen = len;
158               buf = xrealloc (buf, len);
159             }
160           sprintf (buf + offset, "%d", va_arg (ap, int));
161           nargs++;
162           offset += strlen (buf + offset);
163           /* With an ANSI C library one could write
164              out += sprintf (...); */
165         }
166     }
167   buf[offset] = '\0';
168
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);
173
174   if (atarg)
175     {
176       const char *file = cp_file_of (atarg);
177       int   line = cp_line_of (atarg);
178       (*errfn) (file, line, "%s", buf);
179     }
180   else
181     (*errfn) ("%s", buf);
182
183 }
184
185 void
186 cp_error VPARAMS ((const char *format, ...))
187 {
188 #ifndef ANSI_PROTOTYPES
189   char *format;
190 #endif
191   va_list ap;
192
193   VA_START (ap, format);
194
195 #ifndef ANSI_PROTOTYPES
196   format = va_arg (ap, char *);
197 #endif
198
199   if (! cp_silent)
200     cp_thing ((errorfn *) error, 0, format, ap);
201   va_end (ap);
202 }
203
204 void
205 cp_warning VPARAMS ((const char *format, ...))
206 {
207 #ifndef ANSI_PROTOTYPES
208   char *format;
209 #endif
210   va_list ap;
211
212   VA_START (ap, format);
213
214 #ifndef ANSI_PROTOTYPES
215   format = va_arg (ap, char *);
216 #endif
217
218   if (! cp_silent)
219     cp_thing ((errorfn *) warning, 0, format, ap);
220   va_end (ap);
221 }
222
223 void
224 cp_pedwarn VPARAMS ((const char *format, ...))
225 {
226 #ifndef ANSI_PROTOTYPES
227   char *format;
228 #endif
229   va_list ap;
230
231   VA_START (ap, format);
232
233 #ifndef ANSI_PROTOTYPES
234   format = va_arg (ap, char *);
235 #endif
236
237   if (! cp_silent)
238     cp_thing ((errorfn *) pedwarn, 0, format, ap);
239   va_end (ap);
240 }
241
242 void
243 cp_compiler_error VPARAMS ((const char *format, ...))
244 {
245 #ifndef ANSI_PROTOTYPES
246   char *format;
247 #endif
248   va_list ap;
249
250   VA_START (ap, format);
251
252 #ifndef ANSI_PROTOTYPES
253   format = va_arg (ap, char *);
254 #endif
255
256   if (! cp_silent)
257     cp_thing ((errorfn *) compiler_error, 0, format, ap);
258   va_end (ap);
259 }
260
261 void
262 cp_deprecated (msg)
263   const char *msg;
264 {
265   extern int warn_deprecated;
266   if (!warn_deprecated)
267     return;
268   cp_warning ("%s is deprecated, please see the documentation for details", msg);
269 }
270
271 void
272 cp_sprintf VPARAMS ((const char *format, ...))
273 {
274 #ifndef ANSI_PROTOTYPES
275   char *format;
276 #endif
277   va_list ap;
278
279   VA_START (ap, format);
280
281 #ifndef ANSI_PROTOTYPES
282   format = va_arg (ap, char *);
283 #endif
284
285   cp_thing ((errorfn *) sprintf, 0, format, ap);
286   va_end (ap);
287 }
288
289 void
290 cp_error_at VPARAMS ((const char *format, ...))
291 {
292 #ifndef ANSI_PROTOTYPES
293   char *format;
294 #endif
295   va_list ap;
296
297   VA_START (ap, format);
298
299 #ifndef ANSI_PROTOTYPES
300   format = va_arg (ap, char *);
301 #endif
302
303   if (! cp_silent)
304     cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
305   va_end (ap);
306 }
307
308 void
309 cp_warning_at VPARAMS ((const char *format, ...))
310 {
311 #ifndef ANSI_PROTOTYPES
312   char *format;
313 #endif
314   va_list ap;
315
316   VA_START (ap, format);
317
318 #ifndef ANSI_PROTOTYPES
319   format = va_arg (ap, char *);
320 #endif
321
322   if (! cp_silent)
323     cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
324   va_end (ap);
325 }
326
327 void
328 cp_pedwarn_at VPARAMS ((const char *format, ...))
329 {
330 #ifndef ANSI_PROTOTYPES
331   char *format;
332 #endif
333   va_list ap;
334
335   VA_START (ap, format);
336
337 #ifndef ANSI_PROTOTYPES
338   format = va_arg (ap, char *);
339 #endif
340
341   if (! cp_silent)
342     cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);
343   va_end (ap);
344 }