This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 12/24] Change TUI window iteration
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Sat, 4 Jan 2020 11:33:58 -0700
- Subject: [PATCH 12/24] Change TUI window iteration
- 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 <tom@tromey.com>
* tui/tui-winsource.h (struct tui_source_window_iterator)
<inner_iterator>: New etytypedef.
<tui_source_window_iterator>: Take "end" parameter.
<tui_source_window_iterator>: Take iterator.
<operator*, advance>: Update.
<m_iter>: Change type.
<m_end>: New field.
(struct tui_source_windows) <begin, end>: 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_win_info *> tui_windows;
-class tui_window_iterator
+/* Return a range adapter for iterating over TUI windows. */
+static inline std::vector<tui_win_info *> &
+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_win_info *> 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<tui_win_info *> (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<tui_win_info *>::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<tui_source_window_base *> (*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<tui_source_window_base *> (*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.17.2