Change the as_*_interp functions to use dynamic_cast
authorTom Tromey <tom@tromey.com>
Mon, 30 Apr 2018 05:12:05 +0000 (23:12 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 25 May 2018 18:41:00 +0000 (12:41 -0600)
This changes the various as_*_interp functions to be implemented using
dynamic_cast.  I believe this is a small improvement, because it is
more typesafe -- the C++ runtime does the type-checking for us.

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

* tui/tui-interp.c (as_tui_interp): Use dynamic_cast.
* mi/mi-interp.c (as_mi_interp): Use dynamic_cast.
* cli/cli-interp.c (as_cli_interp): Use dynamic_cast.

gdb/ChangeLog
gdb/cli/cli-interp.c
gdb/mi/mi-interp.c
gdb/tui/tui-interp.c

index 3e199b671134dadd60b46050b08f0c1d330779d2..1cf048bbb3beca4a09800b5cef8b09ccc5fb51ce 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-25  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-interp.c (as_tui_interp): Use dynamic_cast.
+       * mi/mi-interp.c (as_mi_interp): Use dynamic_cast.
+       * cli/cli-interp.c (as_cli_interp): Use dynamic_cast.
+
 2018-05-25  Tom Tromey  <tom@tromey.com>
 
        * cli/cli-interp.c (safe_execute_command): Use scoped_restore.
index 0663301c19de5ff72b864839fbba43f987def588..e12d45b4b7aac831a3176a88aed33436ff9ddd22 100644 (file)
@@ -73,9 +73,7 @@ struct cli_suppress_notification cli_suppress_notification =
 static struct cli_interp *
 as_cli_interp (struct interp *interp)
 {
-  if (strcmp (interp_name (interp), INTERP_CONSOLE) == 0)
-    return (struct cli_interp *) interp;
-  return NULL;
+  return dynamic_cast<cli_interp *> (interp);
 }
 
 /* Longjmp-safe wrapper for "execute_command".  */
index 8bfb1298a5c1a65a8dcb0adfb326b7104d877db0..7536817f43a72d96e1a4de66bc73f5a2c373edf9 100644 (file)
@@ -106,9 +106,7 @@ display_mi_prompt (struct mi_interp *mi)
 static struct mi_interp *
 as_mi_interp (struct interp *interp)
 {
-  if (interp_ui_out (interp)->is_mi_like_p ())
-    return (struct mi_interp *) interp;
-  return NULL;
+  return dynamic_cast<mi_interp *> (interp);
 }
 
 void
index cf32c905c5f685817c253f6e6a8b09ad49c883af..aa5e328ded2b6e3f179bf90d7373ae3943ebaf57 100644 (file)
@@ -58,9 +58,7 @@ public:
 static tui_interp *
 as_tui_interp (struct interp *interp)
 {
-  if (strcmp (interp_name (interp), INTERP_TUI) == 0)
-    return (tui_interp *) interp;
-  return NULL;
+  return dynamic_cast<tui_interp *> (interp);
 }
 
 /* Cleanup the tui before exiting.  */
This page took 0.032427 seconds and 4 git commands to generate.