]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Refactor cooked_index_shard::handle_gnat_encoded_entry
authorTom Tromey <tromey@adacore.com>
Tue, 3 Sep 2024 18:04:18 +0000 (12:04 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 9 Sep 2024 17:37:35 +0000 (11:37 -0600)
This changes cooked_index_shard::handle_gnat_encoded_entry to modify
the incoming entry itself, and to return void rather than a new name.
this simplifies the caller a little, which is convenient for a
different series I am working on.

Approved-By: Tom de Vries <tdevries@suse.de>
gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h

index 41aa9d0da5842213d2def15a449cfc02f4891fa7..4073c924890d6aec22989aa1c321a4fd00173a33 100644 (file)
@@ -288,7 +288,7 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
 
 /* See cooked-index.h.  */
 
-gdb::unique_xmalloc_ptr<char>
+void
 cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
                                               htab_t gnat_entries)
 {
@@ -298,7 +298,10 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
      source charset does not affect the indexer directly.  */
   std::string canonical = ada_decode (entry->name, false, false, false);
   if (canonical.empty ())
-    return {};
+    {
+      entry->canonical = entry->name;
+      return;
+    }
   std::vector<std::string_view> names = split_name (canonical.c_str (),
                                                    split_style::DOT_STYLE);
   std::string_view tail = names.back ();
@@ -329,7 +332,9 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
     }
 
   entry->set_parent (parent);
-  return make_unique_xstrndup (tail.data (), tail.length ());
+  auto new_canon = make_unique_xstrndup (tail.data (), tail.length ());
+  entry->canonical = new_canon.get ();
+  m_names.push_back (std::move (new_canon));
 }
 
 /* See cooked-index.h.  */
@@ -389,17 +394,7 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
       if ((entry->flags & IS_LINKAGE) != 0)
        entry->canonical = entry->name;
       else if (entry->lang == language_ada)
-       {
-         gdb::unique_xmalloc_ptr<char> canon_name
-           = handle_gnat_encoded_entry (entry, gnat_entries.get ());
-         if (canon_name == nullptr)
-           entry->canonical = entry->name;
-         else
-           {
-             entry->canonical = canon_name.get ();
-             m_names.push_back (std::move (canon_name));
-           }
-       }
+       handle_gnat_encoded_entry (entry, gnat_entries.get ());
       else if (entry->lang == language_cplus || entry->lang == language_c)
        {
          void **slot = htab_find_slot (seen_names.get (), entry,
index e9f13c97be09b64cfb48c7f8f6342e81d0b395dc..5b48b8162dad59498bc0706ee33392f5247e8fd1 100644 (file)
@@ -338,9 +338,8 @@ private:
   /* GNAT only emits mangled ("encoded") names in the DWARF, and does
      not emit the module structure.  However, we need this structure
      to do lookups.  This function recreates that structure for an
-     existing entry.  It returns the base name (last element) of the
-     full decoded name.  */
-  gdb::unique_xmalloc_ptr<char> handle_gnat_encoded_entry
+     existing entry, modifying ENTRY as appropriate.  */
+  void handle_gnat_encoded_entry
        (cooked_index_entry *entry, htab_t gnat_entries);
 
   /* Finalize the index.  This should be called a single time, when