public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9817] analyzer: respect GCC_COLORS in out-of-bounds diagrams [PR114588]
@ 2024-04-05 18:51 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-04-05 18:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4b02dd48f531ea88587edd2b75b6e5243b4389e8
commit r14-9817-g4b02dd48f531ea88587edd2b75b6e5243b4389e8
Author: David Malcolm <dmalcolm@redhat.com>
Date: Fri Apr 5 14:49:53 2024 -0400
analyzer: respect GCC_COLORS in out-of-bounds diagrams [PR114588]
gcc/analyzer/ChangeLog:
PR analyzer/114588
* access-diagram.cc (access_diagram_impl::access_diagram_impl):
Replace hardcoded colors for valid_style and invalid_style with
calls to text_art::get_style_from_color_cap_name.
gcc/ChangeLog:
PR analyzer/114588
* diagnostic-color.cc (color_dict): Add "valid" and "invalid" as
color capability names.
* doc/invoke.texi: Document them in description of GCC_COLORS.
* text-art/style.cc: Include "diagnostic-color.h".
(text_art::get_style_from_color_cap_name): New.
* text-art/types.h (get_style_from_color_cap_name): New decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/access-diagram.cc | 8 ++------
gcc/diagnostic-color.cc | 2 ++
gcc/doc/invoke.texi | 10 +++++++++-
gcc/text-art/style.cc | 18 ++++++++++++++++++
gcc/text-art/types.h | 2 ++
5 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc
index 4cb6570e90b..85e1049bb89 100644
--- a/gcc/analyzer/access-diagram.cc
+++ b/gcc/analyzer/access-diagram.cc
@@ -2059,14 +2059,10 @@ public:
/* Register painting styles. */
{
- style valid_style;
- valid_style.m_fg_color = style::named_color::GREEN;
- valid_style.m_bold = true;
+ style valid_style (get_style_from_color_cap_name ("valid"));
m_valid_style_id = m_sm.get_or_create_id (valid_style);
- style invalid_style;
- invalid_style.m_fg_color = style::named_color::RED;
- invalid_style.m_bold = true;
+ style invalid_style (get_style_from_color_cap_name ("invalid"));
m_invalid_style_id = m_sm.get_or_create_id (invalid_style);
}
diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc
index 4859f36da6a..f01a0fc2e37 100644
--- a/gcc/diagnostic-color.cc
+++ b/gcc/diagnostic-color.cc
@@ -101,6 +101,8 @@ static struct color_cap color_dict[] =
{ "diff-delete", SGR_SEQ (COLOR_FG_RED), 11, false },
{ "diff-insert", SGR_SEQ (COLOR_FG_GREEN), 11, false },
{ "type-diff", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 9, false },
+ { "valid", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 5, false },
+ { "invalid", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_RED), 7, false },
{ NULL, NULL, 0, false }
};
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e2edf7a6c13..1006510fc6a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -5244,7 +5244,7 @@ The default @env{GCC_COLORS} is
error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:\
quote=01:path=01;36:fixit-insert=32:fixit-delete=31:\
diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\
-type-diff=01;32:fnname=01;32:targs=35
+type-diff=01;32:fnname=01;32:targs=35:valid=01;31:invalid=01;32
@end smallexample
@noindent
where @samp{01;31} is bold red, @samp{01;35} is bold magenta,
@@ -5327,6 +5327,14 @@ SGR substring for inserted lines within generated patches.
@item type-diff=
SGR substring for highlighting mismatching types within template
arguments in the C++ frontend.
+
+@vindex valid GCC_COLORS @r{capability}
+@item valid=
+SGR substring for highlighting valid elements within text art diagrams.
+
+@vindex invalid GCC_COLORS @r{capability}
+@item invalid=
+SGR substring for highlighting invalid elements within text art diagrams.
@end table
@opindex fdiagnostics-urls
diff --git a/gcc/text-art/style.cc b/gcc/text-art/style.cc
index e74efe23014..5c58d432cf4 100644
--- a/gcc/text-art/style.cc
+++ b/gcc/text-art/style.cc
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "text-art/selftests.h"
#include "text-art/types.h"
#include "color-macros.h"
+#include "diagnostic-color.h"
using namespace text_art;
@@ -256,6 +257,23 @@ style::print_changes (pretty_printer *pp,
}
}
+/* Look up the current SGR codes for a color capability NAME
+ (from GCC_COLORS or the defaults), and convert them to
+ a text_art::style. */
+
+style
+text_art::get_style_from_color_cap_name (const char *name)
+{
+ const char *sgr_codes = colorize_start (true, name);
+ gcc_assert (sgr_codes);
+
+ /* Parse the sgr codes. We expect the resulting styled_string to be
+ empty; we're interested in the final style created during parsing. */
+ style_manager sm;
+ styled_string styled_str (sm, sgr_codes);
+ return sm.get_style (sm.get_num_styles () - 1);
+}
+
/* class text_art::style_manager. */
style_manager::style_manager ()
diff --git a/gcc/text-art/types.h b/gcc/text-art/types.h
index 02de2e86122..2b9f8b387c7 100644
--- a/gcc/text-art/types.h
+++ b/gcc/text-art/types.h
@@ -332,6 +332,8 @@ struct style
std::vector<cppchar_t> m_url; // empty = no URL
};
+extern style get_style_from_color_cap_name (const char *name);
+
/* A class to keep track of all the styles in use in a drawing, so that
we can refer to them via the compact style::id_t type, rather than
via e.g. pointers. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-04-05 18:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 18:51 [gcc r14-9817] analyzer: respect GCC_COLORS in out-of-bounds diagrams [PR114588] David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).