public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert block_static_block and block_global_block to methods
@ 2023-02-19 23:38 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-02-19 23:38 UTC (permalink / raw)
  To: gdb-cvs

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

commit d24e14a0c62181b49f513f6ed3704212fd276c79
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Jan 16 18:14:47 2023 -0700

    Convert block_static_block and block_global_block to methods
    
    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.

Diff:
---
 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 e7e40cc140a..1f381a268f8 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13798,7 +13798,7 @@ public:
     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 7af0bff5681..73b4c4db418 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 c183d089d70..02b7b898a64 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 fd5a286b779..c434d5aade4 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1308,13 +1308,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);
     }
@@ -1458,10 +1458,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 528181d4f01..806f41d0afa 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 bd6abbf7319..d6dc323e83f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2159,7 +2159,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.  */
@@ -2463,7 +2463,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)
@@ -2598,7 +2598,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)
     {
@@ -5831,8 +5831,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)
       {

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

only message in thread, other threads:[~2023-02-19 23:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 23:38 [binutils-gdb] Convert block_static_block and block_global_block to methods Tom Tromey

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