forked from Imagelibrary/binutils-gdb
gdb: add context getter/setter to cmd_list_element
Straightforward replacement of get_cmd_context / set_cmd_context with cmd_list_element methods. gdb/ChangeLog: * cli/cli-decode.h (struct cmd_list_element) <set_context, context>: New. <context>: Rename to... <m_context>: ... this. * cli/cli-decode.c (set_cmd_context, get_cmd_context): Remove. * command.h (set_cmd_context, get_cmd_context): Remove, use cmd_list_element::set_context and cmd_list_element::context everywhere instead. Change-Id: I5016b0079014e3f17d1aa449ada7954473bf2b5d
This commit is contained in:
@@ -134,18 +134,6 @@ cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
|
||||
return cmd->func == do_const_cfunc && cmd->function.const_cfunc == cfunc;
|
||||
}
|
||||
|
||||
void
|
||||
set_cmd_context (struct cmd_list_element *cmd, void *context)
|
||||
{
|
||||
cmd->context = context;
|
||||
}
|
||||
|
||||
void *
|
||||
get_cmd_context (struct cmd_list_element *cmd)
|
||||
{
|
||||
return cmd->context;
|
||||
}
|
||||
|
||||
void
|
||||
set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
|
||||
{
|
||||
@@ -593,8 +581,8 @@ add_setshow_enum_cmd (const char *name,
|
||||
set_list, show_list);
|
||||
commands.set->enums = enumlist;
|
||||
|
||||
set_cmd_context (commands.set, context);
|
||||
set_cmd_context (commands.show, context);
|
||||
commands.set->set_context (context);
|
||||
commands.show->set_context (context);
|
||||
|
||||
return commands;
|
||||
}
|
||||
@@ -920,7 +908,8 @@ delete_cmd (const char *name, struct cmd_list_element **list,
|
||||
if (strcmp (iter->name, name) == 0)
|
||||
{
|
||||
if (iter->destroyer)
|
||||
iter->destroyer (iter, iter->context);
|
||||
iter->destroyer (iter, iter->context ());
|
||||
|
||||
if (iter->hookee_pre)
|
||||
iter->hookee_pre->hook_pre = 0;
|
||||
*prehook = iter->hook_pre;
|
||||
|
||||
@@ -93,6 +93,12 @@ struct cmd_list_element
|
||||
bool is_command_class_help () const
|
||||
{ return this->func == nullptr; }
|
||||
|
||||
void set_context (void *context)
|
||||
{ m_context = context; }
|
||||
|
||||
void *context () const
|
||||
{ return m_context; }
|
||||
|
||||
/* Points to next command in this list. */
|
||||
struct cmd_list_element *next = nullptr;
|
||||
|
||||
@@ -173,9 +179,6 @@ struct cmd_list_element
|
||||
}
|
||||
function;
|
||||
|
||||
/* Local state (context) for this command. This can be anything. */
|
||||
void *context = nullptr;
|
||||
|
||||
/* Documentation of this command (or help topic).
|
||||
First line is brief documentation; remaining lines form, with it,
|
||||
the full documentation. First line should end with a period.
|
||||
@@ -256,6 +259,10 @@ struct cmd_list_element
|
||||
when this command is being executed. It will be set back to false
|
||||
when the command has been executed. */
|
||||
int *suppress_notification = nullptr;
|
||||
|
||||
private:
|
||||
/* Local state (context) for this command. This can be anything. */
|
||||
void *m_context = nullptr;
|
||||
};
|
||||
|
||||
/* Functions that implement commands about CLI commands. */
|
||||
|
||||
@@ -333,7 +333,7 @@ struct dump_context
|
||||
static void
|
||||
call_dump_func (struct cmd_list_element *c, const char *args, int from_tty)
|
||||
{
|
||||
struct dump_context *d = (struct dump_context *) get_cmd_context (c);
|
||||
struct dump_context *d = (struct dump_context *) c->context ();
|
||||
|
||||
d->func (args, d->mode);
|
||||
}
|
||||
@@ -352,7 +352,7 @@ add_dump_command (const char *name,
|
||||
d = XNEW (struct dump_context);
|
||||
d->func = func;
|
||||
d->mode = FOPEN_WB;
|
||||
set_cmd_context (c, d);
|
||||
c->set_context (d);
|
||||
c->func = call_dump_func;
|
||||
|
||||
c = add_cmd (name, all_commands, descr, &append_cmdlist);
|
||||
@@ -360,7 +360,7 @@ add_dump_command (const char *name,
|
||||
d = XNEW (struct dump_context);
|
||||
d->func = func;
|
||||
d->mode = FOPEN_AB;
|
||||
set_cmd_context (c, d);
|
||||
c->set_context (d);
|
||||
c->func = call_dump_func;
|
||||
|
||||
/* Replace "Dump " at start of docstring with "Append " (borrowed
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "defs.h"
|
||||
#include "cli/cli-cmds.h"
|
||||
#include "cli/cli-decode.h"
|
||||
#include "cli/cli-setshow.h"
|
||||
#include "cli/cli-style.h"
|
||||
#include "source-cache.h"
|
||||
@@ -167,7 +168,7 @@ void
|
||||
cli_style_option::do_set_value (const char *ignore, int from_tty,
|
||||
struct cmd_list_element *cmd)
|
||||
{
|
||||
cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
|
||||
cli_style_option *cso = (cli_style_option *) cmd->context ();
|
||||
cso->changed.notify ();
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ do_show (const char *what, struct ui_file *file,
|
||||
struct cmd_list_element *cmd,
|
||||
const char *value)
|
||||
{
|
||||
cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
|
||||
cli_style_option *cso = (cli_style_option *) cmd->context ();
|
||||
fputs_filtered (_("The "), file);
|
||||
fprintf_styled (file, cso->style (), _("\"%s\" style"), cso->name ());
|
||||
fprintf_filtered (file, _(" %s is: %s\n"), what, value);
|
||||
|
||||
Reference in New Issue
Block a user