Various places use
  xp.add_text (pp_formatted_text (&pp))
Add a helper function for this.
No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r16-1405-g896edb1d0ae90f.

gcc/ChangeLog:
        * diagnostic-path-output.cc: Use xml::printer::add_text_from_pp.
        * diagnostic-show-locus.cc: Likewise.
        * xml-printer.h (xml::printer::add_text_from_pp): New decl.
        * xml.cc (xml::node_with_children::add_text_from_pp): New.
        (xml::printer::add_text_from_pp): New.
        * xml.h (xml::node_with_children::add_text_from_pp): New decl.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/diagnostic-path-output.cc |  6 +++---
 gcc/diagnostic-show-locus.cc  |  2 +-
 gcc/xml-printer.h             |  1 +
 gcc/xml.cc                    | 12 ++++++++++++
 gcc/xml.h                     |  1 +
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/gcc/diagnostic-path-output.cc b/gcc/diagnostic-path-output.cc
index 199028ea7f3a..bae24bf01a70 100644
--- a/gcc/diagnostic-path-output.cc
+++ b/gcc/diagnostic-path-output.cc
@@ -689,7 +689,7 @@ struct event_range
            iter_event.print_desc (pp);
            if (event_label_writer)
              event_label_writer->begin_label ();
-           xp.add_text (pp_formatted_text (&pp));
+           xp.add_text_from_pp (pp);
            if (event_label_writer)
              event_label_writer->end_label ();
          }
@@ -1243,7 +1243,7 @@ print_path_summary_as_html (const path_summary &ps,
        else
          pp_printf (&pp, "events %i-%i",
                     range->m_start_idx + 1, range->m_end_idx + 1);
-       xp.add_text (pp_formatted_text (&pp));
+       xp.add_text_from_pp (pp);
        xp.pop_tag ("span");
       }
       if (show_depths)
@@ -1252,7 +1252,7 @@ print_path_summary_as_html (const path_summary &ps,
          xp.push_tag_with_class ("span", "depth", true);
          pretty_printer pp;
          pp_printf (&pp, "(depth %i)", range->m_stack_depth);
-         xp.add_text (pp_formatted_text (&pp));
+         xp.add_text_from_pp (pp);
          xp.pop_tag ("span");
        }
       xp.pop_tag ("div");
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index 575c7ec8d709..ffb72da138d9 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -614,7 +614,7 @@ struct to_html
   {
     pp_clear_output_area (&m_scratch_pp);
     pp_unicode_character (&m_scratch_pp, ch);
-    m_xp.add_text (pp_formatted_text (&m_scratch_pp));
+    m_xp.add_text_from_pp (m_scratch_pp);
   }
 
   void add_utf8_byte (char b)
diff --git a/gcc/xml-printer.h b/gcc/xml-printer.h
index 24ac2f42e735..428da0a4245d 100644
--- a/gcc/xml-printer.h
+++ b/gcc/xml-printer.h
@@ -44,6 +44,7 @@ public:
   void set_attr (const char *name, std::string value);
 
   void add_text (std::string text);
+  void add_text_from_pp (pretty_printer &pp);
 
   void add_raw (std::string text);
 
diff --git a/gcc/xml.cc b/gcc/xml.cc
index 0a925619f5d3..9077c1ab1300 100644
--- a/gcc/xml.cc
+++ b/gcc/xml.cc
@@ -121,6 +121,11 @@ node_with_children::add_text (std::string str)
   add_child (std::make_unique <text> (std::move (str)));
 }
 
+void
+node_with_children::add_text_from_pp (pretty_printer &pp)
+{
+  add_text (pp_formatted_text (&pp));
+}
 
 /* struct document : public node_with_children.  */
 
@@ -251,6 +256,13 @@ printer::add_text (std::string text)
   parent->add_text (std::move (text));
 }
 
+void
+printer::add_text_from_pp (pretty_printer &pp)
+{
+  element *parent = m_open_tags.back ();
+  parent->add_text_from_pp (pp);
+}
+
 void
 printer::add_raw (std::string text)
 {
diff --git a/gcc/xml.h b/gcc/xml.h
index 3c5813a22862..952cfa4376b0 100644
--- a/gcc/xml.h
+++ b/gcc/xml.h
@@ -65,6 +65,7 @@ struct node_with_children : public node
 {
   void add_child (std::unique_ptr<node> node);
   void add_text (std::string str);
+  void add_text_from_pp (pretty_printer &pp);
 
   std::vector<std::unique_ptr<node>> m_children;
 };
-- 
2.26.3

Reply via email to