]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pretty-print.h (output_buffer::output_buffer): Declare.
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Thu, 22 Aug 2013 10:14:46 +0000 (10:14 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Thu, 22 Aug 2013 10:14:46 +0000 (10:14 +0000)
* pretty-print.h (output_buffer::output_buffer): Declare.
(pretty_printer::pretty_printer): Likewise.
(pp_construct): Remove.
* pretty-print.c (output_buffer::output_buffer): Define.
(pretty_printer::pretty_printer): Rename from pp_construct.  Simplify.
* gimple-pretty-print.c (print_gimple_stmt): Do not call pp_construct.
(print_gimple_expr): Likewise.
(print_gimple_seq): Likewise.
(gimple_dump_bb): Likewise.
* sched-vis.c (dump_value_slim): Likewise.
(dump_insn_slim): Likewise.
(dump_rtl_slim): Likewise.
(str_pattern_slim): Likewise.
* tree-mudflap.c (mf_varname_tree): Likewise.
* graph.c (print_graph_cfg): Likewise.
(start_graph_dump): Likewise.
* tree-pretty-print.c (maybe_init_pretty_print): Likewise.  Use
placement-new.
* diagnostic.c (diagnostic_initialize): Simplify early diagnostic
pretty printer initialization.
* coretypes.h (diagnostic_context): Remove superflous type alias
declaration.
(pretty_printer): Likewise.  Declare directly as a class.
(pretty_print_info): Remove declaration as class.
* asan.c (asan_emit_stack_protection): Remove call to pp_construct
and pp_clear_output_area.
(asan_add_global): Likewise.

c/
* c-objc-common.c (c_initialize_diagnostics): Simplify C pretty
printer initialization.

c-family/
* c-pretty-print.h (pp_c_pretty_printer_init): Remove.
(c_pretty_printer::c_pretty_printer): Declare.
* c-pretty-print.c (pretty_printer::c_pretty_printer): Rename from
c_pretty_printer_init.  Adjust.
(print_c_tree): Do not call c_pretty_printer_init.
* c-ada-spec.c (dump_ads): Remove call to pp_construct.

cp/
* error.c (init_error): Remove calls to pp_construct and
pp_cxx_pretty_printer_init.  Initialize cxx_pp with placement-new.
* cxx-pretty-print.h (cxx_pretty_printer::cxx_pretty_printer): Declare.
(cxx_pretty_printer_init): Remove.
* cxx-pretty-print.c (cxx_pretty_printer::cxx_pretty_printer):
Rename from cxx_pretty_printer_init.  Adjust.
* cp-objcp-common.c (cxx_initialize_diagnostics): Simplify
initialization of C++ diagnostics pretty printer.

From-SVN: r201918

22 files changed:
gcc/ChangeLog
gcc/asan.c
gcc/c-family/ChangeLog
gcc/c-family/c-ada-spec.c
gcc/c-family/c-pretty-print.c
gcc/c-family/c-pretty-print.h
gcc/c/ChangeLog
gcc/c/c-objc-common.c
gcc/coretypes.h
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/cp/cxx-pretty-print.c
gcc/cp/cxx-pretty-print.h
gcc/cp/error.c
gcc/diagnostic.c
gcc/gimple-pretty-print.c
gcc/graph.c
gcc/pretty-print.c
gcc/pretty-print.h
gcc/sched-vis.c
gcc/tree-mudflap.c
gcc/tree-pretty-print.c

index c38417cf980daafbf20756c065c55013e09e544f..e65e9ce19c7847434878cf449babb33cf0dbe74e 100644 (file)
@@ -1,3 +1,33 @@
+2013-08-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       * pretty-print.h (output_buffer::output_buffer): Declare.
+       (pretty_printer::pretty_printer): Likewise.
+       (pp_construct): Remove.
+       * pretty-print.c (output_buffer::output_buffer): Define.
+       (pretty_printer::pretty_printer): Rename from pp_construct.  Simplify.
+       * gimple-pretty-print.c (print_gimple_stmt): Do not call pp_construct.
+       (print_gimple_expr): Likewise.
+       (print_gimple_seq): Likewise.
+       (gimple_dump_bb): Likewise.
+       * sched-vis.c (dump_value_slim): Likewise.
+       (dump_insn_slim): Likewise.
+       (dump_rtl_slim): Likewise.
+       (str_pattern_slim): Likewise.
+       * tree-mudflap.c (mf_varname_tree): Likewise.
+       * graph.c (print_graph_cfg): Likewise.
+       (start_graph_dump): Likewise.
+       * tree-pretty-print.c (maybe_init_pretty_print): Likewise.  Use
+       placement-new.
+       * diagnostic.c (diagnostic_initialize): Simplify early diagnostic
+       pretty printer initialization.
+       * coretypes.h (diagnostic_context): Remove superflous type alias
+       declaration.
+       (pretty_printer): Likewise.  Declare directly as a class.
+       (pretty_print_info): Remove declaration as class.
+       * asan.c (asan_emit_stack_protection): Remove call to pp_construct
+       and pp_clear_output_area.
+       (asan_add_global): Likewise.
+
 2013-08-22  Jan Hubicka  <jh@suse.cz>
 
        * cgraphunit.c (analyze_functions) Use update_type_inheritance_graph.
index 1756b07805fd5b6e34a80d5b79c0d201b47f277f..81118a7cb4c027e329f86087294ba92901a1faee 100644 (file)
@@ -938,9 +938,7 @@ asan_emit_stack_protection (rtx base, HOST_WIDE_INT *offsets, tree *decls,
 
   /* First of all, prepare the description string.  */
   pretty_printer asan_pp;
-  pp_construct (&asan_pp, /* prefix */NULL, /* line-width */0);
-  
-  pp_clear_output_area (&asan_pp);
+
   if (DECL_NAME (current_function_decl))
     pp_tree_identifier (&asan_pp, DECL_NAME (current_function_decl));
   else
@@ -1963,9 +1961,7 @@ asan_add_global (tree decl, tree type, vec<constructor_elt, va_gc> *v)
   vec<constructor_elt, va_gc> *vinner = NULL;
 
   pretty_printer asan_pp;
-  pp_construct (&asan_pp, /* prefix */NULL, /* line-width */0);
 
-  pp_clear_output_area (&asan_pp);
   if (DECL_NAME (decl))
     pp_tree_identifier (&asan_pp, DECL_NAME (decl));
   else
index 1e053bd6f5170b4d6fcf09c451fb90a66b1eff86..513a927d6989f18bbedec2417ee88c6ab8c261aa 100644 (file)
@@ -1,3 +1,12 @@
+2013-08-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       * c-pretty-print.h (pp_c_pretty_printer_init): Remove.
+       (c_pretty_printer::c_pretty_printer): Declare.
+       * c-pretty-print.c (pretty_printer::c_pretty_printer): Rename from
+       c_pretty_printer_init.  Adjust.
+       (print_c_tree): Do not call c_pretty_printer_init.
+       * c-ada-spec.c (dump_ads): Remove call to pp_construct.
+
 2013-08-09  Arnaud Charlet  <charlet@adacore.com>
 
        * c-ada-spec.c (print_ada_declaration): Prevent accessing null asm name
index 22784c93ec9f681e76c9885c6b92f391c2066576..eac57838752da24c7e830f842b2f7da97e8cd746 100644 (file)
@@ -3304,7 +3304,6 @@ dump_ads (const char *source_file,
     {
       pretty_printer pp;
 
-      pp_construct (&pp, NULL, 0);
       pp_needs_newline (&pp) = true;
       pp.buffer->stream = f;
 
index fed58021cd8b6cf0781ce3d75ac35131d4ad0244..253dfd13ff668086c1875ed799fd5df6289f6d3e 100644 (file)
@@ -2318,39 +2318,37 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
 \f
 /* Initialize the PRETTY-PRINTER for handling C codes.  */
 
-void
-pp_c_pretty_printer_init (c_pretty_printer *pp)
-{
-  pp->offset_list               = 0;
-
-  pp->flags                    = 0;
-
-  pp->declaration               = pp_c_declaration;
-  pp->declaration_specifiers    = pp_c_declaration_specifiers;
-  pp->declarator                = pp_c_declarator;
-  pp->direct_declarator         = pp_c_direct_declarator;
-  pp->type_specifier_seq        = pp_c_specifier_qualifier_list;
-  pp->abstract_declarator       = pp_c_abstract_declarator;
-  pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
-  pp->ptr_operator              = pp_c_pointer;
-  pp->parameter_list            = pp_c_parameter_type_list;
-  pp->type_id                   = pp_c_type_id;
-  pp->simple_type_specifier     = pp_c_type_specifier;
-  pp->function_specifier        = pp_c_function_specifier;
-  pp->storage_class_specifier   = pp_c_storage_class_specifier;
-
-  pp->statement                 = pp_c_statement;
-
-  pp->constant                  = pp_c_constant;
-  pp->id_expression             = pp_c_id_expression;
-  pp->primary_expression        = pp_c_primary_expression;
-  pp->postfix_expression        = pp_c_postfix_expression;
-  pp->unary_expression          = pp_c_unary_expression;
-  pp->initializer               = pp_c_initializer;
-  pp->multiplicative_expression = pp_c_multiplicative_expression;
-  pp->conditional_expression    = pp_c_conditional_expression;
-  pp->assignment_expression     = pp_c_assignment_expression;
-  pp->expression                = pp_c_expression;
+c_pretty_printer::c_pretty_printer ()
+  : pretty_printer ()
+{
+  offset_list               = 0;
+  flags                        = 0;
+  declaration               = pp_c_declaration;
+  declaration_specifiers    = pp_c_declaration_specifiers;
+  declarator                = pp_c_declarator;
+  direct_declarator         = pp_c_direct_declarator;
+  type_specifier_seq        = pp_c_specifier_qualifier_list;
+  abstract_declarator       = pp_c_abstract_declarator;
+  direct_abstract_declarator = pp_c_direct_abstract_declarator;
+  ptr_operator              = pp_c_pointer;
+  parameter_list            = pp_c_parameter_type_list;
+  type_id                   = pp_c_type_id;
+  simple_type_specifier     = pp_c_type_specifier;
+  function_specifier        = pp_c_function_specifier;
+  storage_class_specifier   = pp_c_storage_class_specifier;
+
+  statement                 = pp_c_statement;
+
+  constant                  = pp_c_constant;
+  id_expression             = pp_c_id_expression;
+  primary_expression        = pp_c_primary_expression;
+  postfix_expression        = pp_c_postfix_expression;
+  unary_expression          = pp_c_unary_expression;
+  initializer               = pp_c_initializer;
+  multiplicative_expression = pp_c_multiplicative_expression;
+  conditional_expression    = pp_c_conditional_expression;
+  assignment_expression     = pp_c_assignment_expression;
+  expression                = pp_c_expression;
 }
 
 
@@ -2360,8 +2358,7 @@ void
 print_c_tree (FILE *file, tree t)
 {
   c_pretty_printer pp;
-  pp_construct (&pp, NULL, 0);
-  pp_c_pretty_printer_init (&pp);
+
   pp_needs_newline (&pp) = true;
   pp.buffer->stream = file;
   pp_statement (&pp, t);
index 390477d289e45de6d493e03ffb18a2ae2cabe630..90647558f7c61e8b132f2d4202fddfaa6dbec472 100644 (file)
@@ -49,6 +49,8 @@ typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree);
    and cp/cxx-pretty-print.c for an example of derivation.  */
 struct c_pretty_printer : pretty_printer
 {
+  c_pretty_printer ();
+
   /* Points to the first element of an array of offset-list.
      Not used yet.  */
   int *offset_list;
@@ -120,7 +122,6 @@ struct c_pretty_printer : pretty_printer
 #define pp_expression(PP, E)            (PP)->expression (PP, E)
 
 
-extern void pp_c_pretty_printer_init (c_pretty_printer *);
 void pp_c_whitespace (c_pretty_printer *);
 void pp_c_left_paren (c_pretty_printer *);
 void pp_c_right_paren (c_pretty_printer *);
index 6ce1398dd5bd4ce759fff6a4473d1935b0408578..b0b25aca39d6f04930e309c70ddf325a87516b50 100644 (file)
@@ -1,5 +1,10 @@
+2013-08-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       * c-objc-common.c (c_initialize_diagnostics): Simplify C pretty
+       printer initialization.
+
 2013-08-19  Balaji V. Iyer  <balaji.v.iyer@intel.com>
-       
+
        PR c/57490
        * c-array-notation.c (fix_conditional_array_notations_1): Added a
        check for truth values.
index d832294c976fed59a60833a36cf8eeacf5303430..978c4328d28a1766a422983bd27bd1705d7402dd 100644 (file)
@@ -30,6 +30,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "c-objc-common.h"
 
+#include <new>                          // For placement new.
+
 static bool c_tree_printer (pretty_printer *, text_info *, const char *,
                            int, bool, bool, bool);
 
@@ -183,16 +185,11 @@ has_c_linkage (const_tree decl ATTRIBUTE_UNUSED)
 void
 c_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base;
-  c_pretty_printer *pp;
-
   c_common_initialize_diagnostics (context);
 
-  base = context->printer;
-  pp = XNEW (c_pretty_printer);
-  memcpy (pp, base, sizeof (pretty_printer));
-  pp_c_pretty_printer_init (pp);
-  context->printer = (pretty_printer *) pp;
+  pretty_printer *base = context->printer;
+  c_pretty_printer *pp = XNEW (c_pretty_printer);
+  context->printer = new (pp) c_pretty_printer ();
 
   /* It is safe to free this object because it was previously XNEW()'d.  */
   XDELETE (base);
index 3d020ed1bc9811c8914386aca01b4aa14d9f01be..bff8f5c62d5df3f35c6ef64f9b7a9c80d02ac3ee 100644 (file)
@@ -73,9 +73,7 @@ struct cl_option;
 struct cl_decoded_option;
 struct cl_option_handlers;
 struct diagnostic_context;
-typedef struct diagnostic_context diagnostic_context;
-struct pretty_print_info;
-typedef struct pretty_print_info pretty_printer;
+struct pretty_printer;
 
 /* Address space number for named address space support.  */
 typedef unsigned char addr_space_t;
index c99f9483f0c119b9cf8d8409bcb6de46c51a907d..4624e7395c642c04269e9b6d3c2597fe06d5b2a0 100644 (file)
@@ -1,3 +1,14 @@
+2013-08-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       * error.c (init_error): Remove calls to pp_construct and
+       pp_cxx_pretty_printer_init.  Initialize cxx_pp with placement-new.
+       * cxx-pretty-print.h (cxx_pretty_printer::cxx_pretty_printer): Declare.
+       (cxx_pretty_printer_init): Remove.
+       * cxx-pretty-print.c (cxx_pretty_printer::cxx_pretty_printer):
+       Rename from cxx_pretty_printer_init.  Adjust.
+       * cp-objcp-common.c (cxx_initialize_diagnostics): Simplify
+       initialization of C++ diagnostics pretty printer.
+
 2013-08-21  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * call.c (build_new_method_call_1): Use INDIRECT_REF_P.
index e568a05947ecb25751ab602101d33a55d0d4e3f7..c11ecebf9db6cb56f950e5dd3037279b74280524 100644 (file)
@@ -32,6 +32,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "cxx-pretty-print.h"
 #include "cp-objcp-common.h"
 
+#include <new>                       // For placement new.
+
 /* Special routine to get the alias set for C++.  */
 
 alias_set_type
@@ -131,19 +133,14 @@ cp_var_mod_type_p (tree type, tree fn)
 void
 cxx_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base;
-  cxx_pretty_printer *pp;
-
   c_common_initialize_diagnostics (context);
 
-  base = context->printer;
-  pp = XNEW (cxx_pretty_printer);
-  memcpy (pp, base, sizeof (pretty_printer));
-  pp_cxx_pretty_printer_init (pp);
-  context->printer = (pretty_printer *) pp;
+  pretty_printer *base = context->printer;
+  cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
+  context->printer = new (pp) cxx_pretty_printer ();
 
-  /* It is safe to free this object because it was previously malloc()'d.  */
-  free (base);
+  /* It is safe to free this object because it was previously XNEW()'d.  */
+  XDELETE (base);
 }
 
 /* This compares two types for equivalence ("compatible" in C-based languages).
index 21fc31980add6b73a7704bf62b0f8902a75660f6..6c3236595d23a05ef74f124b0d0c20085349372b 100644 (file)
@@ -2432,34 +2432,33 @@ typedef c_pretty_print_fn pp_fun;
 
 /* Initialization of a C++ pretty-printer object.  */
 
-void
-pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
+cxx_pretty_printer::cxx_pretty_printer ()
+  : c_pretty_printer (),
+    enclosing_scope (global_namespace)
 {
-  pp_c_pretty_printer_init (pp);
-  pp_set_line_maximum_length (pp, 0);
-
-  pp->declaration = (pp_fun) pp_cxx_declaration;
-  pp->declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
-  pp->function_specifier = (pp_fun) pp_cxx_function_specifier;
-  pp->type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
-  pp->declarator = (pp_fun) pp_cxx_declarator;
-  pp->direct_declarator = (pp_fun) pp_cxx_direct_declarator;
-  pp->parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
-  pp->type_id = (pp_fun) pp_cxx_type_id;
-  pp->abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
-  pp->direct_abstract_declarator = (pp_fun) pp_cxx_direct_abstract_declarator;
-  pp->simple_type_specifier = (pp_fun) pp_cxx_simple_type_specifier;
+  pp_set_line_maximum_length (this, 0);
+
+  declaration = (pp_fun) pp_cxx_declaration;
+  declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
+  function_specifier = (pp_fun) pp_cxx_function_specifier;
+  type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
+  declarator = (pp_fun) pp_cxx_declarator;
+  direct_declarator = (pp_fun) pp_cxx_direct_declarator;
+  parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
+  type_id = (pp_fun) pp_cxx_type_id;
+  abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
+  direct_abstract_declarator = (pp_fun) pp_cxx_direct_abstract_declarator;
+  simple_type_specifier = (pp_fun) pp_cxx_simple_type_specifier;
 
   /* pp->statement = (pp_fun) pp_cxx_statement;  */
 
-  pp->constant = (pp_fun) pp_cxx_constant;
-  pp->id_expression = (pp_fun) pp_cxx_id_expression;
-  pp->primary_expression = (pp_fun) pp_cxx_primary_expression;
-  pp->postfix_expression = (pp_fun) pp_cxx_postfix_expression;
-  pp->unary_expression = (pp_fun) pp_cxx_unary_expression;
-  pp->multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
-  pp->conditional_expression = (pp_fun) pp_cxx_conditional_expression;
-  pp->assignment_expression = (pp_fun) pp_cxx_assignment_expression;
-  pp->expression = (pp_fun) pp_cxx_expression;
-  pp->enclosing_scope = global_namespace;
+  constant = (pp_fun) pp_cxx_constant;
+  id_expression = (pp_fun) pp_cxx_id_expression;
+  primary_expression = (pp_fun) pp_cxx_primary_expression;
+  postfix_expression = (pp_fun) pp_cxx_postfix_expression;
+  unary_expression = (pp_fun) pp_cxx_unary_expression;
+  multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
+  conditional_expression = (pp_fun) pp_cxx_conditional_expression;
+  assignment_expression = (pp_fun) pp_cxx_assignment_expression;
+  expression = (pp_fun) pp_cxx_expression;
 }
index 398bd75c6806a21a9b9cf6072e2594cc125dc73b..c4611e2e5234f5d6e01e60f33fac2d64c3944a97 100644 (file)
@@ -31,6 +31,7 @@ enum cxx_pretty_printer_flags
 
 struct cxx_pretty_printer : c_pretty_printer
 {
+  cxx_pretty_printer ();
   /* This is the enclosing scope of the entity being pretty-printed.  */
   tree enclosing_scope;
 };
@@ -59,7 +60,6 @@ struct cxx_pretty_printer : c_pretty_printer
 #define pp_cxx_tree_identifier(PP, T) \
   pp_c_tree_identifier (PP, T)
 
-void pp_cxx_pretty_printer_init (cxx_pretty_printer *);
 void pp_cxx_begin_template_argument_list (cxx_pretty_printer *);
 void pp_cxx_end_template_argument_list (cxx_pretty_printer *);
 void pp_cxx_colon_colon (cxx_pretty_printer *);
index 1fdc8906153192be5c139ed45b6b8bcd46850747..a930803be8a38005121b01ba2c678158de900264 100644 (file)
@@ -33,6 +33,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "pointer-set.h"
 #include "c-family/c-objc.h"
 
+#include <new>                    // For placement-new.
+
 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
 
@@ -109,8 +111,7 @@ init_error (void)
   diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
   diagnostic_format_decoder (global_dc) = cp_printer;
 
-  pp_construct (cxx_pp, NULL, 0);
-  pp_cxx_pretty_printer_init (cxx_pp);
+  new (cxx_pp) cxx_pretty_printer ();
 }
 
 /* Dump a scope, if deemed necessary.  */
index dfc11f2647b10ed0270e2f42c037e1de2aecd61a..98252237e95f3bdd2cb5cbed34d822feab83f886 100644 (file)
@@ -33,6 +33,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "diagnostic-color.h"
 
+#include <new>                     // For placement new.
+
 #define pedantic_warning_kind(DC)                      \
   ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
@@ -120,11 +122,7 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
   /* Allocate a basic pretty-printer.  Clients will replace this a
      much more elaborated pretty-printer if they wish.  */
   context->printer = XNEW (pretty_printer);
-  pp_construct (context->printer, NULL, 0);
-  /* By default, diagnostics are sent to stderr.  */
-  context->printer->buffer->stream = stderr;
-  /* By default, we emit prefixes once per message.  */
-  context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+  new (context->printer) pretty_printer ();
 
   memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
   context->some_warnings_are_errors = false;
index 1d4068079ec6fdeeb2d5a0c0527447b1d315a765..4544e693eb7e9d1b287f6c7e06de56606ce420bc 100644 (file)
@@ -75,7 +75,6 @@ void
 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
 {
   pretty_printer buffer;
-  pp_construct (&buffer, NULL, 0);
   pp_needs_newline (&buffer) = true;
   buffer.buffer->stream = file;
   pp_gimple_stmt_1 (&buffer, g, spc, flags);
@@ -107,7 +106,6 @@ print_gimple_expr (FILE *file, gimple g, int spc, int flags)
 {
   flags |= TDF_RHS_ONLY;
   pretty_printer buffer;
-  pp_construct (&buffer, NULL, 0);
   pp_needs_newline (&buffer) = true;
   buffer.buffer->stream = file;
   pp_gimple_stmt_1 (&buffer, g, spc, flags);
@@ -143,7 +141,6 @@ void
 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
 {
   pretty_printer buffer;
-  pp_construct (&buffer, NULL, 0);
   pp_needs_newline (&buffer) = true;
   buffer.buffer->stream = file;
   dump_gimple_seq (&buffer, seq, spc, flags);
@@ -2270,7 +2267,6 @@ gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
   if (bb->index >= NUM_FIXED_BLOCKS)
     {
       pretty_printer buffer;
-      pp_construct (&buffer, NULL, 0);
       pp_needs_newline (&buffer) = true;
       buffer.buffer->stream = file;
       gimple_dump_bb_buff (&buffer, bb, indent, flags);
index 91391a67afcd52d4251f0df116752756ade3b828..0ec279d86a9a6150c085e63337ba7ca11ac7a4b0 100644 (file)
@@ -278,7 +278,6 @@ print_graph_cfg (const char *base, struct function *fun)
   const char *funcname = function_name (fun);
   FILE *fp = open_graph_file (base, "a");
   pretty_printer graph_slim_pp;
-  pp_construct (&graph_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   graph_slim_pp.buffer->stream = fp;
   pretty_printer *const pp = &graph_slim_pp;
   pp_printf (pp, "subgraph \"%s\" {\n"
@@ -297,7 +296,6 @@ static void
 start_graph_dump (FILE *fp, const char *base)
 {
   pretty_printer graph_slim_pp;
-  pp_construct (&graph_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   graph_slim_pp.buffer->stream = fp;
   pretty_printer *const pp = &graph_slim_pp;
   pp_string (pp, "digraph \"");
index 27fd0d18b1d66b57d3289d4f85d5402509e78275..2d2541048f8ef6956d2966c549cce7ee6d222046 100644 (file)
@@ -25,10 +25,27 @@ along with GCC; see the file COPYING3.  If not see
 #include "pretty-print.h"
 #include "diagnostic-color.h"
 
+#include <new>                    // For placement-new.
+
 #if HAVE_ICONV
 #include <iconv.h>
 #endif
 
+// Default construct an output buffer.
+
+output_buffer::output_buffer ()
+  : formatted_obstack (),
+    chunk_obstack (),
+    obstack (&formatted_obstack),
+    cur_chunk_array (),
+    stream (stderr),
+    line_length (),
+    digit_buffer ()
+{
+  obstack_init (&formatted_obstack);
+  obstack_init (&chunk_obstack);
+}
+
 /* A pointer to the formatted diagnostic message.  */
 #define pp_formatted_text_data(PP) \
    ((const char *) obstack_base ((PP)->buffer->obstack))
@@ -736,19 +753,24 @@ pp_emit_prefix (pretty_printer *pp)
 
 /* Construct a PRETTY-PRINTER with PREFIX and of MAXIMUM_LENGTH
    characters per line.  */
-void
-pp_construct (pretty_printer *pp, const char *prefix, int maximum_length)
+
+pretty_printer::pretty_printer (const char *p, int l)
+  : buffer (new (XCNEW (output_buffer)) output_buffer ()),
+    prefix (),
+    padding (pp_none),
+    maximum_length (),
+    indent_skip (),
+    wrapping (),
+    format_decoder (),
+    emitted_prefix (),
+    need_newline (),
+    translate_identifiers(true),
+    show_color ()
 {
-  memset (pp, 0, sizeof (pretty_printer));
-  pp->buffer = XCNEW (output_buffer);
-  obstack_init (&pp->buffer->chunk_obstack);
-  obstack_init (&pp->buffer->formatted_obstack);
-  pp->buffer->obstack = &pp->buffer->formatted_obstack;
-  pp->buffer->stream = stderr;
-  pp_line_cutoff (pp) = maximum_length;
-  pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
-  pp_set_prefix (pp, prefix);
-  pp_translate_identifiers (pp) = true;
+  pp_line_cutoff (this) = l;
+  /* By default, we emit prefixes once per message.  */
+  pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+  pp_set_prefix (this, p);
 }
 
 /* Append a string delimited by START and END to the output area of
index 95577063da57791d40752aaf9319e53c062e2a94..4c47e2b1a25c554da474c0ff46dfcab2bb160a2c 100644 (file)
@@ -73,6 +73,8 @@ struct chunk_info
    whose fields should not be accessed directly by clients.  */
 struct output_buffer
 {
+  output_buffer ();
+
   /* Obstack where the text is built up.  */
   struct obstack formatted_obstack;
 
@@ -157,8 +159,12 @@ typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
 /* The data structure that contains the bare minimum required to do
    proper pretty-printing.  Clients may derived from this structure
    and add additional fields they need.  */
-struct pretty_print_info
+struct pretty_printer
 {
+  // Default construct a pretty printer with specified prefix
+  // and a maximum line length cut off limit.
+  explicit pretty_printer (const char* = NULL, int = 0);
+
   /* Where we print external representation of ENTITY.  */
   output_buffer *buffer;
 
@@ -283,7 +289,6 @@ pp_get_prefix (const pretty_printer *pp) { return pp->prefix; }
 
 #define pp_buffer(PP) (PP)->buffer
 
-extern void pp_construct (pretty_printer *, const char *, int);
 extern void pp_set_line_maximum_length (pretty_printer *, int);
 extern void pp_set_prefix (pretty_printer *, const char *);
 extern void pp_destroy_prefix (pretty_printer *);
index a65e9229ddacfe950107a363520fa6fec8be0431..eb2410cbc4f1833e9ea33bd52a5c9183623a8489 100644 (file)
@@ -766,7 +766,6 @@ void
 dump_value_slim (FILE *f, const_rtx x, int verbose)
 {
   pretty_printer rtl_slim_pp;
-  pp_construct (&rtl_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   rtl_slim_pp.buffer->stream = f;
   print_value (&rtl_slim_pp, x, verbose);
   pp_flush (&rtl_slim_pp);
@@ -778,7 +777,6 @@ void
 dump_insn_slim (FILE *f, const_rtx x)
 {
   pretty_printer rtl_slim_pp;
-  pp_construct (&rtl_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   rtl_slim_pp.buffer->stream = f;
   print_insn_with_notes (&rtl_slim_pp, x);
   pp_flush (&rtl_slim_pp);
@@ -793,7 +791,6 @@ dump_rtl_slim (FILE *f, const_rtx first, const_rtx last,
 {
   const_rtx insn, tail;
   pretty_printer rtl_slim_pp;
-  pp_construct (&rtl_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   rtl_slim_pp.buffer->stream = f;
 
   tail = last ? NEXT_INSN (last) : NULL_RTX;
@@ -842,7 +839,6 @@ const char *
 str_pattern_slim (const_rtx x)
 {
   pretty_printer rtl_slim_pp;
-  pp_construct (&rtl_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
   print_pattern (&rtl_slim_pp, x, 0);
   return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
 }
index 293ee2c4b756900ec692bab5f0995f8ae56e345a..87431e7237cf418d4fc87f0200bfcde09d736444 100644 (file)
@@ -112,8 +112,6 @@ mf_varname_tree (tree decl)
   gcc_assert (decl);
 
   pretty_printer buf;
-  pp_construct (&buf, /* prefix */ NULL, /* line-width */ 0);
-  pp_clear_output_area (&buf);
 
   /* Add FILENAME[:LINENUMBER[:COLUMNNUMBER]].  */
   {
index f00ac4cdcacf967fc53d2b2dea025315eaf904ca..541269955d0f610ba4f1357cf811ee8adda857bd 100644 (file)
@@ -33,6 +33,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "value-prof.h"
 #include "predict.h"
 
+#include <new>                           // For placement-new.
+
 /* Local functions, macros and variables.  */
 static const char *op_symbol (const_tree);
 static void pretty_print_string (pretty_printer *, const char*);
@@ -3059,7 +3061,7 @@ maybe_init_pretty_print (FILE *file)
 {
   if (!initialized)
     {
-      pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
+      new (&buffer) pretty_printer ();
       pp_needs_newline (&buffer) = true;
       pp_translate_identifiers (&buffer) = false;
       initialized = 1;