aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-format-text.cc
AgeCommit message (Collapse)AuthorFilesLines
2024-09-30diagnostics: isolate diagnostic_context with interface classes [PR116613]David Malcolm1-4/+5
As work towards supporting multiple diagnostic outputs (where each output has its own pretty_printer), avoid passing around diagnostic_context to the various printing routines, so that we can be more explicit about which pretty_printer is in use. Introduce a set of "policy" classes that capture the parts of diagnostic_context that are needed, and use these rather than diagnostic_context *. Pass around pretty_printer & rather than taking value from context. Split out the pretty_printer-using code from class layout into a new class layout_printer, separating the responsibilities of determining layout when quoting source versus actually printing the source. No functional change intended. gcc/analyzer/ChangeLog: PR other/116613 * program-point.cc (function_point::print_source_line): Replace call to diagnostic_show_locus with a call to diagnostic_source_print_policy::print. gcc/ChangeLog: PR other/116613 * diagnostic-format-json.cc (json_from_expanded_location): Replace call to diagnostic_context::converted_column with call to diagnostic_column_policy::converted_column. * diagnostic-format-sarif.cc (sarif_builder::make_location_object): Replace call to diagnostic_show_locus with call to diagnostic_source_print_policy::print. * diagnostic-format-text.cc (get_location_text): Replace call to diagnostic_context::get_location_text with call to diagnostic_column_policy::get_location_text. (diagnostic_text_output_format::report_current_module): Replace call to diagnostic_context::converted_column with call to diagnostic_column_policy::converted_column. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_output_format): Initialize m_column_policy. (diagnostic_text_output_format::get_column_policy): New. (diagnostic_text_output_format::m_column_policy): New. * diagnostic-path.cc (class path_print_policy): New. (event_range::maybe_add_event): Replace diagnostic_context param with path_print_policy. (event_range::print): Convert "pp" from * to &. Convert first param of start_span callback from diagnostic_context to diagnostic_location_print_policy. (path_summary::path_summary): Convert first param from diagnostic_text_output_format to path_print_policy. Add colorize param. Update for changes to event_range::maybe_add_event. (thread_event_printer::print_swimlane_for_event_range): Assert that pp is non-null. Update for change to event_range::print. (diagnostic_text_output_format::print_path): Pass path_print_policy to path_summary's ctor. (selftest::test_empty_path): Likewise. (selftest::test_intraprocedural_path): Likewise. (selftest::test_interprocedural_path_1): Likewise. (selftest::test_interprocedural_path_2): Likewise. (selftest::test_recursion): Likewise. (selftest::test_control_flow_1): Likewise. (selftest::test_control_flow_2): Likewise. (selftest::test_control_flow_3): Likewise. (selftest::assert_cfg_edge_path_streq): Likewise. (selftest::test_control_flow_5): Likewise. (selftest::test_control_flow_6): Likewise. * diagnostic-show-locus.cc (colorizer::set_range): Update for change to m_pp. (colorizer::m_pp): Convert from * to &. (class layout): Add friend class layout_printer and move various decls to it. (layout::m_pp): Drop field. (layout::m_policy): Rename to... (layout::m_char_policy): ...this. (layout::m_colorizer): Move field to class layout_printer. (layout::m_diagnostic_path_p): Drop field. (class layout_printer): New class, by refactoring class layout. (colorizer::colorizer): Convert "pp" param from * to &. (colorizer::set_named_color): Update for above change. (colorizer::begin_state): Likewise. (colorizer::finish_state): Likewise. (make_policy): Rename to... (make_char_policy): ...this, and update param from diagnostic_context to diagnostic_source_print_policy. (layout::layout): Update param from diagnostic_context to diagnostic_source_print_policy. Drop params "diagnostic_kind" and "pp", moving these and other material to class layout_printer. (layout::maybe_add_location_range): Update for renamed field. (layout::print_gap_in_line_numbering): Convert to... (layout_printer::print_gap_in_line_numbering): ...this. (layout::calculate_x_offset_display): Update for renamed field. (layout::print_source_line): Convert to... (layout_printer::print_source_line): ...this. (layout::print_leftmost_column): Convert to... (layout_printer::print_leftmost_column): ...this. (layout::start_annotation_line): Convert to... (layout_printer::start_annotation_line): ...this. (layout::print_annotation_line): Convert to... (layout_printer::print_annotation_line): ...this. (layout::print_any_labels): Convert to... (layout_printer::print_any_labels): ...this. (layout::print_leading_fixits): Convert to... (layout_printer::print_leading_fixits): ...this. (layout::print_trailing_fixits): Convert to... (layout_printer::print_trailing_fixits): ...this. (layout::print_newline): Convert to... (layout_printer::print_newline): ...this. (layout::get_state_at_point): Make const. (layout::get_x_bound_for_row): Make const. (layout::move_to_column): Convert to... (layout_printer::move_to_column): ...this. (layout::show_ruler): Convert to... (layout_printer::show_ruler): ...this. (layout::print_line): Convert to... (layout_printer::print_line): ...this. (layout::print_any_right_to_left_edge_lines): Convert to... (layout_printer::print_any_right_to_left_edge_lines): ...this. (layout::print_any_right_to_left_edge_lines): Likewise. (layout_printer::layout_printer): New. (layout::update_any_effects): Delete, moving logic to layout_printer::print. (gcc_rich_location::add_location_if_nearby): Update param from diagnostic_context to diagnostic_source_print_policy. Add overload taking a diagnostic_context. (diagnostic_context::maybe_show_locus): Move handling of null pretty_printer here, from layout ctor. Convert call to diagnostic_context::show_locus to diagnostic_source_print_policy::print. (diagnostic_source_print_policy::diagnostic_source_print_policy): New. (diagnostic_context::show_locus): Convert to... (diagnostic_source_print_policy::print): ...this. Convert pp from * to &. (layout_printer::print): New, based on material in diagnostic_context::show_locus. (selftest::make_char_policy): New. (selftest::test_display_widths): Update for above changes. (selftest::test_offset_impl): Likewise. (selftest::test_layout_x_offset_display_utf8): Likewise. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_diagnostic_show_locus_unknown_location): Use test_diagnostic_context::test_show_locus rather than diagnostic_show_locus. (selftest::test_one_liner_no_column): Likewise. (selftest::test_one_liner_caret_and_range): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges): Likewise. (selftest::test_one_liner_fixit_insert_before): Likewise. (selftest::test_one_liner_fixit_insert_after): Likewise. (selftest::test_one_liner_fixit_remove): Likewise. (selftest::test_one_liner_fixit_replace): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations): Likewise. (selftest::test_one_liner_many_fixits_1): Likewise. (selftest::test_one_liner_many_fixits_2): Likewise. (selftest::test_one_liner_labels): Likewise. (selftest::test_one_liner_simple_caret_utf8): Likewise. (selftest::test_one_liner_caret_and_range_utf8): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges_utf8): Likewise. (selftest::test_one_liner_fixit_insert_before_utf8): Likewise. (selftest::test_one_liner_fixit_insert_after_utf8): Likewise. (selftest::test_one_liner_fixit_remove_utf8): Likewise. (selftest::test_one_liner_fixit_replace_utf8): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range_utf8): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. (selftest::test_one_liner_many_fixits_1_utf8): Likewise. (selftest::test_one_liner_many_fixits_2_utf8): Likewise. (selftest::test_one_liner_labels_utf8): Likewise. (selftest::test_one_liner_colorized_utf8): Likewise. (selftest::test_add_location_if_nearby): Likewise. (selftest::test_diagnostic_show_locus_fixit_lines): Likewise. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_utf8): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_fixit_insert_containing_newline): Likewise. (selftest::test_fixit_insert_containing_newline_2): Likewise. (selftest::test_fixit_replace_containing_newline): Likewise. (selftest::test_fixit_deletion_affecting_newline): Likewise. (selftest::test_tab_expansion): Likewise. (selftest::test_escaping_bytes_1): Likewise. (selftest::test_escaping_bytes_2): Likewise. (selftest::test_line_numbers_multiline_range): Likewise. * diagnostic.cc (diagnostic_column_policy::diagnostic_column_policy): New. (diagnostic_context::converted_column): Convert to... (diagnostic_column_policy::converted_column): ...this. (diagnostic_context::get_location_text): Convert to... (diagnostic_column_policy::get_location_text): ...this, adding "show_column" param. (diagnostic_location_print_policy::diagnostic_location_print_policy): New ctors. (default_diagnostic_start_span_fn): Convert param from diagnostic_context * to const diagnostic_location_print_policy &. Add "pp" param. (selftest::assert_location_text): Update for above changes. (selftest::test_diagnostic_get_location_text): Rename to... (selftest::test_get_location_text): ...this. (selftest::c_diagnostic_cc_tests): Update for renaming. * diagnostic.h (class diagnostic_location_print_policy): New forward decl. (class diagnostic_source_print_policy): New forward decl. (diagnostic_start_span_fn): Convert first param from diagnostic_context * to const diagnostic_location_print_policy & and add pretty_printer * param. (class diagnostic_column_policy): New. (class diagnostic_location_print_policy): New. (class diagnostic_source_print_policy): New. (class diagnostic_context): Add friend class diagnostic_source_print_policy. (diagnostic_context::converted_column): Drop decl in favor of diagnostic_column_policy::converted_column. (diagnostic_context::get_location_text): Drop decl in favor of diagnostic_column_policy::get_location_text. (diagnostic_context::show_locus): Drop decl in favor of diagnostic_source_print_policy::print. (default_diagnostic_start_span_fn): Update for change to diagnostic_start_span_fn. * gcc-rich-location.h (class diagnostic_source_print_policy): New forward decl. (gcc_rich_location::add_location_if_nearby): Convert first param from diagnostic_context to diagnostic_source_print_policy. Add overload taking diagnostic_context. * selftest-diagnostic.cc (selftest::test_diagnostic_context::test_diagnostic_context): Turn off colorization. (selftest::test_diagnostic_context::start_span_cb): Update for change to callback type. (test_diagnostic_context::test_show_locus): New. * selftest-diagnostic.h (selftest::test_diagnostic_context::start_span_cb): Update for change to callback type. (test_diagnostic_context::test_show_locus): New decl. gcc/fortran/ChangeLog: PR other/116613 * error.cc (gfc_diagnostic_build_locus_prefix): Convert first param from diagnostic_context * to const diagnostic_location_print_policy &. Add colorize param. Likewise for the "two expanded_locations" overload. (gfc_diagnostic_text_starter): Update for above changes. (gfc_diagnostic_start_span): Update for change to callback type. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_start_span_fn): Update for change to callback type. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-09-20diagnostics: convert text hooks to use diagnostic_text_output_format [PR116613]David Malcolm1-6/+180
The diagnostic_starter and diagnostic_finalizer callbacks and most of their support subroutines are only used by the "text" output format. Emphasize this and reduce the binding with diagnostic_context by renaming the callbacks to add "_text" in their names, and converting the first param from diagnostic_context * to diagnostic_text_output_output &. Update the various subroutines used by diagnostic starter/finalizer callbacks to also take a diagnostic_text_output_output & rather than a diagnostic_context *. Move m_includes and m_last_seen from the context to the text output. Use the text_output's get_printer () rather than the context's m_printer, which should ease the transition to multiple output sinks. No functional change intended. gcc/c-family/ChangeLog: PR other/116613 * c-opts.cc: Include "diagnostic-format-text.h". (c_diagnostic_finalizer): Rename to... (c_diagnostic_text_finalizer): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (c_common_diagnostics_set_defaults): Update for renamings. gcc/ChangeLog: PR other/116613 * coretypes.h (class diagnostic_text_output_format): Add forward decl. * diagnostic-format-json.cc (json_output_format::after_diagnostic): New. * diagnostic-format-sarif.cc (sarif_output_format::after_diagnostic): New. * diagnostic-format-text.cc: Use pragmas to ignore -Wformat-diag. (diagnostic_text_output_format::~diagnostic_text_output_format): Use get_printer. Clean up m_includes_seen here, rather than in ~diagnostic_context. (diagnostic_text_output_format::on_report_diagnostic): Use get_printer. Update for callback renamings and pass *this to them, rather than &m_context. (diagnostic_text_output_format::after_diagnostic): New. (diagnostic_text_output_format::includes_seen_p): Move here from diagnostic_context/diagnostic.cc. (diagnostic_text_output_format::get_location_text): New. (maybe_line_and_column): Move here from diagnostic.cc and make non-static. (diagnostic_text_output_format::report_current_module): Move here from diagnostic_context/diagnostic.cc. (default_diagnostic_text_starter): Move here from diagnostic.cc, renaming from default_diagnostic_starter. (default_diagnostic_text_finalizer): Likewise, renaming from default_diagnostic_finalizer. * diagnostic-format-text.h (diagnostic_text_output_format::diagnostic_text_output_format): Initialize m_last_module and m_includes_seen. (diagnostic_text_output_format::after_diagnostic): New decl. (diagnostic_text_output_format::build_prefix): New decl. (diagnostic_text_output_format::report_current_module): New decl. (diagnostic_text_output_format::append_note): New decl. (diagnostic_text_output_format::file_name_as_prefix): New decl. (diagnostic_text_output_format::print_path): New decl. (diagnostic_text_output_format::show_column_p): New decl. (diagnostic_text_output_format::get_location_text): New decl. (diagnostic_text_output_format::includes_seen_p): New decl. (diagnostic_text_output_format::show_any_path): New decl. (diagnostic_text_output_format::m_last_module): New field. (diagnostic_text_output_format::m_includes_seen): New field. * diagnostic-format.h (diagnostic_output_format::after_diagnostic): New vfunc. (diagnostic_output_format::get_context): New. (diagnostic_output_format::get_diagram_theme): New. * diagnostic-macro-unwinding.cc: Include "diagnostic-format-text.h". (maybe_unwind_expanded_macro_loc): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (virt_loc_aware_diagnostic_finalizer): Likewise. * diagnostic-macro-unwinding.h (virt_loc_aware_diagnostic_finalizer): Likewise. (maybe_unwind_expanded_macro_loc): Likewise. * diagnostic-path.cc: Include "diagnostic-format-text.h". (path_label::path_label): Drop "ctxt" param and add "colorize" and "allow_emojis" params. Update initializations. (path_label::get_text): Use m_colorize rather than querying m_ctxt.m_printer. Use m_allow_emojis rather than querying m_ctxt's diagram theme. (path_label::m_ctxt): Drop field. (path_label::m_colorize): Drop field. (path_label::m_allow_emojis): Drop field. (event_range::event_range): Drop param "ctxt". Add params "colorize_labels" and "allow_emojis". (event_range::print): Convert first param from diagnostic_context & to diagnostic_text_output_format & and update accordingly. (path_summary::path_summary): Likewise. (path_summary::print_swimlane_for_event_range): Likewise. (print_path_summary_as_text): Likewise for 3rd param. (diagnostic_context::print_path): Convert to... (diagnostic_text_output_format::print_path): ...this. (selftest::test_empty_path): Update to use a diagnostic_text_output_format. (selftest::test_intraprocedural_path): Likewise. (selftest::test_interprocedural_path_1): Likewise. (selftest::test_interprocedural_path_2): Likewise. (selftest::test_recursion): Likewise. (selftest::test_control_flow_1): Likewise. (selftest::test_control_flow_2): Likewise. (selftest::test_control_flow_3): Likewise. (selftest::assert_cfg_edge_path_streq): Likewise. (selftest::test_control_flow_5): Likewise. (selftest::test_control_flow_6): Likewise. * diagnostic.cc (file_name_as_prefix): Convert to... (diagnostic_text_output_format::file_name_as_prefix): ...this. (diagnostic_context::initialize): Update for renamings. Move m_last_module and m_includes_seen into text output. (diagnostic_context::finish): Likewise. (diagnostic_context::get_location_text): Add "colorize" param. (diagnostic_build_prefix): Convert to... (diagnostic_text_output_format::build_prefix): ...this. (diagnostic_context::includes_seen_p): Move from here to diagnostic_text_output_format/diagnostic-format-text.cc. (diagnostic_context::report_current_module): Likewise. (diagnostic_context::show_any_path): Convert to... (diagnostic_text_output_format::show_any_path): ...this. (default_diagnostic_starter): Rename and move to diagnostic-format-text.cc. (default_diagnostic_start_span_fn): Pass colorize bool to get_location_text. (default_diagnostic_finalizer): Rename and move to diagnostic-format-text.cc. (diagnostic_context::report_diagnostic): Replace call to show_any_path with call to new output format "after_diagnostic" vfunc, moving show_any_path call to the text output format. (diagnostic_append_note): Convert to... (diagnostic_text_output_format::append_note): ...this. (selftest::assert_location_text): Pass in false for colorization. * diagnostic.h (diagnostic_starter_fn): Rename to... (diagnostic_text_starter_fn): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format &. (diagnostic_finalizer_fn, diagnostic_text_finalizer_fn): Likewise. (diagnostic_context): Update friends for renamings. (diagnostic_context::report_current_module): Move to text output format. (diagnostic_context::get_location_text): Add "colorize" bool. (diagnostic_context::includes_seen_p): Move to text output format. (diagnostic_context::show_any_path): Likewise. (diagnostic_context::print_path): Likewise. (diagnostic_context::m_text_callbacks): Update for renamings. (diagnostic_context::m_last_module): Move to text output format. (diagnostic_context::m_includes_seen): Likewise. (diagnostic_starter): Rename to... (diagnostic_text_starter): ...this and update return type. (diagnostic_finalizer): Rename to... (diagnostic_text_finalizer): ...this and update return type. (diagnostic_report_current_module): Drop decl in favor of a member function of diagnostic_text_output_format. (diagnostic_append_note): Likewise. (default_diagnostic_starter): Rename to... (default_diagnostic_text_starter): ...this, updating type. (default_diagnostic_finalizer): Rename to... (default_diagnostic_text_finalizer): ...this, updating type. (file_name_as_prefix): Drop decl. * langhooks-def.h (lhd_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * langhooks.cc: Include "diagnostic-format-text.h". (lhd_print_error_function): Likewise. Update accordingly * langhooks.h (lang_hooks::print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * tree-diagnostic.cc: Include "diagnostic-format-text.h". (diagnostic_report_current_function): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (default_tree_diagnostic_starter): Rename to... (default_tree_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (tree_diagnostics_defaults): Update for renamings. gcc/cp/ChangeLog: PR other/116613 * cp-tree.h (cxx_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format &. * error.cc: Include "diagnostic-format-text.h". (cxx_initialize_diagnostics): Update for renamings. (cxx_print_error_function): Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly (cp_diagnostic_starter): Rename to... (cp_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (cp_print_error_function): Likewise. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context_line): Likewise. (print_instantiation_partial_context): Likewise. (maybe_print_instantiation_context): Likewise. (maybe_print_constexpr_context): Likewise. (print_location): Likewise. (print_constrained_decl_info): Likewise. (print_concept_check_info): Likewise. (print_constraint_context_head): Likewise. (print_requires_expression_info): Likewise. (maybe_print_single_constraint_context): Likewise. gcc/fortran/ChangeLog: PR other/116613 * error.cc: Include "diagnostic-format-text.h". (gfc_diagnostic_starter): Rename to... (gfc_diagnostic_text_starter): ...this. Convert first param from diagnostic_context * to diagnostic_text_output_format & and update accordingly. (gfc_diagnostic_finalizer, gfc_diagnostic_text_finalizer): Likewise. (gfc_diagnostics_init): Update for renamings. (gfc_diagnostics_finish): Likewise. gcc/jit/ChangeLog: PR other/116613 * dummy-frontend.cc: Include "diagnostic-format-text.h". (jit_begin_diagnostic): Convert first param from diagnostic_context * to diagnostic_text_output_format & (jit_end_diagnostic): Likewise. Update accordingly. (jit_langhook_init): Update for renamings. gcc/rust/ChangeLog: PR other/116613 * resolve/rust-ast-resolve-expr.cc (funny_ice_finalizer): : Convert first param from diagnostic_context * to diagnostic_text_output_format &. (ResolveExpr::visit): Update for renaming. gcc/testsuite/ChangeLog: PR other/116613 * g++.dg/plugin/show_template_tree_color_plugin.c (noop_starter_fn): Rename to... (noop_text_starter_fn): ...this. Update first param from dc to text_output. (plugin_init): Update for renamings. * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_starter): Rename to... (test_diagnostic_text_starter): ...this. Update first param from dc to text_output. (plugin_init): Update for renaming. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include "diagnostic-format-text.h". (custom_diagnostic_finalizer): Rename to... (custom_diagnostic_text_finalizer): ...this. Update first param from dc to text_output. (test_show_locus): Update for renamings. * gcc.dg/plugin/location_overflow_plugin.c: Include "diagnostic-format-text.h". (original_finalizer): Rename to... (original_text_finalizer): ...this and update type. (verify_unpacked_ranges): Update first param from dc to text_output. Update for this and for renamings. (verify_no_columns): Likewise. (plugin_init): Update for renamings. libcc1/ChangeLog: PR other/116613 * context.cc: Include "diagnostic-format-text.h". (plugin_print_error_function): Update first param from diagnostic_context * to diagnostic_text_output_format &. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-09-09diagnostics: introduce struct diagnostic_option_idDavid Malcolm1-2/+2
Use a new struct diagnostic_option_id rather than just "int" when referring to command-line options controlling warnings in the diagnostic subsystem. No functional change intended, but better documents the meaning of the code. gcc/c-family/ChangeLog: * c-common.cc (c_option_controlling_cpp_diagnostic): Return diagnostic_option_id rather than int. (c_cpp_diagnostic): Update for renaming of diagnostic_override_option_index to diagnostic_set_option_id. gcc/c/ChangeLog: * c-errors.cc (pedwarn_c23): Use "diagnostic_option_id option_id" rather than "int opt". Update for renaming of diagnostic_info field. (pedwarn_c11): Likewise. (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-tree.h (pedwarn_c90): Likewise for decl. (pedwarn_c99): Likewise. (pedwarn_c11): Likewise. (pedwarn_c23): Likewise. gcc/cp/ChangeLog: * constexpr.cc (constexpr_error): Update for renaming of diagnostic_info field. * cp-tree.h (pedwarn_cxx98): Use "diagnostic_option_id" rather than "int". * error.cc (cp_adjust_diagnostic_info): Update for renaming of diagnostic_info field. (pedwarn_cxx98): Use "diagnostic_option_id option_id" rather than "int opt". Update for renaming of diagnostic_info field. (diagnostic_set_info): Likewise. gcc/d/ChangeLog: * d-diagnostic.cc (d_diagnostic_report_diagnostic): Update for renaming of diagnostic_info field. gcc/ChangeLog: * diagnostic-core.h (struct diagnostic_option_id): New. (warning): Use it rather than "int" for param. (warning_n): Likewise. (warning_at): Likewise. (warning_meta): Likewise. (pedwarn): Likewise. (permerror_opt): Likewise. (emit_diagnostic): Likewise. (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist_meta): Likewise. * diagnostic-format-json.cc (json_output_format::on_report_diagnostic): Update for renaming of diagnostic_info field. * diagnostic-format-sarif.cc (sarif_builder::make_result_object): Likewise. (make_reporting_descriptor_object_for_warning): Likewise. * diagnostic-format-text.cc (print_option_information): Likewise. * diagnostic-global-context.cc (emit_diagnostic): Use "diagnostic_option_id option_id" rather than "int opt". (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist_meta): Likewise. (warning): Likewise. (warning_at): Likewise. (warning_meta): Likewise. (warning_n): Likewise. (pedwarn): Likewise. (permerror_opt): Likewise. * diagnostic.cc (diagnostic_set_info_translated): Update for renaming of diagnostic_info field. (diagnostic_option_classifier::classify_diagnostic): Use "diagnostic_option_id option_id" rather than "int opt". (update_effective_level_from_pragmas): Update for renaming of diagnostic_info field. (diagnostic_context::diagnostic_enabled): Likewise. (diagnostic_context::warning_enabled_at): Use "diagnostic_option_id option_id" rather than "int opt". (diagnostic_context::diagnostic_impl): Likewise. (diagnostic_context::diagnostic_n_impl): Likewise. * diagnostic.h (diagnostic_info::diagnostic_info): Update for... (diagnostic_info::option_index): Rename... (diagnostic_info::option_id): ...to this. (class diagnostic_option_manager): Use "diagnostic_option_id option_id" rather than "int opt" for vfuncs. (diagnostic_option_classifier): Likewise for member funcs. (diagnostic_classification_change_t::option): Add comment. (diagnostic_context::warning_enabled_at): Use "diagnostic_option_id option_id" rather than "int option_index". (diagnostic_context::option_unspecified_p): Likewise. (diagnostic_context::classify_diagnostic): Likewise. (diagnostic_context::option_enabled_p): Likewise. (diagnostic_context::make_option_name): Likewise. (diagnostic_context::make_option_url): Likewise. (diagnostic_context::diagnostic_impl): Likewise. (diagnostic_context::diagnostic_n_impl): Likewise. (diagnostic_override_option_index): Rename... (diagnostic_set_option_id): ...to this, and update for diagnostic_info field renaming. (diagnostic_classify_diagnostic): Use "diagnostic_option_id" rather than "int". (warning_enabled_at): Likewise. (option_unspecified_p): Likewise. gcc/fortran/ChangeLog: * cpp.cc (cb_cpp_diagnostic_cpp_option): Convert return type from "int" to "diagnostic_option_id". (cb_cpp_diagnostic): Update for renaming of diagnostic_override_option_index to diagnostic_set_option_id. * error.cc (gfc_warning): Update for renaming of diagnostic_info field. (gfc_warning_now_at): Likewise. (gfc_warning_now): Likewise. (gfc_warning_internal): Likewise. gcc/ChangeLog: * ipa-pure-const.cc: Replace include of "opts.h" with "opts-diagnostic.h". (suggest_attribute): Convert param from int to diagnostic_option_id. * lto-wrapper.cc (class lto_diagnostic_option_manager): Use diagnostic_option_id rather than "int". * opts-common.cc (compiler_diagnostic_option_manager::option_enabled_p): Likewise. * opts-diagnostic.h (class gcc_diagnostic_option_manager): Likewise. (class compiler_diagnostic_option_manager): Likewise. * opts.cc (compiler_diagnostic_option_manager::make_option_name): Likewise. (gcc_diagnostic_option_manager::make_option_url): Likewise. * substring-locations.cc (format_string_diagnostic_t::emit_warning_n_va): Likewise. (format_string_diagnostic_t::emit_warning_va): Likewise. (format_string_diagnostic_t::emit_warning): Likewise. (format_string_diagnostic_t::emit_warning_n): Likewise. * substring-locations.h (format_string_diagnostic_t::emit_warning_va): Likewise. (format_string_diagnostic_t::emit_warning_n_va): Likewise. (format_string_diagnostic_t::emit_warning): Likewise. (format_string_diagnostic_t::emit_warning_n): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-09-09diagnostics: rename dc.printer to m_printer [PR116613]David Malcolm1-15/+21
Rename diagnostic_context's "printer" field to "m_printer", for consistency with other fields, and to highlight places where we currently use this, to help assess feasibility of supporting multiple output sinks (PR other/116613). No functional change intended. gcc/ChangeLog: PR other/116613 * attribs.cc (decls_mismatched_attributes): Rename diagnostic_context's "printer" field to "m_printer". (attr_access::array_as_string): Likewise. * diagnostic-format-json.cc (json_output_format::on_report_diagnostic): Likewise. (diagnostic_output_format_init_json): Likewise. * diagnostic-format-sarif.cc (sarif_result::on_nested_diagnostic): Likewise. (sarif_ice_notification): Likewise. (sarif_builder::on_report_diagnostic): Likewise. (sarif_builder::make_result_object): Likewise. (sarif_builder::make_location_object): Likewise. (sarif_builder::make_message_object_for_diagram): Likewise. (diagnostic_output_format_init_sarif): Likewise. * diagnostic-format-text.cc (diagnostic_text_output_format::~diagnostic_text_output_format): Likewise. (diagnostic_text_output_format::on_report_diagnostic): Likewise. (diagnostic_text_output_format::on_diagram): Likewise. (diagnostic_text_output_format::print_any_cwe): Likewise. (diagnostic_text_output_format::print_any_rules): Likewise. (diagnostic_text_output_format::print_option_information): Likewise. * diagnostic-format.h (diagnostic_output_format::get_printer): New. * diagnostic-global-context.cc (verbatim): Rename diagnostic_context's "printer" field to "m_printer". * diagnostic-path.cc (path_label::get_text): Likewise. (print_path_summary_as_text): Likewise. (diagnostic_context::print_path): Likewise. (selftest::test_empty_path): Likewise. (selftest::test_intraprocedural_path): Likewise. (selftest::test_interprocedural_path_1): Likewise. (selftest::test_interprocedural_path_2): Likewise. (selftest::test_recursion): Likewise. (selftest::test_control_flow_1): Likewise. (selftest::test_control_flow_2): Likewise. (selftest::test_control_flow_3): Likewise. (assert_cfg_edge_path_streq): Likewise. (selftest::test_control_flow_5): Likewise. (selftest::test_control_flow_6): Likewise. * diagnostic-show-locus.cc (layout::layout): Likewise. (selftest::test_layout_x_offset_display_utf8): Likewise. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_diagnostic_show_locus_unknown_location): Likewise. (selftest::test_one_liner_simple_caret): Likewise. (selftest::test_one_liner_no_column): Likewise. (selftest::test_one_liner_caret_and_range): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges): Likewise. (selftest::test_one_liner_fixit_insert_before): Likewise. (selftest::test_one_liner_fixit_insert_after): Likewise. (selftest::test_one_liner_fixit_remove): Likewise. (selftest::test_one_liner_fixit_replace): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations): Likewise. (selftest::test_one_liner_many_fixits_1): Likewise. (selftest::test_one_liner_many_fixits_2): Likewise. (selftest::test_one_liner_labels): Likewise. (selftest::test_one_liner_simple_caret_utf8): Likewise. (selftest::test_one_liner_caret_and_range_utf8): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges_utf8): Likewise. (selftest::test_one_liner_fixit_insert_before_utf8): Likewise. (selftest::test_one_liner_fixit_insert_after_utf8): Likewise. (selftest::test_one_liner_fixit_remove_utf8): Likewise. (selftest::test_one_liner_fixit_replace_utf8): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range_utf8): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. (selftest::test_one_liner_many_fixits_1_utf8): Likewise. (selftest::test_one_liner_many_fixits_2_utf8): Likewise. (selftest::test_one_liner_labels_utf8): Likewise. (selftest::test_one_liner_colorized_utf8): Likewise. (selftest::test_add_location_if_nearby): Likewise. (selftest::test_diagnostic_show_locus_fixit_lines): Likewise. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_utf8): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_fixit_insert_containing_newline): Likewise. (selftest::test_fixit_insert_containing_newline_2): Likewise. (selftest::test_fixit_replace_containing_newline): Likewise. (selftest::test_fixit_deletion_affecting_newline): Likewise. (selftest::test_tab_expansion): Likewise. (selftest::test_escaping_bytes_1): Likewise. (selftest::test_escaping_bytes_2): Likewise. (selftest::test_line_numbers_multiline_range): Likewise. * diagnostic.cc (file_name_as_prefix): Likewise. (diagnostic_set_caret_max_width): Likewise. (diagnostic_context::initialize): Likewise. (diagnostic_context::color_init): Likewise. (diagnostic_context::urls_init): Likewise. (diagnostic_context::finish): Likewise. (diagnostic_context::get_location_text): Likewise. (diagnostic_build_prefix): Likewise. (diagnostic_context::report_current_module): Likewise. (default_diagnostic_starter): Likewise. (default_diagnostic_start_span_fn): Likewise. (default_diagnostic_finalizer): Likewise. (diagnostic_context::report_diagnostic): Likewise. (diagnostic_append_note): Likewise. (diagnostic_context::error_recursion): Likewise. (fancy_abort): Likewise. * diagnostic.h (diagnostic_context::set_show_highlight_colors): Likewise. (diagnostic_context::printer): Rename to... (diagnostic_context::m_printer): ...this. (diagnostic_format_decoder): Rename diagnostic_context's "printer" field to "m_printer". (diagnostic_prefixing_rule): Likewise. (diagnostic_ready_p): Likewise. * gimple-ssa-warn-access.cc (pass_waccess::maybe_warn_memmodel): Likewise. * langhooks.cc (lhd_print_error_function): Likewise. * lto-wrapper.cc (print_lto_docs_link): Likewise. * opts-global.cc (init_options_once): Likewise. * opts.cc (common_handle_option): Likewise. * simple-diagnostic-path.cc (simple_diagnostic_path_cc_tests): Likewise. * text-art/dump.h (dump_to_file<T>): Likewise. * toplev.cc (announce_function): Likewise. (toplev::main): Likewise. * tree-diagnostic.cc (default_tree_diagnostic_starter): Likewise. * tree.cc (escaped_string::escape): Likewise. (selftest::test_escaped_strings): Likewise. gcc/ada/ChangeLog: PR other/116613 * gcc-interface/misc.cc (internal_error_function): Rename diagnostic_context's "printer" field to "m_printer". gcc/analyzer/ChangeLog: PR other/116613 * access-diagram.cc (access_range::dump): Rename diagnostic_context's "printer" field to "m_printer". * analyzer-language.cc (on_finish_translation_unit): Likewise. * analyzer.cc (make_label_text): Likewise. (make_label_text_n): Likewise. * call-details.cc (call_details::dump): Likewise. * call-summary.cc (call_summary::dump): Likewise. (call_summary_replay::dump): Likewise. * checker-event.cc (checker_event::debug): Likewise. * constraint-manager.cc (range::dump): Likewise. (bounded_range::dump): Likewise. (bounded_ranges::dump): Likewise. (constraint_manager::dump): Likewise. * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostic): Likewise. * engine.cc (exploded_node::dump): Likewise. (exploded_path::dump): Likewise. (run_checkers): Likewise. * kf-analyzer.cc (kf_analyzer_dump_escaped::impl_call_pre): Likewise. * pending-diagnostic.cc (evdesc::event_desc::formatted_print): Likewise. * program-point.cc (function_point::print_source_line): Likewise. (program_point::dump): Likewise. * program-state.cc (extrinsic_state::dump_to_file): Likewise. (sm_state_map::dump): Likewise. (program_state::dump_to_file): Likewise. * ranges.cc (symbolic_byte_offset::dump): Likewise. (symbolic_byte_range::dump): Likewise. * region-model-reachability.cc (reachable_regions::dump): Likewise. * region-model.cc (region_to_value_map::dump): Likewise. (region_model::dump): Likewise. (model_merger::dump): Likewise. * region.cc (region_offset::dump): Likewise. (region::dump): Likewise. * sm-malloc.cc (deallocator_set::dump): Likewise. (sufficiently_similar_p): Likewise. * store.cc (uncertainty_t::dump): Likewise. (binding_key::dump): Likewise. (binding_map::dump): Likewise. (binding_cluster::dump): Likewise. (store::dump): Likewise. * supergraph.cc (supergraph::dump_dot_to_file): Likewise. (superedge::dump): Likewise. * svalue.cc (svalue::dump): Likewise. gcc/c-family/ChangeLog: PR other/116613 * c-format.cc (selftest::test_type_mismatch_range_labels): Rename diagnostic_context's "printer" field to "m_printer". (selftest::test_type_mismatch_range_labels): Likewise. * c-opts.cc (c_diagnostic_finalizer): Likewise. gcc/c/ChangeLog: PR other/116613 * c-objc-common.cc (c_initialize_diagnostics): Rename diagnostic_context's "printer" field to "m_printer". gcc/cp/ChangeLog: PR other/116613 * error.cc (cxx_initialize_diagnostics): Rename diagnostic_context's "printer" field to "m_printer". (cxx_print_error_function): Likewise. (cp_diagnostic_starter): Likewise. (cp_print_error_function): Likewise. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context_line): Likewise. (maybe_print_constexpr_context): Likewise. (print_location): Likewise. (print_constrained_decl_info): Likewise. (print_concept_check_info): Likewise. (print_constraint_context_head): Likewise. (print_requires_expression_info): Likewise. * module.cc (noisy_p): Likewise. gcc/d/ChangeLog: PR other/116613 * d-diagnostic.cc (d_diagnostic_report_diagnostic): Rename diagnostic_context's "printer" field to "m_printer". gcc/fortran/ChangeLog: PR other/116613 * error.cc (gfc_clear_pp_buffer): Rename diagnostic_context's "printer" field to "m_printer". (gfc_warning): Likewise. (gfc_diagnostic_build_kind_prefix): Likewise. (gfc_diagnostic_build_locus_prefix): Likewise. (gfc_diagnostic_starter): Likewise. (gfc_diagnostic_starter): Likewise. (gfc_diagnostic_start_span): Likewise. (gfc_diagnostic_finalizer): Likewise. (gfc_warning_check): Likewise. (gfc_error_opt): Likewise. (gfc_error_check): Likewise. gcc/jit/ChangeLog: PR other/116613 * jit-playback.cc (add_diagnostic): Rename diagnostic_context's "printer" field to "m_printer". gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info): Update for renaming of field "printer" to "m_printer". * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_starter): Likewise. (test_diagnostic_start_span_fn): Likewise. (test_output_format::on_begin_group): Likewise. (test_output_format::on_end_group): Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (custom_diagnostic_finalizer): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-08-26diagnostics: move output formats from diagnostic.{c,h} to their own filesDavid Malcolm1-0/+209
In particular, move the classic text output code to a diagnostic-text.cc (analogous to -json.cc and -sarif.cc). No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostic-format-text.o. * diagnostic-format-json.cc: Include "diagnostic-format.h". * diagnostic-format-sarif.cc: Likewise. * diagnostic-format-text.cc: New file, using material from diagnostics.cc. * diagnostic-global-context.cc: Include "diagnostic-format.h". * diagnostic-format-text.h: New file, using material from diagnostics.h. * diagnostic-format.h: New file, using material from diagnostics.h. * diagnostic.cc: Include "diagnostic-format.h" and "diagnostic-format-text.h". (diagnostic_text_output_format::~diagnostic_text_output_format): Move to diagnostic-format-text.cc. (diagnostic_text_output_format::on_report_diagnostic): Likewise. (diagnostic_text_output_format::on_diagram): Likewise. (diagnostic_text_output_format::print_any_cwe): Likewise. (diagnostic_text_output_format::print_any_rules): Likewise. (diagnostic_text_output_format::print_option_information): Likewise. * diagnostic.h (class diagnostic_output_format): Move to diagnostic-format.h. (class diagnostic_text_output_format): Move to diagnostic-format-text.h. (diagnostic_output_format_init): Move to diagnostic-format.h. (diagnostic_output_format_init_json_stderr): Likewise. (diagnostic_output_format_init_json_file): Likewise. (diagnostic_output_format_init_sarif_stderr): Likewise. (diagnostic_output_format_init_sarif_file): Likewise. (diagnostic_output_format_init_sarif_stream): Likewise. * gcc.cc: Include "diagnostic-format.h". * opts.cc: Include "diagnostic-format.h". gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.c: Include "diagnostic-format-text.h". Signed-off-by: David Malcolm <dmalcolm@redhat.com>