aboutsummaryrefslogtreecommitdiff
path: root/gdb/macroexp.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/macroexp.c
parent889d527eb43c90cc37e757a3cddd0837c3fd9dd9 (diff)
downloadfsf-binutils-gdb-211d5b1c18eb96459289e17b58e91fad46708173.zip
fsf-binutils-gdb-211d5b1c18eb96459289e17b58e91fad46708173.tar.gz
fsf-binutils-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/macroexp.c')
-rw-r--r--gdb/macroexp.c49
1 files changed, 18 insertions, 31 deletions
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 9015bc1..9282380 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -21,6 +21,7 @@
#include "gdb_obstack.h"
#include "macrotab.h"
#include "macroexp.h"
+#include "macroscope.h"
#include "c-lang.h"
@@ -877,9 +878,7 @@ gather_arguments (const char *name, struct macro_buffer *src, int nargs,
static void scan (struct macro_buffer *dest,
struct macro_buffer *src,
struct macro_name_list *no_loop,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton);
-
+ const macro_scope &scope);
/* A helper function for substitute_args.
@@ -959,8 +958,7 @@ substitute_args (struct macro_buffer *dest,
int is_varargs, const struct macro_buffer *va_arg_name,
const std::vector<struct macro_buffer> &argv,
struct macro_name_list *no_loop,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton)
+ const macro_scope &scope)
{
/* The token we are currently considering. */
struct macro_buffer tok;
@@ -1194,7 +1192,7 @@ substitute_args (struct macro_buffer *dest,
referring to the argument's text, not the argument
itself. */
struct macro_buffer arg_src (argv[arg].text, argv[arg].len);
- scan (dest, &arg_src, no_loop, lookup_func, lookup_baton);
+ scan (dest, &arg_src, no_loop, scope);
substituted = 1;
}
@@ -1224,8 +1222,7 @@ expand (const char *id,
struct macro_buffer *dest,
struct macro_buffer *src,
struct macro_name_list *no_loop,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton)
+ const macro_scope &scope)
{
struct macro_name_list new_no_loop;
@@ -1243,7 +1240,7 @@ expand (const char *id,
struct macro_buffer replacement_list (def->replacement,
strlen (def->replacement));
- scan (dest, &replacement_list, &new_no_loop, lookup_func, lookup_baton);
+ scan (dest, &replacement_list, &new_no_loop, scope);
return 1;
}
else if (def->kind == macro_function_like)
@@ -1310,7 +1307,7 @@ expand (const char *id,
expand an argument until we see how it's being used. */
struct macro_buffer substituted (0);
substitute_args (&substituted, def, is_varargs, &va_arg_name,
- argv, no_loop, lookup_func, lookup_baton);
+ argv, no_loop, scope);
/* Now `substituted' is the macro's replacement list, with all
argument values substituted into it properly. Re-scan it for
@@ -1323,7 +1320,7 @@ expand (const char *id,
`substituted's original text buffer after scanning it so we
can free it. */
struct macro_buffer substituted_src (substituted.text, substituted.len);
- scan (dest, &substituted_src, &new_no_loop, lookup_func, lookup_baton);
+ scan (dest, &substituted_src, &new_no_loop, scope);
return 1;
}
@@ -1344,8 +1341,7 @@ maybe_expand (struct macro_buffer *dest,
struct macro_buffer *src_first,
struct macro_buffer *src_rest,
struct macro_name_list *no_loop,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton)
+ const macro_scope &scope)
{
gdb_assert (src_first->shared);
gdb_assert (src_rest->shared);
@@ -1363,11 +1359,9 @@ maybe_expand (struct macro_buffer *dest,
if (! currently_rescanning (no_loop, id.c_str ()))
{
/* Does this identifier have a macro definition in scope? */
- struct macro_definition *def = lookup_func (id.c_str (),
- lookup_baton);
+ macro_definition *def = standard_macro_lookup (id.c_str (), scope);
- if (def && expand (id.c_str (), def, dest, src_rest, no_loop,
- lookup_func, lookup_baton))
+ if (def && expand (id.c_str (), def, dest, src_rest, no_loop, scope))
return 1;
}
}
@@ -1385,8 +1379,7 @@ static void
scan (struct macro_buffer *dest,
struct macro_buffer *src,
struct macro_name_list *no_loop,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton)
+ const macro_scope &scope)
{
gdb_assert (src->shared);
gdb_assert (! dest->shared);
@@ -1408,7 +1401,7 @@ scan (struct macro_buffer *dest,
dest->last_token = dest->len;
}
- if (! maybe_expand (dest, &tok, src, no_loop, lookup_func, lookup_baton))
+ if (! maybe_expand (dest, &tok, src, no_loop, scope))
/* We didn't end up expanding tok as a macro reference, so
simply append it to dest. */
append_tokens_without_splicing (dest, &tok);
@@ -1425,16 +1418,14 @@ scan (struct macro_buffer *dest,
gdb::unique_xmalloc_ptr<char>
-macro_expand (const char *source,
- macro_lookup_ftype *lookup_func,
- void *lookup_func_baton)
+macro_expand (const char *source, const macro_scope &scope)
{
struct macro_buffer src (source, strlen (source));
struct macro_buffer dest (0);
dest.last_token = 0;
- scan (&dest, &src, 0, lookup_func, lookup_func_baton);
+ scan (&dest, &src, 0, scope);
dest.appendc ('\0');
@@ -1443,18 +1434,14 @@ macro_expand (const char *source,
gdb::unique_xmalloc_ptr<char>
-macro_expand_once (const char *source,
- macro_lookup_ftype *lookup_func,
- void *lookup_func_baton)
+macro_expand_once (const char *source, const macro_scope &scope)
{
error (_("Expand-once not implemented yet."));
}
char *
-macro_expand_next (const char **lexptr,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton)
+macro_expand_next (const char **lexptr, const macro_scope &scope)
{
struct macro_buffer tok;
@@ -1470,7 +1457,7 @@ macro_expand_next (const char **lexptr,
return 0;
/* If it's a macro invocation, expand it. */
- if (maybe_expand (&dest, &tok, &src, 0, lookup_func, lookup_baton))
+ if (maybe_expand (&dest, &tok, &src, 0, scope))
{
/* It was a macro invocation! Package up the expansion as a
null-terminated string and return it. Set *lexptr to the