From 716b8bc52eef6044f1ff361e3e2eeb9307849034 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 29 Apr 2018 23:12:05 -0600 Subject: [PATCH] Change the as_*_interp functions to use dynamic_cast 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 * 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 | 6 ++++++ gdb/cli/cli-interp.c | 4 +--- gdb/mi/mi-interp.c | 4 +--- gdb/tui/tui-interp.c | 4 +--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3e199b67113..1cf048bbb3b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-05-25 Tom Tromey + + * 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 * cli/cli-interp.c (safe_execute_command): Use scoped_restore. diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 0663301c19d..e12d45b4b7a 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -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 (interp); } /* Longjmp-safe wrapper for "execute_command". */ diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 8bfb1298a5c..7536817f43a 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -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 (interp); } void diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c index cf32c905c5f..aa5e328ded2 100644 --- a/gdb/tui/tui-interp.c +++ b/gdb/tui/tui-interp.c @@ -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 (interp); } /* Cleanup the tui before exiting. */ -- 2.30.2