From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [pushed] diagnostics: handle SGR codes in line_label::m_display_width
Date: Wed, 15 May 2024 21:29:57 -0400 [thread overview]
Message-ID: <20240516013000.2967650-1-dmalcolm@redhat.com> (raw)
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successful run of analyzer integration tests on x86_64-pc-linux-gnu.
Pushed to trunk as r15-532-ga7be993806a90a.
gcc/ChangeLog:
* diagnostic-show-locus.cc: Define INCLUDE_VECTOR and include
"text-art/types.h".
(line_label::line_label): Drop "policy" argument. Use
styled_string::calc_canvas_width when computing m_display_width,
as this skips SGR codes.
(layout::print_any_labels): Update for line_label ctor change.
(selftest::test_one_liner_labels_utf8): Update expected text to
reflect that the labels can fit on one line if we don't get
confused by SGR colorization codes.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
gcc/diagnostic-show-locus.cc | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index ceccc0b793d1..f42006cfe2a1 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_VECTOR
#include "system.h"
#include "coretypes.h"
#include "version.h"
@@ -31,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "selftest.h"
#include "selftest-diagnostic.h"
#include "cpplib.h"
+#include "text-art/types.h"
#ifdef HAVE_TERMIOS_H
# include <termios.h>
@@ -1923,14 +1925,18 @@ struct pod_label_text
class line_label
{
public:
- line_label (const cpp_char_column_policy &policy,
- int state_idx, int column,
+ line_label (int state_idx, int column,
label_text text)
: m_state_idx (state_idx), m_column (column),
m_text (std::move (text)), m_label_line (0), m_has_vbar (true)
{
- const int bytes = strlen (m_text.m_buffer);
- m_display_width = cpp_display_width (m_text.m_buffer, bytes, policy);
+ /* Using styled_string rather than cpp_display_width here
+ lets us skip SGR formatting characters for color and URLs.
+ It doesn't handle tabs and unicode escaping, but we don't
+ expect to see either of those in labels. */
+ text_art::style_manager sm;
+ text_art::styled_string str (sm, m_text.m_buffer);
+ m_display_width = str.calc_canvas_width ();
}
/* Sorting is primarily by column, then by state index. */
@@ -1990,7 +1996,7 @@ layout::print_any_labels (linenum_type row)
if (text.get () == NULL)
continue;
- labels.safe_push (line_label (m_policy, i, disp_col, std::move (text)));
+ labels.safe_push (line_label (i, disp_col, std::move (text)));
}
}
@@ -4382,9 +4388,9 @@ test_one_liner_labels_utf8 ()
ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
" ^~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
" | | |\n"
- " | | label 2\xcf\x80\n"
- " | label 1\xcf\x80\n"
- " label 0\xf0\x9f\x98\x82\n",
+ " label 0\xf0\x9f\x98\x82"
+ /* ... */ " label 1\xcf\x80"
+ /* ...................*/ " label 2\xcf\x80\n",
pp_formatted_text (dc.printer));
}
{
@@ -4395,9 +4401,9 @@ test_one_liner_labels_utf8 ()
(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
" ^~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
" | | |\n"
- " | | label 2\xcf\x80\n"
- " | label 1\xcf\x80\n"
- " label 0\xf0\x9f\x98\x82\n",
+ " label 0\xf0\x9f\x98\x82"
+ /* ... */ " label 1\xcf\x80"
+ /* ..........................*/ " label 2\xcf\x80\n",
pp_formatted_text (dc.printer));
}
}
--
2.26.3
next reply other threads:[~2024-05-16 1:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 1:29 David Malcolm [this message]
2024-05-16 1:29 ` [pushed] diagnostics: simplify output of purely intraprocedural execution paths David Malcolm
2024-05-16 1:29 ` [pushed] diagnostics: add warning emoji to events with VERB_danger David Malcolm
2024-05-16 1:30 ` [pushed] diagnostics: use unicode art for interprocedural depth David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240516013000.2967650-1-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).