diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-10-09 23:37:19 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-10-09 23:37:19 +0000 |
commit | c24300baea50482b6788041fbac9a6f197c490fc (patch) | |
tree | d3e437990f8267770cb8b4857529ff0c2c7ab49e /gcc | |
parent | 5abdb369eb2f38272bb8ee2ea0488194942c7cff (diff) | |
download | gcc-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 'gcc')
-rw-r--r-- | gcc/ChangeLog | 25 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 17 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 5 | ||||
-rw-r--r-- | gcc/c-family/c-opts.c | 2 | ||||
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/cpp.c | 15 | ||||
-rw-r--r-- | gcc/genmatch.c | 15 | ||||
-rw-r--r-- | gcc/input.c | 50 | ||||
-rw-r--r-- | gcc/opth-gen.awk | 6 |
10 files changed, 103 insertions, 50 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6dfc2ef..7260dd7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,28 @@ +2018-10-09 David Malcolm <dmalcolm@redhat.com> + + * 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". + 2018-10-09 Paul A. Clarke <pc@us.ibm.com> * config.gcc (powerpc*-*-*): Add pmmintrin.h to extra_headers. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 6307337..8e8005d 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,14 @@ +2018-10-09 David Malcolm <dmalcolm@redhat.com> + + * 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. + 2018-10-08 Richard Sandiford <richard.sandiford@arm.com> PR c/87286 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index c0198e1..2e64a6b 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -6068,7 +6068,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, message, or 0 if none. */ static int -c_option_controlling_cpp_error (int reason) +c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason) { const struct cpp_reason_option_codes_t *entry; @@ -6080,7 +6080,7 @@ c_option_controlling_cpp_error (int reason) return 0; } -/* Callback from cpp_error for PFILE to print diagnostics from the +/* Callback from cpp_diagnostic for PFILE to print diagnostics from the preprocessor. The diagnostic is of type LEVEL, with REASON set to the reason code if LEVEL is represents a warning, at location RICHLOC unless this is after lexing and the compiler's location @@ -6089,9 +6089,11 @@ c_option_controlling_cpp_error (int reason) otherwise. */ bool -c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, - rich_location *richloc, - const char *msg, va_list *ap) +c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, + enum cpp_diagnostic_level level, + enum cpp_warning_reason reason, + rich_location *richloc, + const char *msg, va_list *ap) { diagnostic_info diagnostic; diagnostic_t dlevel; @@ -6134,8 +6136,9 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET); diagnostic_set_info_translated (&diagnostic, msg, ap, richloc, dlevel); - diagnostic_override_option_index (&diagnostic, - c_option_controlling_cpp_error (reason)); + diagnostic_override_option_index + (&diagnostic, + c_option_controlling_cpp_diagnostic (reason)); ret = diagnostic_report_diagnostic (global_dc, &diagnostic); if (level == CPP_DL_WARNING_SYSHDR) global_dc->dc_warn_system_headers = save_warn_system_headers; diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 9e86876..70b152f 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1000,8 +1000,9 @@ extern void init_c_lex (void); extern void c_cpp_builtins (cpp_reader *); extern void c_cpp_builtins_optimize_pragma (cpp_reader *, tree, tree); -extern bool c_cpp_error (cpp_reader *, int, int, rich_location *, - const char *, va_list *) +extern bool c_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, + enum cpp_warning_reason, rich_location *, + const char *, va_list *) ATTRIBUTE_GCC_DIAG(5,0); extern int c_common_has_attribute (cpp_reader *); diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index ec05771..10cb53b 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -224,7 +224,7 @@ c_common_init_options (unsigned int decoded_options_count, parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, ident_hash, line_table); cb = cpp_get_callbacks (parse_in); - cb->error = c_cpp_error; + cb->diagnostic = c_cpp_diagnostic; cpp_opts = cpp_get_options (parse_in); cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index ab6b09b..0a7e5f5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2018-10-09 David Malcolm <dmalcolm@redhat.com> + + * cpp.c (gfc_cpp_init_0): Update for renamings. + (cb_cpp_error): Rename to... + (cb_cpp_diagnostic): ...this, converting level and reason to + enums. + 2018-10-09 Tobias Burnus <burnus@net-b.de> PR fortran/83522 diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c index 0b3de42..3091eeb 100644 --- a/gcc/fortran/cpp.c +++ b/gcc/fortran/cpp.c @@ -142,8 +142,9 @@ static void cb_include (cpp_reader *, source_location, const unsigned char *, static void cb_ident (cpp_reader *, source_location, const cpp_string *); static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *); static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *); -static bool cb_cpp_error (cpp_reader *, int, int, rich_location *, - const char *, va_list *) +static bool cb_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, + enum cpp_warning_reason, rich_location *, + const char *, va_list *) ATTRIBUTE_GCC_DIAG(5,0); void pp_dir_change (cpp_reader *, const char *); @@ -504,7 +505,7 @@ gfc_cpp_init_0 (void) cb->line_change = cb_line_change; cb->ident = cb_ident; cb->def_pragma = cb_def_pragma; - cb->error = cb_cpp_error; + cb->diagnostic = cb_cpp_diagnostic; if (gfc_cpp_option.dump_includes) cb->include = cb_include; @@ -1020,9 +1021,11 @@ cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED, Returns true if a diagnostic was emitted, false otherwise. */ static bool -cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, - rich_location *richloc, - const char *msg, va_list *ap) +cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, + enum cpp_diagnostic_level level, + enum cpp_warning_reason reason, + rich_location *richloc, + const char *msg, va_list *ap) { diagnostic_info diagnostic; diagnostic_t dlevel; diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 5f1691a..62a876d 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -73,8 +73,9 @@ static bool #if GCC_VERSION >= 4001 __attribute__((format (printf, 5, 0))) #endif -error_cb (cpp_reader *, int errtype, int, rich_location *richloc, - const char *msg, va_list *ap) +diagnostic_cb (cpp_reader *, enum cpp_diagnostic_level errtype, + enum cpp_warning_reason, rich_location *richloc, + const char *msg, va_list *ap) { const line_map_ordinary *map; source_location location = richloc->get_loc (); @@ -122,7 +123,7 @@ fatal_at (const cpp_token *tk, const char *msg, ...) rich_location richloc (line_table, tk->src_loc); va_list ap; va_start (ap, msg); - error_cb (NULL, CPP_DL_FATAL, 0, &richloc, msg, &ap); + diagnostic_cb (NULL, CPP_DL_FATAL, CPP_W_NONE, &richloc, msg, &ap); va_end (ap); } @@ -135,7 +136,7 @@ fatal_at (source_location loc, const char *msg, ...) rich_location richloc (line_table, loc); va_list ap; va_start (ap, msg); - error_cb (NULL, CPP_DL_FATAL, 0, &richloc, msg, &ap); + diagnostic_cb (NULL, CPP_DL_FATAL, CPP_W_NONE, &richloc, msg, &ap); va_end (ap); } @@ -148,7 +149,7 @@ warning_at (const cpp_token *tk, const char *msg, ...) rich_location richloc (line_table, tk->src_loc); va_list ap; va_start (ap, msg); - error_cb (NULL, CPP_DL_WARNING, 0, &richloc, msg, &ap); + diagnostic_cb (NULL, CPP_DL_WARNING, CPP_W_NONE, &richloc, msg, &ap); va_end (ap); } @@ -161,7 +162,7 @@ warning_at (source_location loc, const char *msg, ...) rich_location richloc (line_table, loc); va_list ap; va_start (ap, msg); - error_cb (NULL, CPP_DL_WARNING, 0, &richloc, msg, &ap); + diagnostic_cb (NULL, CPP_DL_WARNING, CPP_W_NONE, &richloc, msg, &ap); va_end (ap); } @@ -5071,7 +5072,7 @@ main (int argc, char **argv) r = cpp_create_reader (CLK_GNUC99, NULL, line_table); cpp_callbacks *cb = cpp_get_callbacks (r); - cb->error = error_cb; + cb->diagnostic = diagnostic_cb; /* Add the build directory to the #include "" search path. */ cpp_dir *dir = XCNEW (cpp_dir); diff --git a/gcc/input.c b/gcc/input.c index b4b7136..eeeb11e 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -2116,14 +2116,14 @@ class ebcdic_execution_charset : public lexer_test_options cpp_opts->narrow_charset = "IBM1047"; cpp_callbacks *callbacks = cpp_get_callbacks (test.m_parser); - callbacks->error = on_error; + callbacks->diagnostic = on_diagnostic; } - static bool on_error (cpp_reader *pfile ATTRIBUTE_UNUSED, - int level ATTRIBUTE_UNUSED, - int reason ATTRIBUTE_UNUSED, - rich_location *richloc ATTRIBUTE_UNUSED, - const char *msgid, va_list *ap ATTRIBUTE_UNUSED) + static bool on_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, + enum cpp_diagnostic_level level ATTRIBUTE_UNUSED, + enum cpp_warning_reason reason ATTRIBUTE_UNUSED, + rich_location *richloc ATTRIBUTE_UNUSED, + const char *msgid, va_list *ap ATTRIBUTE_UNUSED) ATTRIBUTE_FPTR_PRINTF(5,0) { gcc_assert (s_singleton); @@ -2153,53 +2153,53 @@ class ebcdic_execution_charset : public lexer_test_options ebcdic_execution_charset *ebcdic_execution_charset::s_singleton; -/* A lexer_test_options subclass that records a list of error +/* A lexer_test_options subclass that records a list of diagnostic messages emitted by the lexer. */ -class lexer_error_sink : public lexer_test_options +class lexer_diagnostic_sink : public lexer_test_options { public: - lexer_error_sink () + lexer_diagnostic_sink () { gcc_assert (s_singleton == NULL); s_singleton = this; } - ~lexer_error_sink () + ~lexer_diagnostic_sink () { gcc_assert (s_singleton == this); s_singleton = NULL; int i; char *str; - FOR_EACH_VEC_ELT (m_errors, i, str) + FOR_EACH_VEC_ELT (m_diagnostics, i, str) free (str); } void apply (lexer_test &test) FINAL OVERRIDE { cpp_callbacks *callbacks = cpp_get_callbacks (test.m_parser); - callbacks->error = on_error; + callbacks->diagnostic = on_diagnostic; } - static bool on_error (cpp_reader *pfile ATTRIBUTE_UNUSED, - int level ATTRIBUTE_UNUSED, - int reason ATTRIBUTE_UNUSED, - rich_location *richloc ATTRIBUTE_UNUSED, - const char *msgid, va_list *ap) + static bool on_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, + enum cpp_diagnostic_level level ATTRIBUTE_UNUSED, + enum cpp_warning_reason reason ATTRIBUTE_UNUSED, + rich_location *richloc ATTRIBUTE_UNUSED, + const char *msgid, va_list *ap) ATTRIBUTE_FPTR_PRINTF(5,0) { char *msg = xvasprintf (msgid, *ap); - s_singleton->m_errors.safe_push (msg); + s_singleton->m_diagnostics.safe_push (msg); return true; } - auto_vec<char *> m_errors; + auto_vec<char *> m_diagnostics; private: - static lexer_error_sink *s_singleton; + static lexer_diagnostic_sink *s_singleton; }; -lexer_error_sink *lexer_error_sink::s_singleton; +lexer_diagnostic_sink *lexer_diagnostic_sink::s_singleton; /* Constructor. Override line_table with a new instance based on CASE_, and write CONTENT to a tempfile. Create a cpp_reader, and use it to @@ -3413,21 +3413,21 @@ test_lexer_string_locations_raw_string_unterminated (const line_table_case &case { const char *content = "R\"ouch()ouCh\" /* etc */"; - lexer_error_sink errors; - lexer_test test (case_, content, &errors); + lexer_diagnostic_sink diagnostics; + lexer_test test (case_, content, &diagnostics); test.m_implicitly_expect_EOF = false; /* Attempt to parse the raw string. */ const cpp_token *tok = test.get_token (); ASSERT_EQ (tok->type, CPP_EOF); - ASSERT_EQ (1, errors.m_errors.length ()); + ASSERT_EQ (1, diagnostics.m_diagnostics.length ()); /* We expect the message "unterminated raw string" in the "cpplib" translation domain. It's not clear that dgettext is available on all supported hosts, so this assertion is commented-out for now. ASSERT_STREQ (dgettext ("cpplib", "unterminated raw string"), - errors.m_errors[0]); + diagnostics.m_diagnostics[0]); */ } diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk index c2390de..de2d29f 100644 --- a/gcc/opth-gen.awk +++ b/gcc/opth-gen.awk @@ -503,8 +503,10 @@ print "/* Mapping from cpp message reasons to the options that enable them. */" print "#include <cpplib.h>" print "struct cpp_reason_option_codes_t" print "{" -print " const int reason; /* cpplib message reason. */" -print " const int option_code; /* gcc option that controls this message. */" +print " /* cpplib message reason. */" +print " const enum cpp_warning_reason reason;" +print " /* gcc option that controls this message. */" +print " const int option_code;" print "};" print "" print "static const struct cpp_reason_option_codes_t cpp_reason_option_codes[] = {" |