From patchwork Thu Jun 2 14:16:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 98392 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]) by ozlabs.org (Postfix) with SMTP id 75F06B6F71 for ; Fri, 3 Jun 2011 00:16:42 +1000 (EST) Received: (qmail 4871 invoked by alias); 2 Jun 2011 14:16:40 -0000 Received: (qmail 4861 invoked by uid 22791); 2 Jun 2011 14:16:39 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Jun 2011 14:16:25 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p52EGPc8026391 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Jun 2011 10:16:25 -0400 Received: from host1.jankratochvil.net (ovpn-113-38.phx2.redhat.com [10.3.113.38]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p52EGN47000670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 2 Jun 2011 10:16:24 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p52EGMmw023962; Thu, 2 Jun 2011 16:16:22 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p52EGMAU023961; Thu, 2 Jun 2011 16:16:22 +0200 Date: Thu, 2 Jun 2011 16:16:22 +0200 From: Jan Kratochvil To: gcc-patches@gcc.gnu.org Cc: gdb-patches@sourceware.org Subject: [gcc patch 2/3] cp-demangle.c: New DMGL_RET_DROP Message-ID: <20110602141622.GC15093@host1.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi, implement DMGL_RET_DROP as an alternative form of DMGL_RET_POSTFIX, as described in [gcc patch 0/3]. Thanks, Jan include/ 2011-05-24 Jan Kratochvil * demangle.h (DMGL_RET_POSTFIX): Extend the comment. (DMGL_RET_DROP): New. libiberty/ 2011-05-24 Jan Kratochvil * cp-demangle.c (d_print_comp) : Do not pass DMGL_RET_POSTFIX or DMGL_RET_DROP. Support DMGL_RET_DROP. * testsuite/demangle-expected: New testcases for --ret-drop. * testsuite/test-demangle.c: Document --ret-drop in a comment. (main): New variable ret_drop, fill it, call cplus_demangle with it. --- a/include/demangle.h +++ b/include/demangle.h @@ -45,7 +45,13 @@ extern "C" { #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */ #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */ #define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when - present) after function signature */ + present) after function signature. + It applies only to the toplevel + function type. */ +#define DMGL_RET_DROP (1 << 6) /* Suppress printing function return + types, even if present. It applies + only to the toplevel function type. + */ #define DMGL_AUTO (1 << 8) #define DMGL_GNU (1 << 9) --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -3917,10 +3917,11 @@ d_print_comp (struct d_print_info *dpi, const struct demangle_component *dc, case DEMANGLE_COMPONENT_FUNCTION_TYPE: { if ((options & DMGL_RET_POSTFIX) != 0) - d_print_function_type (dpi, dc, dpi->modifiers, options); + d_print_function_type (dpi, dc, dpi->modifiers, + options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP)); /* Print return type if present */ - if (d_left (dc) != NULL) + if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0) { struct d_print_mod dpm; @@ -3932,7 +3933,8 @@ d_print_comp (struct d_print_info *dpi, const struct demangle_component *dc, dpm.printed = 0; dpm.templates = dpi->templates; - d_print_comp (dpi, d_left (dc), options); + d_print_comp (dpi, d_left (dc), + options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP)); dpi->modifiers = dpm.next; @@ -3946,7 +3948,8 @@ d_print_comp (struct d_print_info *dpi, const struct demangle_component *dc, } if ((options & DMGL_RET_POSTFIX) == 0) - d_print_function_type (dpi, dc, dpi->modifiers, options); + d_print_function_type (dpi, dc, dpi->modifiers, + options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP)); return; } --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3959,6 +3959,24 @@ f(decltype(nullptr)) --format=gnu-v3 _ZN5aaaaa6bbbbbb5cccccIN23ddddddddddddddddddddddd3eeeENS2_4ffff16ggggggggggggggggENS0_9hhhhhhhhhES6_S6_S6_S6_S6_S6_S6_EE aaaaa::bbbbbb::ccccc +--format=gnu-v3 +_Z5outerIsEcPFilE +char outer(int (*)(long)) +--format=gnu-v3 +_Z5outerPFsiEl +outer(short (*)(int), long) +--format=gnu-v3 +_Z6outer2IsEPFilES1_ +int (*outer2(int (*)(long)))(long) +--format=gnu-v3 --ret-drop +_Z5outerIsEcPFilE +outer(int (*)(long)) +--format=gnu-v3 --ret-drop +_Z5outerPFsiEl +outer(short (*)(int), long) +--format=gnu-v3 --ret-drop +_Z6outer2IsEPFilES1_ +outer2(int (*)(long)) # # Ada (GNAT) tests. # --- a/libiberty/testsuite/test-demangle.c +++ b/libiberty/testsuite/test-demangle.c @@ -159,6 +159,7 @@ exp: %s\n", output is an integer representing ctor_kind. --is-v3-dtor Likewise, but for dtors. --ret-postfix Passes the DMGL_RET_POSTFIX option + --ret-drop Passes the DMGL_RET_DROP option For compatibility, just in case it matters, the options line may be empty, to mean --format=auto. If it doesn't start with --, then it @@ -174,7 +175,7 @@ main(argc, argv) int no_params; int is_v3_ctor; int is_v3_dtor; - int ret_postfix; + int ret_postfix, ret_drop; struct line format; struct line input; struct line expect; @@ -209,6 +210,7 @@ main(argc, argv) no_params = 0; ret_postfix = 0; + ret_drop = 0; is_v3_ctor = 0; is_v3_dtor = 0; if (format.data[0] == '\0') @@ -265,6 +267,8 @@ main(argc, argv) is_v3_dtor = 1; else if (strcmp (opt, "--ret-postfix") == 0) ret_postfix = 1; + else if (strcmp (opt, "--ret-drop") == 0) + ret_drop = 1; else { printf ("FAIL at line %d: unrecognized option %s\n", @@ -307,9 +311,9 @@ main(argc, argv) cplus_demangle_set_style (style); - result = cplus_demangle (inp, - DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES - |(ret_postfix ? DMGL_RET_POSTFIX : 0)); + result = cplus_demangle (inp, (DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES + | (ret_postfix ? DMGL_RET_POSTFIX : 0) + | (ret_drop ? DMGL_RET_DROP : 0))); if (result ? strcmp (result, expect.data)