From 7eed1a8e8386e1b93c51768855c32ddae6f088ae Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 22 Feb 2020 11:48:26 -0700 Subject: [PATCH] Change TUI window iteration 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. gdb/ChangeLog 2020-02-22 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/ChangeLog b/gdb/ChangeLog index 83293187444..d0062218a2b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,20 @@ +2020-02-22 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. + 2020-02-22 Tom Tromey PR tui/17850: diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index e15ac585c98..a4601373e11 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -238,74 +238,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 c10378617c2..ad0484018e7 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 ()); } }; -- 2.30.2