]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: implement highlight-a vs -b in HTML output [PR116792]
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 30 May 2025 23:57:46 +0000 (19:57 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 30 May 2025 23:57:46 +0000 (19:57 -0400)
commita746747e2102c965a7736dc22ba56c3bc8e3e61e
treeccf5e373e63f162996ad5b9ba0194aa562902f36
parentd10e3e0900c92479a6621e375070d4a99ca1fd57
diagnostics: implement highlight-a vs -b in HTML output [PR116792]

Update HTML output so that it renders highlight-a vs highlight-b
via <span> tags in the message itself, in the quoted source line,
in the underlines, and in the labels and their vertical bars.

Example output can be seen at:
  https://dmalcolm.fedorapeople.org/gcc/2025-05-28/diagnostic-ranges.c.html

gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc (HTML_STYLE): Add ".highlight-a" and
".highlight-b".
(html_builder::make_element_for_diagnostic): Handle begin_color
and end_color.
* diagnostic-show-locus.cc (to_html::to_html): Add "richloc"
param and use it to initialize m_richloc.
(to_html::colorize_text_for_range_idx): Drop.
(to_html::get_location_range_by_idx): New.
(to_html::get_highlight_color_for_range_idx): New.
(to_html::m_richloc): New field.
(print_html_span_start): Update for new param of to_html ctor.
(line_printer::m_was_in_range_p): New field.
(line_printer::m_last_range_idx): New field.
(layout_printer<Sink>::print_source_line): Use set_in_range
and set_outside_range rather than colorization calls.
(layout_printer<Sink>::set_in_range): New.
(layout_printer<Sink>::set_outside_range): New.
(layout_printer<Sink>::print_annotation_line): Use set_in_range
and set_outside_range rather than colorization calls.
(layout_printer<to_text>::begin_label): Convert param from label
to state_idx.  Add "is_label_text" param and use it to guard logic
for turning off colorization within paths.
(layout_printer<to_html>::begin_label): Likewise.  Push <span>
for any highlight color.
(layout_printer<to_text>::end_label): Likewise.
(layout_printer<to_text>::end_label): Likewise, popping the
<span>.
(layout_printer<Sink>::print_any_labels): Convert begin/end_label
calls to pass in state_idx rather than label.  Use begin/end_label
rather than colorization calls.
(layout_printer<Sink>::layout_printer): Likewise.
(layout_printer<Sink>::layout_printer): Initialize new fields.
(diagnostic_source_print_policy::print_as_html): Update for new
param of to_html ctor.

gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/format/diagnostic-ranges-html.py: New test script.
* gcc.dg/format/diagnostic-ranges.c: Add HTML generation to
options, and invoke the new script to check the HTML output.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-html.cc
gcc/diagnostic-show-locus.cc
gcc/testsuite/gcc.dg/format/diagnostic-ranges-html.py [new file with mode: 0644]
gcc/testsuite/gcc.dg/format/diagnostic-ranges.c