gdb: add cmd_list_element::is_alias
Add the cmd_list_element::is_alias helper to check whether a command is an alias. I find it easier to understand the intention in: if (c->is_alias ()) than if (c->alias_target != nullptr) Change all the spots that are reading alias_target just to compare it to NULL/nullptr to use is_alias instead. gdb/ChangeLog: * cli/cli-decode.h (cmd_list_element) <is_alias>: New, use it. Change-Id: I26ed56f99ee47fe884fdfedf87016501631693ce
This commit is contained in:
parent
9985872497
commit
1be99b11f8
5 changed files with 20 additions and 12 deletions
|
@ -1,3 +1,7 @@
|
|||
2021-05-17 Simon Marchi <simon.marchi@polymtl.ca>
|
||||
|
||||
* cli/cli-decode.h (cmd_list_element) <is_alias>: New, use it.
|
||||
|
||||
2021-05-17 Simon Marchi <simon.marchi@polymtl.ca>
|
||||
|
||||
* cli/cli-decode.h (cmd_list_element) <cmd_pointer>: Rename
|
||||
|
|
|
@ -75,7 +75,7 @@ lookup_cmd_with_subcommands (cmd_list_element **subcommands,
|
|||
{
|
||||
/* If we found an alias, we must return the aliased
|
||||
command. */
|
||||
return p->alias_target ? p->alias_target : p;
|
||||
return p->is_alias () ? p->alias_target : p;
|
||||
}
|
||||
|
||||
q = lookup_cmd_with_subcommands (subcommands, *(p->subcommands));
|
||||
|
@ -405,7 +405,7 @@ static void
|
|||
do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c)
|
||||
{
|
||||
/* Look past all aliases. */
|
||||
while (c->alias_target != nullptr)
|
||||
while (c->is_alias ())
|
||||
c = c->alias_target;
|
||||
|
||||
help_list (*c->subcommands, c->prefixname ().c_str (),
|
||||
|
@ -948,7 +948,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
|
|||
|
||||
/* If this command was an alias, remove it from the list of
|
||||
aliases. */
|
||||
if (iter->alias_target)
|
||||
if (iter->is_alias ())
|
||||
{
|
||||
struct cmd_list_element **prevp = &iter->alias_target->aliases;
|
||||
struct cmd_list_element *a = *prevp;
|
||||
|
@ -1043,7 +1043,7 @@ static void
|
|||
fput_alias_definition_styled (struct cmd_list_element *c,
|
||||
struct ui_file *stream)
|
||||
{
|
||||
gdb_assert (c->alias_target != nullptr);
|
||||
gdb_assert (c->is_alias ());
|
||||
fputs_filtered (" alias ", stream);
|
||||
fput_command_name_styled (c, stream);
|
||||
fprintf_filtered (stream, " = ");
|
||||
|
@ -1146,7 +1146,7 @@ apropos_cmd (struct ui_file *stream,
|
|||
/* Walk through the commands. */
|
||||
for (c=commandlist;c;c=c->next)
|
||||
{
|
||||
if (c->alias_target != nullptr)
|
||||
if (c->is_alias ())
|
||||
{
|
||||
/* Command aliases/abbreviations are skipped to ensure we print the
|
||||
doc of a command only once, when encountering the aliased
|
||||
|
@ -1487,7 +1487,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (c->alias_target != nullptr && theclass != class_alias)
|
||||
if (c->is_alias () && theclass != class_alias)
|
||||
{
|
||||
/* Do not show an alias, unless specifically showing the
|
||||
list of aliases: for all other classes, an alias is
|
||||
|
@ -1509,7 +1509,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
|
|||
list of sub-commands of the aliased command. */
|
||||
print_help_for_command
|
||||
(c,
|
||||
recurse && (theclass != class_alias || c->alias_target == nullptr),
|
||||
recurse && (theclass != class_alias || !c->is_alias ()),
|
||||
stream);
|
||||
continue;
|
||||
}
|
||||
|
@ -1672,7 +1672,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
|
|||
|
||||
*text += len;
|
||||
|
||||
if (found->alias_target)
|
||||
if (found->is_alias ())
|
||||
{
|
||||
/* We drop the alias (abbreviation) in favor of the command it
|
||||
is pointing to. If the alias is deprecated, though, we need to
|
||||
|
@ -2044,7 +2044,7 @@ lookup_cmd_composition_1 (const char *text,
|
|||
return 0;
|
||||
else
|
||||
{
|
||||
if ((*cmd)->alias_target)
|
||||
if ((*cmd)->is_alias ())
|
||||
{
|
||||
/* If the command was actually an alias, we note that an
|
||||
alias was used (by assigning *ALIAS) and we set *CMD. */
|
||||
|
|
|
@ -79,6 +79,10 @@ struct cmd_list_element
|
|||
For non-prefix commands, return an empty string. */
|
||||
std::string prefixname () const;
|
||||
|
||||
/* Return true if this command is an alias of another command. */
|
||||
bool is_alias () const
|
||||
{ return this->alias_target != nullptr; }
|
||||
|
||||
/* Points to next command in this list. */
|
||||
struct cmd_list_element *next = nullptr;
|
||||
|
||||
|
|
|
@ -740,7 +740,7 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
|
|||
|
||||
/* If we find a prefix, run its list, prefixing our output by its
|
||||
prefix (with "show " skipped). */
|
||||
if (list->subcommands && list->alias_target == nullptr)
|
||||
if (list->subcommands && !list->is_alias ())
|
||||
{
|
||||
ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
|
||||
std::string prefixname = list->prefixname ();
|
||||
|
@ -750,7 +750,7 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
|
|||
uiout->field_string ("prefix", new_prefix);
|
||||
cmd_show_list (*list->subcommands, from_tty);
|
||||
}
|
||||
else if (list->theclass != no_set_class && list->alias_target == nullptr)
|
||||
else if (list->theclass != no_set_class && !list->is_alias ())
|
||||
{
|
||||
ui_out_emit_tuple option_emitter (uiout, "option");
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ traverse_command_structure (struct cmd_list_element **list,
|
|||
{
|
||||
/* If this command has subcommands and is not an alias,
|
||||
traverse the subcommands. */
|
||||
if (c->subcommands != NULL && c->alias_target == nullptr)
|
||||
if (c->subcommands != NULL && !c->is_alias ())
|
||||
{
|
||||
/* Recursively call ourselves on the subcommand list,
|
||||
passing the right prefix in. */
|
||||
|
|
Loading…
Add table
Reference in a new issue