From patchwork Sat Nov 17 12:04:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30175 Received: (qmail 32516 invoked by alias); 17 Nov 2018 12:04:58 -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 32053 invoked by uid 89); 17 Nov 2018 12:04:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 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=Hx-languages-length:1396, H*Ad:D*be, HContent-Transfer-Encoding:8bit X-HELO: mailsec112.isp.belgacom.be Received: from mailsec112.isp.belgacom.be (HELO mailsec112.isp.belgacom.be) (195.238.20.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Nov 2018 12:04:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1542456297; x=1573992297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zW30jKHX5grmhgVy2Heg8R7sZXUSecVEcibm/4UWZZ4=; b=ctHV9zFz9KlxZuysZJHXJSTOvWW0po/YPMuGDG2s4tFRpiPUeQBdaCYp t58BeGQ1w5BSZ1W8nRBQW6JWKKQEYg==; 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; 17 Nov 2018 13:04:51 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto. Date: Sat, 17 Nov 2018 13:04:41 +0100 Message-Id: <20181117120445.10805-2-philippe.waroquiers@skynet.be> In-Reply-To: <20181117120445.10805-1-philippe.waroquiers@skynet.be> References: <20181117120445.10805-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 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 * language.h (scoped_switch_to_sym_language_if_auto): New class. --- gdb/language.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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) */