public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 2/4] Change the as_*_interp functions to use dynamic_cast
Date: Mon, 30 Apr 2018 05:12:00 -0000	[thread overview]
Message-ID: <20180430051207.19979-3-tom@tromey.com> (raw)
In-Reply-To: <20180430051207.19979-1-tom@tromey.com>

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-04-29  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        | 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/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 0663301c19..e12d45b4b7 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<cli_interp *> (interp);
 }
 
 /* Longjmp-safe wrapper for "execute_command".  */
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 8bfb1298a5..7536817f43 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<mi_interp *> (interp);
 }
 
 void
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index cf32c905c5..aa5e328ded 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<tui_interp *> (interp);
 }
 
 /* Cleanup the tui before exiting.  */
-- 
2.13.6

  parent reply	other threads:[~2018-04-30  5:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  5:12 [RFA 0/4] minor interp-related cleanups Tom Tromey
2018-04-30  5:12 ` [RFA 3/4] Remove interp_ui_out Tom Tromey
2018-05-25 18:37   ` Pedro Alves
2018-04-30  5:12 ` [RFA 4/4] Remove interp_name Tom Tromey
2018-05-25 18:41   ` Pedro Alves
2018-05-25 18:47     ` Tom Tromey
2018-05-25 19:36       ` Pedro Alves
2018-04-30  5:12 ` [RFA 1/4] Use scoped_restore in a couple of interp-related places Tom Tromey
2018-05-25 18:06   ` Pedro Alves
2018-04-30  5:12 ` Tom Tromey [this message]
2018-05-25 18:12   ` [RFA 2/4] Change the as_*_interp functions to use dynamic_cast Pedro Alves
2018-05-25 17:34 ` [RFA 0/4] minor interp-related cleanups Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180430051207.19979-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).