This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Add class scoped_switch_to_sym_language_if_auto.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9e6a1ab6652e8461f786d5c308f632a7c0acc53f

commit 9e6a1ab6652e8461f786d5c308f632a7c0acc53f
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date:   Sun Oct 28 13:51:32 2018 +0100

    Add class scoped_switch_to_sym_language_if_auto.
    
    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.

Diff:
---
 gdb/ChangeLog  |  4 ++++
 gdb/language.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a04f498..413c612 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 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
 	before entering the loop scanning the minimal symbols.
 
diff --git a/gdb/language.h b/gdb/language.h
index 02a84ff..9577065 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) */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]