OSDN Git Service

* config/alpha/vms.h (VMS_DEBUGGING_INFO): New macro.
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
1 /* Default error handlers for CPP Library.
2    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000
3    Free Software Foundation, Inc.
4    Written by Per Bothner, 1994.
5    Based on CCCP program by Paul Rubin, June 1986
6    Adapted to ANSI C, Richard Stallman, Jan 1987
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 This program 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 this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22  In other words, you are welcome to use, share and improve this program.
23  You are forbidden to forbid anyone else to use, share and improve
24  what you give them.   Help stamp out software-hoarding!  */
25
26 #include "config.h"
27 #include "system.h"
28 #include "cpplib.h"
29 #include "cpphash.h"
30 #include "intl.h"
31
32 static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
33
34 /* Don't remove the blank before do, as otherwise the exgettext
35    script will mistake this as a function definition */
36 #define v_message(msgid, ap) \
37  do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
38
39 static void
40 print_location (pfile, line, col)
41      cpp_reader *pfile;
42      unsigned int line, col;
43 {
44   cpp_buffer *buffer = pfile->buffer;
45
46   if (!buffer)
47     fprintf (stderr, "%s: ", progname);
48   else
49     {
50       const struct line_map *map;
51
52       if (line == 0)
53         {
54           line = pfile->cur_token[-1].line;
55           col = pfile->cur_token[-1].col;
56         }
57
58       map = lookup_line (&pfile->line_maps, line);
59       print_containing_files (&pfile->line_maps, map);
60
61       line = SOURCE_LINE (map, line);
62       if (col == 0)
63         col = 1;
64
65       if (line == 0)
66         fprintf (stderr, "%s:", map->to_file);
67       else if (CPP_OPTION (pfile, show_column) == 0)
68         fprintf (stderr, "%s:%u:", map->to_file, line);
69       else
70         fprintf (stderr, "%s:%u:%u:", map->to_file, line, col);
71
72       fputc (' ', stderr);
73     }
74 }
75
76 /* Set up for an error message: print the file and line, bump the error
77    counter, etc.  LINE is the logical line number; zero means to print
78    at the location of the previously lexed token, which tends to be the
79    correct place by default.  Returns 0 if the error has been suppressed.  */
80
81 int
82 _cpp_begin_message (pfile, code, line, column)
83      cpp_reader *pfile;
84      enum error_type code;
85      unsigned int line, column;
86 {
87   int is_warning = 0;
88
89   switch (code)
90     {
91     case PEDWARN:
92     case WARNING:
93       if (CPP_IN_SYSTEM_HEADER (pfile)
94           && ! CPP_OPTION (pfile, warn_system_headers))
95         return 0;
96     case WARNING_SYSHDR:
97       if (CPP_OPTION (pfile, warnings_are_errors)
98           || (code == PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
99         {
100           if (CPP_OPTION (pfile, inhibit_errors))
101             return 0;
102           if (pfile->errors < CPP_FATAL_LIMIT)
103             pfile->errors++;
104         }
105       else
106         {
107           if (CPP_OPTION (pfile, inhibit_warnings))
108             return 0;
109           is_warning = 1;
110         }
111       break;
112         
113     case ERROR:
114       if (CPP_OPTION (pfile, inhibit_errors))
115         return 0;
116       if (pfile->errors < CPP_FATAL_LIMIT)
117         pfile->errors++;
118       break;
119       /* Fatal errors cannot be inhibited.  */
120     case FATAL:
121       pfile->errors = CPP_FATAL_LIMIT;
122       break;
123     case ICE:
124       fprintf (stderr, _("internal error: "));
125       pfile->errors = CPP_FATAL_LIMIT;
126       break;
127     }
128
129   print_location (pfile, line, column);
130   if (is_warning)
131     fputs (_("warning: "), stderr);
132
133   return 1;
134 }
135
136 /* Exported interface.  */
137
138 /* For reporting internal errors.  Prints "internal error: " for you,
139    otherwise identical to cpp_fatal.  */
140
141 void
142 cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
143 {  
144   VA_OPEN (ap, msgid);
145   VA_FIXEDARG (ap, cpp_reader *, pfile);
146   VA_FIXEDARG (ap, const char *, msgid);
147
148   if (_cpp_begin_message (pfile, ICE, 0, 0))
149     v_message (msgid, ap);
150
151   VA_CLOSE (ap);
152 }
153
154 /* Same as cpp_error, except we consider the error to be "fatal",
155    such as inconsistent options.  I.e. there is little point in continuing.
156    (We do not exit, to support use of cpplib as a library.
157    Instead, it is the caller's responsibility to check
158    CPP_FATAL_ERRORS.  */
159
160 void
161 cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
162 {  
163   VA_OPEN (ap, msgid);
164   VA_FIXEDARG (ap, cpp_reader *, pfile);
165   VA_FIXEDARG (ap, const char *, msgid);
166
167   if (_cpp_begin_message (pfile, FATAL, 0, 0))
168     v_message (msgid, ap);
169
170   VA_CLOSE (ap);
171 }
172
173 void
174 cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
175 {
176   VA_OPEN (ap, msgid);
177   VA_FIXEDARG (ap, cpp_reader *, pfile);
178   VA_FIXEDARG (ap, const char *, msgid);
179
180   if (_cpp_begin_message (pfile, ERROR, 0, 0))
181     v_message (msgid, ap);
182
183   VA_CLOSE (ap);
184 }
185
186 void
187 cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
188                              const char *msgid, ...))
189 {
190   VA_OPEN (ap, msgid);
191   VA_FIXEDARG (ap, cpp_reader *, pfile);
192   VA_FIXEDARG (ap, int, line);
193   VA_FIXEDARG (ap, int, column);
194   VA_FIXEDARG (ap, const char *, msgid);
195
196   if (_cpp_begin_message (pfile, ERROR, line, column))
197     v_message (msgid, ap);
198
199   VA_CLOSE (ap);
200 }
201
202 /* Error including a message from `errno'.  */
203 void
204 cpp_error_from_errno (pfile, name)
205      cpp_reader *pfile;
206      const char *name;
207 {
208   cpp_error (pfile, "%s: %s", name, xstrerror (errno));
209 }
210
211 void
212 cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
213 {
214   VA_OPEN (ap, msgid);
215   VA_FIXEDARG (ap, cpp_reader *, pfile);
216   VA_FIXEDARG (ap, const char *, msgid);
217
218   if (_cpp_begin_message (pfile, WARNING, 0, 0))
219     v_message (msgid, ap);
220
221   VA_CLOSE (ap);
222 }
223
224 void
225 cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
226                                const char *msgid, ...))
227 {
228   VA_OPEN (ap, msgid);
229   VA_FIXEDARG (ap, cpp_reader *, pfile);
230   VA_FIXEDARG (ap, int, line);
231   VA_FIXEDARG (ap, int, column);
232   VA_FIXEDARG (ap, const char *, msgid);
233
234   if (_cpp_begin_message (pfile, WARNING, line, column))
235     v_message (msgid, ap);
236
237   VA_CLOSE (ap);
238 }
239
240 void
241 cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
242 {
243   VA_OPEN (ap, msgid);
244   VA_FIXEDARG (ap, cpp_reader *, pfile);
245   VA_FIXEDARG (ap, const char *, msgid);
246
247   if (_cpp_begin_message (pfile, PEDWARN, 0, 0))
248     v_message (msgid, ap);
249
250   VA_CLOSE (ap);
251 }
252
253 void
254 cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
255                                const char *msgid, ...))
256 {
257   VA_OPEN (ap, msgid);
258   VA_FIXEDARG (ap, cpp_reader *, pfile);
259   VA_FIXEDARG (ap, int, line);
260   VA_FIXEDARG (ap, int, column);
261   VA_FIXEDARG (ap, const char *, msgid);
262
263   if (_cpp_begin_message (pfile, PEDWARN, line, column))
264     v_message (msgid, ap);
265
266   VA_CLOSE (ap);
267 }
268
269 /* Print an error message not associated with a file.  */
270 void
271 cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
272 {
273   VA_OPEN (ap, msgid);
274   VA_FIXEDARG (ap, cpp_reader *, pfile);
275   VA_FIXEDARG (ap, const char *, msgid);
276
277   if (pfile->errors < CPP_FATAL_LIMIT)
278     pfile->errors++;
279
280   v_message (msgid, ap);
281
282   VA_CLOSE (ap);
283 }
284
285 void
286 cpp_notice_from_errno (pfile, name)
287      cpp_reader *pfile;
288      const char *name;
289 {
290   if (name[0] == '\0')
291     name = "stdout";
292   cpp_notice (pfile, "%s: %s", name, xstrerror (errno));
293 }