Message ID | 20181028144614.14149-2-philippe.waroquiers@skynet.be |
---|---|
State | New |
Headers | show |
On 10/28/2018 02:46 PM, Philippe Waroquiers wrote: > The class scoped_switch_auto_to_sym_language allows to switch in a scope > the current language to the language of a symbol when language mode is > set to auto. > > 2018-10-27 Philippe Waroquiers <philippe.waroquiers@skynet.be> > > * language.h (scoped_switch_auto_to_sym_language): new class. s/new/New/ > --- > gdb/language.h | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/gdb/language.h b/gdb/language.h > index 02a84ff9a2..47a88de756 100644 > --- a/gdb/language.h > +++ b/gdb/language.h > @@ -707,4 +707,43 @@ private: > enum language m_lang; > }; > > +/* If language_mode is language_mode_auto, > + then switches current language to the language of SYM > + and restore current language upon destruction. > + > + Else does nothing. */ Either s/switches/switch/ s/does/do/ or s/restore/restores/ I'd go with the former. > + > +class scoped_switch_auto_to_sym_language I have to admit that I had trouble grokking the class's name for a bit. I don't have a much better suggestion, though this would read a bit better to me: scoped_switch_to_sym_language_if_auto scoped_switch_to_sym_lang_if_auto But may well be just me. Feel free to ignore. > +{ > +public: > + > + explicit scoped_switch_auto_to_sym_language (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_auto_to_sym_language () > + { > + if (m_switched) > + set_language (m_lang); > + } > + > + scoped_switch_auto_to_sym_language > + (const scoped_switch_auto_to_sym_language &) > + = delete; > + scoped_switch_auto_to_sym_language &operator= > + (const scoped_switch_auto_to_sym_language &) = delete; Use DISABLE_COPY_AND_ASSIGN instead. Otherwise OK. > + > +private: > + bool m_switched; > + enum language m_lang; > +}; > + > #endif /* defined (LANGUAGE_H) */ > Thanks, Pedro Alves
diff --git a/gdb/language.h b/gdb/language.h index 02a84ff9a2..47a88de756 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -707,4 +707,43 @@ private: enum language m_lang; }; +/* If language_mode is language_mode_auto, + then switches current language to the language of SYM + and restore current language upon destruction. + + Else does nothing. */ + +class scoped_switch_auto_to_sym_language +{ +public: + + explicit scoped_switch_auto_to_sym_language (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_auto_to_sym_language () + { + if (m_switched) + set_language (m_lang); + } + + scoped_switch_auto_to_sym_language + (const scoped_switch_auto_to_sym_language &) + = delete; + scoped_switch_auto_to_sym_language &operator= + (const scoped_switch_auto_to_sym_language &) = delete; + +private: + bool m_switched; + enum language m_lang; +}; + #endif /* defined (LANGUAGE_H) */