From: gdr Date: Thu, 22 Aug 2013 10:14:46 +0000 (+0000) Subject: * pretty-print.h (output_buffer::output_buffer): Declare. X-Git-Tag: upstream/4.9.2~4663 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eed6bc214df1f3b9b1b68c871d4d8ff106ca19f4;p=platform%2Fupstream%2Flinaro-gcc.git * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201918 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c38417c..e65e9ce 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,33 @@ +2013-08-22 Gabriel Dos Reis + + * 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 * cgraphunit.c (analyze_functions) Use update_type_inheritance_graph. diff --git a/gcc/asan.c b/gcc/asan.c index 1756b07..81118a7 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -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 *v) vec *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 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 1e053bd..513a927 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2013-08-22 Gabriel Dos Reis + + * 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 * c-ada-spec.c (print_ada_declaration): Prevent accessing null asm name diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 22784c9..eac5783 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -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; diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index fed5802..253dfd1 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -2318,39 +2318,37 @@ pp_c_statement (c_pretty_printer *pp, tree stmt) /* 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); diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h index 390477d..9064755 100644 --- a/gcc/c-family/c-pretty-print.h +++ b/gcc/c-family/c-pretty-print.h @@ -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 *); diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 6ce1398..b0b25ac 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,10 @@ +2013-08-22 Gabriel Dos Reis + + * c-objc-common.c (c_initialize_diagnostics): Simplify C pretty + printer initialization. + 2013-08-19 Balaji V. Iyer - + PR c/57490 * c-array-notation.c (fix_conditional_array_notations_1): Added a check for truth values. diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c index d832294..978c432 100644 --- a/gcc/c/c-objc-common.c +++ b/gcc/c/c-objc-common.c @@ -30,6 +30,8 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "c-objc-common.h" +#include // 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); diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 3d020ed..bff8f5c 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -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; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c99f948..4624e73 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2013-08-22 Gabriel Dos Reis + + * 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 * call.c (build_new_method_call_1): Use INDIRECT_REF_P. diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index e568a05..c11eceb 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -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 // 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). diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 21fc319..6c32365 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -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; } diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h index 398bd75..c4611e2 100644 --- a/gcc/cp/cxx-pretty-print.h +++ b/gcc/cp/cxx-pretty-print.h @@ -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 *); diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 1fdc8906..a930803 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -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 // 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. */ diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index dfc11f2..9825223 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -33,6 +33,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "diagnostic-color.h" +#include // 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; diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 1d40680..4544e69 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -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); diff --git a/gcc/graph.c b/gcc/graph.c index 91391a6..0ec279d 100644 --- a/gcc/graph.c +++ b/gcc/graph.c @@ -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 \""); diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 27fd0d1..2d25410 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -25,10 +25,27 @@ along with GCC; see the file COPYING3. If not see #include "pretty-print.h" #include "diagnostic-color.h" +#include // For placement-new. + #if HAVE_ICONV #include #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 diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 9557706..4c47e2b 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -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 *); diff --git a/gcc/sched-vis.c b/gcc/sched-vis.c index a65e922..eb2410c 100644 --- a/gcc/sched-vis.c +++ b/gcc/sched-vis.c @@ -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)); } diff --git a/gcc/tree-mudflap.c b/gcc/tree-mudflap.c index 293ee2c..87431e7 100644 --- a/gcc/tree-mudflap.c +++ b/gcc/tree-mudflap.c @@ -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]]. */ { diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index f00ac4c..5412699 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -33,6 +33,8 @@ along with GCC; see the file COPYING3. If not see #include "value-prof.h" #include "predict.h" +#include // 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;