public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5895] diagnostics: add diagnostic_context::get_location_text
@ 2023-11-28 1:22 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-11-28 1:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:93096d3ce14a89603bd30f0298fc15000a61e757
commit r14-5895-g93096d3ce14a89603bd30f0298fc15000a61e757
Author: David Malcolm <dmalcolm@redhat.com>
Date: Mon Nov 27 20:09:35 2023 -0500
diagnostics: add diagnostic_context::get_location_text
No functional change intended.
gcc/ChangeLog:
* diagnostic.cc (diagnostic_get_location_text): Convert to...
(diagnostic_context::get_location_text): ...this, and convert
return type from char * to label_text.
(diagnostic_build_prefix): Update for above change.
(default_diagnostic_start_span_fn): Likewise.
(selftest::assert_location_text): Likewise.
* diagnostic.h (diagnostic_context::get_location_text): New decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/diagnostic.cc | 35 +++++++++++++++--------------------
gcc/diagnostic.h | 2 ++
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index b4ebcd29457..4f66fa6acaa 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -558,14 +558,12 @@ maybe_line_and_column (int line, int col)
return result;
}
-/* Return a malloc'd string describing a location e.g. "foo.c:42:10".
- The caller is responsible for freeing the memory. */
+/* Return a string describing a location e.g. "foo.c:42:10". */
-static char *
-diagnostic_get_location_text (diagnostic_context *context,
- expanded_location s)
+label_text
+diagnostic_context::get_location_text (const expanded_location &s) const
{
- pretty_printer *pp = context->printer;
+ pretty_printer *pp = this->printer;
const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
const char *locus_ce = colorize_stop (pp_show_color (pp));
const char *file = s.file ? s.file : progname;
@@ -574,13 +572,13 @@ diagnostic_get_location_text (diagnostic_context *context,
if (strcmp (file, special_fname_builtin ()))
{
line = s.line;
- if (context->m_show_column)
- col = context->converted_column (s);
+ if (m_show_column)
+ col = this->converted_column (s);
}
const char *line_col = maybe_line_and_column (line, col);
- return build_message_string ("%s%s%s:%s", locus_cs, file,
- line_col, locus_ce);
+ return label_text::take (build_message_string ("%s%s%s:%s", locus_cs, file,
+ line_col, locus_ce));
}
static const char *const diagnostic_kind_text[] = {
@@ -610,12 +608,11 @@ diagnostic_build_prefix (diagnostic_context *context,
text_ce = colorize_stop (pp_show_color (pp));
}
- expanded_location s = diagnostic_expand_location (diagnostic);
- char *location_text = diagnostic_get_location_text (context, s);
+ const expanded_location s = diagnostic_expand_location (diagnostic);
+ label_text location_text = context->get_location_text (s);
- char *result = build_message_string ("%s %s%s%s", location_text,
+ char *result = build_message_string ("%s %s%s%s", location_text.get (),
text_cs, text, text_ce);
- free (location_text);
return result;
}
@@ -1091,9 +1088,8 @@ void
default_diagnostic_start_span_fn (diagnostic_context *context,
expanded_location exploc)
{
- char *text = diagnostic_get_location_text (context, exploc);
- pp_string (context->printer, text);
- free (text);
+ label_text text = context->get_location_text (exploc);
+ pp_string (context->printer, text.get ());
pp_newline (context->printer);
}
@@ -2852,9 +2848,8 @@ assert_location_text (const char *expected_loc_text,
xloc.data = NULL;
xloc.sysp = false;
- char *actual_loc_text = diagnostic_get_location_text (&dc, xloc);
- ASSERT_STREQ (expected_loc_text, actual_loc_text);
- free (actual_loc_text);
+ label_text actual_loc_text = dc.get_location_text (xloc);
+ ASSERT_STREQ (expected_loc_text, actual_loc_text.get ());
}
/* Verify that diagnostic_get_location_text works as expected. */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index cbd25541f50..b57556f9759 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -541,6 +541,8 @@ public:
return m_option_callbacks.m_lang_mask;
}
+ label_text get_location_text (const expanded_location &s) const;
+
private:
bool includes_seen_p (const line_map_ordinary *map);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-28 1:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 1:22 [gcc r14-5895] diagnostics: add diagnostic_context::get_location_text 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).