public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4379] diagnostics: add ctors to text_info; add m_ prefixes to fields
@ 2023-10-03 13:42 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-10-03 13:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c44ca7c01226e0768e58c5b274ddd5e161378010

commit r14-4379-gc44ca7c01226e0768e58c5b274ddd5e161378010
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Oct 3 09:39:16 2023 -0400

    diagnostics: add ctors to text_info; add m_ prefixes to fields
    
    No functional change intended.
    
    gcc/ada/ChangeLog:
            * gcc-interface/misc.cc: Use text_info ctor.
    
    gcc/analyzer/ChangeLog:
            * analyzer-logging.cc (logger::log_va_partial): Use text_info
            ctor.
            * analyzer.cc (make_label_text): Likewise.
            (make_label_text_n): Likewise.
            * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
            Likewise.
    
    gcc/c/ChangeLog:
            * c-objc-common.cc (c_tree_printer): Update for "m_" prefixes to
            text_info fields.
    
    gcc/cp/ChangeLog:
            * error.cc: Update for "m_" prefixes to text_info fields.
    
    gcc/d/ChangeLog:
            * d-diagnostic.cc (d_diagnostic_report_diagnostic): Use text_info
            ctor.
    
    gcc/ChangeLog:
            * diagnostic.cc (diagnostic_set_info_translated): Update for "m_"
            prefixes to text_info fields.
            (diagnostic_report_diagnostic): Likewise.
            (verbatim): Use text_info ctor.
            (simple_diagnostic_path::add_event): Likewise.
            (simple_diagnostic_path::add_thread_event): Likewise.
            * dumpfile.cc (dump_pretty_printer::decode_format): Update for
            "m_" prefixes to text_info fields.
            (dump_context::dump_printf_va): Use text_info ctor.
            * graphviz.cc (graphviz_out::graphviz_out): Use text_info ctor.
            (graphviz_out::print): Likewise.
            * opt-problem.cc (opt_problem::opt_problem): Likewise.
            * pretty-print.cc (pp_format): Update for "m_" prefixes to
            text_info fields.
            (pp_printf): Use text_info ctor.
            (pp_verbatim): Likewise.
            (assert_pp_format_va): Likewise.
            * pretty-print.h (struct text_info): Add ctors.  Add "m_" prefix
            to all fields.
            * text-art/styled-string.cc (styled_string::from_fmt_va): Use
            text_info ctor.
            * tree-diagnostic.cc (default_tree_printer): Update for "m_"
            prefixes to text_info fields.
            * tree-pretty-print.h (pp_ti_abstract_origin): Likewise.
    
    gcc/fortran/ChangeLog:
            * error.cc (gfc_format_decoder): Update for "m_" prefixes to
            text_info fields.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/ada/gcc-interface/misc.cc      |  5 +--
 gcc/analyzer/analyzer-logging.cc   |  5 +--
 gcc/analyzer/analyzer.cc           | 15 ++-------
 gcc/analyzer/pending-diagnostic.cc |  7 +----
 gcc/c/c-objc-common.cc             |  4 +--
 gcc/cp/error.cc                    |  8 ++---
 gcc/d/d-diagnostic.cc              |  6 +---
 gcc/diagnostic.cc                  | 33 ++++++--------------
 gcc/dumpfile.cc                    | 13 +++-----
 gcc/fortran/error.cc               |  2 +-
 gcc/graphviz.cc                    | 10 ++----
 gcc/opt-problem.cc                 |  6 ++--
 gcc/pretty-print.cc                | 63 ++++++++++++++++----------------------
 gcc/pretty-print.h                 | 24 ++++++++++++---
 gcc/text-art/styled-string.cc      |  5 +--
 gcc/tree-diagnostic.cc             |  6 ++--
 gcc/tree-pretty-print.h            |  2 +-
 17 files changed, 81 insertions(+), 133 deletions(-)

diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index 269c15e4b0d..453ae8087a6 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -293,7 +293,6 @@ static void
 internal_error_function (diagnostic_context *context, const char *msgid,
 			 va_list *ap)
 {
-  text_info tinfo;
   char *buffer, *p, *loc;
   String_Template temp, temp_loc;
   String_Pointer sp, sp_loc;
@@ -309,9 +308,7 @@ internal_error_function (diagnostic_context *context, const char *msgid,
   pp_clear_output_area (context->printer);
 
   /* Format the message into the pretty-printer.  */
-  tinfo.format_spec = msgid;
-  tinfo.args_ptr = ap;
-  tinfo.err_no = errno;
+  text_info tinfo (msgid, ap, errno);
   pp_format_verbatim (context->printer, &tinfo);
 
   /* Extract a (writable) pointer to the formatted text.  */
diff --git a/gcc/analyzer/analyzer-logging.cc b/gcc/analyzer/analyzer-logging.cc
index b78481c4098..ddfbb5b4c04 100644
--- a/gcc/analyzer/analyzer-logging.cc
+++ b/gcc/analyzer/analyzer-logging.cc
@@ -144,10 +144,7 @@ logger::log_partial (const char *fmt, ...)
 void
 logger::log_va_partial (const char *fmt, va_list *ap)
 {
-  text_info text;
-  text.format_spec = fmt;
-  text.args_ptr = ap;
-  text.err_no = 0;
+  text_info text (fmt, ap, 0);
   pp_format (m_pp, &text);
   pp_output_formatted_text (m_pp);
 }
diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc
index 94c5cf242b2..9d4bc788f31 100644
--- a/gcc/analyzer/analyzer.cc
+++ b/gcc/analyzer/analyzer.cc
@@ -425,19 +425,13 @@ make_label_text (bool can_colorize, const char *fmt, ...)
   if (!can_colorize)
     pp_show_color (pp) = false;
 
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
   va_list ap;
 
   va_start (ap, fmt);
 
-  ti.format_spec = _(fmt);
-  ti.args_ptr = &ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
-
+  text_info ti (_(fmt), &ap, 0, NULL, &rich_loc);
   pp_format (pp, &ti);
   pp_output_formatted_text (pp);
 
@@ -461,7 +455,6 @@ make_label_text_n (bool can_colorize, unsigned HOST_WIDE_INT n,
   if (!can_colorize)
     pp_show_color (pp) = false;
 
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
   va_list ap;
@@ -470,11 +463,7 @@ make_label_text_n (bool can_colorize, unsigned HOST_WIDE_INT n,
 
   const char *fmt = ngettext (singular_fmt, plural_fmt, n);
 
-  ti.format_spec = fmt;
-  ti.args_ptr = &ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
+  text_info ti (fmt, &ap, 0, NULL, &rich_loc);
 
   pp_format (pp, &ti);
   pp_output_formatted_text (pp);
diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc
index e36ed4fd9c1..c7d337033f1 100644
--- a/gcc/analyzer/pending-diagnostic.cc
+++ b/gcc/analyzer/pending-diagnostic.cc
@@ -96,15 +96,10 @@ evdesc::event_desc::formatted_print (const char *fmt, ...) const
 
   pp_show_color (pp) = m_colorize;
 
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
   va_list ap;
   va_start (ap, fmt);
-  ti.format_spec = _(fmt);
-  ti.args_ptr = &ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
+  text_info ti (_(fmt), &ap, 0, nullptr, &rich_loc);
   pp_format (pp, &ti);
   pp_output_formatted_text (pp);
   va_end (ap);
diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc
index e4aed61ed00..c8f49aa2370 100644
--- a/gcc/c/c-objc-common.cc
+++ b/gcc/c/c-objc-common.cc
@@ -272,7 +272,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
 
   if (*spec != 'v')
     {
-      t = va_arg (*text->args_ptr, tree);
+      t = va_arg (*text->m_args_ptr, tree);
       if (set_locus)
 	text->set_location (0, DECL_SOURCE_LOCATION (t),
 			    SHOW_RANGE_WITH_CARET);
@@ -316,7 +316,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
       return true;
 
     case 'v':
-      pp_c_cv_qualifiers (cpp, va_arg (*text->args_ptr, int), hash);
+      pp_c_cv_qualifiers (cpp, va_arg (*text->m_args_ptr, int), hash);
       return true;
 
     default:
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 8a5219a68a1..ef96e140f24 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -4454,10 +4454,10 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
 
   const char *result;
   tree t = NULL;
-#define next_tree    (t = va_arg (*text->args_ptr, tree))
-#define next_tcode   ((enum tree_code) va_arg (*text->args_ptr, int))
-#define next_lang    ((enum languages) va_arg (*text->args_ptr, int))
-#define next_int     va_arg (*text->args_ptr, int)
+#define next_tree    (t = va_arg (*text->m_args_ptr, tree))
+#define next_tcode   ((enum tree_code) va_arg (*text->m_args_ptr, int))
+#define next_lang    ((enum languages) va_arg (*text->m_args_ptr, int))
+#define next_int     va_arg (*text->m_args_ptr, int)
 
   if (precision != 0 || wide)
     return false;
diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index 57f36f2f8dd..be779d93297 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -205,11 +205,7 @@ d_diagnostic_report_diagnostic (const Loc &loc, int opt, const char *format,
   else
     {
       /* Write verbatim messages with no location direct to stream.  */
-      text_info text;
-      text.err_no = errno;
-      text.args_ptr = &argp;
-      text.format_spec = expand_d_format (format);
-      text.x_data = NULL;
+      text_info text (expand_d_format (format), &argp, errno, nullptr);
 
       pp_format_verbatim (global_dc->printer, &text);
       pp_newline_and_flush (global_dc->printer);
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 65a78840a66..9c15f0d8c50 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -348,9 +348,9 @@ diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
 				diagnostic_t kind)
 {
   gcc_assert (richloc);
-  diagnostic->message.err_no = errno;
-  diagnostic->message.args_ptr = args;
-  diagnostic->message.format_spec = msg;
+  diagnostic->message.m_err_no = errno;
+  diagnostic->message.m_args_ptr = args;
+  diagnostic->message.m_format_spec = msg;
   diagnostic->message.m_richloc = richloc;
   diagnostic->richloc = richloc;
   diagnostic->metadata = NULL;
@@ -1529,7 +1529,7 @@ diagnostic_report_diagnostic (diagnostic_context *context,
       && diagnostic->kind == DK_WARNING)
     diagnostic->kind = DK_ERROR;
 
-  diagnostic->message.x_data = &diagnostic->x_data;
+  diagnostic->message.m_data = &diagnostic->x_data;
 
   /* Check to see if the diagnostic is enabled at the location and
      not disabled by #pragma GCC diagnostic anywhere along the inlining
@@ -1565,8 +1565,8 @@ diagnostic_report_diagnostic (diagnostic_context *context,
 	}
       if (context->internal_error)
 	(*context->internal_error) (context,
-				    diagnostic->message.format_spec,
-				    diagnostic->message.args_ptr);
+				    diagnostic->message.m_format_spec,
+				    diagnostic->message.m_args_ptr);
     }
   if (diagnostic->kind == DK_ERROR && orig_diag_kind == DK_WARNING)
     ++diagnostic_kind_count (context, DK_WERROR);
@@ -1678,14 +1678,10 @@ trim_filename (const char *name)
 void
 verbatim (const char *gmsgid, ...)
 {
-  text_info text;
   va_list ap;
 
   va_start (ap, gmsgid);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = _(gmsgid);
-  text.x_data = NULL;
+  text_info text (_(gmsgid), &ap, errno);
   pp_format_verbatim (global_dc->printer, &text);
   pp_newline_and_flush (global_dc->printer);
   va_end (ap);
@@ -2470,19 +2466,13 @@ simple_diagnostic_path::add_event (location_t loc, tree fndecl, int depth,
   pretty_printer *pp = m_event_pp;
   pp_clear_output_area (pp);
 
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
   va_list ap;
 
   va_start (ap, fmt);
 
-  ti.format_spec = _(fmt);
-  ti.args_ptr = &ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
-
+  text_info ti (_(fmt), &ap, 0, nullptr, &rich_loc);
   pp_format (pp, &ti);
   pp_output_formatted_text (pp);
 
@@ -2507,18 +2497,13 @@ simple_diagnostic_path::add_thread_event (diagnostic_thread_id_t thread_id,
   pretty_printer *pp = m_event_pp;
   pp_clear_output_area (pp);
 
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
   va_list ap;
 
   va_start (ap, fmt);
 
-  ti.format_spec = _(fmt);
-  ti.args_ptr = &ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
+  text_info ti (_(fmt), &ap, 0, nullptr, &rich_loc);
 
   pp_format (pp, &ti);
   pp_output_formatted_text (pp);
diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc
index a2050d13009..1e72aaf70f2 100644
--- a/gcc/dumpfile.cc
+++ b/gcc/dumpfile.cc
@@ -951,7 +951,7 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
     {
     case 'C':
       {
-	cgraph_node *node = va_arg (*text->args_ptr, cgraph_node *);
+	cgraph_node *node = va_arg (*text->m_args_ptr, cgraph_node *);
 
 	/* Make an item for the node, and stash it.  */
 	optinfo_item *item = make_item_for_dump_symtab_node (node);
@@ -961,7 +961,7 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
 
     case 'E':
       {
-	gimple *stmt = va_arg (*text->args_ptr, gimple *);
+	gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
 
 	/* Make an item for the stmt, and stash it.  */
 	optinfo_item *item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
@@ -971,7 +971,7 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
 
     case 'G':
       {
-	gimple *stmt = va_arg (*text->args_ptr, gimple *);
+	gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
 
 	/* Make an item for the stmt, and stash it.  */
 	optinfo_item *item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
@@ -981,7 +981,7 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
 
     case 'T':
       {
-	tree t = va_arg (*text->args_ptr, tree);
+	tree t = va_arg (*text->m_args_ptr, tree);
 
 	/* Make an item for the tree, and stash it.  */
 	optinfo_item *item = make_item_for_dump_generic_expr (t, TDF_SLIM);
@@ -1002,10 +1002,7 @@ dump_context::dump_printf_va (const dump_metadata_t &metadata, const char *forma
 {
   dump_pretty_printer pp (this, metadata.get_dump_flags ());
 
-  text_info text;
-  text.err_no = errno;
-  text.args_ptr = ap;
-  text.format_spec = format;
+  text_info text (format, ap, errno);
 
   /* Phases 1 and 2, using pp_format.  */
   pp_format (&pp, &text);
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index 0b6c850e6d9..1b346192738 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -1074,7 +1074,7 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
 	if (*spec == 'C')
 	  loc = &gfc_current_locus;
 	else
-	  loc = va_arg (*text->args_ptr, locus *);
+	  loc = va_arg (*text->m_args_ptr, locus *);
 	gcc_assert (loc->nextc - loc->lb->line >= 0);
 	unsigned int offset = loc->nextc - loc->lb->line;
 	if (*spec == 'C' && *loc->nextc != '\0')
diff --git a/gcc/graphviz.cc b/gcc/graphviz.cc
index 177fc203d9c..ea7bb9d0480 100644
--- a/gcc/graphviz.cc
+++ b/gcc/graphviz.cc
@@ -36,13 +36,10 @@ graphviz_out::graphviz_out (pretty_printer *pp)
 void
 graphviz_out::print (const char *fmt, ...)
 {
-  text_info text;
   va_list ap;
 
   va_start (ap, fmt);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = fmt;
+  text_info text (fmt, &ap, errno);
   pp_format (m_pp, &text);
   pp_output_formatted_text (m_pp);
   va_end (ap);
@@ -54,15 +51,12 @@ graphviz_out::print (const char *fmt, ...)
 void
 graphviz_out::println (const char *fmt, ...)
 {
-  text_info text;
   va_list ap;
 
   write_indent ();
 
   va_start (ap, fmt);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = fmt;
+  text_info text (fmt, &ap, errno);
   pp_format (m_pp, &text);
   pp_output_formatted_text (m_pp);
   va_end (ap);
diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index 99172719205..ae85df3c9a3 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -62,10 +62,8 @@ opt_problem::opt_problem (const dump_location_t &loc,
   {
     dump_pretty_printer pp (&dump_context::get (), MSG_MISSED_OPTIMIZATION);
 
-    text_info text;
-    text.err_no = errno;
-    text.args_ptr = ap;
-    text.format_spec = fmt; /* No i18n is performed.  */
+    text_info text (fmt, /* No i18n is performed.  */
+		    ap, errno);
 
     /* Phases 1 and 2, using pp_format.  */
     pp_format (&pp, &text);
diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index ee01d895d61..75446cc73a1 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -1063,7 +1063,7 @@ static const char *get_end_url_string (pretty_printer *);
    A format string can have at most 30 arguments.  */
 
 /* Formatting phases 1 and 2: render TEXT->format_spec plus
-   TEXT->args_ptr into a series of chunks in pp_buffer (PP)->args[].
+   text->m_args_ptr into a series of chunks in pp_buffer (PP)->args[].
    Phase 3 is in pp_output_formatted_text.  */
 
 void
@@ -1093,7 +1093,7 @@ pp_format (pretty_printer *pp, text_info *text)
 
   memset (formatters, 0, sizeof formatters);
 
-  for (p = text->format_spec; *p; )
+  for (p = text->m_format_spec; *p; )
     {
       while (*p != '\0' && *p != '%')
 	{
@@ -1157,7 +1157,7 @@ pp_format (pretty_printer *pp, text_info *text)
 
 	case 'm':
 	  {
-	    const char *errstr = xstrerror (text->err_no);
+	    const char *errstr = xstrerror (text->m_err_no);
 	    obstack_grow (&buffer->chunk_obstack, errstr, strlen (errstr));
 	  }
 	  p++;
@@ -1316,7 +1316,7 @@ pp_format (pretty_printer *pp, text_info *text)
 	{
 	case 'r':
 	  pp_string (pp, colorize_start (pp_show_color (pp),
-					 va_arg (*text->args_ptr,
+					 va_arg (*text->m_args_ptr,
 						 const char *)));
 	  break;
 
@@ -1325,7 +1325,7 @@ pp_format (pretty_printer *pp, text_info *text)
 	    /* When quoting, print alphanumeric, punctuation, and the space
 	       character unchanged, and all others in hexadecimal with the
 	       "\x" prefix.  Otherwise print them all unchanged.  */
-	    int chr = va_arg (*text->args_ptr, int);
+	    int chr = va_arg (*text->m_args_ptr, int);
 	    if (ISPRINT (chr) || !quote)
 	      pp_character (pp, chr);
 	    else
@@ -1339,49 +1339,49 @@ pp_format (pretty_printer *pp, text_info *text)
 	case 'd':
 	case 'i':
 	  if (wide)
-	    pp_wide_integer (pp, va_arg (*text->args_ptr, HOST_WIDE_INT));
+	    pp_wide_integer (pp, va_arg (*text->m_args_ptr, HOST_WIDE_INT));
 	  else
 	    pp_integer_with_precision
-	      (pp, *text->args_ptr, precision, int, "d");
+	      (pp, *text->m_args_ptr, precision, int, "d");
 	  break;
 
 	case 'o':
 	  if (wide)
 	    pp_scalar (pp, "%" HOST_WIDE_INT_PRINT "o",
-		       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+		       va_arg (*text->m_args_ptr, unsigned HOST_WIDE_INT));
 	  else
 	    pp_integer_with_precision
-	      (pp, *text->args_ptr, precision, unsigned, "o");
+	      (pp, *text->m_args_ptr, precision, unsigned, "o");
 	  break;
 
 	case 's':
 	  if (quote)
-	    pp_quoted_string (pp, va_arg (*text->args_ptr, const char *));
+	    pp_quoted_string (pp, va_arg (*text->m_args_ptr, const char *));
 	  else
-	    pp_string (pp, va_arg (*text->args_ptr, const char *));
+	    pp_string (pp, va_arg (*text->m_args_ptr, const char *));
 	  break;
 
 	case 'p':
-	  pp_pointer (pp, va_arg (*text->args_ptr, void *));
+	  pp_pointer (pp, va_arg (*text->m_args_ptr, void *));
 	  break;
 
 	case 'u':
 	  if (wide)
 	    pp_scalar (pp, HOST_WIDE_INT_PRINT_UNSIGNED,
-		       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+		       va_arg (*text->m_args_ptr, unsigned HOST_WIDE_INT));
 	  else
 	    pp_integer_with_precision
-	      (pp, *text->args_ptr, precision, unsigned, "u");
+	      (pp, *text->m_args_ptr, precision, unsigned, "u");
 	  break;
 
 	case 'f':
-	  pp_double (pp, va_arg (*text->args_ptr, double));
+	  pp_double (pp, va_arg (*text->m_args_ptr, double));
 	  break;
 
 	case 'Z':
 	  {
-	    int *v = va_arg (*text->args_ptr, int *);
-	    unsigned len = va_arg (*text->args_ptr, unsigned); 
+	    int *v = va_arg (*text->m_args_ptr, int *);
+	    unsigned len = va_arg (*text->m_args_ptr, unsigned);
 
 	    for (unsigned i = 0; i < len; ++i)
 	      {
@@ -1398,10 +1398,10 @@ pp_format (pretty_printer *pp, text_info *text)
 	case 'x':
 	  if (wide)
 	    pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
-		       va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
+		       va_arg (*text->m_args_ptr, unsigned HOST_WIDE_INT));
 	  else
 	    pp_integer_with_precision
-	      (pp, *text->args_ptr, precision, unsigned, "x");
+	      (pp, *text->m_args_ptr, precision, unsigned, "x");
 	  break;
 
 	case '.':
@@ -1425,14 +1425,14 @@ pp_format (pretty_printer *pp, text_info *text)
 		gcc_assert (*p == '*');
 		p++;
 		gcc_assert (*p == 's');
-		n = va_arg (*text->args_ptr, int);
+		n = va_arg (*text->m_args_ptr, int);
 
 		/* This consumes a second entry in the formatters array.  */
 		gcc_assert (formatters[argno] == formatters[argno+1]);
 		argno++;
 	      }
 
-	    s = va_arg (*text->args_ptr, const char *);
+	    s = va_arg (*text->m_args_ptr, const char *);
 
 	    /* Append the lesser of precision and strlen (s) characters
 	       from the array (which need not be a nul-terminated string).
@@ -1447,7 +1447,7 @@ pp_format (pretty_printer *pp, text_info *text)
 	  {
 	    /* diagnostic_event_id_t *.  */
 	    diagnostic_event_id_ptr event_id
-	      = va_arg (*text->args_ptr, diagnostic_event_id_ptr);
+	      = va_arg (*text->m_args_ptr, diagnostic_event_id_ptr);
 	    gcc_assert (event_id->known_p ());
 
 	    pp_string (pp, colorize_start (pp_show_color (pp), "path"));
@@ -1459,7 +1459,7 @@ pp_format (pretty_printer *pp, text_info *text)
 	  break;
 
 	case '{':
-	  pp_begin_url (pp, va_arg (*text->args_ptr, const char *));
+	  pp_begin_url (pp, va_arg (*text->m_args_ptr, const char *));
 	  break;
 
 	default:
@@ -1763,13 +1763,10 @@ pp_remaining_character_count_for_line (pretty_printer *pp)
 void
 pp_printf (pretty_printer *pp, const char *msg, ...)
 {
-  text_info text;
   va_list ap;
 
   va_start (ap, msg);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = msg;
+  text_info text (msg, &ap, errno);
   pp_format (pp, &text);
   pp_output_formatted_text (pp);
   va_end (ap);
@@ -1780,13 +1777,10 @@ pp_printf (pretty_printer *pp, const char *msg, ...)
 void
 pp_verbatim (pretty_printer *pp, const char *msg, ...)
 {
-  text_info text;
   va_list ap;
 
   va_start (ap, msg);
-  text.err_no = errno;
-  text.args_ptr = &ap;
-  text.format_spec = msg;
+  text_info text (msg, &ap, errno);
   pp_format_verbatim (pp, &text);
   va_end (ap);
 }
@@ -2290,14 +2284,9 @@ assert_pp_format_va (const location &loc, const char *expected,
 		     bool show_color, const char *fmt, va_list *ap)
 {
   pretty_printer pp;
-  text_info ti;
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
-  ti.format_spec = fmt;
-  ti.args_ptr = ap;
-  ti.err_no = 0;
-  ti.x_data = NULL;
-  ti.m_richloc = &rich_loc;
+  text_info ti (fmt, ap, 0, nullptr, &rich_loc);
 
   pp_show_color (&pp) = show_color;
   pp_format (&pp, &ti);
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index 8ba4296578b..ad6d659175d 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -31,15 +31,29 @@ along with GCC; see the file COPYING3.  If not see
    along with a list of things.  */
 struct text_info
 {
-  const char *format_spec;
-  va_list *args_ptr;
-  int err_no;  /* for %m */
-  void **x_data;
-  rich_location *m_richloc;
+  text_info () = default;
+  text_info (const char *format_spec,
+	     va_list *args_ptr,
+	     int err_no,
+	     void **data = nullptr,
+	     rich_location *rich_loc = nullptr)
+  : m_format_spec (format_spec),
+    m_args_ptr (args_ptr),
+    m_err_no (err_no),
+    m_data (data),
+    m_richloc (rich_loc)
+  {
+  }
 
   void set_location (unsigned int idx, location_t loc,
 		     enum range_display_kind range_display_kind);
   location_t get_location (unsigned int index_of_location) const;
+
+  const char *m_format_spec;
+  va_list *m_args_ptr;
+  int m_err_no;  /* for %m */
+  void **m_data;
+  rich_location *m_richloc;
 };
 
 /* How often diagnostics are prefixed by their locations:
diff --git a/gcc/text-art/styled-string.cc b/gcc/text-art/styled-string.cc
index a0cc187c8cb..1a66a152ab5 100644
--- a/gcc/text-art/styled-string.cc
+++ b/gcc/text-art/styled-string.cc
@@ -563,10 +563,7 @@ styled_string::from_fmt_va (style_manager &sm,
 			    const char *fmt,
 			    va_list *args)
 {
-  text_info text;
-  text.err_no = errno;
-  text.args_ptr = args;
-  text.format_spec = fmt;
+  text_info text (fmt, args, errno);
   pretty_printer pp;
   pp_show_color (&pp) = true;
   pp.url_format = URL_FORMAT_DEFAULT;
diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc
index d2f6637b6d9..a600f0e9f64 100644
--- a/gcc/tree-diagnostic.cc
+++ b/gcc/tree-diagnostic.cc
@@ -261,7 +261,7 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
   switch (*spec)
     {
     case 'E':
-      t = va_arg (*text->args_ptr, tree);
+      t = va_arg (*text->m_args_ptr, tree);
       if (TREE_CODE (t) == IDENTIFIER_NODE)
 	{
 	  pp_identifier (pp, IDENTIFIER_POINTER (t));
@@ -270,14 +270,14 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
       break;
 
     case 'D':
-      t = va_arg (*text->args_ptr, tree);
+      t = va_arg (*text->m_args_ptr, tree);
       if (VAR_P (t) && DECL_HAS_DEBUG_EXPR_P (t))
 	t = DECL_DEBUG_EXPR (t);
       break;
 
     case 'F':
     case 'T':
-      t = va_arg (*text->args_ptr, tree);
+      t = va_arg (*text->m_args_ptr, tree);
       break;
 
     default:
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index 2c8ee9aa377..12bae053e5a 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3.  If not see
   pp_verbatim (PP, "%qs not supported by %s", \
 	       get_tree_code_name (TREE_CODE (T)), __FUNCTION__)
 
-#define pp_ti_abstract_origin(TI) ((tree *) (TI)->x_data)
+#define pp_ti_abstract_origin(TI) ((tree *) (TI)->m_data)
 
 
 extern void debug_generic_expr (tree);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-03 13:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03 13:42 [gcc r14-4379] diagnostics: add ctors to text_info; add m_ prefixes to fields 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).