aboutsummaryrefslogtreecommitdiff
path: root/gdb/macrocmd.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-07-02 20:38:25 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2020-07-03 22:27:08 -0400
commit211d5b1c18eb96459289e17b58e91fad46708173 (patch)
tree9167b6d775563b6970d1d0c9a5b36b4d4197de94 /gdb/macrocmd.c
parent889d527eb43c90cc37e757a3cddd0837c3fd9dd9 (diff)
downloadgdb-211d5b1c18eb96459289e17b58e91fad46708173.zip
gdb-211d5b1c18eb96459289e17b58e91fad46708173.tar.gz
gdb-211d5b1c18eb96459289e17b58e91fad46708173.tar.bz2
gdb: remove callback in macro expand functions
I started to look into changing the callbacks in macroexp.h to use gdb::function_view. However, I noticed that the passed lookup function was always `standard_macro_lookup`, which looks up a macro in a `macro_scope` object. Since that doesn't look like a very useful abstraction, it would be simpler to just pass the scope around and have the various functions call standard_macro_lookup themselves. This is what this patch does. gdb/ChangeLog: * macroexp.h (macro_lookup_ftype): Remove. (macro_expand, macro_expand_once, macro_expand_next): Remove lookup function parameters, add scope parameter. * macroexp.c (scan, substitute_args, expand, maybe_expand, macro_expand, macro_expand_once, macro_expand_next): Likewise. * macroscope.h (standard_macro_lookup): Change parameter type to macro_scope. * macroscope.c (standard_macro_lookup): Likewise. * c-exp.y (lex_one_token): Update. * macrocmd.c (macro_expand_command): Likewise. (macro_expand_once_command): Likewise. Change-Id: Id2431b1489359e1b0274dc2b81e5ea5d225d730c
Diffstat (limited to 'gdb/macrocmd.c')
-rw-r--r--gdb/macrocmd.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index 42915db..3e900fe 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -47,9 +47,6 @@ macro_inform_no_debuginfo (void)
static void
macro_expand_command (const char *exp, int from_tty)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> ms;
- gdb::unique_xmalloc_ptr<char> expanded;
-
/* You know, when the user doesn't specify any expression, it would be
really cool if this defaulted to the last expression evaluated.
Then it would be easy to ask, "Hey, what did I just evaluate?" But
@@ -60,10 +57,12 @@ macro_expand_command (const char *exp, int from_tty)
" expression you\n"
"want to expand."));
- ms = default_macro_scope ();
- if (ms)
+ gdb::unique_xmalloc_ptr<macro_scope> ms = default_macro_scope ();
+
+ if (ms != nullptr)
{
- expanded = macro_expand (exp, standard_macro_lookup, ms.get ());
+ gdb::unique_xmalloc_ptr<char> expanded = macro_expand (exp, *ms);
+
fputs_filtered ("expands to: ", gdb_stdout);
fputs_filtered (expanded.get (), gdb_stdout);
fputs_filtered ("\n", gdb_stdout);
@@ -76,9 +75,6 @@ macro_expand_command (const char *exp, int from_tty)
static void
macro_expand_once_command (const char *exp, int from_tty)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> ms;
- gdb::unique_xmalloc_ptr<char> expanded;
-
/* You know, when the user doesn't specify any expression, it would be
really cool if this defaulted to the last expression evaluated.
And it should set the once-expanded text as the new `last
@@ -89,10 +85,12 @@ macro_expand_once_command (const char *exp, int from_tty)
" the expression\n"
"you want to expand."));
- ms = default_macro_scope ();
- if (ms)
+ gdb::unique_xmalloc_ptr<macro_scope> ms = default_macro_scope ();
+
+ if (ms != nullptr)
{
- expanded = macro_expand_once (exp, standard_macro_lookup, ms.get ());
+ gdb::unique_xmalloc_ptr<char> expanded = macro_expand_once (exp, *ms);
+
fputs_filtered ("expands to: ", gdb_stdout);
fputs_filtered (expanded.get (), gdb_stdout);
fputs_filtered ("\n", gdb_stdout);