https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117943

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>:

https://gcc.gnu.org/g:ea7da640cf234ebde8d73d996dd14e6563c1ffcf

commit r15-6283-gea7da640cf234ebde8d73d996dd14e6563c1ffcf
Author: David Malcolm <dmalc...@redhat.com>
Date:   Mon Dec 16 11:22:49 2024 -0500

    diagnostics: move libgdiagnostics dc from sinks into diagnostic_manager

    libgdiagnostics was written before the fixes for PR other/116613 allowed
    a diagnostic_context to have multiple output sinks.

    Hence each libgdiagnostics sink had its own diagnostic_context with just
    one diagnostic_output_format.

    This wart is no longer necessary and makes it harder to move state
    into the manager/context; in particular for quoting source code
    from the .sarif file (PR sarif-replay/117943).

    Simplify, by making libgdiagnostics' implementation more similar to
    GCC's implementation, by moving the diagnostic_context from sink into
    diagnostic_manager.

    Doing so requires generalizing where the
    diagnostic_source_printing_options comes from in class
    diagnostic_text_output_format: for GCC we use
    the instance within the diagnostic_context, whereas for
    libgdiagnostics each diagnostic_text_sink has its own instance.

    No functional change intended.

    gcc/c-family/ChangeLog:
            PR sarif-replay/117943
            * c-format.cc (selftest::test_type_mismatch_range_labels): Use
            dc.m_source_printing.
            * c-opts.cc (c_diagnostic_text_finalizer): Use source-printing
            options from text_output.

    gcc/cp/ChangeLog:
            PR sarif-replay/117943
            * error.cc (auto_context_line::~auto_context_line): Use
            source-printing options from text_output.

    gcc/ChangeLog:
            PR sarif-replay/117943
            * diagnostic-format-text.cc
            (diagnostic_text_output_format::append_note): Use source-printing
            options from text_output.
            (diagnostic_text_output_format::update_printer): Copy
            source-printing options from dc.
            (default_diagnostic_text_finalizer): Use source-printing
            options from text_output.
            * diagnostic-format-text.h
            (diagnostic_text_output_format::diagnostic_text_output_format):
            Add optional diagnostic_source_printing_options param, using
            the context's if null.
            (diagnostic_text_output_format::get_source_printing_options): New
            accessor.
            (diagnostic_text_output_format::m_source_printing): New field.
            * diagnostic-path.cc (event_range::print): Use source-printing
            options from text_output.
            (selftest::test_interprocedural_path_1): Use source-printing
            options from dc.
            * diagnostic-show-locus.cc
            (gcc_rich_location::add_location_if_nearby): Likewise.
            (diagnostic_context::maybe_show_locus): Add "opts" param
            and use in place of m_source_printing.  Pass it to source_policy
            ctor.
            (diagnostic_source_print_policy::diagnostic_source_print_policy):
            Add overload taking a const diagnostic_source_printing_options &.
            * diagnostic.cc (diagnostic_context::initialize): Pass nullptr
            for source options when creating text sink, so that it uses
            the dc's options.
            (diagnostic_context::dump): Add an "output sinks:" heading and
            print "(none)" if there aren't any.
            (diagnostic_context::set_output_format): Split out code into...
            (diagnostic_context::remove_all_output_sinks): ...this new
            function.
            * diagnostic.h
            (diagnostic_source_print_policy::diagnostic_source_print_policy):
            Add overload taking a const diagnostic_source_printing_options &.
            (diagnostic_context::maybe_show_locus): Add "opts" param.
            (diagnostic_context::remove_all_output_sinks): New decl.
            (diagnostic_context::m_source_printing): New field.
            (diagnostic_show_locus): Add "opts" param and pass to
            maybe_show_locus.
            * libgdiagnostics.cc (sink::~sink): Delete.
            (sink::begin_group): Delete.
            (sink::end_group): Delete.
            (sink::emit): Delete.
            (sink::m_dc): Drop field.
            (diagnostic_text_sink::on_begin_text_diagnostic): Delete.
            (diagnostic_text_sink::get_source_printing_options): Use
            m_souece_printing.
            (diagnostic_text_sink::m_current_logical_loc): Drop field.
            (diagnostic_text_sink::m_inner_sink): New field.
            (diagnostic_text_sink::m_source_printing): New field.
            (diagnostic_manager::diagnostic_manager): Update for changes
            to fields.  Initialize m_dc.
            (diagnostic_manager::~diagnostic_manager): Call diagnostic_finish.
            (diagnostic_manager::get_file_cache): Drop.
            (diagnostic_manager::get_dc): New accessor.
            (diagnostic_manager::begin_group): Reimplement.
            (diagnostic_manager::end_group): Reimplement.
            (diagnostic_manager::get_prev_diag_logical_loc): New accessor.
            (diagnostic_manager::m_dc): New field.
            (diagnostic_manager::m_file_cache): Drop field.
            (diagnostic_manager::m_edit_context): Convert to a std::unique_ptr
            so that object can be constructed after m_dc is initialized.
            (diagnostic_manager::m_prev_diag_logical_loc): New field.
            (diagnostic_text_sink::diagnostic_text_sink): Reimplement.
            (get_color_rule): Delete.
            (diagnostic_text_sink::set_colorize): Reimplement.
            (diagnostic_text_sink::text_starter): New.
            (sarif_sink::sarif_sink): Reimplement.
            (diagnostic_manager::write_patch): Update for change to
            m_edit_context.
            (diagnostic_manager::emit): Update now that each sink has a
            corresponding diagnostic_output_format object within m_dc.

    gcc/fortran/ChangeLog:
            PR sarif-replay/117943
            * error.cc (gfc_diagnostic_text_starter): Use source-printing
            options from text_output.

    gcc/testsuite/ChangeLog:
            PR sarif-replay/117943
            * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
            (custom_diagnostic_text_finalizer): Use source-printing options
            from text_output.
            * gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc
            (xhtml_builder::make_element_for_diagnostic): Use source-printing
            options from diagnostic_context.
            * gcc.dg/plugin/expensive_selftests_plugin.cc (test_richloc):
            Likewise.

    Signed-off-by: David Malcolm <dmalc...@redhat.com>

Reply via email to