aboutsummaryrefslogtreecommitdiff
path: root/libcpp/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp/errors.c')
-rw-r--r--libcpp/errors.c82
1 files changed, 63 insertions, 19 deletions
diff --git a/libcpp/errors.c b/libcpp/errors.c
index 5e1bf33..f34334a 100644
--- a/libcpp/errors.c
+++ b/libcpp/errors.c
@@ -27,6 +27,31 @@ along with this program; see the file COPYING3. If not see
#include "cpplib.h"
#include "internal.h"
+/* Get a location_t for the current location in PFILE,
+ generally that of the previously lexed token. */
+
+location_t
+cpp_diagnostic_get_current_location (cpp_reader *pfile)
+{
+ if (CPP_OPTION (pfile, traditional))
+ {
+ if (pfile->state.in_directive)
+ return pfile->directive_line;
+ else
+ return pfile->line_table->highest_line;
+ }
+ /* We don't want to refer to a token before the beginning of the
+ current run -- that is invalid. */
+ else if (pfile->cur_token == pfile->cur_run->base)
+ {
+ return 0;
+ }
+ else
+ {
+ return pfile->cur_token[-1].src_loc;
+ }
+}
+
/* Print a diagnostic at the given location. */
ATTRIBUTE_FPTR_PRINTF(5,0)
@@ -52,25 +77,7 @@ cpp_diagnostic (cpp_reader * pfile, enum cpp_diagnostic_level level,
enum cpp_warning_reason reason,
const char *msgid, va_list *ap)
{
- location_t src_loc;
-
- if (CPP_OPTION (pfile, traditional))
- {
- if (pfile->state.in_directive)
- src_loc = pfile->directive_line;
- else
- src_loc = pfile->line_table->highest_line;
- }
- /* We don't want to refer to a token before the beginning of the
- current run -- that is invalid. */
- else if (pfile->cur_token == pfile->cur_run->base)
- {
- src_loc = 0;
- }
- else
- {
- src_loc = pfile->cur_token[-1].src_loc;
- }
+ location_t src_loc = cpp_diagnostic_get_current_location (pfile);
rich_location richloc (pfile->line_table, src_loc);
return cpp_diagnostic_at (pfile, level, reason, &richloc, msgid, ap);
}
@@ -144,6 +151,43 @@ cpp_warning_syshdr (cpp_reader * pfile, enum cpp_warning_reason reason,
return ret;
}
+/* As cpp_warning above, but use RICHLOC as the location of the diagnostic. */
+
+bool cpp_warning_at (cpp_reader *pfile, enum cpp_warning_reason reason,
+ rich_location *richloc, const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ ret = cpp_diagnostic_at (pfile, CPP_DL_WARNING, reason, richloc,
+ msgid, &ap);
+
+ va_end (ap);
+ return ret;
+
+}
+
+/* As cpp_pedwarning above, but use RICHLOC as the location of the
+ diagnostic. */
+
+bool
+cpp_pedwarning_at (cpp_reader * pfile, enum cpp_warning_reason reason,
+ rich_location *richloc, const char *msgid, ...)
+{
+ va_list ap;
+ bool ret;
+
+ va_start (ap, msgid);
+
+ ret = cpp_diagnostic_at (pfile, CPP_DL_PEDWARN, reason, richloc,
+ msgid, &ap);
+
+ va_end (ap);
+ return ret;
+}
+
/* Print a diagnostic at a specific location. */
ATTRIBUTE_FPTR_PRINTF(6,0)