#include "gdb_obstack.h"
#include "macrotab.h"
#include "macroexp.h"
+#include "macroscope.h"
#include "c-lang.h"
xfree (text);
}
- /* Release the text of the buffer to the caller, which is now
- responsible for freeing it. */
- ATTRIBUTE_UNUSED_RESULT char *release ()
+ /* Release the text of the buffer to the caller. */
+ gdb::unique_xmalloc_ptr<char> release ()
{
gdb_assert (! shared);
gdb_assert (size);
char *result = text;
text = NULL;
- return result;
+ return gdb::unique_xmalloc_ptr<char> (result);
}
/* Resize the buffer to be at least N bytes long. Raise an error if
/* See macroexp.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
macro_stringify (const char *str)
{
int len = strlen (str);
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.
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;
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;
}
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;
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)
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
`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;
}
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);
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;
}
}
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);
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);
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');
- return gdb::unique_xmalloc_ptr<char> (dest.release ());
+ return dest.release ();
}
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)
+gdb::unique_xmalloc_ptr<char>
+macro_expand_next (const char **lexptr, const macro_scope &scope)
{
struct macro_buffer tok;
/* Get the text's first preprocessing token. */
if (! get_token (&tok, &src))
- return 0;
+ return nullptr;
/* 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
else
{
/* It wasn't a macro invocation. */
- return 0;
+ return nullptr;
}
}