Add "name" method to class interp
authorTom Tromey <tom@tromey.com>
Fri, 25 May 2018 18:39:51 +0000 (12:39 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 25 May 2018 18:41:02 +0000 (12:41 -0600)
In a review Pedro pointed out that interp::name is intended to be
read-only, and so an accessor would be a better fit.  This patch
renames the field and adds a "name" method that is used instead.

ChangeLog
2018-05-25  Tom Tromey  <tom@tromey.com>

* tui/tui.c (tui_enable): Update.
* mi/mi-interp.c (mi_interp::init): Update.
* interps.h (class interp) <name>: New method.
<m_name>: Rename from name.
(~scoped_restore_interp): Update.
* interps.c (interp::interp): Update.
(interp_add, interp_set, interp_lookup_existing)
(current_interp_named_p): Update.

gdb/ChangeLog
gdb/interps.c
gdb/interps.h
gdb/mi/mi-interp.c
gdb/tui/tui.c

index 0bf350c2554658b7ad3db179269416babe467a04..a01f60c3b0e162dec5cfe98aca5699e2413b80cf 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-25  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui.c (tui_enable): Update.
+       * mi/mi-interp.c (mi_interp::init): Update.
+       * interps.h (class interp) <name>: New method.
+       <m_name>: Rename from name.
+       (~scoped_restore_interp): Update.
+       * interps.c (interp::interp): Update.
+       (interp_add, interp_set, interp_lookup_existing)
+       (current_interp_named_p): Update.
+
 2018-05-25  Tom Tromey <tom@tromey.com>
 
        * interps.c (interp_name): Remove.
index 8ec9744fdfe5e7d2c4e0d88bb43df1a6876c25f3..789ae8694694ed1e9d5c610af32ea2b7f8da9aa3 100644 (file)
@@ -78,8 +78,8 @@ static struct interp *interp_lookup_existing (struct ui *ui,
                                              const char *name);
 
 interp::interp (const char *name)
+  : m_name (xstrdup (name))
 {
-  this->name = xstrdup (name);
   this->inited = false;
 }
 
@@ -129,7 +129,7 @@ interp_add (struct ui *ui, struct interp *interp)
 {
   struct ui_interp_info *ui_interp = get_interp_info (ui);
 
-  gdb_assert (interp_lookup_existing (ui, interp->name) == NULL);
+  gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
 
   interp->next = ui_interp->interp_list;
   ui_interp->interp_list = interp;
@@ -170,11 +170,11 @@ interp_set (struct interp *interp, bool top_level)
   /* We use interpreter_p for the "set interpreter" variable, so we need
      to make sure we have a malloc'ed copy for the set command to free.  */
   if (interpreter_p != NULL
-      && strcmp (interp->name, interpreter_p) != 0)
+      && strcmp (interp->name (), interpreter_p) != 0)
     {
       xfree (interpreter_p);
 
-      interpreter_p = xstrdup (interp->name);
+      interpreter_p = xstrdup (interp->name ());
     }
 
   /* Run the init proc.  */
@@ -206,7 +206,7 @@ interp_lookup_existing (struct ui *ui, const char *name)
        interp != NULL;
        interp = interp->next)
     {
-      if (strcmp (interp->name, name) == 0)
+      if (strcmp (interp->name (), name) == 0)
        return interp;
     }
 
@@ -282,7 +282,7 @@ current_interp_named_p (const char *interp_name)
   struct interp *interp = ui_interp->current_interpreter;
 
   if (interp != NULL)
-    return (strcmp (interp->name, interp_name) == 0);
+    return (strcmp (interp->name (), interp_name) == 0);
 
   return 0;
 }
index a689be56253d361c66153879df2bfdebf6345032..74c9a80918c7ae602053d95c6ca7f112884d3bbb 100644 (file)
@@ -74,8 +74,13 @@ public:
   virtual bool supports_command_editing ()
   { return false; }
 
+  const char *name () const
+  {
+    return m_name;
+  }
+
   /* This is the name in "-i=" and "set interpreter".  */
-  const char *name;
+  const char *m_name;
 
   /* Interpreters are stored in a linked list, this is the next
      one...  */
@@ -111,7 +116,7 @@ public:
 
   ~scoped_restore_interp ()
   {
-    set_interp (m_interp->name);
+    set_interp (m_interp->name ());
   }
 
   scoped_restore_interp (const scoped_restore_interp &) = delete;
index e52d7979738830b78c1b5ca40c557c95242f84a6..ebc899f6319916e2d652f264164d12c0aa28ef65 100644 (file)
@@ -130,13 +130,13 @@ mi_interp::init (bool top_level)
 
   /* INTERP_MI selects the most recent released version.  "mi2" was
      released as part of GDB 6.0.  */
-  if (strcmp (name, INTERP_MI) == 0)
+  if (strcmp (name (), INTERP_MI) == 0)
     mi_version = 2;
-  else if (strcmp (name, INTERP_MI1) == 0)
+  else if (strcmp (name (), INTERP_MI1) == 0)
     mi_version = 1;
-  else if (strcmp (name, INTERP_MI2) == 0)
+  else if (strcmp (name (), INTERP_MI2) == 0)
     mi_version = 2;
-  else if (strcmp (name, INTERP_MI3) == 0)
+  else if (strcmp (name (), INTERP_MI3) == 0)
     mi_version = 3;
   else
     gdb_assert_not_reached ("unhandled MI version");
index 9e2520b4fc6ee4289e65f15af3e385dba5ce1ead..75a9ced6190e6daec5e2904a236cdd2a1a87360e 100644 (file)
@@ -415,7 +415,7 @@ tui_enable (void)
 
       /* If the top level interpreter is not the console/tui (e.g.,
         MI), enabling curses will certainly lose.  */
-      interp = top_level_interpreter ()->name;
+      interp = top_level_interpreter ()->name ();
       if (strcmp (interp, INTERP_TUI) != 0)
        error (_("Cannot enable the TUI when the interpreter is '%s'"), interp);
 
This page took 0.032146 seconds and 4 git commands to generate.