From patchwork Thu Feb 23 19:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65538 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B7F5385021E for ; Thu, 23 Feb 2023 19:49:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B7F5385021E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677181743; bh=jvHv1aYbbeYM4jOKEm4rMOs1oTRZ0KT/1rqbQhijY9U=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PGWrn7XSqDqw60e1zXg8qYY2aoplKPpJQHaL1Ce5Cc5HRlNFjsPNZhFgzubpSDPcV kXojiov7qnW2j21ioOwSrBUdLbJUMLU/pCoB5vmq3HPVT77wLqi5ZLeS0ntiskJrfQ o+hGbD2YNPzvFqiGRdz+U/AjA1J1spTFevVJkrgk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 63BB33857437 for ; Thu, 23 Feb 2023 19:48:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63BB33857437 Received: by mail-il1-x133.google.com with SMTP id i12so87568ila.5 for ; Thu, 23 Feb 2023 11:48:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jvHv1aYbbeYM4jOKEm4rMOs1oTRZ0KT/1rqbQhijY9U=; b=HIc+2N113kswLvh4qnDgDZ1D5E7u+2bWDyHVz7bBR0O5scwDe4AmtJ5Y9fda7PUG+P 4YgUHtXMHHVKTUFIsrMtvvPaY0FDbcPuiVolou4D03Mel37gD1+4f+VrCxW4QYGDsYTr NgNyvK4ErenBMG0ifvJyM8iEJjuABIx3Xj/rmRO9Oj89Z71HyFjDEGp1tHoVoXYjVTK4 1Jkbpex6MlD3zHC/hCsJ4HE+zA3YHCu81DL3THMeRE9VajzR8aGQLTM7wWcpCbyLNJdO ArIzoOVhon/lJintU0LyxdG5SZt9qd3kAG+grsc+kQQyLdIvNuab5SZ2CydZQD3dsmVL wjBQ== X-Gm-Message-State: AO0yUKVOtjrSSDYxuYRJ6Kv8CoLm8CzxMI8ZUT2e/eUMPVAgOQMW+ysb +02P/bkfFCSHPAz/Ks87AspRjaxK+atIiHUL X-Google-Smtp-Source: AK7set+eayRUXNhKrAHKJhTiZqMAoZ36qekkZqRFlJ/kSy2oKakdtq7rcl1CQjbQnTIt7SyKv3XGBg== X-Received: by 2002:a05:6e02:154c:b0:313:e397:ee95 with SMTP id j12-20020a056e02154c00b00313e397ee95mr10433410ilu.4.1677181685538; Thu, 23 Feb 2023 11:48:05 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id x4-20020a920604000000b00316e4139270sm2038351ilg.35.2023.02.23.11.48.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 11:48:05 -0800 (PST) Date: Thu, 23 Feb 2023 12:48:03 -0700 Subject: [PATCH 5/6] Rename gdb_mpq::val and make contents private MIME-Version: 1.0 Message-Id: <20230223-submit-gmp-hiding-v1-5-ea6ff9e32716@adacore.com> References: <20230223-submit-gmp-hiding-v1-0-ea6ff9e32716@adacore.com> In-Reply-To: <20230223-submit-gmp-hiding-v1-0-ea6ff9e32716@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes gdb_mpq to hide its data, and renames the data member from 'val' to 'm_val', following gdb convention. --- gdb/gmp-utils.c | 18 +++++++-------- gdb/gmp-utils.h | 72 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c index aaa075e236e..d134bc32a1d 100644 --- a/gdb/gmp-utils.c +++ b/gdb/gmp-utils.c @@ -162,8 +162,8 @@ gdb_mpq::get_rounded () const /* Work with a positive number so as to make the "floor" rounding always round towards zero. */ - gdb_mpq abs_val (val); - mpq_abs (abs_val.val, abs_val.val); + gdb_mpq abs_val (m_val); + mpq_abs (abs_val.m_val, abs_val.m_val); /* Convert our rational number into a quotient and remainder, with "floor" rounding, which in our case means rounding @@ -171,17 +171,17 @@ gdb_mpq::get_rounded () const gdb_mpz quotient, remainder; mpz_fdiv_qr (quotient.m_val, remainder.m_val, - mpq_numref (abs_val.val), mpq_denref (abs_val.val)); + mpq_numref (abs_val.m_val), mpq_denref (abs_val.m_val)); /* Multiply the remainder by 2, and see if it is greater or equal to abs_val's denominator. If yes, round to the next integer. */ mpz_mul_ui (remainder.m_val, remainder.m_val, 2); - if (mpz_cmp (remainder.m_val, mpq_denref (abs_val.val)) >= 0) + if (mpz_cmp (remainder.m_val, mpq_denref (abs_val.m_val)) >= 0) mpz_add_ui (quotient.m_val, quotient.m_val, 1); /* Re-apply the sign if needed. */ - if (mpq_sgn (val) < 0) + if (mpq_sgn (m_val) < 0) mpz_neg (quotient.m_val, quotient.m_val); return quotient; @@ -197,8 +197,8 @@ gdb_mpq::read_fixed_point (gdb::array_view buf, gdb_mpz vz; vz.read (buf, byte_order, unsigned_p); - mpq_set_z (val, vz.m_val); - mpq_mul (val, val, scaling_factor.val); + mpq_set_z (m_val, vz.m_val); + mpq_mul (m_val, m_val, scaling_factor.m_val); } /* See gmp-utils.h. */ @@ -208,9 +208,9 @@ gdb_mpq::write_fixed_point (gdb::array_view buf, enum bfd_endian byte_order, bool unsigned_p, const gdb_mpq &scaling_factor) const { - gdb_mpq unscaled (val); + gdb_mpq unscaled (m_val); - mpq_div (unscaled.val, unscaled.val, scaling_factor.val); + mpq_div (unscaled.m_val, unscaled.m_val, scaling_factor.m_val); gdb_mpz unscaled_z = unscaled.get_rounded (); unscaled_z.write (buf, byte_order, unsigned_p); diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h index dfb61302f6b..7889756a0ea 100644 --- a/gdb/gmp-utils.h +++ b/gdb/gmp-utils.h @@ -214,126 +214,124 @@ struct gdb_mpz struct gdb_mpq { - mpq_t val; - /* Constructors. */ - gdb_mpq () { mpq_init (val); } + gdb_mpq () { mpq_init (m_val); } explicit gdb_mpq (const mpq_t &from_val) { - mpq_init (val); - mpq_set (val, from_val); + mpq_init (m_val); + mpq_set (m_val, from_val); } gdb_mpq (const gdb_mpq &from) { - mpq_init (val); - mpq_set (val, from.val); + mpq_init (m_val); + mpq_set (m_val, from.m_val); } explicit gdb_mpq (gdb_mpq &&from) { - mpq_init (val); - mpq_swap (val, from.val); + mpq_init (m_val); + mpq_swap (m_val, from.m_val); } gdb_mpq (const gdb_mpz &num, const gdb_mpz &denom) { - mpq_init (val); - mpz_set (mpq_numref (val), num.m_val); - mpz_set (mpq_denref (val), denom.m_val); - mpq_canonicalize (val); + mpq_init (m_val); + mpz_set (mpq_numref (m_val), num.m_val); + mpz_set (mpq_denref (m_val), denom.m_val); + mpq_canonicalize (m_val); } gdb_mpq (long num, long denom) { - mpq_init (val); - mpq_set_si (val, num, denom); - mpq_canonicalize (val); + mpq_init (m_val); + mpq_set_si (m_val, num, denom); + mpq_canonicalize (m_val); } /* Copy assignment operator. */ gdb_mpq &operator= (const gdb_mpq &from) { - mpq_set (val, from.val); + mpq_set (m_val, from.m_val); return *this; } gdb_mpq &operator= (gdb_mpq &&from) { - mpq_swap (val, from.val); + mpq_swap (m_val, from.m_val); return *this; } gdb_mpq &operator= (const gdb_mpz &from) { - mpq_set_z (val, from.m_val); + mpq_set_z (m_val, from.m_val); return *this; } gdb_mpq &operator= (double d) { - mpq_set_d (val, d); + mpq_set_d (m_val, d); return *this; } /* Return the sign of this value. This returns -1 for a negative value, 0 if the value is 0, and 1 for a positive value. */ int sgn () const - { return mpq_sgn (val); } + { return mpq_sgn (m_val); } gdb_mpq operator+ (const gdb_mpq &other) const { gdb_mpq result; - mpq_add (result.val, val, other.val); + mpq_add (result.m_val, m_val, other.m_val); return result; } gdb_mpq operator- (const gdb_mpq &other) const { gdb_mpq result; - mpq_sub (result.val, val, other.val); + mpq_sub (result.m_val, m_val, other.m_val); return result; } gdb_mpq operator* (const gdb_mpq &other) const { gdb_mpq result; - mpq_mul (result.val, val, other.val); + mpq_mul (result.m_val, m_val, other.m_val); return result; } gdb_mpq operator/ (const gdb_mpq &other) const { gdb_mpq result; - mpq_div (result.val, val, other.val); + mpq_div (result.m_val, m_val, other.m_val); return result; } gdb_mpq &operator*= (const gdb_mpq &other) { - mpq_mul (val, val, other.val); + mpq_mul (m_val, m_val, other.m_val); return *this; } gdb_mpq &operator/= (const gdb_mpq &other) { - mpq_div (val, val, other.val); + mpq_div (m_val, m_val, other.m_val); return *this; } bool operator== (const gdb_mpq &other) const { - return mpq_cmp (val, other.val) == 0; + return mpq_cmp (m_val, other.m_val) == 0; } bool operator< (const gdb_mpq &other) const { - return mpq_cmp (val, other.val) < 0; + return mpq_cmp (m_val, other.m_val) < 0; } /* Return a string representing VAL as " / ". */ - std::string str () const { return gmp_string_printf ("%Qd", val); } + std::string str () const { return gmp_string_printf ("%Qd", m_val); } /* Return VAL rounded to the nearest integer. */ gdb_mpz get_rounded () const; @@ -342,13 +340,13 @@ struct gdb_mpq gdb_mpz as_integer () const { gdb_mpz result; - mpz_tdiv_q (result.m_val, mpq_numref (val), mpq_denref (val)); + mpz_tdiv_q (result.m_val, mpq_numref (m_val), mpq_denref (m_val)); return result; } /* Return this value converted to a host double. */ double as_double () const - { return mpq_get_d (val); } + { return mpq_get_d (m_val); } /* Set VAL from the contents of the given byte array (BUF), which contains the unscaled value of a fixed point type object. @@ -374,7 +372,13 @@ struct gdb_mpq const gdb_mpq &scaling_factor) const; /* The destructor. */ - ~gdb_mpq () { mpq_clear (val); } + ~gdb_mpq () { mpq_clear (m_val); } + +private: + + friend struct gdb_mpf; + + mpq_t m_val; }; /* A class to make it easier to use GMP's mpf_t values within GDB. @@ -405,7 +409,7 @@ struct gdb_mpf gdb_mpq tmp_q; tmp_q.read_fixed_point (buf, byte_order, unsigned_p, scaling_factor); - mpf_set_q (val, tmp_q.val); + mpf_set_q (val, tmp_q.m_val); } /* The destructor. */