Same idea as the previous patch, but for prefix instead of alias.
gdb/ChangeLog:
* cli/cli-decode.h (cmd_list_element) <is_prefix>: New, use it.
Change-Id: I76a9d2e82fc8d7429904424674d99ce6f9880e2b
{
ui_out_emit_tuple option_emitter (uiout, "option");
- gdb_assert (!list->subcommands);
+ gdb_assert (!list->is_prefix ());
gdb_assert (list->type == not_set_cmd);
uiout->field_string ("name", list->name);
{
for (c = cmdlist; c; c = c->next)
{
- if (cli_user_command_p (c) || c->subcommands != NULL)
+ if (cli_user_command_p (c) || c->is_prefix ())
show_user_1 (c, "", c->name, gdb_stdout);
}
}
/* We've already tried to look up COMMAND. */
gdb_assert (c_command != NULL
&& c_command != (struct cmd_list_element *) -1);
- gdb_assert (c_command->subcommands != NULL);
+ gdb_assert (c_command->is_prefix ());
c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, NULL, 1);
if (c_alias != c_command)
error (_("ALIAS and COMMAND prefixes do not match."));
{
struct cmd_list_element *q;
- if (p->subcommands == NULL)
+ if (!p->is_prefix ())
continue;
+
else if (p->subcommands == subcommands)
{
/* If we found an alias, we must return the aliased
std::string
cmd_list_element::prefixname () const
{
- if (this->subcommands == nullptr)
+ if (!this->is_prefix ())
/* Not a prefix command. */
return "";
'auto-load' command was not yet reachable by
lookup_cmd_for_subcommands (list, cmdlist)
that searches from the top level 'cmdlist'. */
- if (p->subcommands != nullptr)
+ if (p->is_prefix ())
update_prefix_field_of_prefixed_commands (p);
}
}
print_doc_of_command (c, prefix, verbose, regex, stream);
}
/* Check if this command has subcommands. */
- if (c->subcommands != NULL)
+ if (c->is_prefix ())
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */
fputs_filtered (c->doc, stream);
fputs_filtered ("\n", stream);
- if (c->subcommands == 0 && c->func != NULL)
+ if (!c->is_prefix () && c->func != NULL)
return;
+
fprintf_filtered (stream, "\n");
/* If this is a prefix command, print it's subcommands. */
- if (c->subcommands)
+ if (c->is_prefix ())
help_list (*c->subcommands, c->prefixname ().c_str (),
all_commands, stream);
fput_aliases_definition_styled (c, stream);
if (recurse
- && c->subcommands != 0
+ && c->is_prefix ()
&& c->abbrev_flag == 0)
/* Subcommands of a prefix command typically have 'all_commands'
as class. If we pass CLASS to recursive invocation,
if (recurse
&& (theclass == class_user || theclass == class_alias)
- && c->subcommands != NULL)
+ && c->is_prefix ())
{
/* User-defined commands or aliases may be subcommands. */
help_cmd_list (*c->subcommands, theclass, recurse, stream);
}
/* If we found a prefix command, keep looking. */
- if (found->subcommands)
+ if (found->is_prefix ())
{
c = lookup_cmd_1 (text, *found->subcommands, result_list, default_args,
ignore_help_classes, lookup_for_completion_p);
while (**line == ' ' || **line == '\t')
(*line)++;
- if (c->subcommands && **line && !c->allow_unknown)
+ if (c->is_prefix () && **line && !c->allow_unknown)
undef_cmd_error (c->prefixname ().c_str (), *line);
/* Seems to be what he wants. Return it. */
text += len;
text = skip_spaces (text);
- if ((*cmd)->subcommands != nullptr && *text != '\0')
+ if ((*cmd)->is_prefix () && *text != '\0')
{
cur_list = *(*cmd)->subcommands;
*prefix_cmd = *cmd;
if (!strncmp (ptr->name, text, textlen)
&& !ptr->abbrev_flag
&& (!ignore_help_classes || ptr->func
- || ptr->subcommands))
+ || ptr->is_prefix ()))
{
if (pass == 0)
{
bool is_alias () const
{ return this->alias_target != nullptr; }
+ /* Return true if this command is a prefix command. */
+ bool is_prefix () const
+ { return this->subcommands != nullptr; }
+
/* Points to next command in this list. */
struct cmd_list_element *next = nullptr;
const char *tem = prefix.c_str ();
c = lookup_cmd (&tem, cmdlist, "", NULL, 0, 1);
- if (c->subcommands == NULL)
+ if (!c->is_prefix ())
error (_("\"%s\" is not a prefix command."), prefix.c_str ());
list = c->subcommands;
/* if C is a prefix command that was previously defined,
tell the user its subcommands will be kept, and ask
if ok to redefine the command. */
- if (c->subcommands != nullptr)
+ if (c->is_prefix ())
q = (c->user_commands.get () == nullptr
|| query (_("Keeping subcommands of prefix command \"%s\".\n"
"Redefine command \"%s\"? "), c->name, c->name));
if (c != nullptr && c->theclass != class_user)
error (_("Command \"%s\" is built-in."), comfull);
- if (c != nullptr && c->subcommands != nullptr)
+ if (c != nullptr && c->is_prefix ())
{
/* c is already a user defined prefix command. */
return;
struct command_line *cmdlines = c->user_commands.get ();
fprintf_filtered (stream, "User %scommand \"",
- c->subcommands == NULL ? "" : "prefix ");
+ c->is_prefix () ? "prefix" : "");
fprintf_styled (stream, title_style.style (), "%s%s",
prefix, name);
fprintf_filtered (stream, "\":\n");
}
}
- if (c->subcommands != NULL)
+ if (c->is_prefix ())
{
const std::string prefixname = c->prefixname ();
for (c = *c->subcommands; c != NULL; c = c->next)
- if (c->theclass == class_user || c->subcommands != NULL)
+ if (c->theclass == class_user || c->is_prefix ())
show_user_1 (c, prefixname.c_str (), c->name, gdb_stdout);
}
/* If we find a prefix, run its list, prefixing our output by its
prefix (with "show " skipped). */
- if (list->subcommands && !list->is_alias ())
+ if (list->is_prefix () && !list->is_alias ())
{
ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
std::string prefixname = list->prefixname ();
{
/* If we find a prefix, output it (with "show " skipped). */
std::string prefixname = list->prefix->prefixname ();
- prefixname = (list->prefix->subcommands == nullptr ? ""
+ prefixname = (!list->prefix->is_prefix () ? ""
: strstr (prefixname.c_str (), "show ") + 5);
uiout->text (prefixname.c_str ());
}
{
/* The command is followed by whitespace; we need to
complete on whatever comes after command. */
- if (c->subcommands)
+ if (c->is_prefix ())
{
/* It is a prefix command; what comes after it is
a subcommand (e.g. "info "). */
{
/* There is non-whitespace beyond the command. */
- if (c->subcommands && !c->allow_unknown)
+ if (c->is_prefix () && !c->allow_unknown)
{
/* It is an unrecognized subcommand of a prefix command,
e.g. "info adsfkdj". */
gdbscm_scm_from_c_string (name), msg);
}
- if (elt->subcommands)
+ if (elt->is_prefix ())
{
xfree (prefix_text);
*base_list = elt->subcommands;
error (_("Invalid invocation of Python command object."));
if (! PyObject_HasAttr ((PyObject *) obj, invoke_cst))
{
- if (obj->command->subcommands != nullptr)
+ if (obj->command->is_prefix ())
{
/* A prefix command does not need an invoke method. */
return;
return NULL;
}
- if (elt->subcommands)
+ if (elt->is_prefix ())
{
*base_list = elt->subcommands;
return result;
if (c->theclass == class_user && c->user_commands)
execute_user_command (c, arg);
else if (c->theclass == class_user
- && c->subcommands && !c->allow_unknown)
+ && c->is_prefix () && !c->allow_unknown)
/* If this is a user defined prefix that does not allow unknown
(in other words, C is a prefix command and not a command
that can be followed by its args), report the list of
/* Check if this command has subcommands and is not an
abbreviation. We skip checking subcommands of abbreviations
in order to avoid duplicates in the output. */
- if (c->subcommands != NULL && !c->abbrev_flag)
+ if (c->is_prefix () && !c->abbrev_flag)
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */
{
/* If this command has subcommands and is not an alias,
traverse the subcommands. */
- if (c->subcommands != NULL && !c->is_alias ())
+ if (c->is_prefix () && !c->is_alias ())
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */