OSDN Git Service

* decl.c (cp_finish_decl): When bailing on a comdat variable, also
[pf3gnuchains/gcc-fork.git] / gcc / cp / errfn.c
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)
4
5    This file is part of GNU CC.
6
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)
10 any later version.
11
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.
16
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.  */
21    
22 #include "config.h"
23 #include "tree.h"
24 #include <stdio.h>
25 #include <ctype.h>
26
27 /* cp_printer is the type of a function which converts an argument into
28    a string for digestion by printf.  The cp_printer function should deal
29    with all memory management; the functions in this file will not free
30    the char*s returned.  See error.c for an example use of this code.  */
31
32 typedef char* cp_printer PROTO((HOST_WIDE_INT, int));
33 extern cp_printer * cp_printers[256];
34
35 /* Whether or not we should try to be quiet for errors and warnings; this is
36    used to avoid being too talkative about problems with tentative choices
37    when we're computing the conversion costs for a method call.  */
38 int cp_silent = 0;
39
40 typedef void errorfn ();        /* deliberately vague */
41
42 extern char* cp_file_of PROTO((tree));
43 extern int   cp_line_of PROTO((tree));
44
45 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
46
47 #define NARGS 5
48 #define arglist a1, a2, a3, a4, a5
49 #define arglist_dcl HOST_WIDE_INT a1, a2, a3, a4, a5;
50 #define ARGSINIT \
51   args[0] = a1; args[1] = a2; args[2] = a3; args[3] = a4; args[4] = a5;
52 #define ARGSLIST args[0], args[1], args[2], args[3], args[4]
53
54 static void
55 cp_thing (errfn, atarg1, format, arglist)
56      errorfn *errfn;
57      int atarg1;
58      char *format;
59      arglist_dcl
60 {
61   char *fmt;
62   char *f;
63   char *ap;
64   int arg;
65   HOST_WIDE_INT atarg = atarg1 ? a1 : 0;
66   HOST_WIDE_INT args[NARGS];
67   ARGSINIT
68
69   fmt = STRDUP(format);
70   
71   for (f = fmt, arg = 0; *f; ++f)
72     {
73       cp_printer * function;
74       int alternate;
75       int maybe_here;
76       
77       /* ignore text */
78       if (*f != '%') continue;
79
80       ++f;
81
82       alternate = 0;
83       maybe_here = 0;
84
85       /* ignore most flags */
86       while (*f == ' ' || *f == '-' || *f == '+' || *f == '#')
87         {
88           if (*f == '+')
89             maybe_here = 1;
90           else if (*f == '#')
91             alternate = 1;
92           ++f;
93         }
94
95       /* ignore field width */
96       if (*f == '*')
97         {
98           ++f;
99           ++arg;
100         }
101       else
102         while (isdigit (*f))
103           ++f;
104
105       /* ignore precision */
106       if (*f == '.')
107         {
108           ++f;
109           if (*f == '*')
110             {
111               ++f;
112               ++arg;
113             }
114           else
115             while (isdigit (*f))
116               ++f;
117         }
118
119       /* ignore "long" */
120       if (*f == 'l')
121         ++f;
122
123       function = cp_printers[(int)*f];
124
125       if (function)
126         {
127           char *p;
128
129           if (arg >= NARGS) abort ();
130           
131           if (maybe_here && atarg1)
132             atarg = args[arg];
133
134           /* Must use a temporary to avoid calling *function twice */
135           p = (*function) (args[arg], alternate);
136           args[arg] = (HOST_WIDE_INT) STRDUP(p);
137           *f = 's';
138         }
139
140       ++arg;                    /* Assume valid format string */
141
142     }
143
144   if (atarg)
145     {
146       char *file = cp_file_of ((tree) atarg);
147       int   line = cp_line_of ((tree) atarg);
148       (*errfn) (file, line, fmt, ARGSLIST);
149     }
150   else
151     (*errfn) (fmt, ARGSLIST);
152
153 }
154
155 void
156 cp_error (format, arglist)
157      char *format;
158      arglist_dcl
159 {
160   extern errorfn error;
161   if (! cp_silent)
162     cp_thing (error, 0, format, arglist);
163 }
164
165 void
166 cp_warning (format, arglist)
167      char *format;
168      arglist_dcl
169 {
170   extern errorfn warning;
171   if (! cp_silent)
172     cp_thing (warning, 0, format, arglist);
173 }
174
175 void
176 cp_pedwarn (format, arglist)
177      char *format;
178      arglist_dcl
179 {
180   if (! cp_silent)
181     cp_thing ((errorfn *) pedwarn, 0, format, arglist);
182 }
183
184 void
185 cp_compiler_error (format, arglist)
186      char *format;
187      arglist_dcl
188 {
189   extern errorfn compiler_error;
190   if (! cp_silent)
191     cp_thing (compiler_error, 0, format, arglist);
192 }
193
194 void
195 cp_sprintf (format, arglist)
196      char *format;
197      arglist_dcl
198 {
199   cp_thing ((errorfn *) sprintf, 0, format, arglist);
200 }
201
202 void
203 cp_error_at (format, arglist)
204      char *format;
205      arglist_dcl
206 {
207   if (! cp_silent)
208     cp_thing ((errorfn *) error_with_file_and_line, 1, format, arglist);
209 }
210
211 void
212 cp_warning_at (format, arglist)
213      char *format;
214      arglist_dcl
215 {
216   if (! cp_silent)
217     cp_thing ((errorfn *) warning_with_file_and_line, 1, format, arglist);
218 }
219
220 void
221 cp_pedwarn_at (format, arglist)
222      char *format;
223      arglist_dcl
224 {
225   if (! cp_silent)
226     cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, arglist);
227 }