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:
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
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));
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)
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);
}
{
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
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 ();
{
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);
/* 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
};
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
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. */
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;