From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.21]) by sourceware.org (Postfix) with ESMTPS id 107A93948451 for ; Fri, 20 Mar 2020 21:53:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 107A93948451 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway33.websitewelcome.com (Postfix) with ESMTP id AA11911B3A for ; Fri, 20 Mar 2020 16:53:42 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id FPaIjPOHT1s2xFPaIj7aXr; Fri, 20 Mar 2020 16:53:42 -0500 X-Authority-Reason: nr=8 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=hkIiMOXzCuXd832IJlJfy3Prbe5cb0Dd+zeydcvmjzM=; b=mHtgnPxokFcERELJ2d7pf60Vtq jcQgpWHejZNSIc4dcTHDKw5lQqalZql92G/M9Vt7bge9Y8DopeEJIxfcCLyPt27WWuOtEXM2fmWvW LGM+zd3YjgPVs36FkcfIXe6vc; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:35792 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jFPaI-003c6k-FJ; Fri, 20 Mar 2020 15:53:42 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 2/7] Add accessors for members of complex numbers Date: Fri, 20 Mar 2020 15:53:35 -0600 Message-Id: <20200320215340.16749-3-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200320215340.16749-1-tom@tromey.com> References: <20200320215340.16749-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.118.117.21 X-Source-L: No X-Exim-ID: 1jFPaI-003c6k-FJ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:35792 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-19.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 21:53:44 -0000 This introduces two new functions that make it simpler to access the components of a complex number. gdb/ChangeLog 2020-03-20 Tom Tromey * valprint.c (generic_value_print_complex): Use accessors. * value.h (value_real_part, value_imaginary_part): Declare. * valops.c (value_real_part, value_imaginary_part): New functions. * value.c (creal_internal_fn, cimag_internal_fn): Use accessors. --- gdb/ChangeLog | 8 ++++++++ gdb/valops.c | 25 +++++++++++++++++++++++++ gdb/valprint.c | 9 ++------- gdb/value.c | 5 ++--- gdb/value.h | 8 ++++++++ 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/gdb/valops.c b/gdb/valops.c index d48474665c3..83fd2584b59 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3877,6 +3877,31 @@ value_literal_complex (struct value *arg1, return val; } +/* See value.h. */ + +struct value * +value_real_part (struct value *value) +{ + struct type *type = check_typedef (value_type (value)); + struct type *ttype = TYPE_TARGET_TYPE (type); + + gdb_assert (TYPE_CODE (type) == TYPE_CODE_COMPLEX); + return value_from_component (value, ttype, 0); +} + +/* See value.h. */ + +struct value * +value_imaginary_part (struct value *value) +{ + struct type *type = check_typedef (value_type (value)); + struct type *ttype = TYPE_TARGET_TYPE (type); + + gdb_assert (TYPE_CODE (type) == TYPE_CODE_COMPLEX); + return value_from_component (value, ttype, + TYPE_LENGTH (check_typedef (ttype))); +} + /* Cast a value into the appropriate complex data type. */ static struct value * diff --git a/gdb/valprint.c b/gdb/valprint.c index 108a21b6849..80b7514b7e3 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -811,16 +811,11 @@ generic_value_print_complex (struct value *val, struct ui_file *stream, { 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); + struct value *real_part = value_real_part (val); 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))); - + struct value *imag_part = value_imaginary_part (val); value_print_scalar_formatted (imag_part, options, 0, stream); fprintf_filtered (stream, "%s", decorations->complex_suffix); } diff --git a/gdb/value.c b/gdb/value.c index ceaeb835fa7..f722c272d8b 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -3962,7 +3962,7 @@ creal_internal_fn (struct gdbarch *gdbarch, type *ctype = check_typedef (value_type (cval)); if (TYPE_CODE (ctype) != TYPE_CODE_COMPLEX) error (_("expected a complex number")); - return value_from_component (cval, TYPE_TARGET_TYPE (ctype), 0); + return value_real_part (cval); } /* Implementation of the convenience function $_cimag. Extracts the @@ -3981,8 +3981,7 @@ cimag_internal_fn (struct gdbarch *gdbarch, type *ctype = check_typedef (value_type (cval)); if (TYPE_CODE (ctype) != TYPE_CODE_COMPLEX) error (_("expected a complex number")); - return value_from_component (cval, TYPE_TARGET_TYPE (ctype), - TYPE_LENGTH (TYPE_TARGET_TYPE (ctype))); + return value_imaginary_part (cval); } #if GDB_SELF_TEST diff --git a/gdb/value.h b/gdb/value.h index e4fd258aa8f..85fe6c297f5 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1141,6 +1141,14 @@ extern struct value *value_slice (struct value *, int, int); extern struct value *value_literal_complex (struct value *, struct value *, struct type *); +/* Return the real part of a complex value. */ + +extern struct value *value_real_part (struct value *value); + +/* Return the imaginary part of a complex value. */ + +extern struct value *value_imaginary_part (struct value *value); + extern struct value *find_function_in_inferior (const char *, struct objfile **); -- 2.17.2