From patchwork Thu Aug 29 18:51:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Butcher X-Patchwork-Id: 270892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3D51A2C0091 for ; Fri, 30 Aug 2013 04:51:33 +1000 (EST) 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; q=dns; s= default; b=nekqJQiXC1lJGixy6uJqGqWUWSAs+vUWKs/L4NwoL61ItTn+Hppmk 0x5cSx/0JgdBrODPEX7O8DT5E1N96JINcSudkLrRnlZ7+VFcuBReCqdxiqGvw1CQ KpKKHz0BQlqc9XSdW2GrAmGFzN1JiAwzOw1j9eDjhzXm5Ooi0fZNQs= 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; s= default; bh=XgrffrAvpsQHKWUF5ZeATSBaydM=; b=ulaX3qfVshD9XRO4Yz1v c9P+rNBF0YV7pUPX76z4Q0N35QiKBLhmnACdbtB9dBKDOb5Vclc5iazS0tYANgU1 BfwDKPCKjCmahUUsekpJyBafjywsIZsTdVuVtdfWMzFhBDcffP+VImXGE8quY+qf it/YFekaYOksIJL4IQM96so= Received: (qmail 1531 invoked by alias); 29 Aug 2013 18:51:26 -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 1522 invoked by uid 89); 29 Aug 2013 18:51:26 -0000 Received: from mail-wg0-f50.google.com (HELO mail-wg0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 29 Aug 2013 18:51:26 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, FREEMAIL_FROM, KHOP_THREADED autolearn=ham version=3.3.2 X-HELO: mail-wg0-f50.google.com Received: by mail-wg0-f50.google.com with SMTP id m14so797773wgh.5 for ; Thu, 29 Aug 2013 11:51:22 -0700 (PDT) X-Received: by 10.194.241.228 with SMTP id wl4mr7728000wjc.2.1377802282558; Thu, 29 Aug 2013 11:51:22 -0700 (PDT) Received: from sphere.lan (munkyhouse.force9.co.uk. [84.92.244.81]) by mx.google.com with ESMTPSA id eb3sm14530817wic.10.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Aug 2013 11:51:21 -0700 (PDT) From: Adam Butcher To: Gabriel Dos Reis Cc: gcc-patches@gcc.gnu.org, Jason Merrill , Andrew Sutton , Adam Butcher Subject: Re: [PATCH] Support dumping type bindings and 'mutable' qualifier in lambda diagnostics. Date: Thu, 29 Aug 2013 19:51:14 +0100 Message-Id: <1377802274-14253-1-git-send-email-adam@jessamine.co.uk> In-Reply-To: <4c459051d38accbc80560880b8ec9eb6@imap.force9.net> References: <4c459051d38accbc80560880b8ec9eb6@imap.force9.net> * error.c (dump_lambda_function): New function, dependent on ... (maybe_dump_with_clause): ... this new function, factored out of ... (subst_to_string): ... here and ... (dump_function_decl): ... here. Updated to early-out with call to dump_lambda_function after determining template bindings. --- Hi Gaby, On 29.08.2013 18:04, Adam Butcher wrote: > On 29.08.2013 16:25, Gabriel Dos Reis wrote: > > > > Document the new functions. > > Use pp->translate_string ("with") instead of > > pp_cxx_ws_string (pp, M_("with")). > > > Done. In documenting 'maybe_dump_template_bindings' and reviewing > it again I'm not sure it's got the right name. It wraps > 'dump_template_bindings' in "[with " and "]". So it does more than > just filter a call to 'dump_template_bindings'. > > Any suggestions? What do you think of 'maybe_dump_with_clause' or > something similar? > Here's a diff with the name change (though I'm not all that happy with it) and the docs. I've also reimplemented subst_to_string in terms of the new function as it was duplicating much of the code from dump_function_decl (the only downside of this is some unnecessary tests in the subst_to_string case but I think they should get optimized away if it were inlined -- we're dealing with diagnostics formatting here anyway so performance is probably not a big factor). Cheers, Adam --- gcc/cp/error.c | 73 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index c82a0ce..3d1e173 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1363,6 +1363,47 @@ find_typenames (tree t) return ft.typenames; } +/* Output the "[with ...]" clause for a template instantiation T iff + TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if + formatting a deduction/substitution diagnostic rather than an + instantiation. */ + +static void +maybe_dump_with_clause (cxx_pretty_printer *pp, + tree t, tree template_parms, tree template_args, + int flags) +{ + if (template_parms != NULL_TREE && template_args != NULL_TREE + && !(flags & TFF_NO_TEMPLATE_BINDINGS)) + { + vec *typenames = t ? find_typenames (t) : NULL; + pp_cxx_whitespace (pp); + pp_cxx_left_bracket (pp); + pp->translate_string ("with"); + pp_cxx_whitespace (pp); + dump_template_bindings (pp, template_parms, template_args, typenames); + pp_cxx_right_bracket (pp); + } +} + +/* Dump the lambda function FN including its 'mutable' qualifier and any + template bindings. */ + +static void +dump_lambda_function (cxx_pretty_printer *pp, + tree fn, tree template_parms, tree template_args, + int flags) +{ + /* A lambda's signature is essentially its "type". */ + dump_type (pp, DECL_CONTEXT (fn), flags); + if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST)) + { + pp->padding = pp_before; + pp_c_ws_string (pp, "mutable"); + } + maybe_dump_with_clause (pp, fn, template_parms, template_args, flags); +} + /* Pretty print a function decl. There are several ways we want to print a function declaration. The TFF_ bits in FLAGS tells us how to behave. As error can only apply the '#' flag once to give 0 and 1 for V, there @@ -1379,15 +1420,6 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS; int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME); tree exceptions; - vec *typenames = NULL; - - if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) - { - /* A lambda's signature is essentially its "type", so defer. */ - gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t))); - dump_type (pp, DECL_CONTEXT (t), flags); - return; - } flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME); if (TREE_CODE (t) == TEMPLATE_DECL) @@ -1409,10 +1441,12 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) { template_parms = DECL_TEMPLATE_PARMS (tmpl); t = tmpl; - typenames = find_typenames (t); } } + if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) + return dump_lambda_function (pp, t, template_parms, template_args, flags); + fntype = TREE_TYPE (t); parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t); @@ -1476,17 +1510,7 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) if (show_return) dump_type_suffix (pp, TREE_TYPE (fntype), flags); - /* If T is a template instantiation, dump the parameter binding. */ - if (template_parms != NULL_TREE && template_args != NULL_TREE - && !(flags & TFF_NO_TEMPLATE_BINDINGS)) - { - pp_cxx_whitespace (pp); - pp_cxx_left_bracket (pp); - pp_cxx_ws_string (pp, M_("with")); - pp_cxx_whitespace (pp); - dump_template_bindings (pp, template_parms, template_args, typenames); - pp_cxx_right_bracket (pp); - } + maybe_dump_with_clause (pp, t, template_parms, template_args, flags); } else if (template_args) { @@ -2950,12 +2974,7 @@ subst_to_string (tree p) reinit_cxx_pp (); dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags); - pp_cxx_whitespace (cxx_pp); - pp_cxx_left_bracket (cxx_pp); - pp_cxx_ws_string (cxx_pp, M_("with")); - pp_cxx_whitespace (cxx_pp); - dump_template_bindings (cxx_pp, tparms, targs, NULL); - pp_cxx_right_bracket (cxx_pp); + maybe_dump_with_clause (cxx_pp, NULL, tparms, targs, /*flags=*/0); return pp_ggc_formatted_text (cxx_pp); }