aboutsummaryrefslogtreecommitdiff
path: root/gdb/language.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-26 22:41:30 -0600
committerTom Tromey <tom@tromey.com>2017-08-03 07:58:58 -0600
commite3ad2841b1c75837a901618651fed23013643e3f (patch)
tree8bd5273ccd8abe8528e2b280ab67992bfa61ad28 /gdb/language.h
parentb80cf838447322778f04059a1f58b78ffbbeb597 (diff)
downloadgdb-e3ad2841b1c75837a901618651fed23013643e3f.zip
gdb-e3ad2841b1c75837a901618651fed23013643e3f.tar.gz
gdb-e3ad2841b1c75837a901618651fed23013643e3f.tar.bz2
Remove make_cleanup_restore_current_language
This patch replaces make_cleanup_restore_current_language with an RAII class that saves the current language, and restores it when the object is destroyed. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * utils.h (make_cleanup_restore_current_language): Remove. * utils.c (do_restore_current_language) (make_cleanup_restore_current_language): Remove. * parse.c (parse_exp_in_context_1) (parse_expression_with_language): Use scoped_restore_current_language. * mi/mi-main.c (mi_cmd_execute): Use scoped_restore_current_language. * language.h (scoped_restore_current_language): New class.
Diffstat (limited to 'gdb/language.h')
-rw-r--r--gdb/language.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/language.h b/gdb/language.h
index f4852c1..57e48bd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -633,4 +633,30 @@ extern const struct language_defn opencl_language_defn;
extern const struct language_defn pascal_language_defn;
extern const struct language_defn rust_language_defn;
+/* Save the current language and restore it upon destruction. */
+
+class scoped_restore_current_language
+{
+public:
+
+ explicit scoped_restore_current_language ()
+ : m_lang (current_language->la_language)
+ {
+ }
+
+ ~scoped_restore_current_language ()
+ {
+ set_language (m_lang);
+ }
+
+ scoped_restore_current_language (const scoped_restore_current_language &)
+ = delete;
+ scoped_restore_current_language &operator=
+ (const scoped_restore_current_language &) = delete;
+
+private:
+
+ enum language m_lang;
+};
+
#endif /* defined (LANGUAGE_H) */