gdb: add cmd_list_element::is_alias
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 17 May 2021 18:01:20 +0000 (14:01 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 17 May 2021 18:01:20 +0000 (14:01 -0400)
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

gdb/ChangeLog
gdb/cli/cli-decode.c
gdb/cli/cli-decode.h
gdb/cli/cli-setshow.c
gdb/unittests/command-def-selftests.c

index e430506373323f3602de25be9cb522d4961fc9c8..b39879fcd5b81f5ce47502dcc792261b1c649b79 100644 (file)
@@ -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
index ec579ff196175f86ec3dfd58d5896a044629ee41..29b4ed2f6bd7f266222b1d61ccb43fcbe92531bb 100644 (file)
@@ -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.  */
index 68a9b8586b4019f71c6b424b8ebab5cf200f5378..8caf6023454892319c2c97efe31134228e6f2a30 100644 (file)
@@ -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;
 
index cb821c5b3c03fddf1c0ed05566a69a62630058ae..7e93a70349421d78f04601fa2e951e001442ab88 100644 (file)
@@ -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");
 
index 123667d33699a0d95d401529f9577c783b0f9422..4a6b6789b370cf6c562b344187a595e21e132152 100644 (file)
@@ -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.  */
This page took 0.044298 seconds and 4 git commands to generate.