From patchwork Sun Oct 28 14:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 29928 Received: (qmail 101294 invoked by alias); 28 Oct 2018 14:46:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101205 invoked by uid 89); 28 Oct 2018 14:46:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mailsec110.isp.belgacom.be Received: from mailsec110.isp.belgacom.be (HELO mailsec110.isp.belgacom.be) (195.238.20.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 Oct 2018 14:46:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1540737989; x=1572273989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TuBQPXoJBOkCrunxMf9DPTBCX0+If7rgmHQnpwXK/bs=; b=wz6HfEbi3cU+Wl802VQ6t5VvezXaWAEtkQhqnVO6Cs1bqqU2TPN+Gouf dypIK3tzqMTK7ttT3bRHNs3PBGVUxw==; Received: from 110.212-243-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.243.212.110]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 28 Oct 2018 15:46:23 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA 1/5] Add class scoped_switch_auto_to_sym_language. Date: Sun, 28 Oct 2018 15:46:10 +0100 Message-Id: <20181028144614.14149-2-philippe.waroquiers@skynet.be> In-Reply-To: <20181028144614.14149-1-philippe.waroquiers@skynet.be> References: <20181028144614.14149-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 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 * language.h (scoped_switch_auto_to_sym_language): new class. --- 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. */ + +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) */