c_parse_state cstate;
scoped_restore cstate_restore = make_scoped_restore (&cpstate, &cstate);
- gdb::unique_xmalloc_ptr<struct macro_scope> macro_scope;
+ macro_scope macro_scope;
if (par_state->expression_context_block)
macro_scope
= sal_macro_scope (find_pc_line (par_state->expression_context_pc, 0));
else
macro_scope = default_macro_scope ();
- if (! macro_scope)
+ if (!macro_scope.is_valid ())
macro_scope = user_macro_scope ();
scoped_restore restore_macro_scope
- = make_scoped_restore (&expression_macro_scope, macro_scope.get ());
+ = make_scoped_restore (&expression_macro_scope, ¯o_scope);
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
par_state->debug);
write_macro_definitions (const struct block *block, CORE_ADDR pc,
struct ui_file *file)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> scope;
+ macro_scope scope;
if (block != NULL)
scope = sal_macro_scope (find_pc_line (pc, 0));
else
scope = default_macro_scope ();
- if (scope == NULL)
+ if (!scope.is_valid ())
scope = user_macro_scope ();
- if (scope != NULL && scope->file != NULL && scope->file->table != NULL)
+ if (scope.is_valid () && scope.file->table != nullptr)
{
- macro_for_each_in_scope (scope->file, scope->line,
+ macro_for_each_in_scope (scope.file, scope.line,
[&] (const char *name,
const macro_definition *macro,
macro_source_file *source,
" expression you\n"
"want to expand."));
- gdb::unique_xmalloc_ptr<macro_scope> ms = default_macro_scope ();
+ macro_scope ms = default_macro_scope ();
- if (ms != nullptr)
+ if (ms.is_valid ())
{
- gdb::unique_xmalloc_ptr<char> expanded = macro_expand (exp, *ms);
+ gdb::unique_xmalloc_ptr<char> expanded = macro_expand (exp, ms);
gdb_puts ("expands to: ");
gdb_puts (expanded.get ());
" the expression\n"
"you want to expand."));
- gdb::unique_xmalloc_ptr<macro_scope> ms = default_macro_scope ();
+ macro_scope ms = default_macro_scope ();
- if (ms != nullptr)
+ if (ms.is_valid ())
{
- gdb::unique_xmalloc_ptr<char> expanded = macro_expand_once (exp, *ms);
+ gdb::unique_xmalloc_ptr<char> expanded = macro_expand_once (exp, ms);
gdb_puts ("expands to: ");
gdb_puts (expanded.get ());
static void
info_macro_command (const char *args, int from_tty)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> ms;
const char *name;
int show_all_macros_named = 0;
const char *arg_start = args;
" of the macro\n"
"whose definition you want to see."));
- ms = default_macro_scope ();
+ macro_scope ms = default_macro_scope ();
- if (! ms)
+ if (!ms.is_valid ())
macro_inform_no_debuginfo ();
else if (show_all_macros_named)
- macro_for_each (ms->file->table, [&] (const char *macro_name,
- const macro_definition *macro,
- macro_source_file *source,
- int line)
+ macro_for_each (ms.file->table, [&] (const char *macro_name,
+ const macro_definition *macro,
+ macro_source_file *source,
+ int line)
{
if (strcmp (name, macro_name) == 0)
print_macro_definition (name, macro, source, line);
{
struct macro_definition *d;
- d = macro_lookup_definition (ms->file, ms->line, name);
+ d = macro_lookup_definition (ms.file, ms.line, name);
if (d)
{
int line;
struct macro_source_file *file
- = macro_definition_location (ms->file, ms->line, name, &line);
+ = macro_definition_location (ms.file, ms.line, name, &line);
print_macro_definition (name, d, file, line);
}
gdb_printf ("The symbol `%s' has no definition as a C/C++"
" preprocessor macro\n"
"at ", name);
- show_pp_source_pos (gdb_stdout, ms->file, ms->line);
+ show_pp_source_pos (gdb_stdout, ms.file, ms.line);
}
}
}
static void
info_macros_command (const char *args, int from_tty)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> ms;
+ macro_scope ms;
if (args == NULL)
ms = default_macro_scope ();
ms = sal_macro_scope (sals[0]);
}
- if (! ms || ! ms->file || ! ms->file->table)
+ if (!ms.is_valid () || ms.file->table == nullptr)
macro_inform_no_debuginfo ();
else
- macro_for_each_in_scope (ms->file, ms->line, print_macro_definition);
+ macro_for_each_in_scope (ms.file, ms.line, print_macro_definition);
}
\f
struct macro_table *macro_user_macros;
-gdb::unique_xmalloc_ptr<struct macro_scope>
+macro_scope
sal_macro_scope (struct symtab_and_line sal)
{
+ macro_scope result;
struct macro_source_file *main_file, *inclusion;
struct compunit_symtab *cust;
if (sal.symtab == NULL)
- return NULL;
+ return result;
cust = sal.symtab->compunit ();
if (cust->macro_table () == NULL)
- return NULL;
+ return result;
- gdb::unique_xmalloc_ptr<struct macro_scope> ms (XNEW (struct macro_scope));
+ macro_scope ms;
main_file = macro_main (cust->macro_table ());
inclusion = macro_lookup_inclusion (main_file, sal.symtab->filename_for_id);
if (inclusion)
{
- ms->file = inclusion;
- ms->line = sal.line;
+ ms.file = inclusion;
+ ms.line = sal.line;
}
else
{
For the time being, though, we'll just treat these as
occurring at the end of the main source file. */
- ms->file = main_file;
- ms->line = -1;
+ ms.file = main_file;
+ ms.line = -1;
complaint (_("symtab found for `%s', but that file\n"
"is not covered in the compilation unit's macro information"),
}
-gdb::unique_xmalloc_ptr<struct macro_scope>
-user_macro_scope (void)
+macro_scope
+user_macro_scope ()
{
- gdb::unique_xmalloc_ptr<struct macro_scope> ms (XNEW (struct macro_scope));
- ms->file = macro_main (macro_user_macros);
- ms->line = -1;
- return ms;
+ return { macro_main (macro_user_macros), -1 };
}
-gdb::unique_xmalloc_ptr<struct macro_scope>
-default_macro_scope (void)
+macro_scope
+default_macro_scope ()
{
struct symtab_and_line sal;
- gdb::unique_xmalloc_ptr<struct macro_scope> ms;
frame_info_ptr frame;
CORE_ADDR pc;
sal.line = cursal.line;
}
- ms = sal_macro_scope (sal);
- if (! ms)
+ macro_scope ms = sal_macro_scope (sal);
+ if (!ms.is_valid ())
ms = user_macro_scope ();
return ms;
in scope: a source file (either a main source file or an
#inclusion), and a line number in that file. */
struct macro_scope {
- struct macro_source_file *file;
- int line;
+ struct macro_source_file *file = nullptr;
+ int line = 0;
+
+ /* Return true if this scope is valid. */
+ bool is_valid () const
+ {
+ return file != nullptr;
+ }
};
/* Return a `struct macro_scope' object corresponding to the symtab
and line given in SAL. If we have no macro information for that
- location, or if SAL's pc is zero, return zero. */
-gdb::unique_xmalloc_ptr<struct macro_scope> sal_macro_scope
- (struct symtab_and_line sal);
-
+ location, or if SAL's pc is zero, return an invalid scope. */
+macro_scope sal_macro_scope (struct symtab_and_line sal);
/* Return a `struct macro_scope' object representing just the
user-defined macros. */
-gdb::unique_xmalloc_ptr<struct macro_scope> user_macro_scope (void);
+macro_scope user_macro_scope ();
/* Return a `struct macro_scope' object describing the scope the `macro
expand' and `macro expand-once' commands should use for looking up
If we have no macro information for the current location, return
the user macro scope. */
-gdb::unique_xmalloc_ptr<struct macro_scope> default_macro_scope (void);
+macro_scope default_macro_scope ();
/* Look up the definition of the macro named NAME in scope at the source
location given by MS. */
if (current_language->macro_expansion () == macro_expansion_c
&& code == TYPE_CODE_UNDEF)
{
- gdb::unique_xmalloc_ptr<struct macro_scope> scope;
-
/* This adds a macro's name to the current completion list. */
auto add_macro_name = [&] (const char *macro_name,
const macro_definition *,
resulting expression will be evaluated at "file:line" -- but
at there does not seem to be a way to detect this at
completion time. */
- scope = default_macro_scope ();
- if (scope)
- macro_for_each_in_scope (scope->file, scope->line,
- add_macro_name);
+ macro_scope scope = default_macro_scope ();
+ if (scope.is_valid ())
+ macro_for_each_in_scope (scope.file, scope.line, add_macro_name);
/* User-defined macros are always visible. */
macro_for_each (macro_user_macros, add_macro_name);