Commit 025311c4 by Gabriel Dos Reis

diagnostic.c (diagnostic_set_caret_max_width): Use pp_buffer.

	* 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.

From-SVN: r201956
parent 0cadbfaa
2013-08-23 Gabriel Dos Reis <gdr@integrable-solutions.net>
* 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 <marc.glisse@inria.fr> 2013-08-24 Marc Glisse <marc.glisse@inria.fr>
PR other/57324 PR other/57324
......
2013-08-23 Gabriel Dos Reis <gdr@integrable-solutions.net>
* 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 <gdr@integrable-solutions.net> 2013-08-22 Gabriel Dos Reis <gdr@integrable-solutions.net>
* c-objc-common.c (c_initialize_diagnostics): Simplify C pretty * c-objc-common.c (c_initialize_diagnostics): Simplify C pretty
......
...@@ -92,6 +92,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec, ...@@ -92,6 +92,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
{ {
tree t = NULL_TREE; tree t = NULL_TREE;
tree name; tree name;
// FIXME: the next cast should be a dynamic_cast, when it is permitted.
c_pretty_printer *cpp = (c_pretty_printer *) pp; c_pretty_printer *cpp = (c_pretty_printer *) pp;
pp->padding = pp_none; pp->padding = pp_none;
...@@ -192,6 +193,7 @@ c_initialize_diagnostics (diagnostic_context *context) ...@@ -192,6 +193,7 @@ c_initialize_diagnostics (diagnostic_context *context)
context->printer = new (pp) c_pretty_printer (); context->printer = new (pp) c_pretty_printer ();
/* It is safe to free this object because it was previously XNEW()'d. */ /* It is safe to free this object because it was previously XNEW()'d. */
base->~pretty_printer ();
XDELETE (base); XDELETE (base);
} }
......
2013-08-23 Gabriel Dos Reis <gdr@integrable-solutiobs.net>
* 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 <paolo.carlini@oracle.com> 2013-08-22 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56380 PR c++/56380
......
...@@ -140,6 +140,7 @@ cxx_initialize_diagnostics (diagnostic_context *context) ...@@ -140,6 +140,7 @@ cxx_initialize_diagnostics (diagnostic_context *context)
context->printer = new (pp) cxx_pretty_printer (); context->printer = new (pp) cxx_pretty_printer ();
/* It is safe to free this object because it was previously XNEW()'d. */ /* It is safe to free this object because it was previously XNEW()'d. */
base->~pretty_printer ();
XDELETE (base); XDELETE (base);
} }
......
...@@ -2881,7 +2881,7 @@ type_to_string (tree typ, int verbose) ...@@ -2881,7 +2881,7 @@ type_to_string (tree typ, int verbose)
&& !uses_template_parms (typ)) && !uses_template_parms (typ))
{ {
int aka_start; char *p; 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. */ /* Remember the end of the initial dump. */
int len = obstack_object_size (ob); int len = obstack_object_size (ob);
tree aka = strip_typedefs (typ); tree aka = strip_typedefs (typ);
......
...@@ -104,7 +104,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value) ...@@ -104,7 +104,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value)
{ {
/* One minus to account for the leading empty space. */ /* One minus to account for the leading empty space. */
value = value ? value - 1 value = value ? value - 1
: (isatty (fileno (context->printer->buffer->stream)) : (isatty (fileno (pp_buffer (context->printer)->stream))
? getenv_columns () - 1: INT_MAX); ? getenv_columns () - 1: INT_MAX);
if (value <= 0) if (value <= 0)
......
...@@ -2249,7 +2249,7 @@ gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent, ...@@ -2249,7 +2249,7 @@ gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
pp_newline_and_flush (buffer); pp_newline_and_flush (buffer);
gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl)); gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
dump_histograms_for_stmt (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); dump_implicit_edges (buffer, bb, indent, flags);
......
...@@ -46,9 +46,17 @@ output_buffer::output_buffer () ...@@ -46,9 +46,17 @@ output_buffer::output_buffer ()
obstack_init (&chunk_obstack); 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. */ /* A pointer to the formatted diagnostic message. */
#define pp_formatted_text_data(PP) \ #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 /* Format an integer given by va_arg (ARG, type-specifier T) where
type-specifier is a precision modifier as indicated by PREC. F is type-specifier is a precision modifier as indicated by PREC. F is
...@@ -112,7 +120,7 @@ void ...@@ -112,7 +120,7 @@ void
pp_write_text_to_stream (pretty_printer *pp) pp_write_text_to_stream (pretty_printer *pp)
{ {
const char *text = pp_formatted_text (pp); const char *text = pp_formatted_text (pp);
fputs (text, pp->buffer->stream); fputs (text, pp_buffer (pp)->stream);
pp_clear_output_area (pp); pp_clear_output_area (pp);
} }
...@@ -130,7 +138,7 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record) ...@@ -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 *text = pp_formatted_text (pp);
const char *p = text; const char *p = text;
FILE *fp = pp->buffer->stream; FILE *fp = pp_buffer (pp)->stream;
while (*p) while (*p)
{ {
...@@ -216,8 +224,8 @@ pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end) ...@@ -216,8 +224,8 @@ pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end)
static inline void static inline void
pp_append_r (pretty_printer *pp, const char *start, int length) pp_append_r (pretty_printer *pp, const char *start, int length)
{ {
obstack_grow (pp->buffer->obstack, start, length); obstack_grow (pp_buffer (pp)->obstack, start, length);
pp->buffer->line_length += length; pp_buffer (pp)->line_length += length;
} }
/* Insert enough spaces into the output area of PRETTY-PRINTER to bring /* Insert enough spaces into the output area of PRETTY-PRINTER to bring
...@@ -268,13 +276,13 @@ pp_indent (pretty_printer *pp) ...@@ -268,13 +276,13 @@ pp_indent (pretty_printer *pp)
A format string can have at most 30 arguments. */ A format string can have at most 30 arguments. */
/* Formatting phases 1 and 2: render TEXT->format_spec plus /* 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. */ Phase 3 is in pp_format_text. */
void void
pp_format (pretty_printer *pp, text_info *text) pp_format (pretty_printer *pp, text_info *text)
{ {
output_buffer *buffer = pp->buffer; output_buffer *buffer = pp_buffer (pp);
const char *p; const char *p;
const char **args; const char **args;
struct chunk_info *new_chunk_array; struct chunk_info *new_chunk_array;
...@@ -291,7 +299,7 @@ pp_format (pretty_printer *pp, text_info *text) ...@@ -291,7 +299,7 @@ pp_format (pretty_printer *pp, text_info *text)
args = new_chunk_array->args; args = new_chunk_array->args;
/* Formatting phase 1: split up TEXT->format_spec into chunks in /* 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. verbatim, odd-numbered chunks are format specifiers.
%m, %%, %<, %>, and %' are replaced with the appropriate text at %m, %%, %<, %>, and %' are replaced with the appropriate text at
this point. */ this point. */
...@@ -677,7 +685,7 @@ pp_flush (pretty_printer *pp) ...@@ -677,7 +685,7 @@ pp_flush (pretty_printer *pp)
{ {
pp_write_text_to_stream (pp); pp_write_text_to_stream (pp);
pp_clear_state (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 /* 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) ...@@ -694,8 +702,9 @@ pp_set_line_maximum_length (pretty_printer *pp, int length)
void void
pp_clear_output_area (pretty_printer *pp) pp_clear_output_area (pretty_printer *pp)
{ {
obstack_free (pp->buffer->obstack, obstack_base (pp->buffer->obstack)); obstack_free (pp_buffer (pp)->obstack,
pp->buffer->line_length = 0; obstack_base (pp_buffer (pp)->obstack));
pp_buffer (pp)->line_length = 0;
} }
/* Set PREFIX for PRETTY-PRINTER. */ /* Set PREFIX for PRETTY-PRINTER. */
...@@ -773,6 +782,12 @@ pretty_printer::pretty_printer (const char *p, int l) ...@@ -773,6 +782,12 @@ pretty_printer::pretty_printer (const char *p, int l)
pp_set_prefix (this, p); 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 /* Append a string delimited by START and END to the output area of
PRETTY-PRINTER. No line wrapping is done. However, if beginning a PRETTY-PRINTER. No line wrapping is done. However, if beginning a
new line then emit PRETTY-PRINTER's prefix and skip any leading new line then emit PRETTY-PRINTER's prefix and skip any leading
...@@ -782,7 +797,7 @@ void ...@@ -782,7 +797,7 @@ void
pp_append_text (pretty_printer *pp, const char *start, const char *end) pp_append_text (pretty_printer *pp, const char *start, const char *end)
{ {
/* Emit prefix and skip whitespace if we're starting a new line. */ /* 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); pp_emit_prefix (pp);
if (pp_is_wrapping_line (pp)) if (pp_is_wrapping_line (pp))
...@@ -797,7 +812,7 @@ pp_append_text (pretty_printer *pp, const char *start, const char *end) ...@@ -797,7 +812,7 @@ pp_append_text (pretty_printer *pp, const char *start, const char *end)
const char * const char *
pp_formatted_text (pretty_printer *pp) 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); return pp_formatted_text_data (pp);
} }
...@@ -807,7 +822,7 @@ const char * ...@@ -807,7 +822,7 @@ const char *
pp_last_position_in_text (const pretty_printer *pp) pp_last_position_in_text (const pretty_printer *pp)
{ {
const char *p = NULL; 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)) if (obstack_base (text) != obstack_next_free (text))
p = ((const char *) obstack_next_free (text)) - 1; p = ((const char *) obstack_next_free (text)) - 1;
...@@ -819,7 +834,7 @@ pp_last_position_in_text (const pretty_printer *pp) ...@@ -819,7 +834,7 @@ pp_last_position_in_text (const pretty_printer *pp)
int int
pp_remaining_character_count_for_line (pretty_printer *pp) 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, ...) ...@@ -863,9 +878,9 @@ pp_verbatim (pretty_printer *pp, const char *msg, ...)
void void
pp_newline (pretty_printer *pp) pp_newline (pretty_printer *pp)
{ {
obstack_1grow (pp->buffer->obstack, '\n'); obstack_1grow (pp_buffer (pp)->obstack, '\n');
pp_needs_newline (pp) = false; pp_needs_newline (pp) = false;
pp->buffer->line_length = 0; pp_buffer (pp)->line_length = 0;
} }
/* Have PRETTY-PRINTER add a CHARACTER. */ /* Have PRETTY-PRINTER add a CHARACTER. */
...@@ -879,8 +894,8 @@ pp_character (pretty_printer *pp, int c) ...@@ -879,8 +894,8 @@ pp_character (pretty_printer *pp, int c)
if (ISSPACE (c)) if (ISSPACE (c))
return; return;
} }
obstack_1grow (pp->buffer->obstack, c); obstack_1grow (pp_buffer (pp)->obstack, c);
++pp->buffer->line_length; ++pp_buffer (pp)->line_length;
} }
/* Append a STRING to the output area of PRETTY-PRINTER; the STRING may /* Append a STRING to the output area of PRETTY-PRINTER; the STRING may
......
...@@ -74,6 +74,7 @@ struct chunk_info ...@@ -74,6 +74,7 @@ struct chunk_info
struct output_buffer struct output_buffer
{ {
output_buffer (); output_buffer ();
~output_buffer ();
/* Obstack where the text is built up. */ /* Obstack where the text is built up. */
struct obstack formatted_obstack; struct obstack formatted_obstack;
...@@ -165,6 +166,8 @@ struct pretty_printer ...@@ -165,6 +166,8 @@ struct pretty_printer
// and a maximum line length cut off limit. // and a maximum line length cut off limit.
explicit pretty_printer (const char* = NULL, int = 0); explicit pretty_printer (const char* = NULL, int = 0);
virtual ~pretty_printer ();
/* Where we print external representation of ENTITY. */ /* Where we print external representation of ENTITY. */
output_buffer *buffer; output_buffer *buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment