public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/6] Hide the implementation of gdb_mpf
Date: Thu, 23 Feb 2023 12:48:04 -0700	[thread overview]
Message-ID: <20230223-submit-gmp-hiding-v1-6-ea6ff9e32716@adacore.com> (raw)
In-Reply-To: <20230223-submit-gmp-hiding-v1-0-ea6ff9e32716@adacore.com>

This renames the data member of gdb_mpf and makes it private.  It also
adds a single new method to aid in this change.  Unlike the earlier
changes here, I did this one all together because gdb_mpf has very few
uses.
---
 gdb/gmp-utils.h | 17 ++++++++++++-----
 gdb/valprint.c  |  2 +-
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
index 7889756a0ea..274c28c0ce8 100644
--- a/gdb/gmp-utils.h
+++ b/gdb/gmp-utils.h
@@ -388,10 +388,8 @@ struct gdb_mpq
 
 struct gdb_mpf
 {
-  mpf_t val;
-
   /* Constructors.  */
-  gdb_mpf () { mpf_init (val); }
+  gdb_mpf () { mpf_init (m_val); }
 
   DISABLE_COPY_AND_ASSIGN (gdb_mpf);
 
@@ -409,11 +407,20 @@ 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.m_val);
+    mpf_set_q (m_val, tmp_q.m_val);
   }
 
+  /* Convert this value to a string.  FMT is the format to use, and
+     should have a single '%' substitution.  */
+  std::string str (const char *fmt) const
+  { return gmp_string_printf (fmt, m_val); }
+
   /* The destructor.  */
-  ~gdb_mpf () { mpf_clear (val); }
+  ~gdb_mpf () { mpf_clear (m_val); }
+
+private:
+
+  mpf_t m_val;
 };
 
 /* See declaration above.  */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 357db3815b0..b05d90dd26b 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -856,7 +856,7 @@ generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
 			  type->fixed_point_scaling_factor ());
 
       const char *fmt = type->length () < 4 ? "%.11Fg" : "%.17Fg";
-      std::string str = gmp_string_printf (fmt, f.val);
+      std::string str = f.str (fmt);
       gdb_printf (stream, "%s", str.c_str ());
     }
 }

-- 
2.39.1


  parent reply	other threads:[~2023-02-23 19:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 19:47 [PATCH 0/6] Make GMP data members private Tom Tromey
2023-02-23 19:47 ` [PATCH 1/6] Clean up gmp-utils.h includes Tom Tromey
2023-02-23 19:48 ` [PATCH 2/6] Add methods and operators to gdb_mpz Tom Tromey
2023-02-23 19:48 ` [PATCH 3/6] Rename gdb_mpz::val and make contents private Tom Tromey
2023-02-23 19:48 ` [PATCH 4/6] Add operators and methods to gdb_mpq Tom Tromey
2023-02-23 19:48 ` [PATCH 5/6] Rename gdb_mpq::val and make contents private Tom Tromey
2023-02-23 19:48 ` Tom Tromey [this message]
2023-03-14 14:15 ` [PATCH 0/6] Make GMP data members private Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230223-submit-gmp-hiding-v1-6-ea6ff9e32716@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).