From patchwork Sun Dec 8 18:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36601 Received: (qmail 101526 invoked by alias); 8 Dec 2019 18:30:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101283 invoked by uid 89); 8 Dec 2019 18:30:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=H*r:esmtpa, HX-Spam-Relays-External:esmtpa, H*RU:esmtpa X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:30:13 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 6CCD13F6CC7 for ; Sun, 8 Dec 2019 12:30:09 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JpiZZBa4kpje1Jpi9V7s; Sun, 08 Dec 2019 12:30:09 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7lYCt504q5CIqaMRzVyppmE9XYtO4+FoQcjxH/ZWpkM=; b=BKzypJnloIwYBcsgCUk0ybQBnW nCsuG8dr6N+cW+F+CALAQ8ib/mND9Awb8VVj+txcYBNvZ45XDJStKWZSsScJDt7zAzb6g0rT0dAVz K7CmnPjX+fQgZ8HY4VF/vZrdI; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53624 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Jp-0045Im-7I; Sun, 08 Dec 2019 11:30:09 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 38/55] Introduce generic_value_print_complex Date: Sun, 8 Dec 2019 11:29:41 -0700 Message-Id: <20191208182958.10181-39-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds generic_value_print_complex, a value-based analogue of generic_val_print_complex. gdb/ChangeLog 2019-12-08 Tom Tromey * valprint.c (generic_value_print_complex): New function. (generic_value_print): Use it. Change-Id: Ie3a455dc94226eaf7943bed8fd2520be87c067bd --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 27 +++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 630b6567cd0..251eae2d844 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -940,6 +940,30 @@ generic_val_print_complex (struct type *type, fprintf_filtered (stream, "%s", decorations->complex_suffix); } +/* generic_value_print helper for TYPE_CODE_COMPLEX. */ + +static void +generic_value_print_complex (struct value *val, struct ui_file *stream, + const struct value_print_options *options, + const struct generic_val_print_decorations + *decorations) +{ + fprintf_filtered (stream, "%s", decorations->complex_prefix); + + struct type *type = check_typedef (value_type (val)); + struct value *real_part + = value_from_component (val, TYPE_TARGET_TYPE (type), 0); + value_print_scalar_formatted (real_part, options, 0, stream); + fprintf_filtered (stream, "%s", decorations->complex_infix); + + struct value *imag_part + = value_from_component (val, TYPE_TARGET_TYPE (type), + TYPE_LENGTH (TYPE_TARGET_TYPE (type))); + + value_print_scalar_formatted (imag_part, options, 0, stream); + fprintf_filtered (stream, "%s", decorations->complex_suffix); +} + /* A generic val_print that is suitable for use by language implementations of the la_val_print method. This function can handle most type codes, though not all, notably exception @@ -1180,8 +1204,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse, break; case TYPE_CODE_COMPLEX: - generic_val_print_complex (type, 0, stream, - val, options, decorations); + generic_value_print_complex (val, stream, options, decorations); break; case TYPE_CODE_UNION: