diff mbox

[RFAv2,1/5] Add class scoped_switch_to_sym_language_if_auto.

Message ID 20181117120445.10805-2-philippe.waroquiers@skynet.be
State New
Headers show

Commit Message

Philippe Waroquiers Nov. 17, 2018, 12:04 p.m. UTC
The class scoped_switch_to_sym_language_if_auto allows to switch in a scope
the current language to the language of a symbol when language mode is
set to auto.

2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* language.h (scoped_switch_to_sym_language_if_auto): New class.
---
 gdb/language.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
diff mbox

Patch

diff --git a/gdb/language.h b/gdb/language.h
index 02a84ff9a2..9577065669 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -707,4 +707,39 @@  private:
   enum language m_lang;
 };
 
+/* If language_mode is language_mode_auto,
+   then switch current language to the language of SYM
+   and restore current language upon destruction.
+
+   Else do nothing.  */
+
+class scoped_switch_to_sym_language_if_auto
+{
+public:
+
+  explicit scoped_switch_to_sym_language_if_auto (const struct symbol *sym)
+  {
+    if (language_mode == language_mode_auto)
+      {
+	m_lang = current_language->la_language;
+	m_switched = true;
+	set_language (SYMBOL_LANGUAGE (sym));
+      }
+    else
+      m_switched = false;
+  }
+
+  ~scoped_switch_to_sym_language_if_auto ()
+  {
+    if (m_switched)
+      set_language (m_lang);
+  }
+
+  DISABLE_COPY_AND_ASSIGN (scoped_switch_to_sym_language_if_auto);
+
+private:
+  bool m_switched;
+  enum language m_lang;
+};
+
 #endif /* defined (LANGUAGE_H) */