diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/error.cc | 10 | ||||
-rw-r--r-- | gcc/dumpfile.cc | 9 | ||||
-rw-r--r-- | gcc/pretty-print.cc | 96 | ||||
-rw-r--r-- | gcc/pretty-print.h | 30 |
4 files changed, 90 insertions, 55 deletions
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 01ad794..171a352 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -4307,14 +4307,8 @@ static void append_formatted_chunk (pretty_printer *pp, const char *content) { output_buffer *buffer = pp_buffer (pp); - struct chunk_info *chunk_array = buffer->cur_chunk_array; - const char **args = chunk_array->args; - - unsigned int chunk_idx; - for (chunk_idx = 0; args[chunk_idx]; chunk_idx++) - ; - args[chunk_idx++] = content; - args[chunk_idx] = NULL; + chunk_info *chunk_array = buffer->cur_chunk_array; + chunk_array->append_formatted_chunk (content); } /* Create a copy of CONTENT, with quotes added, and, diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc index 097f9bc..82bd8b0 100644 --- a/gcc/dumpfile.cc +++ b/gcc/dumpfile.cc @@ -819,8 +819,8 @@ void dump_pretty_printer::emit_items (optinfo *dest) { output_buffer *buffer = pp_buffer (this); - struct chunk_info *chunk_array = buffer->cur_chunk_array; - const char **args = chunk_array->args; + chunk_info *chunk_array = buffer->cur_chunk_array; + const char * const *args = chunk_array->get_args (); gcc_assert (buffer->obstack == &buffer->formatted_obstack); gcc_assert (buffer->line_length == 0); @@ -847,10 +847,7 @@ dump_pretty_printer::emit_items (optinfo *dest) /* Ensure that we consumed all of stashed_items. */ gcc_assert (stashed_item_idx == m_stashed_items.length ()); - /* Deallocate the chunk structure and everything after it (i.e. the - associated series of formatted strings). */ - buffer->cur_chunk_array = chunk_array->prev; - obstack_free (&buffer->chunk_obstack, chunk_array); + chunk_array->pop_from_output_buffer (*buffer); } /* Subroutine of dump_pretty_printer::emit_items diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc index 271cd65..639e2b8 100644 --- a/gcc/pretty-print.cc +++ b/gcc/pretty-print.cc @@ -1239,29 +1239,53 @@ private: std::vector<run> m_phase_3_quotes; }; -static void -on_begin_quote (const output_buffer &buf, - unsigned chunk_idx, - const urlifier *urlifier) +/* Adds a chunk to the end of formatted output, so that it + will be printed by pp_output_formatted_text. */ + +void +chunk_info::append_formatted_chunk (const char *content) +{ + unsigned int chunk_idx; + for (chunk_idx = 0; m_args[chunk_idx]; chunk_idx++) + ; + m_args[chunk_idx++] = content; + m_args[chunk_idx] = nullptr; +} + +/* Deallocate the current chunk structure and everything after it (i.e. the + associated series of formatted strings). */ + +void +chunk_info::pop_from_output_buffer (output_buffer &buf) +{ + delete m_quotes; + buf.cur_chunk_array = m_prev; + obstack_free (&buf.chunk_obstack, this); +} + +void +chunk_info::on_begin_quote (const output_buffer &buf, + unsigned chunk_idx, + const urlifier *urlifier) { if (!urlifier) return; - if (!buf.cur_chunk_array->m_quotes) - buf.cur_chunk_array->m_quotes = new quoting_info (); - buf.cur_chunk_array->m_quotes->on_begin_quote (buf, chunk_idx); + if (!m_quotes) + m_quotes = new quoting_info (); + m_quotes->on_begin_quote (buf, chunk_idx); } -static void -on_end_quote (pretty_printer *pp, - output_buffer &buf, - unsigned chunk_idx, - const urlifier *urlifier) +void +chunk_info::on_end_quote (pretty_printer *pp, + output_buffer &buf, + unsigned chunk_idx, + const urlifier *urlifier) { if (!urlifier) return; - if (!buf.cur_chunk_array->m_quotes) - buf.cur_chunk_array->m_quotes = new quoting_info (); - buf.cur_chunk_array->m_quotes->on_end_quote (pp, buf, chunk_idx, *urlifier); + if (!m_quotes) + m_quotes = new quoting_info (); + m_quotes->on_end_quote (pp, buf, chunk_idx, *urlifier); } /* The following format specifiers are recognized as being client independent: @@ -1333,13 +1357,12 @@ pretty_printer::format (text_info *text, const char **formatters[PP_NL_ARGMAX]; /* Allocate a new chunk structure. */ - struct chunk_info *new_chunk_array - = XOBNEW (&buffer->chunk_obstack, struct chunk_info); + chunk_info *new_chunk_array = XOBNEW (&buffer->chunk_obstack, chunk_info); - new_chunk_array->prev = buffer->cur_chunk_array; + new_chunk_array->m_prev = buffer->cur_chunk_array; new_chunk_array->m_quotes = nullptr; buffer->cur_chunk_array = new_chunk_array; - const char **args = new_chunk_array->args; + const char **args = new_chunk_array->m_args; /* Formatting phase 1: split up TEXT->format_spec into chunks in pp_buffer (PP)->args[]. Even-numbered chunks are to be output @@ -1380,13 +1403,13 @@ pretty_printer::format (text_info *text, obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr)); p++; - on_begin_quote (*buffer, chunk, urlifier); + buffer->cur_chunk_array->on_begin_quote (*buffer, chunk, urlifier); continue; } case '>': { - on_end_quote (this, *buffer, chunk, urlifier); + buffer->cur_chunk_array->on_end_quote (this, *buffer, chunk, urlifier); const char *colorstr = colorize_stop (m_show_color); obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr)); @@ -1584,7 +1607,7 @@ pretty_printer::format (text_info *text, if (quote) { pp_begin_quote (this, m_show_color); - on_begin_quote (*buffer, chunk, urlifier); + buffer->cur_chunk_array->on_begin_quote (*buffer, chunk, urlifier); } switch (*p) @@ -1756,7 +1779,8 @@ pretty_printer::format (text_info *text, if (quote) { - on_end_quote (this, *buffer, chunk, urlifier); + buffer->cur_chunk_array->on_end_quote (this, *buffer, + chunk, urlifier); pp_end_quote (this, m_show_color); } @@ -1840,8 +1864,9 @@ quoting_info::handle_phase_3 (pretty_printer *pp, { unsigned int chunk; output_buffer * const buffer = pp_buffer (pp); - struct chunk_info *chunk_array = buffer->cur_chunk_array; - const char **args = chunk_array->args; + chunk_info *chunk_array = buffer->cur_chunk_array; + const char * const *args = chunk_array->get_args (); + quoting_info *quoting = chunk_array->get_quoting_info (); /* We need to construct the string into an intermediate buffer for this case, since using pp_string can introduce prefixes @@ -1856,9 +1881,9 @@ quoting_info::handle_phase_3 (pretty_printer *pp, correspond to. */ size_t start_of_run_byte_offset = 0; std::vector<quoting_info::run>::const_iterator iter_run - = buffer->cur_chunk_array->m_quotes->m_phase_3_quotes.begin (); + = quoting->m_phase_3_quotes.begin (); std::vector<quoting_info::run>::const_iterator end_runs - = buffer->cur_chunk_array->m_quotes->m_phase_3_quotes.end (); + = quoting->m_phase_3_quotes.end (); for (chunk = 0; args[chunk]; chunk++) { size_t start_of_chunk_idx = combined_buf.object_size (); @@ -1913,8 +1938,9 @@ pp_output_formatted_text (pretty_printer *pp, { unsigned int chunk; output_buffer * const buffer = pp_buffer (pp); - struct chunk_info *chunk_array = buffer->cur_chunk_array; - const char **args = chunk_array->args; + chunk_info *chunk_array = buffer->cur_chunk_array; + const char * const *args = chunk_array->get_args (); + quoting_info *quoting = chunk_array->get_quoting_info (); gcc_assert (buffer->obstack == &buffer->formatted_obstack); @@ -1924,18 +1950,14 @@ pp_output_formatted_text (pretty_printer *pp, /* If we have any deferred urlification, handle it now. */ if (urlifier && pp->supports_urls_p () - && buffer->cur_chunk_array->m_quotes - && buffer->cur_chunk_array->m_quotes->has_phase_3_quotes_p ()) - buffer->cur_chunk_array->m_quotes->handle_phase_3 (pp, *urlifier); + && quoting + && quoting->has_phase_3_quotes_p ()) + quoting->handle_phase_3 (pp, *urlifier); else for (chunk = 0; args[chunk]; chunk++) pp_string (pp, args[chunk]); - /* Deallocate the chunk structure and everything after it (i.e. the - associated series of formatted strings). */ - delete buffer->cur_chunk_array->m_quotes; - buffer->cur_chunk_array = chunk_array->prev; - obstack_free (&buffer->chunk_obstack, chunk_array); + chunk_array->pop_from_output_buffer (*buffer); } /* Helper subroutine of output_verbatim and verbatim. Do the appropriate diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 99e55dc..b41d3ce 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -70,16 +70,38 @@ enum diagnostic_prefixing_rule_t }; class quoting_info; +class output_buffer; +class urlifier; /* The chunk_info data structure forms a stack of the results from the first phase of formatting (pp_format) which have not yet been output (pp_output_formatted_text). A stack is necessary because the diagnostic starter may decide to generate its own output by way of the formatter. */ -struct chunk_info +class chunk_info { + friend class pretty_printer; + +public: + const char * const *get_args () const { return m_args; } + quoting_info *get_quoting_info () const { return m_quotes; } + + void append_formatted_chunk (const char *content); + + void pop_from_output_buffer (output_buffer &buf); + +private: + void on_begin_quote (const output_buffer &buf, + unsigned chunk_idx, + const urlifier *urlifier); + + void on_end_quote (pretty_printer *pp, + output_buffer &buf, + unsigned chunk_idx, + const urlifier *urlifier); + /* Pointer to previous chunk on the stack. */ - struct chunk_info *prev; + chunk_info *m_prev; /* Array of chunks to output. Each chunk is a NUL-terminated string. In the first phase of formatting, even-numbered chunks are @@ -87,7 +109,7 @@ struct chunk_info The second phase replaces all odd-numbered chunks with formatted text, and the third phase simply emits all the chunks in sequence with appropriate line-wrapping. */ - const char *args[PP_NL_ARGMAX * 2]; + const char *m_args[PP_NL_ARGMAX * 2]; /* If non-null, information on quoted text runs within the chunks for use by a urlifier. */ @@ -114,7 +136,7 @@ public: struct obstack *obstack; /* Stack of chunk arrays. These come from the chunk_obstack. */ - struct chunk_info *cur_chunk_array; + chunk_info *cur_chunk_array; /* Where to output formatted text. */ FILE *stream; |