Convert more block functions to methods
authorTom Tromey <tom@tromey.com>
Tue, 17 Jan 2023 00:39:55 +0000 (17:39 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 19 Feb 2023 19:51:05 +0000 (12:51 -0700)
This converts block_scope, block_set_scope, block_using, and
block_set_using to be methods.  These are all done at once to make it
easier to also convert block_initialize_namespace at the same time.
This was mostly written by script.

13 files changed:
gdb/ada-lang.c
gdb/block.c
gdb/block.h
gdb/buildsym.c
gdb/cp-namespace.c
gdb/cp-support.c
gdb/d-namespace.c
gdb/dbxread.c
gdb/dwarf2/read.c
gdb/rust-lang.c
gdb/rust-lang.h
gdb/rust-parse.c
gdb/symtab.c

index a1de8c43bf2dfc8929e551dccb07fb8cd5d4ffb5..e063f58a1a284ec2e889f193c5769798cfba4bdd 100644 (file)
@@ -5424,7 +5424,7 @@ ada_add_block_renamings (std::vector<struct block_symbol> &result,
   symbol_name_matcher_ftype *name_match
     = ada_get_symbol_name_matcher (lookup_name);
 
-  for (renaming = block_using (block);
+  for (renaming = block->get_using ();
        renaming != NULL;
        renaming = renaming->next)
     {
index 574086aa4f6b29cca57403f75465d25c71013e8a..fc523332a3dafdc1ec3a9873791e383637621843 100644 (file)
@@ -285,40 +285,36 @@ block_for_pc (CORE_ADDR pc)
 /* Now come some functions designed to deal with C++ namespace issues.
    The accessors are safe to use even in the non-C++ case.  */
 
-/* This returns the namespace that BLOCK is enclosed in, or "" if it
-   isn't enclosed in a namespace at all.  This travels the chain of
-   superblocks looking for a scope, if necessary.  */
+/* See block.h.  */
 
 const char *
-block_scope (const struct block *block)
+block::scope () const
 {
-  for (; block != NULL; block = block->superblock ())
+  for (const block *block = this;
+       block != nullptr;
+       block = block->superblock ())
     {
-      if (block->namespace_info () != NULL
-         && block->namespace_info ()->scope != NULL)
-       return block->namespace_info ()->scope;
+      if (block->m_namespace_info != nullptr
+         && block->m_namespace_info->scope != nullptr)
+       return block->m_namespace_info->scope;
     }
 
   return "";
 }
 
-/* If block->namespace_info () is NULL, allocate it via OBSTACK and
-   initialize its members to zero.  */
+/* See block.h.  */
 
-static void
-block_initialize_namespace (struct block *block, struct obstack *obstack)
+void
+block::initialize_namespace (struct obstack *obstack)
 {
-  if (block->namespace_info () == NULL)
-    block->set_namespace_info (new (obstack) struct block_namespace_info ());
+  if (m_namespace_info == nullptr)
+    m_namespace_info = new (obstack) struct block_namespace_info;
 }
 
-/* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
-   OBSTACK.  (It won't make a copy of SCOPE, however, so that already
-   has to be allocated correctly.)  */
+/* See block.h.  */
 
 void
-block_set_scope (struct block *block, const char *scope,
-                struct obstack *obstack)
+block::set_scope (const char *scope, struct obstack *obstack)
 {
   if (scope == nullptr || scope[0] == '\0')
     {
@@ -326,31 +322,25 @@ block_set_scope (struct block *block, const char *scope,
       return;
     }
 
-  block_initialize_namespace (block, obstack);
-
-  block->namespace_info ()->scope = scope;
+  initialize_namespace (obstack);
+  m_namespace_info->scope = scope;
 }
 
-/* This returns the using directives list associated with BLOCK, if
-   any.  */
+/* See block.h.  */
 
 struct using_direct *
-block_using (const struct block *block)
+block::get_using () const
 {
-  if (block->namespace_info () == NULL)
-    return NULL;
+  if (m_namespace_info == nullptr)
+    return nullptr;
   else
-    return block->namespace_info ()->using_decl;
+    return m_namespace_info->using_decl;
 }
 
-/* Set BLOCK's using member to USING; if needed, allocate memory via
-   OBSTACK.  (It won't make a copy of USING, however, so that already
-   has to be allocated correctly.)  */
+/* See block.h.  */
 
 void
-block_set_using (struct block *block,
-                struct using_direct *using_decl,
-                struct obstack *obstack)
+block::set_using (struct using_direct *using_decl, struct obstack *obstack)
 {
   if (using_decl == nullptr)
     {
@@ -358,9 +348,8 @@ block_set_using (struct block *block,
       return;
     }
 
-  block_initialize_namespace (block, obstack);
-
-  block->namespace_info ()->using_decl = using_decl;
+  initialize_namespace (obstack);
+  m_namespace_info->using_decl = using_decl;
 }
 
 /* Return the static block associated to BLOCK.  Return NULL if block
index ab343b446981dfb34ddc75b58afa4abbdc3ee239..680b7d0161e1b43e12d4b61428d0cb578e0055b2 100644 (file)
@@ -147,14 +147,6 @@ struct block
   void set_multidict (multidictionary *multidict)
   { m_multidict = multidict; }
 
-  /* Return this block's namespace info.  */
-  block_namespace_info *namespace_info () const
-  { return m_namespace_info; }
-
-  /* Set this block's namespace info.  */
-  void set_namespace_info (block_namespace_info *namespace_info)
-  { m_namespace_info = namespace_info; }
-
   /* Return a view on this block's ranges.  */
   gdb::array_view<blockrange> ranges ()
   {
@@ -216,6 +208,29 @@ struct block
 
   bool inlined_p () const;
 
+  /* This returns the namespace that this block is enclosed in, or ""
+     if it isn't enclosed in a namespace at all.  This travels the
+     chain of superblocks looking for a scope, if necessary.  */
+
+  const char *scope () const;
+
+  /* Set this block's scope member to SCOPE; if needed, allocate
+     memory via OBSTACK.  (It won't make a copy of SCOPE, however, so
+     that already has to be allocated correctly.)  */
+
+  void set_scope (const char *scope, struct obstack *obstack);
+
+  /* This returns the using directives list associated with this
+     block, if any.  */
+
+  struct using_direct *get_using () const;
+
+  /* Set this block's using member to USING; if needed, allocate
+     memory via OBSTACK.  (It won't make a copy of USING, however, so
+     that already has to be allocated correctly.)  */
+
+  void set_using (struct using_direct *using_decl, struct obstack *obstack);
+
   /* Addresses in the executable code that are in this block.  */
 
   CORE_ADDR m_start;
@@ -248,6 +263,12 @@ struct block
      startaddr and endaddr above.  */
 
   struct blockranges *m_ranges;
+
+private:
+
+  /* If the namespace_info is NULL, allocate it via OBSTACK and
+     initialize its members to zero.  */
+  void initialize_namespace (struct obstack *obstack);
 };
 
 /* The global block is singled out so that we can provide a back-link
@@ -373,17 +394,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 char *block_scope (const struct block *block);
-
-extern void block_set_scope (struct block *block, const char *scope,
-                            struct obstack *obstack);
-
-extern struct using_direct *block_using (const struct block *block);
-
-extern void block_set_using (struct block *block,
-                            struct using_direct *using_decl,
-                            struct obstack *obstack);
-
 extern const struct block *block_static_block (const struct block *block);
 
 extern const struct block *block_global_block (const struct block *block);
index 8dbb327f0eb4877fc57fdd89db66258b88d759c3..adc554e587a39de893a6c91d053ddb8dbb1c5c61 100644 (file)
@@ -372,11 +372,10 @@ buildsym_compunit::finish_block_internal
       opblock = pblock;
     }
 
-  block_set_using (block,
-                  (is_global
-                   ? m_global_using_directives
-                   : m_local_using_directives),
-                  &m_objfile->objfile_obstack);
+  block->set_using ((is_global
+                    ? m_global_using_directives
+                    : m_local_using_directives),
+                   &m_objfile->objfile_obstack);
   if (is_global)
     m_global_using_directives = NULL;
   else
index 97b7a653e3374026cef7bb050de9c791b2843bf2..2d44b7bc04796ef6c17376055d7023892654177b 100644 (file)
@@ -413,7 +413,7 @@ cp_lookup_symbol_via_imports (const char *scope,
   /* Go through the using directives.  If any of them add new names to
      the namespace we're searching in, see if we can find a match by
      applying them.  */
-  for (current = block_using (block);
+  for (current = block->get_using ();
        current != NULL;
        current = current->next)
     {
@@ -769,7 +769,7 @@ cp_lookup_symbol_nonlocal (const struct language_defn *langdef,
                           const domain_enum domain)
 {
   struct block_symbol sym;
-  const char *scope = block_scope (block);
+  const char *scope = block == nullptr ? "" : block->scope ();
 
   symbol_lookup_debug_printf
     ("cp_lookup_symbol_non_local (%s, %s (scope %s), %s)",
@@ -1025,7 +1025,7 @@ cp_lookup_transparent_type (const char *name)
 
   /* If that doesn't work and we're within a namespace, look there
      instead.  */
-  scope = block_scope (get_selected_block (0));
+  scope = get_selected_block (0)->scope ();
 
   if (scope[0] == '\0')
     return NULL;
index 764e2b8b4696cd476682eda4ebd222813ea5ce3b..fd5a286b7792887f6161fb47c08a9268133b5f57 100644 (file)
@@ -1403,7 +1403,7 @@ add_symbol_overload_list_using (const char *func_name,
   for (block = get_selected_block (0);
        block != NULL;
        block = block->superblock ())
-    for (current = block_using (block);
+    for (current = block->get_using ();
        current != NULL;
        current = current->next)
       {
index aaef1dfae1f7f43feffd27ad000e03b8e0054d60..6153e5b32394eeb08c88e1690939b5cbcbde9eee 100644 (file)
@@ -375,7 +375,7 @@ d_lookup_symbol_imports (const char *scope, const char *name,
      the module we're searching in, see if we can find a match by
      applying them.  */
 
-  for (current = block_using (block);
+  for (current = block->get_using ();
        current != NULL;
        current = current->next)
     {
@@ -511,7 +511,7 @@ d_lookup_symbol_nonlocal (const struct language_defn *langdef,
                          const domain_enum domain)
 {
   struct block_symbol sym;
-  const char *scope = block == nullptr ? "" : block_scope (block);
+  const char *scope = block == nullptr ? "" : block->scope ();
 
   sym = lookup_module_scope (langdef, name, block, domain, scope, 0);
   if (sym.symbol != NULL)
index 36e744fa61fce0fc4b9dce8ec2976b43945709c2..02c7e3118adcaf5f9592cb18bd66fe6b51cfd33a 100644 (file)
@@ -2361,8 +2361,8 @@ cp_set_block_scope (const struct symbol *symbol,
       const char *name = symbol->demangled_name ();
       unsigned int prefix_len = cp_entire_prefix_len (name);
 
-      block_set_scope (block, obstack_strndup (obstack, name, prefix_len),
-                      obstack);
+      block->set_scope (obstack_strndup (obstack, name, prefix_len),
+                       obstack);
     }
 }
 
index 9ad1afa5d612cbacf49e59c4d4e2cf1ba9681afd..11a2d3e7c9a53e45fa3f98eb5c6c5d067a8cca15 100644 (file)
@@ -10170,8 +10170,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
        || cu->lang () == language_d
        || cu->lang () == language_rust)
       && cu->processing_has_namespace_info)
-    block_set_scope (block, determine_prefix (die, cu),
-                    &objfile->objfile_obstack);
+    block->set_scope (determine_prefix (die, cu),
+                     &objfile->objfile_obstack);
 
   /* If we have address ranges, record them.  */
   dwarf2_record_block_ranges (die, block, baseaddr, cu);
index fb9db9fe31b67a1e40870ef6e80c637dd4f5f1a4..fe260f175f8d069ca00ab372970fd7aba6842b8d 100644 (file)
@@ -58,7 +58,7 @@ rust_last_path_segment (const char *path)
 std::string
 rust_crate_for_block (const struct block *block)
 {
-  const char *scope = block_scope (block);
+  const char *scope = block->scope ();
 
   if (scope[0] == '\0')
     return std::string ();
index 497342d4ef32539683a1278092e4d9b0492492ad..37a22e7a404b29e4917617e84d7ad76691bd795e 100644 (file)
@@ -148,7 +148,7 @@ public:
   {
     struct block_symbol result = {};
 
-    const char *scope = block == nullptr ? "" : block_scope (block);
+    const char *scope = block == nullptr ? "" : block->scope ();
     symbol_lookup_debug_printf
       ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)",
        name, host_address_to_string (block), scope,
index 72b843ef40c5ba9b1761a2c9f23b054b0581ee98..9074d651d85c8525bce3b80a2c5175b5c7877a2a 100644 (file)
@@ -375,7 +375,7 @@ rust_parser::super_name (const std::string &ident, unsigned int n_supers)
 {
   const char *scope = "";
   if (pstate->expression_context_block != nullptr)
-    scope = block_scope (pstate->expression_context_block);
+    scope = pstate->expression_context_block->scope ();
   int offset;
 
   if (scope[0] == '\0')
index 52043e4de0629bb6d007a562461fd50348c85e84..bd6abbf7319a3428b0e219e0a20a47643bac5b48 100644 (file)
@@ -2160,7 +2160,7 @@ lookup_local_symbol (const char *name,
 
   struct symbol *sym;
   const struct block *static_block = block_static_block (block);
-  const char *scope = block_scope (block);
+  const char *scope = block->scope ();
   
   /* Check if it's a global block.  */
   if (static_block == nullptr)