public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert set_location_spec_string to a method
@ 2022-06-17  9:23 Pedro Alves
  0 siblings, 0 replies; only message in thread
From: Pedro Alves @ 2022-06-17  9:23 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dac9773e17261f905d51684fe35da036e82c69cd

commit dac9773e17261f905d51684fe35da036e82c69cd
Author: Pedro Alves <pedro@palves.net>
Date:   Fri May 27 16:53:49 2022 +0100

    Convert set_location_spec_string to a method
    
    This converts set_location_spec_string to a method of location_spec,
    and makes the location_spec::as_string field protected, renaming it to
    m_as_string along the way.
    
    Change-Id: Iccfb1654e9fa7808d0512df89e775f9eacaeb9e0

Diff:
---
 gdb/linespec.c |  2 +-
 gdb/location.c | 13 ++-----------
 gdb/location.h | 31 ++++++++++++++++---------------
 3 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 5c75e2ec979..10dca95e767 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2015,7 +2015,7 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
   /* If this location originally came from a linespec, save a string
      representation of it for display and saving to file.  */
   if (state->is_linespec)
-    set_location_spec_string (explicit_loc, explicit_loc->to_linespec ());
+    explicit_loc->set_string (explicit_loc->to_linespec ());
 }
 
 /* Given a line offset in LS, construct the relevant SALs.  */
diff --git a/gdb/location.c b/gdb/location.c
index e22ee414070..2b31baa4c85 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -60,7 +60,7 @@ probe_location_spec::empty_p () const
 
 std::string probe_location_spec::compute_string () const
 {
-  return std::move (as_string);
+  return std::move (m_as_string);
 }
 
 /* A "normal" linespec.  */
@@ -131,7 +131,7 @@ address_location_spec::address_location_spec (CORE_ADDR addr,
     address (addr)
 {
   if (addr_string != nullptr)
-    as_string = std::string (addr_string, addr_string_len);
+    m_as_string = std::string (addr_string, addr_string_len);
 }
 
 location_spec_up
@@ -857,12 +857,3 @@ string_to_location_spec (const char **stringp,
      spec.  */
   return string_to_location_spec_basic (stringp, language, match_type);
 }
-
-/* See description in location.h.  */
-
-void
-set_location_spec_string (struct location_spec *locspec,
-			  std::string &&string)
-{
-  locspec->as_string = std::move (string);
-}
diff --git a/gdb/location.h b/gdb/location.h
index cc9dfe4d7fa..fd0b320628d 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -91,11 +91,17 @@ struct location_spec
      The result is cached in the locspec.  */
   const char *to_string () const
   {
-    if (as_string.empty ())
-      as_string = compute_string ();
-    if (as_string.empty ())
+    if (m_as_string.empty ())
+      m_as_string = compute_string ();
+    if (m_as_string.empty ())
       return nullptr;
-    return as_string.c_str ();
+    return m_as_string.c_str ();
+  }
+
+  /* Set this location spec's string representation.  */
+  void set_string (std::string &&string)
+  {
+    m_as_string = std::move (string);
   }
 
   /* Return this location spec's type.  */
@@ -104,10 +110,6 @@ struct location_spec
     return m_type;
   }
 
-  /* Cached string representation of this location spec.  This is
-     used, e.g., to save location specs to file.  */
-  mutable std::string as_string;
-
 protected:
 
   explicit location_spec (enum location_spec_type t)
@@ -116,13 +118,13 @@ protected:
   }
 
   location_spec (enum location_spec_type t, std::string &&str)
-    : as_string (std::move (str)),
+    : m_as_string (std::move (str)),
       m_type (t)
   {
   }
 
   location_spec (const location_spec &other)
-    : as_string (other.as_string),
+    : m_as_string (other.m_as_string),
       m_type (other.m_type)
   {
   }
@@ -131,6 +133,10 @@ protected:
      by to_string when needed.  */
   virtual std::string compute_string () const = 0;
 
+  /* Cached string representation of this location spec.  This is
+     used, e.g., to save location specs to file.  */
+  mutable std::string m_as_string;
+
 private:
   /* The type of this location specification.  */
   enum location_spec_type m_type;
@@ -361,9 +367,4 @@ extern location_spec_up
 				    const struct language_defn *language,
 				    explicit_completion_info *completion_info);
 
-/* Set the location specs's string representation.  */
-
-extern void set_location_spec_string (struct location_spec *locspec,
-				      std::string &&string);
-
 #endif /* LOCATION_H */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-17  9:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17  9:23 [binutils-gdb] Convert set_location_spec_string to a method Pedro Alves

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).