From patchwork Sat Jan 4 18:33:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37183 Received: (qmail 717 invoked by alias); 4 Jan 2020 18:34:25 -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 363 invoked by uid 89); 4 Jan 2020 18:34:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=adapter X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 18:34:16 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 7F4A1B4BD3 for ; Sat, 4 Jan 2020 12:34:15 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id noFbiWgDVW4frnoFbinK1Q; Sat, 04 Jan 2020 12:34:15 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=u63b0jqGftO7KwGfu/q/Ckg0xmP0wIromsMqIsSCvrg=; b=xZ0aTSMiUj//TIpqDFq3JBdmNC CTKZsUGGa8ekqAPFdpqwFK4IIdtBDM22k3cwVm02/eeTa/1k7XeZMprj+Qn4n3DPcaTfJUfbhjf1+ VAH588byQSOpGulLSPlrRMSgn; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:48942 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1inoFb-0026Lh-Bj; Sat, 04 Jan 2020 11:34:15 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/24] Change TUI window iteration Date: Sat, 4 Jan 2020 11:33:58 -0700 Message-Id: <20200104183410.17114-13-tom@tromey.com> In-Reply-To: <20200104183410.17114-1-tom@tromey.com> References: <20200104183410.17114-1-tom@tromey.com> This changes the TUI to track all the instantiated windows in a new global vector. After this, iteration over TUI windows is done by simply iterating over this vector. This approach makes it simpler to define new window types. In particular, a subsequent patch will add the ability to define a TUI window from Python. Note that this series will not remove tui_win_list. This will continue to exist in parallel, only because it was simpler to leave this alone. Perhaps it could still be removed in the future. 2020-01-04 Tom Tromey * tui/tui-winsource.h (struct tui_source_window_iterator) : New etytypedef. : Take "end" parameter. : Take iterator. : Update. : Change type. : New field. (struct tui_source_windows) : Update. * tui/tui-layout.c (tui_windows): New global. (tui_apply_current_layout): Clear tui_windows. (tui_layout_window::apply): Update tui_windows. * tui/tui-data.h (tui_windows): Declare. (all_tui_windows): Now inline function. (class tui_window_iterator, struct all_tui_windows): Remove. Change-Id: I6ab77976d6326f427178f725434f8f82046e0bbf --- gdb/ChangeLog | 17 ++++++++++ gdb/tui/tui-data.h | 74 +++++------------------------------------ gdb/tui/tui-layout.c | 6 ++++ gdb/tui/tui-winsource.h | 26 +++++++++------ 4 files changed, 47 insertions(+), 76 deletions(-) diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index 570b55b1962..a5e4940666c 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -231,74 +231,16 @@ extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; #define TUI_DATA_WIN ((tui_data_window *) tui_win_list[DATA_WIN]) #define TUI_CMD_WIN ((tui_cmd_window *) tui_win_list[CMD_WIN]) -/* An iterator that iterates over all windows. */ +/* All the windows that are currently instantiated, in layout + order. */ +extern std::vector tui_windows; -class tui_window_iterator +/* Return a range adapter for iterating over TUI windows. */ +static inline std::vector & +all_tui_windows () { -public: - - typedef tui_window_iterator self_type; - typedef struct tui_win_info *value_type; - typedef struct tui_win_info *&reference; - typedef struct tui_win_info **pointer; - typedef std::forward_iterator_tag iterator_category; - typedef int difference_type; - - explicit tui_window_iterator (enum tui_win_type type) - : m_type (type) - { - advance (); - } - - tui_window_iterator () - : m_type (MAX_MAJOR_WINDOWS) - { - } - - bool operator!= (const self_type &other) const - { - return m_type != other.m_type; - } - - value_type operator* () const - { - gdb_assert (m_type < MAX_MAJOR_WINDOWS); - return tui_win_list[m_type]; - } - - self_type &operator++ () - { - ++m_type; - advance (); - return *this; - } - -private: - - void advance () - { - while (m_type < MAX_MAJOR_WINDOWS && tui_win_list[m_type] == nullptr) - ++m_type; - } - - int m_type; -}; - -/* A range adapter for iterating over TUI windows. */ - -struct all_tui_windows -{ - tui_window_iterator begin () const - { - return tui_window_iterator (SRC_WIN); - } - - tui_window_iterator end () const - { - return tui_window_iterator (); - } -}; - + return tui_windows; +} /* Data Manipulation Functions. */ extern int tui_term_height (void); diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index f33317beee8..9ad91ce713b 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -61,11 +61,15 @@ static tui_layout_split *applied_skeleton; static tui_layout_split *src_regs_layout; static tui_layout_split *asm_regs_layout; +/* See tui-data.h. */ +std::vector tui_windows; + /* See tui-layout.h. */ void tui_apply_current_layout () { + tui_windows.clear (); applied_layout->apply (0, 0, tui_term_width (), tui_term_height ()); } @@ -350,6 +354,8 @@ tui_layout_window::apply (int x_, int y_, int width_, int height_) height = height_; gdb_assert (m_window != nullptr); m_window->resize (height, width, x, y); + if (dynamic_cast (m_window) != nullptr) + tui_windows.push_back ((tui_win_info *) m_window); } /* See tui-layout.h. */ diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 87bd3b61d97..cae535fab07 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -153,6 +153,8 @@ struct tui_source_window_iterator { public: + typedef std::vector::iterator inner_iterator; + typedef tui_source_window_iterator self_type; typedef struct tui_source_window_base *value_type; typedef struct tui_source_window_base *&reference; @@ -160,14 +162,16 @@ public: typedef std::forward_iterator_tag iterator_category; typedef int difference_type; - explicit tui_source_window_iterator (bool dummy) - : m_iter (SRC_WIN) + explicit tui_source_window_iterator (const inner_iterator &it, + const inner_iterator &end) + : m_iter (it), + m_end (end) { advance (); } - tui_source_window_iterator () - : m_iter (tui_win_type (DISASSEM_WIN + 1)) + explicit tui_source_window_iterator (const inner_iterator &it) + : m_iter (it) { } @@ -178,7 +182,7 @@ public: value_type operator* () const { - return (value_type) *m_iter; + return dynamic_cast (*m_iter); } self_type &operator++ () @@ -192,12 +196,13 @@ private: void advance () { - tui_window_iterator end; - while (m_iter != end && *m_iter == nullptr) + while (m_iter != m_end + && dynamic_cast (*m_iter) == nullptr) ++m_iter; } - tui_window_iterator m_iter; + inner_iterator m_iter; + inner_iterator m_end; }; /* A range adapter for source windows. */ @@ -206,12 +211,13 @@ struct tui_source_windows { tui_source_window_iterator begin () const { - return tui_source_window_iterator (true); + return tui_source_window_iterator (tui_windows.begin (), + tui_windows.end ()); } tui_source_window_iterator end () const { - return tui_source_window_iterator (); + return tui_source_window_iterator (tui_windows.end ()); } };