public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/2] Simplify use of map_matching_symbols in ada-lang.c
Date: Wed, 24 Mar 2021 13:38:35 -0600	[thread overview]
Message-ID: <20210324193836.3656070-2-tom@tromey.com> (raw)
In-Reply-To: <20210324193836.3656070-1-tom@tromey.com>

I noticed that ada-lang.c creates a lambda to call
aux_add_nonlocal_symbols.  However, this code can be simplified a bit
by changing match_data to implement operator(), and then simply
passing the object as the callback.  That is what this patch
implements.

2021-03-24  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (struct match_data): Add operator().
	(match_data::operator()): Rename from aux_add_nonlocal_symbols.
	(callback): Remove 'callback'.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/ada-lang.c | 36 ++++++++++++++++--------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d0374780b98..a7dd88ad86f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4970,7 +4970,7 @@ ada_add_local_symbols (std::vector<struct block_symbol> &result,
     add_symbols_from_enclosing_procs (result, lookup_name, domain);
 }
 
-/* An object of this type is used as the user_data argument when
+/* An object of this type is used as the callback argument when
    calling the map_matching_symbols method.  */
 
 struct match_data
@@ -4981,6 +4981,8 @@ struct match_data
   }
   DISABLE_COPY_AND_ASSIGN (match_data);
 
+  bool operator() (struct block_symbol *bsym);
+
   struct objfile *objfile = nullptr;
   std::vector<struct block_symbol> *resultp;
   struct symbol *arg_sym = nullptr;
@@ -4996,33 +4998,32 @@ struct match_data
    marking the end of a block, the argument symbol is added if no
    other has been found.  */
 
-static bool
-aux_add_nonlocal_symbols (struct block_symbol *bsym,
-			  struct match_data *data)
+bool
+match_data::operator() (struct block_symbol *bsym)
 {
   const struct block *block = bsym->block;
   struct symbol *sym = bsym->symbol;
 
   if (sym == NULL)
     {
-      if (!data->found_sym && data->arg_sym != NULL) 
-	add_defn_to_vec (*data->resultp,
-			 fixup_symbol_section (data->arg_sym, data->objfile),
+      if (!found_sym && arg_sym != NULL)
+	add_defn_to_vec (*resultp,
+			 fixup_symbol_section (arg_sym, objfile),
 			 block);
-      data->found_sym = false;
-      data->arg_sym = NULL;
+      found_sym = false;
+      arg_sym = NULL;
     }
   else 
     {
       if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
 	return true;
       else if (SYMBOL_IS_ARGUMENT (sym))
-	data->arg_sym = sym;
+	arg_sym = sym;
       else
 	{
-	  data->found_sym = true;
-	  add_defn_to_vec (*data->resultp,
-			   fixup_symbol_section (sym, data->objfile),
+	  found_sym = true;
+	  add_defn_to_vec (*resultp,
+			   fixup_symbol_section (sym, objfile),
 			   block);
 	}
     }
@@ -5194,16 +5195,11 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
-  auto callback = [&] (struct block_symbol *bsym)
-    {
-      return aux_add_nonlocal_symbols (bsym, &data);
-    };
-
   for (objfile *objfile : current_program_space->objfiles ())
     {
       data.objfile = objfile;
 
-      objfile->map_matching_symbols (lookup_name, domain, global, callback,
+      objfile->map_matching_symbols (lookup_name, domain, global, data,
 				     is_wild_match ? NULL : compare_names);
 
       for (compunit_symtab *cu : objfile->compunits ())
@@ -5226,7 +5222,7 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
       for (objfile *objfile : current_program_space->objfiles ())
 	{
 	  data.objfile = objfile;
-	  objfile->map_matching_symbols (name1, domain, global, callback,
+	  objfile->map_matching_symbols (name1, domain, global, data,
 					 compare_names);
 	}
     }      	
-- 
2.26.2


  reply	other threads:[~2021-03-24 19:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 19:38 [PATCH 0/2] Two quick-function simplifications Tom Tromey
2021-03-24 19:38 ` Tom Tromey [this message]
2021-03-25 19:41   ` [PATCH 1/2] Simplify use of map_matching_symbols in ada-lang.c Simon Marchi
2021-03-26 19:40     ` Tom Tromey
2021-03-24 19:38 ` [PATCH 2/2] Use function view in quick_symbol_functions::map_symbol_filenames Tom Tromey
2021-03-25 19:49   ` Simon Marchi
2021-03-26 19:43     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210324193836.3656070-2-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).