Add class scoped_switch_to_sym_language_if_auto.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 28 Oct 2018 12:51:32 +0000 (13:51 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 20 Nov 2018 21:39:08 +0000 (22:39 +0100)
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-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* language.h (scoped_switch_to_sym_language_if_auto): New class.

gdb/ChangeLog
gdb/language.h

index a04f498c927d98cb7ec9202e479163c679daaf98..413c61243c469ff3feed2cf9002187413c10b9c3 100644 (file)
@@ -1,3 +1,7 @@
+2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+       * language.h (scoped_switch_to_sym_language_if_auto): New class.
+
 2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * symtab.c (search_symbols): Properly check absence of type regexp
index 02a84ff9a2b92c24cc95f279e2fcc887539185b0..957706566996a35ec2023f2df40bb8fb4c71f5e5 100644 (file)
@@ -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) */
This page took 0.043612 seconds and 4 git commands to generate.