From 2cc31e2fd5cae3c87ee47acfe66d4cbaf29699b7 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 19 Jun 2019 16:22:20 -0400
Subject: [PATCH 016/108] FIXME: introduce pretty_printer::clone vfunc

---
 gcc/c-family/c-pretty-print.c |  7 +++++++
 gcc/c-family/c-pretty-print.h |  1 +
 gcc/cp/cxx-pretty-print.c     |  8 ++++++++
 gcc/cp/cxx-pretty-print.h     |  2 ++
 gcc/cp/error.c                |  5 +++++
 gcc/pretty-print.c            | 32 ++++++++++++++++++++++++++++++++
 gcc/pretty-print.h            |  4 ++++
 7 files changed, 59 insertions(+)

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 46db469..909562d 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -2358,6 +2358,13 @@ c_pretty_printer::c_pretty_printer ()
   parameter_list            = pp_c_parameter_type_list;
 }
 
+/* FIXME.  */
+
+pretty_printer *
+c_pretty_printer::clone () const
+{
+  return new c_pretty_printer (*this);
+}
 
 /* Print the tree T in full, on file FILE.  */
 
diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h
index 6084dcf..1100b76 100644
--- a/gcc/c-family/c-pretty-print.h
+++ b/gcc/c-family/c-pretty-print.h
@@ -50,6 +50,7 @@ typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree);
 struct c_pretty_printer : pretty_printer
 {
   c_pretty_printer ();
+  pretty_printer *clone () const OVERRIDE;
 
   // Format string, possibly translated.
   void translate_string (const char *);
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index 47eebd1..26fa9e1 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -3030,3 +3030,11 @@ cxx_pretty_printer::cxx_pretty_printer ()
   type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
   parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
 }
+
+/* FIXME.  */
+
+pretty_printer *
+cxx_pretty_printer::clone () const
+{
+  return new cxx_pretty_printer (*this);
+}
diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h
index aba3e84..742ac4a 100644
--- a/gcc/cp/cxx-pretty-print.h
+++ b/gcc/cp/cxx-pretty-print.h
@@ -33,6 +33,8 @@ struct cxx_pretty_printer : c_pretty_printer
 {
   cxx_pretty_printer ();
 
+  pretty_printer *clone () const OVERRIDE;
+
   void constant (tree);
   void id_expression (tree);
   void primary_expression (tree);
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 9d05b43..b868c99 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -141,6 +141,11 @@ class cxx_format_postprocessor : public format_postprocessor
   : m_type_a (), m_type_b ()
   {}
 
+  format_postprocessor *clone() const FINAL OVERRIDE
+  {
+    return new cxx_format_postprocessor ();
+  }
+
   void handle (pretty_printer *pp) FINAL OVERRIDE;
 
   deferred_printed_type m_type_a;
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index a2d6f04..686e7a5 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -1588,6 +1588,30 @@ pretty_printer::pretty_printer (int maximum_length)
   pp_set_prefix (this, NULL);
 }
 
+pretty_printer::pretty_printer (const pretty_printer &other)
+: buffer (new (XCNEW (output_buffer)) output_buffer ()),
+  prefix (),
+  padding (other.padding),
+  maximum_length (other.maximum_length),
+  indent_skip (other.indent_skip),
+  wrapping (other.wrapping),
+  format_decoder (other.format_decoder),
+  m_format_postprocessor (NULL),
+  emitted_prefix (other.emitted_prefix),
+  need_newline (other.need_newline),
+  translate_identifiers (other.translate_identifiers),
+  show_color (other.show_color),
+  show_urls (other.show_urls)
+{
+  pp_line_cutoff (this) = maximum_length;
+  /* By default, we emit prefixes once per message.  */
+  pp_prefixing_rule (this) = pp_prefixing_rule (&other);
+  pp_set_prefix (this, NULL);
+
+  if (other.m_format_postprocessor)
+    m_format_postprocessor = other.m_format_postprocessor->clone ();
+}
+
 pretty_printer::~pretty_printer ()
 {
   if (m_format_postprocessor)
@@ -1597,6 +1621,14 @@ pretty_printer::~pretty_printer ()
   free (prefix);
 }
 
+/* FIXME.  */
+
+pretty_printer *
+pretty_printer::clone () const
+{
+  return new pretty_printer (*this);
+}
+
 /* Append a string delimited by START and END to the output area of
    PRETTY-PRINTER.  No line wrapping is done.  However, if beginning a
    new line then emit PRETTY-PRINTER's prefix and skip any leading
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index 07cd391..9a8b81a 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -191,6 +191,7 @@ class format_postprocessor
 {
  public:
   virtual ~format_postprocessor () {}
+  virtual format_postprocessor *clone() const = 0;
   virtual void handle (pretty_printer *) = 0;
 };
 
@@ -219,9 +220,12 @@ struct pretty_printer
   /* Default construct a pretty printer with specified
      maximum line length cut off limit.  */
   explicit pretty_printer (int = 0);
+  explicit pretty_printer (const pretty_printer &other);
 
   virtual ~pretty_printer ();
 
+  virtual pretty_printer *clone () const;
+
   /* Where we print external representation of ENTITY.  */
   output_buffer *buffer;
 
-- 
1.8.5.3

