1 /* Default error handlers for CPP Library.
2 Copyright (C) 1986-2016 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 This program 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 this program; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
30 /* Print a diagnostic at the location of the previously lexed token. */
32 ATTRIBUTE_FPTR_PRINTF(4,0)
34 cpp_diagnostic (cpp_reader
* pfile
, int level
, int reason
,
35 const char *msgid
, va_list *ap
)
37 source_location src_loc
;
40 if (CPP_OPTION (pfile
, traditional
))
42 if (pfile
->state
.in_directive
)
43 src_loc
= pfile
->directive_line
;
45 src_loc
= pfile
->line_table
->highest_line
;
47 /* We don't want to refer to a token before the beginning of the
48 current run -- that is invalid. */
49 else if (pfile
->cur_token
== pfile
->cur_run
->base
)
55 src_loc
= pfile
->cur_token
[-1].src_loc
;
60 rich_location
richloc (pfile
->line_table
, src_loc
);
61 ret
= pfile
->cb
.error (pfile
, level
, reason
, &richloc
, _(msgid
), ap
);
66 /* Print a warning or error, depending on the value of LEVEL. */
69 cpp_error (cpp_reader
* pfile
, int level
, const char *msgid
, ...)
76 ret
= cpp_diagnostic (pfile
, level
, CPP_W_NONE
, msgid
, &ap
);
82 /* Print a warning. The warning reason may be given in REASON. */
85 cpp_warning (cpp_reader
* pfile
, int reason
, const char *msgid
, ...)
92 ret
= cpp_diagnostic (pfile
, CPP_DL_WARNING
, reason
, msgid
, &ap
);
98 /* Print a pedantic warning. The warning reason may be given in REASON. */
101 cpp_pedwarning (cpp_reader
* pfile
, int reason
, const char *msgid
, ...)
106 va_start (ap
, msgid
);
108 ret
= cpp_diagnostic (pfile
, CPP_DL_PEDWARN
, reason
, msgid
, &ap
);
114 /* Print a warning, including system headers. The warning reason may be
118 cpp_warning_syshdr (cpp_reader
* pfile
, int reason
, const char *msgid
, ...)
123 va_start (ap
, msgid
);
125 ret
= cpp_diagnostic (pfile
, CPP_DL_WARNING_SYSHDR
, reason
, msgid
, &ap
);
131 /* Print a diagnostic at a specific location. */
133 ATTRIBUTE_FPTR_PRINTF(6,0)
135 cpp_diagnostic_with_line (cpp_reader
* pfile
, int level
, int reason
,
136 source_location src_loc
, unsigned int column
,
137 const char *msgid
, va_list *ap
)
141 if (!pfile
->cb
.error
)
143 rich_location
richloc (pfile
->line_table
, src_loc
);
145 richloc
.override_column (column
);
146 ret
= pfile
->cb
.error (pfile
, level
, reason
, &richloc
, _(msgid
), ap
);
151 /* Print a warning or error, depending on the value of LEVEL. */
154 cpp_error_with_line (cpp_reader
*pfile
, int level
,
155 source_location src_loc
, unsigned int column
,
156 const char *msgid
, ...)
161 va_start (ap
, msgid
);
163 ret
= cpp_diagnostic_with_line (pfile
, level
, CPP_W_NONE
, src_loc
,
170 /* Print a warning. The warning reason may be given in REASON. */
173 cpp_warning_with_line (cpp_reader
*pfile
, int reason
,
174 source_location src_loc
, unsigned int column
,
175 const char *msgid
, ...)
180 va_start (ap
, msgid
);
182 ret
= cpp_diagnostic_with_line (pfile
, CPP_DL_WARNING
, reason
, src_loc
,
189 /* Print a pedantic warning. The warning reason may be given in REASON. */
192 cpp_pedwarning_with_line (cpp_reader
*pfile
, int reason
,
193 source_location src_loc
, unsigned int column
,
194 const char *msgid
, ...)
199 va_start (ap
, msgid
);
201 ret
= cpp_diagnostic_with_line (pfile
, CPP_DL_PEDWARN
, reason
, src_loc
,
208 /* Print a warning, including system headers. The warning reason may be
212 cpp_warning_with_line_syshdr (cpp_reader
*pfile
, int reason
,
213 source_location src_loc
, unsigned int column
,
214 const char *msgid
, ...)
219 va_start (ap
, msgid
);
221 ret
= cpp_diagnostic_with_line (pfile
, CPP_DL_WARNING_SYSHDR
, reason
, src_loc
,
228 /* Print a warning or error, depending on the value of LEVEL. Include
229 information from errno. */
232 cpp_errno (cpp_reader
*pfile
, int level
, const char *msgid
)
234 return cpp_error (pfile
, level
, "%s: %s", _(msgid
), xstrerror (errno
));
237 /* Print a warning or error, depending on the value of LEVEL. Include
238 information from errno. Unlike cpp_errno, the argument is a filename
239 that is not localized, but "" is replaced with localized "stdout". */
242 cpp_errno_filename (cpp_reader
*pfile
, int level
, const char *filename
)
244 if (filename
[0] == '\0')
245 filename
= _("stdout");
247 return cpp_error (pfile
, level
, "%s: %s", filename
, xstrerror (errno
));