1 /* Provide a call-back mechanism for handling error output.
2 Copyright (C) 1993 Free Software Foundation, Inc.
3 Contributed by Jason Merrill (jason@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* cp_printer is the type of a function which converts an argument into
26 a string for digestion by printf. The cp_printer function should deal
27 with all memory management; the functions in this file will not free
28 the char*s returned. See error.c for an example use of this code. */
30 typedef char* cp_printer PROTO((HOST_WIDE_INT, int));
31 extern cp_printer * cp_printers[256];
33 typedef void errorfn (); /* deliberately vague */
35 extern char* cp_file_of PROTO((tree));
36 extern int cp_line_of PROTO((tree));
38 #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
41 #define arglist a1, a2, a3
42 #define arglist_dcl HOST_WIDE_INT a1, a2, a3;
43 #define ARGSINIT args[0] = a1; args[1] = a2; args[2] = a3;
44 #define ARGSLIST args[0], args[1], args[2]
47 cp_thing (errfn, atarg1, format, arglist)
57 HOST_WIDE_INT atarg = atarg1 ? a1 : 0;
58 HOST_WIDE_INT args[NARGS];
63 for (f = fmt, arg = 0; *f; ++f)
65 cp_printer * function;
70 if (*f != '%') continue;
77 /* ignore most flags */
78 while (*f == ' ' || *f == '-' || *f == '+' || *f == '#')
87 /* ignore field width */
97 /* ignore precision */
115 function = cp_printers[(int)*f];
121 if (arg >= NARGS) abort ();
123 if (maybe_here && atarg1)
126 /* Must use a temporary to avoid calling *function twice */
127 p = (*function) (args[arg], alternate);
128 args[arg] = (HOST_WIDE_INT) STRDUP(p);
132 ++arg; /* Assume valid format string */
138 char *file = cp_file_of ((tree) atarg);
139 int line = cp_line_of ((tree) atarg);
140 (*errfn) (file, line, fmt, ARGSLIST);
143 (*errfn) (fmt, ARGSLIST);
148 cp_error (format, arglist)
152 extern errorfn error;
153 cp_thing (error, 0, format, arglist);
157 cp_warning (format, arglist)
161 extern errorfn warning;
162 cp_thing (warning, 0, format, arglist);
166 cp_pedwarn (format, arglist)
170 extern errorfn pedwarn;
171 cp_thing (pedwarn, 0, format, arglist);
175 cp_compiler_error (format, arglist)
179 extern errorfn compiler_error;
180 cp_thing (compiler_error, 0, format, arglist);
184 cp_sprintf (format, arglist)
188 extern errorfn sprintf;
189 cp_thing (sprintf, 0, format, arglist);
193 cp_error_at (format, arglist)
197 extern errorfn error_with_file_and_line;
198 cp_thing (error_with_file_and_line, 1, format, arglist);
202 cp_warning_at (format, arglist)
206 extern errorfn warning_with_file_and_line;
207 cp_thing (warning_with_file_and_line, 1, format, arglist);
211 cp_pedwarn_at (format, arglist)
215 extern errorfn pedwarn_with_file_and_line;
216 cp_thing (pedwarn_with_file_and_line, 1, format, arglist);