]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert ada_language_defn::collect_symbol_completion_matches
authorTom Tromey <tom@tromey.com>
Sun, 8 Dec 2024 00:30:42 +0000 (17:30 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 10 Sep 2025 22:07:57 +0000 (16:07 -0600)
This converts ada_language_defn::collect_symbol_completion_matches to
the callback approach, merging the search loop and the call to
expand_symtabs_matching.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
Acked-By: Simon Marchi <simon.marchi@efficios.com>
gdb/ada-lang.c

index d19dd721e521d67e2b6f2a491d0d82386cbdb1ca..2b83cbb72ec2bb3376b1dfc04a198f8cf73ca8cd 100644 (file)
@@ -13655,20 +13655,12 @@ public:
                                          const char *text, const char *word,
                                          enum type_code code) const override
   {
-    const struct block *b, *surrounding_static_block = 0;
+    const struct block *surrounding_static_block = 0;
 
     gdb_assert (code == TYPE_CODE_UNDEF);
 
     lookup_name_info lookup_name (text, name_match_type, true);
 
-    /* First, look at the partial symtab symbols.  */
-    expand_symtabs_matching (NULL,
-                            lookup_name,
-                            NULL,
-                            NULL,
-                            SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
-                            SEARCH_ALL_DOMAINS);
-
     /* At this point scan through the misc symbol vectors and add each
        symbol you find to the list.  Eventually we want to ignore
        anything that isn't a text symbol (everything else will be
@@ -13710,7 +13702,9 @@ public:
     /* Search upwards from currently selected frame (so that we can
        complete on local vars.  */
 
-    for (b = get_selected_block (0); b != NULL; b = b->superblock ())
+    for (const block *b = get_selected_block (0);
+        b != nullptr;
+        b = b->superblock ())
       {
        if (b->is_static_block ())
          surrounding_static_block = b;   /* For elmin of dups */
@@ -13732,43 +13726,36 @@ public:
 
     for (objfile *objfile : current_program_space->objfiles ())
       {
-       for (compunit_symtab *s : objfile->compunits ())
+       auto callback = [&] (compunit_symtab *s)
          {
            QUIT;
-           b = s->blockvector ()->global_block ();
-           for (struct symbol *sym : block_iterator_range (b))
+           for (const block *b = s->blockvector ()->static_block ();
+                b != nullptr;
+                b = b->superblock ())
              {
-               if (completion_skip_symbol (mode, sym))
-                 continue;
+               /* Don't do this block twice.  */
+               if (b == surrounding_static_block)
+                 break;
+
+               for (struct symbol *sym : block_iterator_range (b))
+                 {
+                   if (completion_skip_symbol (mode, sym))
+                     continue;
 
-               completion_list_add_name (tracker,
-                                         sym->language (),
-                                         sym->linkage_name (),
-                                         lookup_name, text, word);
+                   completion_list_add_name (tracker,
+                                             sym->language (),
+                                             sym->linkage_name (),
+                                             lookup_name, text, word);
+                 }
              }
-         }
-      }
 
-    for (objfile *objfile : current_program_space->objfiles ())
-      {
-       for (compunit_symtab *s : objfile->compunits ())
-         {
-           QUIT;
-           b = s->blockvector ()->static_block ();
-           /* Don't do this block twice.  */
-           if (b == surrounding_static_block)
-             continue;
-           for (struct symbol *sym : block_iterator_range (b))
-             {
-               if (completion_skip_symbol (mode, sym))
-                 continue;
+           return true;
+         };
 
-               completion_list_add_name (tracker,
-                                         sym->language (),
-                                         sym->linkage_name (),
-                                         lookup_name, text, word);
-             }
-         }
+       objfile->expand_symtabs_matching
+         (nullptr, &lookup_name, nullptr, callback,
+          SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+          SEARCH_ALL_DOMAINS);
       }
   }