Convert block_static_block and block_global_block to methods
authorTom Tromey <tom@tromey.com>
Tue, 17 Jan 2023 01:14:47 +0000 (18:14 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 19 Feb 2023 19:51:06 +0000 (12:51 -0700)
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.

12 files changed:
gdb/ada-lang.c
gdb/block.c
gdb/block.h
gdb/compile/compile-c-symbols.c
gdb/compile/compile-cplus-symbols.c
gdb/cp-namespace.c
gdb/cp-support.c
gdb/findvar.c
gdb/guile/scm-block.c
gdb/python/py-block.c
gdb/rust-parse.c
gdb/symtab.c

index e7e40cc140a4f07bd2e5214672ffd2113cbabdce..1f381a268f8f067e113a29231f280fe5a5d80046 100644 (file)
@@ -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;
index 31916ce48dc75bd597e251cab8a07b9115d551ac..c0d6ed7da9759ff8a0de52bf533c9fecfaf976e3 100644 (file)
@@ -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 ();
 
index 9f1ba935abb2bba077d0f2bd9dacb2ab5273b54e..9ce8ef519457d882122265d22cfa28bae81db16a 100644 (file)
@@ -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);
index 7af0bff56814e2a210b33130654cefb7a44c0409..73b4c4db4187e74d131ec2eb3c7858ac21997735 100644 (file)
@@ -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.  */
index c183d089d70234b2b64c8feb46b5bc72eeb2bc3b..02b7b898a646eccc8a4f812e2a50b0a24514c538 100644 (file)
@@ -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,
index 2d44b7bc04796ef6c17376055d7023892654177b..14d807694b7e9e5f80002a7c8519a19f8ee498ef 100644 (file)
@@ -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)
        {
index fd5a286b7792887f6161fb47c08a9268133b5f57..c434d5aade4f5df45881236892b6d65ca204c368 100644 (file)
@@ -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.  */
index 528181d4f01a6bf30bb1cfa0fa304b0f2c91e25e..806f41d0afa202fd1bdbb4cb828204ddd89f011f 100644 (file)
@@ -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;
index 02cd3ff9a4347b90cae389445999342f6dddf01f..c9d847a4d6060c93a709c7921447f0c68bd60bb1 100644 (file)
@@ -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);
 }
index c399a01c4fb257bf65e9e2344836d863d3ea493d..bd2ce7fc1818063d5d422e38918ecb168ff923ad 100644 (file)
@@ -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);
 }
index 9074d651d85c8525bce3b80a2c5175b5c7877a2a..545d0141183f2be870c74d5180e2cbc3f208add3 100644 (file)
@@ -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 ();
     }
 }
 
index bd6abbf7319a3428b0e219e0a20a47643bac5b48..d6dc323e83f11b3f47848056426b919440cb050f 100644 (file)
@@ -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)
       {