OSDN Git Service

Remove CYGNUS LOCAL tags.
[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 4
48 #define arglist a1, a2, a3, a4
49 #define arglist_dcl HOST_WIDE_INT a1, a2, a3, a4;
50 #define ARGSINIT args[0] = a1; args[1] = a2; args[2] = a3; args[3] = a4;
51 #define ARGSLIST args[0], args[1], args[2], args[3]
52
53 static void
54 cp_thing (errfn, atarg1, format, arglist)
55      errorfn *errfn;
56      int atarg1;
57      char *format;
58      arglist_dcl
59 {
60   char *fmt;
61   char *f;
62   char *ap;
63   int arg;
64   HOST_WIDE_INT atarg = atarg1 ? a1 : 0;
65   HOST_WIDE_INT args[NARGS];
66   ARGSINIT
67
68   fmt = STRDUP(format);
69   
70   for (f = fmt, arg = 0; *f; ++f)
71     {
72       cp_printer * function;
73       int alternate;
74       int maybe_here;
75       
76       /* ignore text */
77       if (*f != '%') continue;
78
79       ++f;
80
81       alternate = 0;
82       maybe_here = 0;
83
84       /* ignore most flags */
85       while (*f == ' ' || *f == '-' || *f == '+' || *f == '#')
86         {
87           if (*f == '+')
88             maybe_here = 1;
89           else if (*f == '#')
90             alternate = 1;
91           ++f;
92         }
93
94       /* ignore field width */
95       if (*f == '*')
96         {
97           ++f;
98           ++arg;
99         }
100       else
101         while (isdigit (*f))
102           ++f;
103
104       /* ignore precision */
105       if (*f == '.')
106         {
107           ++f;
108           if (*f == '*')
109             {
110               ++f;
111               ++arg;
112             }
113           else
114             while (isdigit (*f))
115               ++f;
116         }
117
118       /* ignore "long" */
119       if (*f == 'l')
120         ++f;
121
122       function = cp_printers[(int)*f];
123
124       if (function)
125         {
126           char *p;
127
128           if (arg >= NARGS) abort ();
129           
130           if (maybe_here && atarg1)
131             atarg = args[arg];
132
133           /* Must use a temporary to avoid calling *function twice */
134           p = (*function) (args[arg], alternate);
135           args[arg] = (HOST_WIDE_INT) STRDUP(p);
136           *f = 's';
137         }
138
139       ++arg;                    /* Assume valid format string */
140
141     }
142
143   if (atarg)
144     {
145       char *file = cp_file_of ((tree) atarg);
146       int   line = cp_line_of ((tree) atarg);
147       (*errfn) (file, line, fmt, ARGSLIST);
148     }
149   else
150     (*errfn) (fmt, ARGSLIST);
151
152 }
153
154 void
155 cp_error (format, arglist)
156      char *format;
157      arglist_dcl
158 {
159   extern errorfn error;
160   if (! cp_silent)
161     cp_thing (error, 0, format, arglist);
162 }
163
164 void
165 cp_warning (format, arglist)
166      char *format;
167      arglist_dcl
168 {
169   extern errorfn warning;
170   if (! cp_silent)
171     cp_thing (warning, 0, format, arglist);
172 }
173
174 void
175 cp_pedwarn (format, arglist)
176      char *format;
177      arglist_dcl
178 {
179   extern errorfn pedwarn;
180   if (! cp_silent)
181     cp_thing (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   extern errorfn error_with_file_and_line;
208   if (! cp_silent)
209     cp_thing (error_with_file_and_line, 1, format, arglist);
210 }
211
212 void
213 cp_warning_at (format, arglist)
214      char *format;
215      arglist_dcl
216 {
217   extern errorfn warning_with_file_and_line;
218   if (! cp_silent)
219     cp_thing (warning_with_file_and_line, 1, format, arglist);
220 }
221
222 void
223 cp_pedwarn_at (format, arglist)
224      char *format;
225      arglist_dcl
226 {
227   extern errorfn pedwarn_with_file_and_line;
228   if (! cp_silent)
229     cp_thing (pedwarn_with_file_and_line, 1, format, arglist);
230 }