From patchwork Wed Jun 12 13:37:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1946929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PU1K+dMq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzmpP46p8z20Wd for ; Wed, 12 Jun 2024 23:38:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 178DF3882051 for ; Wed, 12 Jun 2024 13:38:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 336583882050 for ; Wed, 12 Jun 2024 13:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 336583882050 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 336583882050 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718199491; cv=none; b=kXpQuZXVEd5LWTeaUhhNNaKyRUcRvOX08waSkKrNiASgFrurMl2F4rGnmR15fNDgGY8vrlZfEfJHQGayjLsAX9ibUe2/qqwGxadcvX0r7jttbna43NxwovXaf0vaRO9C98mWZi9a30GT4jEaFft60l3WmAbtJpNEknuic+fkeFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718199491; c=relaxed/simple; bh=wQIdKO0MkOM69j2sDlkO2q3nju9TC4wMhyEf4pZChqk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KF04Cd4FDPEf+1EmOdlAqtNNsPB7m8VDj1sJzQ8j6YFIiP3LEEIhxNPcXv8zwLDSv8NyL4mC6LZyCkmXNoKKq+e6V+JGdzAqrnbE2+VjVhjlv6hNNJEjRCI5EJDYOsis4pHfk0STryBu778cLPdUqnjV50l0F0sWWcl16glEXgY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718199486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UjVxdhINUNuI1U7/NWf7ljFlQShJXxnOyuZdO2HNi3g=; b=PU1K+dMqDWX8pZWuR7YgWhyMBe7SF4Ms53N3Lg1gkeTPpS5B8tlRyG7fPufpQOMnXYtRBu /KYZjQDE06+6YZZkMs1VMwrTQC+uL9r2Pblj2ClYA5XXrv5THQZVyzzFbmL7+rYBnNSOzd /4wcMQVyXvU9ZK/4iBrUOQk7uhK4XDQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-aN_LunmLMASlM8zVngWmdg-1; Wed, 12 Jun 2024 09:38:05 -0400 X-MC-Unique: aN_LunmLMASlM8zVngWmdg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 394B11955E87 for ; Wed, 12 Jun 2024 13:38:04 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 759E119560AE; Wed, 12 Jun 2024 13:37:57 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed 3/3] pretty_printer: convert chunk_info into a class Date: Wed, 12 Jun 2024 09:37:52 -0400 Message-Id: <20240612133752.558463-3-dmalcolm@redhat.com> In-Reply-To: <20240612133752.558463-1-dmalcolm@redhat.com> References: <20240612133752.558463-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Successful run of analyzer integration tests on x86_64-pc-linux-gnu. Pushed to trunk as r15-1210-g1cae1a5ce088c1. gcc/cp/ChangeLog: * error.cc (append_formatted_chunk): Move part of body into chunk_info::append_formatted_chunk. gcc/ChangeLog: * dumpfile.cc (dump_pretty_printer::emit_items): Update for changes to chunk_info. * pretty-print.cc (chunk_info::append_formatted_chunk): New, based on code in cp/error.cc's append_formatted_chunk. (chunk_info::pop_from_output_buffer): New, based on code in pp_output_formatted_text and dump_pretty_printer::emit_items. (on_begin_quote): Convert to... (chunk_info::on_begin_quote): ...this. (on_end_quote): Convert to... (chunk_info::on_end_quote): ...this. (pretty_printer::format): Update for chunk_info becoming a class and its fields gaining "m_" prefixes. Update for on_begin_quote and on_end_quote moving to chunk_info. (quoting_info::handle_phase_3): Update for changes to chunk_info. (pp_output_formatted_text): Likewise. Move cleanup code to chunk_info::pop_from_output_buffer. * pretty-print.h (class output_buffer): New forward decl. (class urlifier): New forward decl. (struct chunk_info): Convert to... (class chunk_info): ...this. Add friend class pretty_printer. (chunk_info::get_args): New accessor. (chunk_info::get_quoting_info): New accessor. (chunk_info::append_formatted_chunk): New decl. (chunk_info::pop_from_output_buffer): New decl. (chunk_info::on_begin_quote): New decl. (chunk_info::on_end_quote): New decl. (chunk_info::prev): Rename to... (chunk_info::m_prev): ...this. (chunk_info::args): Rename to... (chunk_info::m_args): ...this. (output_buffer::cur_chunk_array): Drop "struct" from decl. Signed-off-by: David Malcolm --- gcc/cp/error.cc | 10 +---- gcc/dumpfile.cc | 9 ++--- gcc/pretty-print.cc | 96 ++++++++++++++++++++++++++++----------------- 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 01ad794df8e3..171a352c85fd 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 097f9bcfff21..82bd8b06bebf 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 271cd650c4d1..639e2b881586 100644 --- a/gcc/pretty-print.cc +++ b/gcc/pretty-print.cc @@ -1239,29 +1239,53 @@ private: std::vector 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::const_iterator iter_run - = buffer->cur_chunk_array->m_quotes->m_phase_3_quotes.begin (); + = quoting->m_phase_3_quotes.begin (); std::vector::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 99e55dc6a3c0..b41d3ce31d22 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;