struct ui_interp_info
{
+ ui_interp_info () = default;
+ DISABLE_COPY_AND_ASSIGN (ui_interp_info);
+
/* Each top level has its own independent set of interpreters. */
- struct interp *interp_list;
- struct interp *current_interpreter;
- struct interp *top_level_interpreter;
+ interp *interp_list = nullptr;
+ interp *current_interpreter = nullptr;
+ interp *top_level_interpreter = nullptr;
/* The interpreter that is active while `interp_exec' is active, NULL
at all other times. */
- struct interp *command_interpreter;
+ interp *command_interpreter = nullptr;
};
-/* Get UI's ui_interp_info object. Never returns NULL. */
+/* Get UI's ui_interp_info object. */
-static struct ui_interp_info *
+static ui_interp_info &
get_interp_info (struct ui *ui)
{
if (ui->interp_info == NULL)
- ui->interp_info = XCNEW (struct ui_interp_info);
- return ui->interp_info;
+ ui->interp_info = new ui_interp_info;
+ return *ui->interp_info;
}
-/* Get the current UI's ui_interp_info object. Never returns
- NULL. */
+/* Get the current UI's ui_interp_info object. */
-static struct ui_interp_info *
+static ui_interp_info &
get_current_interp_info (void)
{
return get_interp_info (current_ui);
static void
interp_add (struct ui *ui, struct interp *interp)
{
- struct ui_interp_info *ui_interp = get_interp_info (ui);
+ ui_interp_info &ui_interp = get_interp_info (ui);
gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
- interp->next = ui_interp->interp_list;
- ui_interp->interp_list = interp;
+ interp->next = ui_interp.interp_list;
+ ui_interp.interp_list = interp;
}
/* This sets the current interpreter to be INTERP. If INTERP has not
static void
interp_set (struct interp *interp, bool top_level)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
- struct interp *old_interp = ui_interp->current_interpreter;
+ ui_interp_info &ui_interp = get_current_interp_info ();
+ struct interp *old_interp = ui_interp.current_interpreter;
/* If we already have an interpreter, then trying to
set top level interpreter is kinda pointless. */
- gdb_assert (!top_level || !ui_interp->current_interpreter);
- gdb_assert (!top_level || !ui_interp->top_level_interpreter);
+ gdb_assert (!top_level || !ui_interp.current_interpreter);
+ gdb_assert (!top_level || !ui_interp.top_level_interpreter);
if (old_interp != NULL)
{
old_interp->suspend ();
}
- ui_interp->current_interpreter = interp;
+ ui_interp.current_interpreter = interp;
if (top_level)
- ui_interp->top_level_interpreter = interp;
+ ui_interp.top_level_interpreter = interp;
if (interpreter_p != interp->name ())
interpreter_p = interp->name ();
static struct interp *
interp_lookup_existing (struct ui *ui, const char *name)
{
- struct ui_interp_info *ui_interp = get_interp_info (ui);
+ ui_interp_info &ui_interp = get_interp_info (ui);
struct interp *interp;
- for (interp = ui_interp->interp_list;
+ for (interp = ui_interp.interp_list;
interp != NULL;
interp = interp->next)
{
current_interp_set_logging (ui_file_up logfile, bool logging_redirect,
bool debug_redirect)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
- struct interp *interp = ui_interp->current_interpreter;
+ ui_interp_info &ui_interp = get_current_interp_info ();
+ struct interp *interp = ui_interp.current_interpreter;
interp->set_logging (std::move (logfile), logging_redirect, debug_redirect);
}
struct interp *
scoped_restore_interp::set_interp (const char *name)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
+ ui_interp_info &ui_interp = get_current_interp_info ();
struct interp *interp = interp_lookup (current_ui, name);
- struct interp *old_interp = ui_interp->current_interpreter;
+ struct interp *old_interp = ui_interp.current_interpreter;
if (interp)
- ui_interp->current_interpreter = interp;
+ ui_interp.current_interpreter = interp;
return old_interp;
}
int
current_interp_named_p (const char *interp_name)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
- struct interp *interp = ui_interp->current_interpreter;
+ ui_interp_info &ui_interp = get_current_interp_info ();
+ struct interp *interp = ui_interp.current_interpreter;
if (interp != NULL)
return (strcmp (interp->name (), interp_name) == 0);
struct interp *
command_interp (void)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
+ ui_interp_info &ui_interp = get_current_interp_info ();
- if (ui_interp->command_interpreter != NULL)
- return ui_interp->command_interpreter;
+ if (ui_interp.command_interpreter != NULL)
+ return ui_interp.command_interpreter;
else
- return ui_interp->current_interpreter;
+ return ui_interp.current_interpreter;
}
/* See interps.h. */
void
interp_exec (struct interp *interp, const char *command_str)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
+ ui_interp_info &ui_interp = get_current_interp_info ();
/* See `command_interp' for why we do this. */
scoped_restore save_command_interp
- = make_scoped_restore (&ui_interp->command_interpreter, interp);
+ = make_scoped_restore (&ui_interp.command_interpreter, interp);
interp->exec (command_str);
}
static void
interpreter_exec_cmd (const char *args, int from_tty)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
+ ui_interp_info &ui_interp = get_current_interp_info ();
struct interp *old_interp, *interp_to_use;
unsigned int nrules;
unsigned int i;
if (nrules < 2)
error (_("Usage: interpreter-exec INTERPRETER COMMAND..."));
- old_interp = ui_interp->current_interpreter;
+ old_interp = ui_interp.current_interpreter;
interp_to_use = interp_lookup (current_ui, prules[0]);
if (interp_to_use == NULL)
struct interp *
top_level_interpreter (void)
{
- struct ui_interp_info *ui_interp = get_current_interp_info ();
+ ui_interp_info &ui_interp = get_current_interp_info ();
- return ui_interp->top_level_interpreter;
+ return ui_interp.top_level_interpreter;
}
/* See interps.h. */
struct interp *
current_interpreter (void)
{
- struct ui_interp_info *ui_interp = get_interp_info (current_ui);
+ ui_interp_info &ui_interp = get_interp_info (current_ui);
- return ui_interp->current_interpreter;
+ return ui_interp.current_interpreter;
}
/* This just adds the "interpreter-exec" command. */