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.
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.
* interps.c (interp_exec): Use scoped_restore.
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". */
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
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. */