From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 729E03858C2F; Tue, 14 Mar 2023 14:19:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 729E03858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678803581; bh=8mC52MsKRCfwGN0YTW8NCmvD0z1vLChKnzrAHe8z0oY=; h=From:To:Subject:Date:From; b=Blb4U+BBjMS99Fy6Yx/PyyjjFxOOGJSZdCdoOinfZzhtVTByqEZ/CLuldGqBNLpMh 80lAakuJHdSWzGbc7sFjRiqeQdj15bW31CitaC2cJm+LvHwF42giV5QSWevGEfSNV+ X25xQyakz0bl6mGNup+JG+CMDr3/WVFoTPs5xGsY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Rename gdb_mpz::val and make contents private X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 302273ca843fc3ddbe8210e6d30459316bf04f0e X-Git-Newrev: 7aeae94f88791399ca4b50f850c36180de420e92 Message-Id: <20230314141941.729E03858C2F@sourceware.org> Date: Tue, 14 Mar 2023 14:19:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7aeae94f8879= 1399ca4b50f850c36180de420e92 commit 7aeae94f88791399ca4b50f850c36180de420e92 Author: Tom Tromey Date: Thu Feb 23 10:05:58 2023 -0700 Rename gdb_mpz::val and make contents private =20 This changes gdb_mpz to hide its data, and renames the data member from 'val' to 'm_val', following gdb convention. Diff: --- gdb/gmp-utils.c | 46 ++++++++++++++++++------------------- gdb/gmp-utils.h | 70 +++++++++++++++++++++++++++++++----------------------= ---- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c index 8150fa5dcdf..aaa075e236e 100644 --- a/gdb/gmp-utils.c +++ b/gdb/gmp-utils.c @@ -46,7 +46,7 @@ void gdb_mpz::read (gdb::array_view buf, enum bfd_endian byte_o= rder, bool unsigned_p) { - mpz_import (val, 1 /* count */, -1 /* order */, buf.size () /* size */, + mpz_import (m_val, 1 /* count */, -1 /* order */, buf.size () /* size */, byte_order =3D=3D BFD_ENDIAN_BIG ? 1 : -1 /* endian */, 0 /* nails */, buf.data () /* op */); =20 @@ -57,9 +57,9 @@ gdb_mpz::read (gdb::array_view buf, enum = bfd_endian byte_order, was in fact negative, we need to adjust VAL accordingly. */ gdb_mpz max; =20 - mpz_ui_pow_ui (max.val, 2, buf.size () * HOST_CHAR_BIT - 1); - if (mpz_cmp (val, max.val) >=3D 0) - mpz_submul_ui (val, max.val, 2); + mpz_ui_pow_ui (max.m_val, 2, buf.size () * HOST_CHAR_BIT - 1); + if (mpz_cmp (m_val, max.m_val) >=3D 0) + mpz_submul_ui (m_val, max.m_val, 2); } } =20 @@ -81,7 +81,7 @@ gdb_mpz::safe_export (gdb::array_view buf, { gdb_assert (buf.size () > 0); =20 - if (mpz_sgn (val) =3D=3D 0) + if (mpz_sgn (m_val) =3D=3D 0) { /* Our value is zero, so no need to call mpz_export to do the work, especially since mpz_export's documentation explicitly says @@ -100,19 +100,19 @@ gdb_mpz::safe_export (gdb::array_view buf, { lo =3D 0; =20 - mpz_ui_pow_ui (hi.val, 2, max_usable_bits); - mpz_sub_ui (hi.val, hi.val, 1); + mpz_ui_pow_ui (hi.m_val, 2, max_usable_bits); + mpz_sub_ui (hi.m_val, hi.m_val, 1); } else { - mpz_ui_pow_ui (lo.val, 2, max_usable_bits - 1); - mpz_neg (lo.val, lo.val); + mpz_ui_pow_ui (lo.m_val, 2, max_usable_bits - 1); + mpz_neg (lo.m_val, lo.m_val); =20 - mpz_ui_pow_ui (hi.val, 2, max_usable_bits - 1); - mpz_sub_ui (hi.val, hi.val, 1); + mpz_ui_pow_ui (hi.m_val, 2, max_usable_bits - 1); + mpz_sub_ui (hi.m_val, hi.m_val, 1); } =20 - if (mpz_cmp (val, lo.val) < 0 || mpz_cmp (val, hi.val) > 0) + if (mpz_cmp (m_val, lo.m_val) < 0 || mpz_cmp (m_val, hi.m_val) > 0) error (_("Cannot export value %s as %zu-bits %s integer" " (must be between %s and %s)"), this->str ().c_str (), @@ -121,17 +121,17 @@ gdb_mpz::safe_export (gdb::array_view buf, lo.str ().c_str (), hi.str ().c_str ()); =20 - gdb_mpz exported_val (val); + gdb_mpz exported_val (m_val); =20 - if (mpz_cmp_ui (exported_val.val, 0) < 0) + if (mpz_cmp_ui (exported_val.m_val, 0) < 0) { /* mpz_export does not handle signed values, so create a positive value whose bit representation as an unsigned of the same length would be the same as our negative value. */ gdb_mpz neg_offset; =20 - mpz_ui_pow_ui (neg_offset.val, 2, buf.size () * HOST_CHAR_BIT); - mpz_add (exported_val.val, exported_val.val, neg_offset.val); + mpz_ui_pow_ui (neg_offset.m_val, 2, buf.size () * HOST_CHAR_BIT); + mpz_add (exported_val.m_val, exported_val.m_val, neg_offset.m_val); } =20 /* Do the export into a buffer allocated by GMP itself; that way, @@ -147,7 +147,7 @@ gdb_mpz::safe_export (gdb::array_view buf, size_t word_countp; gdb::unique_xmalloc_ptr exported (mpz_export (NULL, &word_countp, -1 /* order */, buf.size () /* size *= /, - endian, 0 /* nails */, exported_val.val)); + endian, 0 /* nails */, exported_val.m_val)); =20 gdb_assert (word_countp =3D=3D 1); =20 @@ -170,19 +170,19 @@ gdb_mpq::get_rounded () const towards zero. */ =20 gdb_mpz quotient, remainder; - mpz_fdiv_qr (quotient.val, remainder.val, + mpz_fdiv_qr (quotient.m_val, remainder.m_val, mpq_numref (abs_val.val), mpq_denref (abs_val.val)); =20 /* 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. */ =20 - mpz_mul_ui (remainder.val, remainder.val, 2); - if (mpz_cmp (remainder.val, mpq_denref (abs_val.val)) >=3D 0) - mpz_add_ui (quotient.val, quotient.val, 1); + mpz_mul_ui (remainder.m_val, remainder.m_val, 2); + if (mpz_cmp (remainder.m_val, mpq_denref (abs_val.val)) >=3D 0) + mpz_add_ui (quotient.m_val, quotient.m_val, 1); =20 /* Re-apply the sign if needed. */ if (mpq_sgn (val) < 0) - mpz_neg (quotient.val, quotient.val); + mpz_neg (quotient.m_val, quotient.m_val); =20 return quotient; } @@ -197,7 +197,7 @@ gdb_mpq::read_fixed_point (gdb::array_view buf, gdb_mpz vz; vz.read (buf, byte_order, unsigned_p); =20 - mpq_set_z (val, vz.val); + mpq_set_z (val, vz.m_val); mpq_mul (val, val, scaling_factor.val); } =20 diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h index 75e2273a322..3f43f5f835b 100644 --- a/gdb/gmp-utils.h +++ b/gdb/gmp-utils.h @@ -31,25 +31,26 @@ =20 std::string gmp_string_printf (const char *fmt, ...); =20 +struct gdb_mpq; +struct gdb_mpf; + /* A class to make it easier to use GMP's mpz_t values within GDB. */ =20 struct gdb_mpz { - mpz_t val; - /* Constructors. */ - gdb_mpz () { mpz_init (val); } + gdb_mpz () { mpz_init (m_val); } =20 explicit gdb_mpz (const mpz_t &from_val) { - mpz_init (val); - mpz_set (val, from_val); + mpz_init (m_val); + mpz_set (m_val, from_val); } =20 gdb_mpz (const gdb_mpz &from) { - mpz_init (val); - mpz_set (val, from.val); + mpz_init (m_val); + mpz_set (m_val, from.m_val); } =20 /* Initialize using the given integral value. @@ -59,26 +60,26 @@ struct gdb_mpz template>> explicit gdb_mpz (T src) { - mpz_init (val); + mpz_init (m_val); set (src); } =20 explicit gdb_mpz (gdb_mpz &&from) { - mpz_init (val); - mpz_swap (val, from.val); + mpz_init (m_val); + mpz_swap (m_val, from.m_val); } =20 =20 gdb_mpz &operator=3D (const gdb_mpz &from) { - mpz_set (val, from.val); + mpz_set (m_val, from.m_val); return *this; } =20 gdb_mpz &operator=3D (gdb_mpz &&other) { - mpz_swap (val, other.val); + mpz_swap (m_val, other.m_val); return *this; } =20 @@ -93,14 +94,14 @@ struct gdb_mpz the string was parsed successfully, false otherwise. */ bool set (const char *str, int base) { - return mpz_set_str (val, str, base) !=3D -1; + return mpz_set_str (m_val, str, base) !=3D -1; } =20 /* Return a new value that is BASE**EXP. */ static gdb_mpz pow (unsigned long base, unsigned long exp) { gdb_mpz result; - mpz_ui_pow_ui (result.val, base, exp); + mpz_ui_pow_ui (result.m_val, base, exp); return result; } =20 @@ -125,59 +126,59 @@ struct gdb_mpz bool unsigned_p) const; =20 /* Return a string containing VAL. */ - std::string str () const { return gmp_string_printf ("%Zd", val); } + std::string str () const { return gmp_string_printf ("%Zd", m_val); } =20 /* The destructor. */ - ~gdb_mpz () { mpz_clear (val); } + ~gdb_mpz () { mpz_clear (m_val); } =20 /* Negate this value in place. */ void negate () { - mpz_neg (val, val); + mpz_neg (m_val, m_val); } =20 gdb_mpz &operator*=3D (long other) { - mpz_mul_si (val, val, other); + mpz_mul_si (m_val, m_val, other); return *this; } =20 gdb_mpz &operator+=3D (unsigned long other) { - mpz_add_ui (val, val, other); + mpz_add_ui (m_val, m_val, other); return *this; } =20 gdb_mpz &operator-=3D (unsigned long other) { - mpz_sub_ui (val, val, other); + mpz_sub_ui (m_val, m_val, other); return *this; } =20 gdb_mpz &operator<<=3D (unsigned long nbits) { - mpz_mul_2exp (val, val, nbits); + mpz_mul_2exp (m_val, m_val, nbits); return *this; } =20 bool operator> (const gdb_mpz &other) const { - return mpz_cmp (val, other.val) > 0; + return mpz_cmp (m_val, other.m_val) > 0; } =20 bool operator< (int other) const { - return mpz_cmp_si (val, other) < 0; + return mpz_cmp_si (m_val, other) < 0; } =20 bool operator=3D=3D (int other) const { - return mpz_cmp_si (val, other) =3D=3D 0; + return mpz_cmp_si (m_val, other) =3D=3D 0; } =20 bool operator=3D=3D (const gdb_mpz &other) const { - return mpz_cmp (val, other.val) =3D=3D 0; + return mpz_cmp (m_val, other.m_val) =3D=3D 0; } =20 private: @@ -202,6 +203,11 @@ private: being exported. */ void safe_export (gdb::array_view buf, int endian, bool unsigned_p) const; + + friend struct gdb_mpq; + friend struct gdb_mpf; + + mpz_t m_val; }; =20 /* A class to make it easier to use GMP's mpq_t values within GDB. */ @@ -234,8 +240,8 @@ struct gdb_mpq gdb_mpq (const gdb_mpz &num, const gdb_mpz &denom) { mpq_init (val); - mpz_set (mpq_numref (val), num.val); - mpz_set (mpq_denref (val), denom.val); + mpz_set (mpq_numref (val), num.m_val); + mpz_set (mpq_denref (val), denom.m_val); mpq_canonicalize (val); } =20 @@ -254,7 +260,7 @@ struct gdb_mpq =20 gdb_mpq &operator=3D (const gdb_mpz &from) { - mpq_set_z (val, from.val); + mpq_set_z (val, from.m_val); return *this; } =20 @@ -268,7 +274,7 @@ struct gdb_mpq gdb_mpz as_integer () const { gdb_mpz result; - mpz_tdiv_q (result.val, mpq_numref (val), mpq_denref (val)); + mpz_tdiv_q (result.m_val, mpq_numref (val), mpq_denref (val)); return result; } =20 @@ -340,7 +346,7 @@ template void gdb_mpz::set (T src) { - mpz_import (val, 1 /* count */, -1 /* order */, + mpz_import (m_val, 1 /* count */, -1 /* order */, sizeof (T) /* size */, 0 /* endian (0 =3D native) */, 0 /* nails */, &src /* op */); if (std::is_signed::value && src < 0) @@ -350,8 +356,8 @@ gdb_mpz::set (T src) the correct negative value. */ gdb_mpz neg_offset; =20 - mpz_ui_pow_ui (neg_offset.val, 2, sizeof (T) * HOST_CHAR_BIT); - mpz_sub (val, val, neg_offset.val); + mpz_ui_pow_ui (neg_offset.m_val, 2, sizeof (T) * HOST_CHAR_BIT); + mpz_sub (m_val, m_val, neg_offset.m_val); } }