From: gdr Date: Fri, 23 Aug 2013 23:58:55 +0000 (+0000) Subject: * diagnostic.c (diagnostic_set_caret_max_width): Use pp_buffer. X-Git-Tag: upstream/4.9.2~4638 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f07f480160fb41636ceca31b54e0a38edaab83d;p=platform%2Fupstream%2Flinaro-gcc.git * diagnostic.c (diagnostic_set_caret_max_width): Use pp_buffer. * gimple-pretty-print.c (gimple_dump_bb_buff): Likewise. * pretty-print.c (pp_formatted_text_data): Likewise. (pp_write_text_to_stream): Likewise. (pp_write_text_as_dot_label_to_stream): Likewise. (pp_append_r): Likewise. (pp_format): Likewise. (pp_flush): Likewise. (pp_clear_output_area): Likewise. (pp_append_text): Likewise. (pp_formatted_text): Likewise. (pp_remaining_character_count_for_line): Likewise. (pp_newline): Likewise. (pp_character): Likewise. (output_buffer::~output_buffer): Define. (pretty_printer::~pretty_printer): Destruct output buffer. * pretty-print.h (output_buffer::~output_buffer): Declare. (pretty_printer::~pretty_printer): Declare virtual. c/ * c-objc-common.c (c_tree_printer): Document the nature of the cast. (c_initialize_diagnostics): Call a destructor for the early printer. cp/ * cp-objcp-common.c (cxx_initialize_diagnostics): Call a destructor for the early printer. * error.c (type_to_string): Use pp_buffer. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201956 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a659a86..b35e5f3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,24 @@ +2013-08-23 Gabriel Dos Reis + + * diagnostic.c (diagnostic_set_caret_max_width): Use pp_buffer. + * gimple-pretty-print.c (gimple_dump_bb_buff): Likewise. + * pretty-print.c (pp_formatted_text_data): Likewise. + (pp_write_text_to_stream): Likewise. + (pp_write_text_as_dot_label_to_stream): Likewise. + (pp_append_r): Likewise. + (pp_format): Likewise. + (pp_flush): Likewise. + (pp_clear_output_area): Likewise. + (pp_append_text): Likewise. + (pp_formatted_text): Likewise. + (pp_remaining_character_count_for_line): Likewise. + (pp_newline): Likewise. + (pp_character): Likewise. + (output_buffer::~output_buffer): Define. + (pretty_printer::~pretty_printer): Destruct output buffer. + * pretty-print.h (output_buffer::~output_buffer): Declare. + (pretty_printer::~pretty_printer): Declare virtual. + 2013-08-24 Marc Glisse PR other/57324 diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b0b25ac..574e7c0 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2013-08-23 Gabriel Dos Reis + + * c-objc-common.c (c_tree_printer): Document the nature of the cast. + (c_initialize_diagnostics): Call a destructor for the early printer. + 2013-08-22 Gabriel Dos Reis * c-objc-common.c (c_initialize_diagnostics): Simplify C pretty diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c index 978c432..421c452 100644 --- a/gcc/c/c-objc-common.c +++ b/gcc/c/c-objc-common.c @@ -92,6 +92,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec, { tree t = NULL_TREE; tree name; + // FIXME: the next cast should be a dynamic_cast, when it is permitted. c_pretty_printer *cpp = (c_pretty_printer *) pp; pp->padding = pp_none; @@ -192,6 +193,7 @@ c_initialize_diagnostics (diagnostic_context *context) context->printer = new (pp) c_pretty_printer (); /* It is safe to free this object because it was previously XNEW()'d. */ + base->~pretty_printer (); XDELETE (base); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 92884a0..6972868 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-08-23 Gabriel Dos Reis + + * cp-objcp-common.c (cxx_initialize_diagnostics): Call a + destructor for the early printer. + * error.c (type_to_string): Use pp_buffer. + 2013-08-22 Paolo Carlini PR c++/56380 diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index c11eceb..d70766f 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -140,6 +140,7 @@ cxx_initialize_diagnostics (diagnostic_context *context) context->printer = new (pp) cxx_pretty_printer (); /* It is safe to free this object because it was previously XNEW()'d. */ + base->~pretty_printer (); XDELETE (base); } diff --git a/gcc/cp/error.c b/gcc/cp/error.c index a930803..c82a0ce 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -2881,7 +2881,7 @@ type_to_string (tree typ, int verbose) && !uses_template_parms (typ)) { int aka_start; char *p; - struct obstack *ob = cxx_pp->buffer->obstack; + struct obstack *ob = pp_buffer (cxx_pp)->obstack; /* Remember the end of the initial dump. */ int len = obstack_object_size (ob); tree aka = strip_typedefs (typ); diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 9825223..87c002a 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -104,7 +104,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value) { /* One minus to account for the leading empty space. */ value = value ? value - 1 - : (isatty (fileno (context->printer->buffer->stream)) + : (isatty (fileno (pp_buffer (context->printer)->stream)) ? getenv_columns () - 1: INT_MAX); if (value <= 0) diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 4544e69..e6eb5d4 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -2249,7 +2249,7 @@ gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent, pp_newline_and_flush (buffer); gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl)); dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl), - buffer->buffer->stream, stmt); + pp_buffer(buffer)->stream, stmt); } dump_implicit_edges (buffer, bb, indent, flags); diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index a465454..05f345c 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -46,9 +46,17 @@ output_buffer::output_buffer () obstack_init (&chunk_obstack); } +// Release resources owned by an output buffer at the end of lifetime. + +output_buffer::~output_buffer () +{ + obstack_free (&chunk_obstack, obstack_finish (&chunk_obstack)); + obstack_free (&formatted_obstack, obstack_finish (&formatted_obstack)); +} + /* A pointer to the formatted diagnostic message. */ #define pp_formatted_text_data(PP) \ - ((const char *) obstack_base ((PP)->buffer->obstack)) + ((const char *) obstack_base (pp_buffer (PP)->obstack)) /* Format an integer given by va_arg (ARG, type-specifier T) where type-specifier is a precision modifier as indicated by PREC. F is @@ -112,7 +120,7 @@ void pp_write_text_to_stream (pretty_printer *pp) { const char *text = pp_formatted_text (pp); - fputs (text, pp->buffer->stream); + fputs (text, pp_buffer (pp)->stream); pp_clear_output_area (pp); } @@ -130,7 +138,7 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record) { const char *text = pp_formatted_text (pp); const char *p = text; - FILE *fp = pp->buffer->stream; + FILE *fp = pp_buffer (pp)->stream; while (*p) { @@ -216,8 +224,8 @@ pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end) static inline void pp_append_r (pretty_printer *pp, const char *start, int length) { - obstack_grow (pp->buffer->obstack, start, length); - pp->buffer->line_length += length; + obstack_grow (pp_buffer (pp)->obstack, start, length); + pp_buffer (pp)->line_length += length; } /* Insert enough spaces into the output area of PRETTY-PRINTER to bring @@ -268,13 +276,13 @@ pp_indent (pretty_printer *pp) 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->args[]. + TEXT->args_ptr into a series of chunks in pp_buffer (PP)->args[]. Phase 3 is in pp_format_text. */ void pp_format (pretty_printer *pp, text_info *text) { - output_buffer *buffer = pp->buffer; + output_buffer *buffer = pp_buffer (pp); const char *p; const char **args; struct chunk_info *new_chunk_array; @@ -291,7 +299,7 @@ pp_format (pretty_printer *pp, text_info *text) args = new_chunk_array->args; /* Formatting phase 1: split up TEXT->format_spec into chunks in - PP->buffer->args[]. Even-numbered chunks are to be output + pp_buffer (PP)->args[]. Even-numbered chunks are to be output verbatim, odd-numbered chunks are format specifiers. %m, %%, %<, %>, and %' are replaced with the appropriate text at this point. */ @@ -677,7 +685,7 @@ pp_flush (pretty_printer *pp) { pp_write_text_to_stream (pp); pp_clear_state (pp); - fflush (pp->buffer->stream); + fflush (pp_buffer (pp)->stream); } /* Sets the number of maximum characters per line PRETTY-PRINTER can @@ -694,8 +702,9 @@ pp_set_line_maximum_length (pretty_printer *pp, int length) void pp_clear_output_area (pretty_printer *pp) { - obstack_free (pp->buffer->obstack, obstack_base (pp->buffer->obstack)); - pp->buffer->line_length = 0; + obstack_free (pp_buffer (pp)->obstack, + obstack_base (pp_buffer (pp)->obstack)); + pp_buffer (pp)->line_length = 0; } /* Set PREFIX for PRETTY-PRINTER. */ @@ -773,6 +782,12 @@ pretty_printer::pretty_printer (const char *p, int l) pp_set_prefix (this, p); } +pretty_printer::~pretty_printer () +{ + buffer->~output_buffer (); + XDELETE (buffer); +} + /* 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 @@ -782,7 +797,7 @@ void pp_append_text (pretty_printer *pp, const char *start, const char *end) { /* Emit prefix and skip whitespace if we're starting a new line. */ - if (pp->buffer->line_length == 0) + if (pp_buffer (pp)->line_length == 0) { pp_emit_prefix (pp); if (pp_is_wrapping_line (pp)) @@ -797,7 +812,7 @@ pp_append_text (pretty_printer *pp, const char *start, const char *end) const char * pp_formatted_text (pretty_printer *pp) { - obstack_1grow (pp->buffer->obstack, '\0'); + obstack_1grow (pp_buffer (pp)->obstack, '\0'); return pp_formatted_text_data (pp); } @@ -807,7 +822,7 @@ const char * pp_last_position_in_text (const pretty_printer *pp) { const char *p = NULL; - struct obstack *text = pp->buffer->obstack; + struct obstack *text = pp_buffer (pp)->obstack; if (obstack_base (text) != obstack_next_free (text)) p = ((const char *) obstack_next_free (text)) - 1; @@ -819,7 +834,7 @@ pp_last_position_in_text (const pretty_printer *pp) int pp_remaining_character_count_for_line (pretty_printer *pp) { - return pp->maximum_length - pp->buffer->line_length; + return pp->maximum_length - pp_buffer (pp)->line_length; } @@ -863,9 +878,9 @@ pp_verbatim (pretty_printer *pp, const char *msg, ...) void pp_newline (pretty_printer *pp) { - obstack_1grow (pp->buffer->obstack, '\n'); + obstack_1grow (pp_buffer (pp)->obstack, '\n'); pp_needs_newline (pp) = false; - pp->buffer->line_length = 0; + pp_buffer (pp)->line_length = 0; } /* Have PRETTY-PRINTER add a CHARACTER. */ @@ -879,8 +894,8 @@ pp_character (pretty_printer *pp, int c) if (ISSPACE (c)) return; } - obstack_1grow (pp->buffer->obstack, c); - ++pp->buffer->line_length; + obstack_1grow (pp_buffer (pp)->obstack, c); + ++pp_buffer (pp)->line_length; } /* Append a STRING to the output area of PRETTY-PRINTER; the STRING may diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 9b9b2cf..a60be32 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -74,6 +74,7 @@ struct chunk_info struct output_buffer { output_buffer (); + ~output_buffer (); /* Obstack where the text is built up. */ struct obstack formatted_obstack; @@ -165,6 +166,8 @@ struct pretty_printer // and a maximum line length cut off limit. explicit pretty_printer (const char* = NULL, int = 0); + virtual ~pretty_printer (); + /* Where we print external representation of ENTITY. */ output_buffer *buffer;