From patchwork Sat Nov 16 01:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1196001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513725-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SPC9JJYV"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="GWR5sCbA"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47FHSF6rkYz9sQy for ; Sat, 16 Nov 2019 12:19:25 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=h1P Ak9f1Iroa4r82UMZXyOodoso0aZVnxotI7e+/u1wT42Ce4BAY528pCvuIEJtHYAV AeqQNjbAPDzgvD7ZAN0g7p0gU6WeoKLhJpuwICwhvBKFjdlSU9Ck29sg6BO0hDE8 Cp6EqXo7W8pl2bB5cqoJo8GwrkBlOaAOe5/TY6I8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=I/+RFatmk OchNRoI/I5vjnFy0S8=; b=SPC9JJYVwOOluFaBj67urKo87wNn+c5zhBuUJVcD6 FPXzL6uuZ+g/td0lCKkQwRZZf7Aai5AUSURCPhXdC4v0WXNC8H/KFjmKeFxvURxB H74ctGznHDRu6Z6pwwHWLOy1uIhalFkCuA1YFpqz77aAvC3TFxXGw1bgS6kEYHuu zM= Received: (qmail 56016 invoked by alias); 16 Nov 2019 01:17:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 55965 invoked by uid 89); 16 Nov 2019 01:17:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=sk:cxx_pre, sk:c_prett X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Nov 2019 01:17:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573867032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MhC8LxR58P1qaHXJOts7A00NIs9/EHqVmEyeGuvESxI=; b=GWR5sCbA1z6yfYSOiEN0L2sp37iUub9a0re0pIauyFNQH++mXJQ6BkGFdEcIRmwS8b3+k9 xFwrlebA2nuXDYsdBL+80U10xFATU3TZGkvcQBmpbCg18+jOChwLqOzeOMTBJupG6vDU/9 Sq9i43iQU8/1CeH9LyZgFAw790e145o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-oTiDQ4SuNRyirbRVDd8pUQ-1; Fri, 15 Nov 2019 20:17:11 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82A46107ACC9 for ; Sat, 16 Nov 2019 01:17:10 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-32.phx2.redhat.com [10.3.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 976EE10246FB; Sat, 16 Nov 2019 01:17:09 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 08/49] Introduce pretty_printer::clone vfunc Date: Fri, 15 Nov 2019 20:22:55 -0500 Message-Id: <1573867416-55618-9-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> References: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch provides a way to clone a pretty_printer. This is needed so that we can capture text in a label_text and make layout decisions based on it, using the policy of global_dc's printer, whilst within a call to diagnostic_show_locus. We can't print with the pretty_printer itself within a call to diagnostic_show_locus since it has partly-buffered content. gcc/c-family/ChangeLog: * c-pretty-print.c (c_pretty_printer::clone): New vfunc implementation. * c-pretty-print.h (c_pretty_printer::clone): New vfunc decl. gcc/cp/ChangeLog: * cxx-pretty-print.c (cxx_pretty_printer::clone): New vfunc implementation. * cxx-pretty-print.h (cxx_pretty_printer::clone): New vfunc decl. * error.c (cxx_format_postprocessor::clone): New vfunc. gcc/ChangeLog: * pretty-print.c (pretty_printer::pretty_printer): New copy-ctor. (pretty_printer::clone): New vfunc implementation. * pretty-print.h (format_postprocessor::clone): New pure vfunc decl. (pretty_printer::pretty_printer): New copy-ctor decl. (pretty_printer::clone): New vfunc decl. --- gcc/c-family/c-pretty-print.c | 7 +++++++ gcc/c-family/c-pretty-print.h | 1 + gcc/cp/cxx-pretty-print.c | 8 ++++++++ gcc/cp/cxx-pretty-print.h | 2 ++ gcc/cp/error.c | 5 +++++ gcc/pretty-print.c | 34 ++++++++++++++++++++++++++++++++++ gcc/pretty-print.h | 4 ++++ 7 files changed, 61 insertions(+) diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index 1b06cc2..9f73d23 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -2368,6 +2368,13 @@ c_pretty_printer::c_pretty_printer () parameter_list = pp_c_parameter_type_list; } +/* c_pretty_printer's implementation of pretty_printer::clone vfunc. */ + +pretty_printer * +c_pretty_printer::clone () const +{ + return new c_pretty_printer (*this); +} /* Print the tree T in full, on file FILE. */ diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h index 8d69620..df21e21 100644 --- a/gcc/c-family/c-pretty-print.h +++ b/gcc/c-family/c-pretty-print.h @@ -51,6 +51,7 @@ class c_pretty_printer : public pretty_printer { public: c_pretty_printer (); + pretty_printer *clone () const OVERRIDE; // Format string, possibly translated. void translate_string (const char *); diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 2a129a3..d9d57be 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -3012,3 +3012,11 @@ cxx_pretty_printer::cxx_pretty_printer () type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq; parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause; } + +/* cxx_pretty_printer's implementation of pretty_printer::clone vfunc. */ + +pretty_printer * +cxx_pretty_printer::clone () const +{ + return new cxx_pretty_printer (*this); +} diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h index 347811f..dd96226 100644 --- a/gcc/cp/cxx-pretty-print.h +++ b/gcc/cp/cxx-pretty-print.h @@ -34,6 +34,8 @@ class cxx_pretty_printer : public c_pretty_printer public: cxx_pretty_printer (); + pretty_printer *clone () const OVERRIDE; + void constant (tree); void id_expression (tree); void primary_expression (tree); diff --git a/gcc/cp/error.c b/gcc/cp/error.c index f40b90d..bc8c9dc 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -143,6 +143,11 @@ class cxx_format_postprocessor : public format_postprocessor : m_type_a (), m_type_b () {} + format_postprocessor *clone() const FINAL OVERRIDE + { + return new cxx_format_postprocessor (); + } + void handle (pretty_printer *pp) FINAL OVERRIDE; deferred_printed_type m_type_a; diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index c57a3db..89242ed 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -1588,6 +1588,32 @@ pretty_printer::pretty_printer (int maximum_length) pp_set_prefix (this, NULL); } +/* Copy constructor for pretty_printer. */ + +pretty_printer::pretty_printer (const pretty_printer &other) +: buffer (new (XCNEW (output_buffer)) output_buffer ()), + prefix (), + padding (other.padding), + maximum_length (other.maximum_length), + indent_skip (other.indent_skip), + wrapping (other.wrapping), + format_decoder (other.format_decoder), + m_format_postprocessor (NULL), + emitted_prefix (other.emitted_prefix), + need_newline (other.need_newline), + translate_identifiers (other.translate_identifiers), + show_color (other.show_color), + show_urls (other.show_urls) +{ + pp_line_cutoff (this) = maximum_length; + /* By default, we emit prefixes once per message. */ + pp_prefixing_rule (this) = pp_prefixing_rule (&other); + pp_set_prefix (this, NULL); + + if (other.m_format_postprocessor) + m_format_postprocessor = other.m_format_postprocessor->clone (); +} + pretty_printer::~pretty_printer () { if (m_format_postprocessor) @@ -1597,6 +1623,14 @@ pretty_printer::~pretty_printer () free (prefix); } +/* Base class implementation of pretty_printer::clone vfunc. */ + +pretty_printer * +pretty_printer::clone () const +{ + return new pretty_printer (*this); +} + /* 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 diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index c73fc30..493507d 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -192,6 +192,7 @@ class format_postprocessor { public: virtual ~format_postprocessor () {} + virtual format_postprocessor *clone() const = 0; virtual void handle (pretty_printer *) = 0; }; @@ -221,9 +222,12 @@ public: /* Default construct a pretty printer with specified maximum line length cut off limit. */ explicit pretty_printer (int = 0); + explicit pretty_printer (const pretty_printer &other); virtual ~pretty_printer (); + virtual pretty_printer *clone () const; + /* Where we print external representation of ENTITY. */ output_buffer *buffer;