aboutsummaryrefslogtreecommitdiff
path: root/gdb/interps.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-08-13 14:40:46 -0600
committerTom Tromey <tom@tromey.com>2017-09-11 16:15:08 -0600
commitbe0d7abb5e3b0be4cb928845e70a9134f1b19700 (patch)
tree0452caa65b7bef568c9f1c9667f97d2db5e8ba76 /gdb/interps.h
parent00f675ff65ff6f78712a46e9699856e935d86d86 (diff)
downloadfsf-binutils-gdb-be0d7abb5e3b0be4cb928845e70a9134f1b19700.zip
fsf-binutils-gdb-be0d7abb5e3b0be4cb928845e70a9134f1b19700.tar.gz
fsf-binutils-gdb-be0d7abb5e3b0be4cb928845e70a9134f1b19700.tar.bz2
Replace interp_set_temp with scoped_restore_interp
This removes interp_set_temp and an associated cleanup, in favor of a new RAII class, scoped_restore_interp. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * cli/cli-script.c (restore_interp): Remove. (read_command_lines): Use scoped_restore_interp. * interps.c (scoped_restore_interp::set_temp): Rename from interp_set_temp. * interps.h (class scoped_restore_interp): New. (interp_set_temp): Remove.
Diffstat (limited to 'gdb/interps.h')
-rw-r--r--gdb/interps.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/interps.h b/gdb/interps.h
index b20cf5c..09d1314 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -104,6 +104,32 @@ extern struct ui_out *interp_ui_out (struct interp *interp);
extern const char *interp_name (struct interp *interp);
extern struct interp *interp_set_temp (const char *name);
+/* Temporarily set the current interpreter, and reset it on
+ destruction. */
+class scoped_restore_interp
+{
+public:
+
+ scoped_restore_interp (const char *name)
+ : m_interp (set_interp (name))
+ {
+ }
+
+ ~scoped_restore_interp ()
+ {
+ set_interp (interp_name (m_interp));
+ }
+
+ scoped_restore_interp (const scoped_restore_interp &) = delete;
+ scoped_restore_interp &operator= (const scoped_restore_interp &) = delete;
+
+private:
+
+ struct interp *set_interp (const char *name);
+
+ struct interp *m_interp;
+};
+
extern int current_interp_named_p (const char *name);
/* Call this function to give the current interpreter an opportunity