aboutsummaryrefslogtreecommitdiff
path: root/gdb/macroexp.h
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.h
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.h')
-rw-r--r--gdb/macroexp.h52
1 files changed, 19 insertions, 33 deletions
diff --git a/gdb/macroexp.h b/gdb/macroexp.h
index bbb0ecd..ec992f2 100644
--- a/gdb/macroexp.h
+++ b/gdb/macroexp.h
@@ -21,38 +21,26 @@
#ifndef MACROEXP_H
#define MACROEXP_H
-/* A function for looking up preprocessor macro definitions. Return
- the preprocessor definition of NAME in scope according to BATON, or
- zero if NAME is not defined as a preprocessor macro.
-
- The caller must not free or modify the definition returned. It is
- probably unwise for the caller to hold pointers to it for very
- long; it probably lives in some objfile's obstacks. */
-typedef struct macro_definition *(macro_lookup_ftype) (const char *name,
- void *baton);
-
-
-/* Expand any preprocessor macros in SOURCE, and return the expanded
- text. Use LOOKUP_FUNC and LOOKUP_FUNC_BATON to find identifiers'
- preprocessor definitions. SOURCE is a null-terminated string. The
- result is a null-terminated string, allocated using xmalloc; it is
- the caller's responsibility to free it. */
+struct macro_scope;
+
+/* Expand any preprocessor macros in SOURCE (a null-terminated string), and
+ return the expanded text.
+
+ Use SCOPE to find identifiers' preprocessor definitions.
+
+ The result is a null-terminated string. */
gdb::unique_xmalloc_ptr<char> macro_expand (const char *source,
- macro_lookup_ftype *lookup_func,
- void *lookup_func_baton);
+ const macro_scope &scope);
+/* Expand all preprocessor macro references that appear explicitly in SOURCE
+ (a null-terminated string), but do not expand any new macro references
+ introduced by that first level of expansion.
-/* Expand all preprocessor macro references that appear explicitly in
- SOURCE, but do not expand any new macro references introduced by
- that first level of expansion. Use LOOKUP_FUNC and
- LOOKUP_FUNC_BATON to find identifiers' preprocessor definitions.
- SOURCE is a null-terminated string. The result is a
- null-terminated string, allocated using xmalloc; it is the caller's
- responsibility to free it. */
-gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
- macro_lookup_ftype *lookup_func,
- void *lookup_func_baton);
+ Use SCOPE to find identifiers' preprocessor definitions.
+ The result is a null-terminated string. */
+gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
+ const macro_scope &scope);
/* If the null-terminated string pointed to by *LEXPTR begins with a
macro invocation, return the result of expanding that invocation as
@@ -61,9 +49,9 @@ gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
contains no further macro invocations.
Otherwise, if *LEXPTR does not start with a macro invocation,
- return zero, and leave *LEXPTR unchanged.
+ return nullptr, and leave *LEXPTR unchanged.
- Use LOOKUP_FUNC and LOOKUP_BATON to find macro definitions.
+ Use SCOPE to find macro definitions.
If this function returns a string, the caller is responsible for
freeing it, using xfree.
@@ -80,9 +68,7 @@ gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
much have to do tokenization to find the end of the string that
needs to be macro-expanded. Our C/C++ tokenizer isn't really
designed to be called by anything but the yacc parser engine. */
-char *macro_expand_next (const char **lexptr,
- macro_lookup_ftype *lookup_func,
- void *lookup_baton);
+char *macro_expand_next (const char **lexptr, const macro_scope &scope);
/* Functions to classify characters according to cpp rules. */