gdb: remove context parameter from add_setshow_enum_cmd
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:38:25 +0000 (21:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:39:26 +0000 (21:39 -0400)
I propose removing the context parameter from add_setshow_enum_cmd.  It
was useful before add_setshow_enum_cmd returned both created commands,
as the caller couldn't easily set the context itself.  But now, I think
it's fine to just let the caller do it.

gdb/ChangeLog:

* command.h (add_setshow_enum_cmd): Remove context parameter.
* cli/cli-decode.c (add_setshow_enum_cmd): Likewise, and don't
set context.
* cli/cli-style.c (cli_style_option::add_setshow_commands): Set
context here.

Change-Id: I377c4e6820ec9d5069492ed28f4cba342ce1336e

gdb/ChangeLog
gdb/cli/cli-decode.c
gdb/cli/cli-style.c
gdb/command.h

index 6ba91d8ec6ef43c6ea495dfa6cb78f0332682537..9acde122a2a8aa8edaab4d0fc00b716e0ec7bd6e 100644 (file)
@@ -1,3 +1,11 @@
+2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * command.h (add_setshow_enum_cmd): Remove context parameter.
+       * cli/cli-decode.c (add_setshow_enum_cmd): Likewise, and don't
+       set context.
+       * cli/cli-style.c (cli_style_option::add_setshow_commands): Set
+       context here.
+
 2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * cli/cli-decode.h (struct cmd_list_element) <set_context>: Add
index f2fdeb03a285554c24aa223a612832246cd47e3d..633a3ad930950aaf1e8ed05c23fdc2ee116de34b 100644 (file)
@@ -571,8 +571,7 @@ add_setshow_enum_cmd (const char *name,
                      cmd_const_sfunc_ftype *set_func,
                      show_value_ftype *show_func,
                      struct cmd_list_element **set_list,
-                     struct cmd_list_element **show_list,
-                     void *context)
+                     struct cmd_list_element **show_list)
 {
   set_show_commands commands
     =  add_setshow_cmd_full (name, theclass, var_enum, var,
@@ -580,10 +579,6 @@ add_setshow_enum_cmd (const char *name,
                             set_func, show_func,
                             set_list, show_list);
   commands.set->enums = enumlist;
-
-  commands.set->set_context (context);
-  commands.show->set_context (context);
-
   return commands;
 }
 
index 0b88dba562278a3fcae38282e23e6efb74ce85a8..aca19c51b848a2ec094ba8a0a9cd43059d11b7b9 100644 (file)
@@ -230,32 +230,46 @@ cli_style_option::add_setshow_commands (enum command_class theclass,
                        0, set_list);
   add_show_prefix_cmd (m_name, no_class, prefix_doc, &m_show_list,
                       0, show_list);
+  set_show_commands commands;
+
+  commands = add_setshow_enum_cmd
+    ("foreground", theclass, cli_colors,
+     &m_foreground,
+     _("Set the foreground color for this property."),
+     _("Show the foreground color for this property."),
+     nullptr,
+     do_set_value,
+     do_show_foreground,
+     &m_set_list, &m_show_list);
+  commands.set->set_context (this);
+  commands.show->set_context (this);
+
+  commands = add_setshow_enum_cmd
+    ("background", theclass, cli_colors,
+     &m_background,
+     _("Set the background color for this property."),
+     _("Show the background color for this property."),
+     nullptr,
+     do_set_value,
+     do_show_background,
+     &m_set_list, &m_show_list);
+  commands.set->set_context (this);
+  commands.show->set_context (this);
 
-  add_setshow_enum_cmd ("foreground", theclass, cli_colors,
-                       &m_foreground,
-                       _("Set the foreground color for this property."),
-                       _("Show the foreground color for this property."),
-                       nullptr,
-                       do_set_value,
-                       do_show_foreground,
-                       &m_set_list, &m_show_list, (void *) this);
-  add_setshow_enum_cmd ("background", theclass, cli_colors,
-                       &m_background,
-                       _("Set the background color for this property."),
-                       _("Show the background color for this property."),
-                       nullptr,
-                       do_set_value,
-                       do_show_background,
-                       &m_set_list, &m_show_list, (void *) this);
   if (!skip_intensity)
-    add_setshow_enum_cmd ("intensity", theclass, cli_intensities,
-                         &m_intensity,
-                         _("Set the display intensity for this property."),
-                         _("Show the display intensity for this property."),
-                         nullptr,
-                         do_set_value,
-                         do_show_intensity,
-                         &m_set_list, &m_show_list, (void *) this);
+    {
+      commands = add_setshow_enum_cmd
+       ("intensity", theclass, cli_intensities,
+        &m_intensity,
+        _("Set the display intensity for this property."),
+        _("Show the display intensity for this property."),
+        nullptr,
+        do_set_value,
+        do_show_intensity,
+        &m_set_list, &m_show_list);
+      commands.set->set_context (this);
+      commands.show->set_context (this);
+    }
 }
 
 static cmd_list_element *style_set_list;
index 9413a50c297144c8b8ea4d706c39120d410fcad6..711cbdcf43e10044746ba2281fd25edbb7a10483 100644 (file)
@@ -403,7 +403,7 @@ extern set_show_commands add_setshow_enum_cmd
    const char **var, const char *set_doc, const char *show_doc,
    const char *help_doc, cmd_const_sfunc_ftype *set_func,
    show_value_ftype *show_func, cmd_list_element **set_list,
-   cmd_list_element **show_list, void *context = nullptr);
+   cmd_list_element **show_list);
 
 extern set_show_commands add_setshow_auto_boolean_cmd
   (const char *name, command_class theclass, auto_boolean *var,