mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
diagnostics: make experimental-html sink prettier [PR116792]
This patch to the "experimental-html" diagnostic sink:
* adds use of the PatternFly 3 CSS library (via an optional link
in the generated html to a copy in a CDN)
* uses PatternFly's "alert" pattern to show severities for diagnostics,
properly nesting "note" diagnostics for diagnostic groups.
Example:
before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/diagnostic-ranges.c.html
after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/diagnostic-ranges.c.html
* adds initial support for logical locations and physical locations
* adds initial support for multi-level nested diagnostics such as those
for C++ concepts diagnostics. Ideally this would show a clickable
disclosure widget to expand/collapse a level, but for now it uses
nested <ul> elements with <li> for the child diagnostics.
Example:
before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/nested-diagnostics-1.C.html
after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/nested-diagnostics-1.C.html
gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc: Include "diagnostic-path.h" and
"diagnostic-client-data-hooks.h".
(html_builder::m_logical_loc_mgr): New field.
(html_builder::m_cur_nesting_levels): New field.
(html_builder::m_last_logical_location): New field.
(html_builder::m_last_location): New field.
(html_builder::m_last_expanded_location): New field.
(HTML_STYLE): Add "white-space: pre;" to .source and .annotation.
Add "gcc-quoted-text" CSS class.
(html_builder::html_builder): Initialize the new fields. If CSS
is enabled, add CDN links to PatternFly 3 stylesheets.
(html_builder::add_stylesheet): New.
(html_builder::on_report_diagnostic): Add "alert" param to
make_element_for_diagnostic, setting it by default, but unsetting
it for nested diagnostics below the top level. Use
add_at_nesting_level for nested diagnostics.
(add_nesting_level_attr): New.
(html_builder::add_at_nesting_level): New.
(get_pf_class_for_alert_div): New.
(get_pf_class_for_alert_icon): New.
(get_label_for_logical_location_kind): New.
(add_labelled_value): New.
(html_builder::make_element_for_diagnostic): Add leading comment.
Add "alert" param. Drop class="gcc-diagnostic" from <div> tag,
instead adding the class for a PatternFly 3 alert if "alert" is
true, and adding a <span> with an alert icon, both according to
the diagnostic severity. Add a severity prefix to the message for
alerts. Add any metadata/option text as suffixes to the message.
Show any logical location. Show any physical location. Don't
show the locus if the last location is unchanged within the
diagnostic_group. Wrap any execution path element in a
<div id="execution-path"> and add a label to it. Wrap any
generated patch in a <div id="suggested-fix"> and add a label
to it.
(selftest::test_simple_log): Update expected HTML.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.py: Update for changes
to diagnostic elements.
* gcc.dg/format/diagnostic-ranges-html.py: Likewise.
* gcc.dg/plugin/diagnostic-test-metadata-html.py: Likewise. Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-paths-2.py: Likewise.
* gcc.dg/plugin/diagnostic-test-paths-4.py: Likewise. Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-show-locus.py: Likewise.
* lib/htmltest.py (get_diag_by_index): Update to use search by id.
(get_message_within_diag): Update to use search by class.
libcpp/ChangeLog:
PR other/116792
* include/line-map.h (typedef expanded_location): Convert to...
(struct expanded_location): ...this.
(operator==): New decl, for expanded_location.
(operator!=): Likewise.
* line-map.cc (operator==): New decl, for expanded_location.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
@@ -1280,7 +1280,7 @@ linemap_location_before_p (const line_maps *set,
|
||||
return linemap_compare_locations (set, loc_a, loc_b) >= 0;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
struct expanded_location
|
||||
{
|
||||
/* The name of the source file involved. */
|
||||
const char *file;
|
||||
@@ -1294,7 +1294,18 @@ typedef struct
|
||||
|
||||
/* In a system header?. */
|
||||
bool sysp;
|
||||
} expanded_location;
|
||||
};
|
||||
|
||||
extern bool
|
||||
operator== (const expanded_location &a,
|
||||
const expanded_location &b);
|
||||
inline bool
|
||||
operator!= (const expanded_location &a,
|
||||
const expanded_location &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
|
||||
/* This is enum is used by the function linemap_resolve_location
|
||||
below. The meaning of the values is explained in the comment of
|
||||
|
||||
@@ -1949,6 +1949,28 @@ linemap_expand_location (const line_maps *set,
|
||||
return xloc;
|
||||
}
|
||||
|
||||
bool
|
||||
operator== (const expanded_location &a,
|
||||
const expanded_location &b)
|
||||
{
|
||||
/* "file" can be null; for them to be equal they must both
|
||||
have either null or nonnull values, and if non-null
|
||||
they must compare as equal. */
|
||||
if ((a.file == nullptr) != (b.file == nullptr))
|
||||
return false;
|
||||
if (a.file && strcmp (a.file, b.file))
|
||||
return false;
|
||||
|
||||
if (a.line != b.line)
|
||||
return false;
|
||||
if (a.column != b.column)
|
||||
return false;
|
||||
if (a.data != b.data)
|
||||
return false;
|
||||
if (a.sysp != b.sysp)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Dump line map at index IX in line table SET to STREAM. If STREAM
|
||||
is NULL, use stderr. IS_MACRO is true if the caller wants to
|
||||
|
||||
Reference in New Issue
Block a user