aboutsummaryrefslogtreecommitdiff
path: root/libcpp/errors.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-10-09 23:37:19 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-10-09 23:37:19 +0000
commitc24300baea50482b6788041fbac9a6f197c490fc (patch)
treed3e437990f8267770cb8b4857529ff0c2c7ab49e /libcpp/errors.c
parent5abdb369eb2f38272bb8ee2ea0488194942c7cff (diff)
downloadgcc-c24300baea50482b6788041fbac9a6f197c490fc.zip
gcc-c24300baea50482b6788041fbac9a6f197c490fc.tar.gz
gcc-c24300baea50482b6788041fbac9a6f197c490fc.tar.bz2
Cleanup of libcpp diagnostic callbacks
This patch renames the "error" callback within libcpp to "diagnostic", and uses the pair of enums in cpplib.h, rather than passing two different kinds of "int" around. gcc/c-family/ChangeLog: * c-common.c (c_option_controlling_cpp_error): Rename to... (c_option_controlling_cpp_diagnostic): ...this, and convert "reason" from int to enum. (c_cpp_error): Rename to... (c_cpp_diagnostic): ...this, converting level and reason to enums. * c-common.h (c_cpp_error): Rename to... (c_cpp_diagnostic): ...this, converting level and reason to enums. * c-opts.c (c_common_init_options): Update for renaming. gcc/fortran/ChangeLog: * cpp.c (gfc_cpp_init_0): Update for renamings. (cb_cpp_error): Rename to... (cb_cpp_diagnostic): ...this, converting level and reason to enums. gcc/ChangeLog: * genmatch.c (error_cb): Rename to... (diagnostic_cb): ...this, converting int params to enums. (fatal_at): Update for renaming. (warning_at): Likewise. (main): Likewise. * input.c (selftest::ebcdic_execution_charset::apply): Update for renaming of... (selftest::ebcdic_execution_charset::on_error): ...this, renaming to... (selftest::ebcdic_execution_charset::on_diagnostic): ...this, converting level and reason to enums. (class selftest::lexer_error_sink): Rename to... (class selftest::lexer_test_options): ...this, renaming field "m_errors" to "m_diagnostics". (selftest::lexer_test_options::apply): Update for renaming of... (selftest::lexer_test_options::on_error): ...this, renaming to... (selftest::lexer_test_options::on_diagnostic): ...this converting level and reason to enums. (selftest::test_lexer_string_locations_raw_string_unterminated): Update for renamings. * opth-gen.awk (struct cpp_reason_option_codes_t): Use enum for "reason". libcpp/ChangeLog: * charset.c (noop_error_cb): Rename to... (noop_diagnostic_cb): ...this, converting params to enums. (cpp_interpret_string_ranges): Update for renaming and enums. * directives.c (check_eol_1): Convert reason to enum. (do_diagnostic): Convert code and reason to enum. (do_error): Use CPP_W_NONE rather than 0. (do_pragma_dependency): Likewise. * errors.c (cpp_diagnostic_at): Convert level and reason to enums. Update for renaming. (cpp_diagnostic): Convert level and reason to enums. (cpp_error): Convert level to enum. (cpp_warning): Convert reason to enums. (cpp_pedwarning): Likewise. (cpp_warning_syshdr): Likewise. (cpp_diagnostic_with_line): Convert level and reason to enums. Update for renaming. (cpp_error_with_line): Convert level to enum. (cpp_warning_with_line): Convert reason to enums. (cpp_pedwarning_with_line): Likewise. (cpp_warning_with_line_syshdr): Likewise. (cpp_error_at): Convert level to enum. (cpp_errno): Likewise. (cpp_errno_filename): Likewise. * include/cpplib.h (enum cpp_diagnostic_level): Name this enum, and move to before struct cpp_callbacks. (enum cpp_warning_reason): Likewise. (cpp_callbacks::diagnostic): Convert params from int to enums. (cpp_error): Convert int param to enum cpp_diagnostic_level. (cpp_warning): Convert int param to enum cpp_warning_reason. (cpp_pedwarning): Likewise. (cpp_warning_syshdr): Likewise. (cpp_errno): Convert int param to enum cpp_diagnostic_level. (cpp_errno_filename): Likewise. (cpp_error_with_line): Likewise. (cpp_warning_with_line): Convert int param to enum cpp_warning_reason. (cpp_pedwarning_with_line): Likewise. (cpp_warning_with_line_syshdr): Likewise. (cpp_error_at): Convert int param to enum cpp_diagnostic_level. * macro.c (create_iso_definition): Convert int to enum. (_cpp_create_definition): Likewise. From-SVN: r264999
Diffstat (limited to 'libcpp/errors.c')
-rw-r--r--libcpp/errors.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/libcpp/errors.c b/libcpp/errors.c
index a68ae98..2268fc4 100644
--- a/libcpp/errors.c
+++ b/libcpp/errors.c
@@ -31,15 +31,15 @@ along with this program; see the file COPYING3. If not see
ATTRIBUTE_FPTR_PRINTF(5,0)
static bool
-cpp_diagnostic_at (cpp_reader * pfile, int level, int reason,
- rich_location *richloc,
+cpp_diagnostic_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason, rich_location *richloc,
const char *msgid, va_list *ap)
{
bool ret;
- if (!pfile->cb.error)
+ if (!pfile->cb.diagnostic)
abort ();
- ret = pfile->cb.error (pfile, level, reason, richloc, _(msgid), ap);
+ ret = pfile->cb.diagnostic (pfile, level, reason, richloc, _(msgid), ap);
return ret;
}
@@ -48,8 +48,9 @@ cpp_diagnostic_at (cpp_reader * pfile, int level, int reason,
ATTRIBUTE_FPTR_PRINTF(4,0)
static bool
-cpp_diagnostic (cpp_reader * pfile, int level, int reason,
- const char *msgid, va_list *ap)
+cpp_diagnostic (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason,
+ const char *msgid, va_list *ap)
{
source_location src_loc;
@@ -77,7 +78,8 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
/* Print a warning or error, depending on the value of LEVEL. */
bool
-cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
+cpp_error (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -93,7 +95,8 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
/* Print a warning. The warning reason may be given in REASON. */
bool
-cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_warning (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -109,7 +112,8 @@ cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
-cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_pedwarning (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -126,7 +130,8 @@ cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
given in REASON. */
bool
-cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
+cpp_warning_syshdr (cpp_reader * pfile, enum cpp_warning_reason reason,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -143,18 +148,19 @@ cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
ATTRIBUTE_FPTR_PRINTF(6,0)
static bool
-cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, va_list *ap)
+cpp_diagnostic_with_line (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ enum cpp_warning_reason reason,
+ source_location src_loc, unsigned int column,
+ const char *msgid, va_list *ap)
{
bool ret;
- if (!pfile->cb.error)
+ if (!pfile->cb.diagnostic)
abort ();
rich_location richloc (pfile->line_table, src_loc);
if (column)
richloc.override_column (column);
- ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap);
+ ret = pfile->cb.diagnostic (pfile, level, reason, &richloc, _(msgid), ap);
return ret;
}
@@ -162,7 +168,7 @@ cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
/* Print a warning or error, depending on the value of LEVEL. */
bool
-cpp_error_with_line (cpp_reader *pfile, int level,
+cpp_error_with_line (cpp_reader *pfile, enum cpp_diagnostic_level level,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
@@ -181,7 +187,7 @@ cpp_error_with_line (cpp_reader *pfile, int level,
/* Print a warning. The warning reason may be given in REASON. */
bool
-cpp_warning_with_line (cpp_reader *pfile, int reason,
+cpp_warning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
@@ -200,9 +206,9 @@ cpp_warning_with_line (cpp_reader *pfile, int reason,
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
-cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, ...)
+cpp_pedwarning_with_line (cpp_reader *pfile, enum cpp_warning_reason reason,
+ source_location src_loc, unsigned int column,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -220,9 +226,9 @@ cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
given in REASON. */
bool
-cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
- source_location src_loc, unsigned int column,
- const char *msgid, ...)
+cpp_warning_with_line_syshdr (cpp_reader *pfile, enum cpp_warning_reason reason,
+ source_location src_loc, unsigned int column,
+ const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -240,8 +246,8 @@ cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
a column override. */
bool
-cpp_error_at (cpp_reader * pfile, int level, source_location src_loc,
- const char *msgid, ...)
+cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ source_location src_loc, const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -260,8 +266,8 @@ cpp_error_at (cpp_reader * pfile, int level, source_location src_loc,
a column override. */
bool
-cpp_error_at (cpp_reader * pfile, int level, rich_location *richloc,
- const char *msgid, ...)
+cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level level,
+ rich_location *richloc, const char *msgid, ...)
{
va_list ap;
bool ret;
@@ -279,7 +285,8 @@ cpp_error_at (cpp_reader * pfile, int level, rich_location *richloc,
information from errno. */
bool
-cpp_errno (cpp_reader *pfile, int level, const char *msgid)
+cpp_errno (cpp_reader *pfile, enum cpp_diagnostic_level level,
+ const char *msgid)
{
return cpp_error (pfile, level, "%s: %s", _(msgid), xstrerror (errno));
}
@@ -289,7 +296,8 @@ cpp_errno (cpp_reader *pfile, int level, const char *msgid)
that is not localized, but "" is replaced with localized "stdout". */
bool
-cpp_errno_filename (cpp_reader *pfile, int level, const char *filename,
+cpp_errno_filename (cpp_reader *pfile, enum cpp_diagnostic_level level,
+ const char *filename,
source_location loc)
{
if (filename[0] == '\0')