public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 13/27] Convert block_static_block and block_global_block to methods
Date: Fri, 20 Jan 2023 14:46:04 -0700	[thread overview]
Message-ID: <20230120214618.3236224-14-tom@tromey.com> (raw)
In-Reply-To: <20230120214618.3236224-1-tom@tromey.com>

This converts block_static_block and block_global_block to be methods.
This was mostly written by script.  It was simpler to convert them at
the same time because they're often used near each other.
---
 gdb/ada-lang.c                      |  2 +-
 gdb/block.c                         | 18 ++++++++++--------
 gdb/block.h                         | 13 +++++++++----
 gdb/compile/compile-c-symbols.c     |  6 +++---
 gdb/compile/compile-cplus-symbols.c |  4 ++--
 gdb/cp-namespace.c                  |  2 +-
 gdb/cp-support.c                    |  8 ++++----
 gdb/findvar.c                       |  6 +++---
 gdb/guile/scm-block.c               |  4 ++--
 gdb/python/py-block.c               |  4 ++--
 gdb/rust-parse.c                    |  2 +-
 gdb/symtab.c                        | 10 +++++-----
 12 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2602700e0ce..57676f0de95 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13818,7 +13818,7 @@ class ada_language : public language_defn
     sym = ada_lookup_symbol (name,
 			     (block == nullptr
 			      ? nullptr
-			      : block_static_block (block)),
+			      : block->static_block ()),
 			     domain);
     if (sym.symbol != NULL)
       return sym;
diff --git a/gdb/block.c b/gdb/block.c
index 31916ce48dc..c0d6ed7da97 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -47,7 +47,7 @@ block::objfile () const
   if (function () != nullptr)
     return function ()->objfile ();
 
-  global_block = (struct global_block *) block_global_block (this);
+  global_block = (struct global_block *) this->global_block ();
   return global_block->compunit_symtab->objfile ();
 }
 
@@ -349,26 +349,28 @@ block::set_using (struct using_direct *using_decl, struct obstack *obstack)
   m_namespace_info->using_decl = using_decl;
 }
 
-/* Return the static block associated to BLOCK.  Return NULL if block
-   is a global block.  */
+/* See block.h.  */
 
 const struct block *
-block_static_block (const struct block *block)
+block::static_block () const
 {
-  if (block->superblock () == NULL)
-    return NULL;
+  if (superblock () == nullptr)
+    return nullptr;
 
+  const block *block = this;
   while (block->superblock ()->superblock () != NULL)
     block = block->superblock ();
 
   return block;
 }
 
-/* Return the static block associated to BLOCK.  */
+/* See block.h.  */
 
 const struct block *
-block_global_block (const struct block *block)
+block::global_block () const
 {
+  const block *block = this;
+
   while (block->superblock () != NULL)
     block = block->superblock ();
 
diff --git a/gdb/block.h b/gdb/block.h
index 9f1ba935abb..9ce8ef51945 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -245,6 +245,15 @@ struct block
 
   struct symbol *containing_function () const;
 
+  /* Return the static block associated with this block.  Return NULL
+     if block is a global block.  */
+
+  const struct block *static_block () const;
+
+  /* Return the static block associated with block.  */
+
+  const struct block *global_block () const;
+
   /* Addresses in the executable code that are in this block.  */
 
   CORE_ADDR m_start;
@@ -404,10 +413,6 @@ extern const struct block *block_for_pc (CORE_ADDR);
 
 extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);
 
-extern const struct block *block_static_block (const struct block *block);
-
-extern const struct block *block_global_block (const struct block *block);
-
 extern struct block *allocate_block (struct obstack *obstack);
 
 extern struct block *allocate_global_block (struct obstack *obstack);
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 79490b811c3..678cbcd5c44 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -228,7 +228,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier,
 
   const struct block *static_block = nullptr;
   if (sym.block != nullptr)
-    static_block = block_static_block (sym.block);
+    static_block = sym.block->static_block ();
   /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block.  */
   is_local_symbol = (sym.block != static_block && static_block != NULL);
   if (is_local_symbol)
@@ -239,7 +239,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier,
       /* If the outer symbol is in the static block, we ignore it, as
 	 it cannot be referenced.  */
       if (global_sym.symbol != NULL
-	  && global_sym.block != block_static_block (global_sym.block))
+	  && global_sym.block != global_sym.block->static_block ())
 	{
 	  if (compile_debug)
 	    gdb_printf (gdb_stdlog,
@@ -617,7 +617,7 @@ generate_c_for_variable_locations (compile_instance *compiler,
   if (block == nullptr)
     return {};
 
-  const struct block *static_block = block_static_block (block);
+  const struct block *static_block = block->static_block ();
 
   /* If we're already in the static or global block, there is nothing
      to write.  */
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 45a76eef303..eff04406fb5 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -241,7 +241,7 @@ convert_symbol_sym (compile_cplus_instance *instance,
 
   const struct block *static_block = nullptr;
   if (sym.block != nullptr)
-    static_block = block_static_block (sym.block);
+    static_block = sym.block->static_block ();
   /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block.  */
   bool is_local_symbol = (sym.block != static_block && static_block != nullptr);
   if (is_local_symbol)
@@ -252,7 +252,7 @@ convert_symbol_sym (compile_cplus_instance *instance,
       /* If the outer symbol is in the static block, we ignore it, as
 	 it cannot be referenced.  */
       if (global_sym.symbol != nullptr
-	  && global_sym.block != block_static_block (global_sym.block))
+	  && global_sym.block != global_sym.block->static_block ())
 	{
 	  if (compile_debug)
 	    gdb_printf (gdb_stdlog,
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 2d44b7bc047..14d807694b7 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -141,7 +141,7 @@ cp_basic_lookup_symbol (const char *name, const struct block *block,
 	 but should be treated as local to a single file nonetheless.
 	 So we only search the current file's global block.  */
 
-      const struct block *global_block = block_global_block (block);
+      const struct block *global_block = block->global_block ();
 
       if (global_block != NULL)
 	{
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 76407fdeb2f..cdaf5fd3e8e 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1307,13 +1307,13 @@ add_symbol_overload_list_namespace (const char *func_name,
 
   /* Look in the static block.  */
   block = get_selected_block (0);
-  block = block == nullptr ? nullptr : block_static_block (block);
+  block = block == nullptr ? nullptr : block->static_block ();
   if (block != nullptr)
     {
       add_symbol_overload_list_block (name, block, overload_list);
 
       /* Look in the global block.  */
-      block = block_global_block (block);
+      block = block->global_block ();
       if (block)
 	add_symbol_overload_list_block (name, block, overload_list);
     }
@@ -1457,10 +1457,10 @@ add_symbol_overload_list_qualified (const char *func_name,
        b = b->superblock ())
     add_symbol_overload_list_block (func_name, b, overload_list);
 
-  surrounding_static_block = block_static_block (get_selected_block (0));
+  surrounding_static_block = get_selected_block (0);
   surrounding_static_block = (surrounding_static_block == nullptr
 			      ? nullptr
-			      : block_static_block (surrounding_static_block));
+			      : surrounding_static_block->static_block ());
 
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 656f982be2d..586ceb9dc72 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -460,8 +460,8 @@ get_hosting_frame (struct symbol *var, const struct block *var_block,
      tests that embed global/static symbols with null location lists.
      We want to get <optimized out> instead of <frame required> when evaluating
      them so return a frame instead of raising an error.  */
-  else if (var_block == block_global_block (var_block)
-	   || var_block == block_static_block (var_block))
+  else if (var_block == var_block->global_block ()
+	   || var_block == var_block->static_block ())
     return frame;
 
   /* We have to handle the "my_func::my_local_var" notation.  This requires us
@@ -486,7 +486,7 @@ get_hosting_frame (struct symbol *var, const struct block *var_block,
 
       /* If we failed to find the proper frame, fallback to the heuristic
 	 method below.  */
-      else if (frame_block == block_global_block (frame_block))
+      else if (frame_block == frame_block->global_block ())
 	{
 	  frame = NULL;
 	  break;
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index 02cd3ff9a43..c9d847a4d60 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -438,7 +438,7 @@ gdbscm_block_global_block (SCM self)
   const struct block *block = b_smob->block;
   const struct block *global_block;
 
-  global_block = block_global_block (block);
+  global_block = block->global_block ();
 
   return bkscm_scm_from_block (global_block, b_smob->objfile);
 }
@@ -458,7 +458,7 @@ gdbscm_block_static_block (SCM self)
   if (block->superblock () == NULL)
     return SCM_BOOL_F;
 
-  static_block = block_static_block (block);
+  static_block = block->static_block ();
 
   return bkscm_scm_from_block (static_block, b_smob->objfile);
 }
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index c399a01c4fb..bd2ce7fc181 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -188,7 +188,7 @@ blpy_get_global_block (PyObject *self, void *closure)
 
   BLPY_REQUIRE_VALID (self, block);
 
-  global_block = block_global_block (block);
+  global_block = block->global_block ();
 
   return block_to_block_object (global_block,
 				self_obj->objfile);
@@ -210,7 +210,7 @@ blpy_get_static_block (PyObject *self, void *closure)
   if (block->superblock () == NULL)
     Py_RETURN_NONE;
 
-  static_block = block_static_block (block);
+  static_block = block->static_block ();
 
   return block_to_block_object (static_block, self_obj->objfile);
 }
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 9074d651d85..545d0141183 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -421,7 +421,7 @@ munge_name_and_block (const char **name, const struct block **block)
   if (startswith (*name, "::"))
     {
       *name += 2;
-      *block = block_static_block (*block);
+      *block = (*block)->static_block ();
     }
 }
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 71b9ebe9efc..dd9cc7d5163 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2183,7 +2183,7 @@ lookup_local_symbol (const char *name,
     return {};
 
   struct symbol *sym;
-  const struct block *static_block = block_static_block (block);
+  const struct block *static_block = block->static_block ();
   const char *scope = block->scope ();
   
   /* Check if it's a global block.  */
@@ -2489,7 +2489,7 @@ lookup_symbol_in_static_block (const char *name,
   if (block == nullptr)
     return {};
 
-  const struct block *static_block = block_static_block (block);
+  const struct block *static_block = block->static_block ();
   struct symbol *sym;
 
   if (static_block == NULL)
@@ -2624,7 +2624,7 @@ lookup_global_symbol (const char *name,
      global block first.  This yields "more expected" behavior, and is
      needed to support 'FILENAME'::VARIABLE lookups.  */
   const struct block *global_block
-    = block == nullptr ? nullptr : block_global_block (block);
+    = block == nullptr ? nullptr : block->global_block ();
   symbol *sym = NULL;
   if (global_block != nullptr)
     {
@@ -5861,8 +5861,8 @@ default_collect_symbol_completion_matches_break_on
      visible from current context.  */
 
   b = get_selected_block (0);
-  surrounding_static_block = b == nullptr ? nullptr : block_static_block (b);
-  surrounding_global_block = b == nullptr : nullptr : block_global_block (b);
+  surrounding_static_block = b == nullptr ? nullptr : b->static_block ();
+  surrounding_global_block = b == nullptr ? nullptr : b->global_block ();
   if (surrounding_static_block != NULL)
     while (b != surrounding_static_block)
       {
-- 
2.39.0


  parent reply	other threads:[~2023-01-20 21:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 21:45 [PATCH 00/27] C++-ify struct block Tom Tromey
2023-01-20 21:45 ` [PATCH 01/27] Rearrange block.c to avoid a forward declaration Tom Tromey
2023-01-20 21:45 ` [PATCH 02/27] Avoid extra allocations in block Tom Tromey
2023-01-20 21:45 ` [PATCH 03/27] Don't allow NULL as an argument to block_scope Tom Tromey
2023-01-20 21:45 ` [PATCH 04/27] Don't allow NULL as an argument to block_using Tom Tromey
2023-01-20 21:45 ` [PATCH 05/27] Don't allow NULL as an argument to block_static_block Tom Tromey
2023-01-20 21:45 ` [PATCH 06/27] Don't allow NULL as an argument to block_global_block Tom Tromey
2023-01-20 21:45 ` [PATCH 07/27] Convert block_objfile to method Tom Tromey
2023-01-20 21:45 ` [PATCH 08/27] Convert block_gdbarch " Tom Tromey
2023-01-20 21:46 ` [PATCH 09/27] Convert block_inlined_p " Tom Tromey
2023-01-20 21:46 ` [PATCH 10/27] Convert more block functions to methods Tom Tromey
2023-01-20 21:46 ` [PATCH 11/27] Convert block_linkage_function to method Tom Tromey
2023-01-20 21:46 ` [PATCH 12/27] Convert block_containing_function " Tom Tromey
2023-01-20 21:46 ` Tom Tromey [this message]
2023-01-20 21:46 ` [PATCH 14/27] Convert set_block_compunit_symtab " Tom Tromey
2023-01-20 21:46 ` [PATCH 15/27] Convert block_static_link " Tom Tromey
2023-01-20 21:46 ` [PATCH 16/27] Store 'name' in block_iterator Tom Tromey
2023-01-20 21:46 ` [PATCH 17/27] Combine both styles of block iterator Tom Tromey
2023-01-20 21:46 ` [PATCH 18/27] Introduce a block iterator wrapper Tom Tromey
2023-01-20 21:46 ` [PATCH 19/27] Convert explicit iterator uses to foreach Tom Tromey
2023-01-20 21:46 ` [PATCH 20/27] Remove ALL_BLOCK_SYMBOLS_WITH_NAME Tom Tromey
2023-01-20 21:46 ` [PATCH 21/27] Remove ALL_BLOCK_SYMBOLS Tom Tromey
2023-01-20 21:46 ` [PATCH 22/27] Fix memory leak in mdebugread.c Tom Tromey
2023-01-20 21:46 ` [PATCH 23/27] Use 'new' for block and global_block Tom Tromey
2023-01-20 21:46 ` [PATCH 24/27] Have global_block inherit from block Tom Tromey
2023-01-20 21:46 ` [PATCH 25/27] Remove allocate_block and allocate_global_block Tom Tromey
2023-01-20 21:46 ` [PATCH 26/27] Make block members 'private' Tom Tromey
2023-01-20 21:46 ` [PATCH 27/27] Convert contained_in to method 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=20230120214618.3236224-14-tom@tromey.com \
    --to=tom@tromey.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).