public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 12/24] Change TUI window iteration
Date: Sat, 04 Jan 2020 18:34:00 -0000	[thread overview]
Message-ID: <20200104183410.17114-13-tom@tromey.com> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2020-01-04 18:34 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-04 18:34 [PATCH 00/24] Horizontal TUI layout + windows in Python Tom Tromey
2020-01-04 18:34 ` [PATCH 20/24] Allow TUI " Tom Tromey
2020-01-04 18:57   ` Eli Zaretskii
2020-02-22 19:57     ` Tom Tromey
2020-02-22 20:18       ` Eli Zaretskii
2020-03-10 22:23   ` Simon Marchi
2020-03-11  0:23     ` Tom Tromey
2020-03-11  4:47       ` Simon Marchi
2020-03-11  5:07         ` Simon Marchi
2020-03-11 18:05         ` Tom Tromey
2020-01-04 18:34 ` [PATCH 14/24] Handle ambiguity in tui_partial_win_by_name Tom Tromey
2020-01-04 18:34 ` [PATCH 16/24] TUI windows do not need to store their type Tom Tromey
2020-01-04 18:34 ` [PATCH 13/24] Reimplement tui_next_win and tui_prev_win Tom Tromey
2020-01-04 18:34 ` [PATCH 11/24] Add horizontal splitting to TUI layout Tom Tromey
2020-01-04 18:47   ` Eli Zaretskii
2020-01-04 18:34 ` Tom Tromey [this message]
2020-01-04 18:34 ` [PATCH 07/24] Remove hard-coded TUI layouts Tom Tromey
2020-01-04 18:34 ` [PATCH 01/24] Use TUI_DISASM_WIN instead of tui_win_list array Tom Tromey
2020-01-04 18:34 ` [PATCH 22/24] Use error_no_arg in TUI Tom Tromey
2020-01-04 18:34 ` [PATCH 03/24] Fix latent display bug in tui_data_window Tom Tromey
2020-01-04 18:34 ` [PATCH 09/24] Allow TUI sub-layouts in "new-layout" command Tom Tromey
2020-01-04 18:34 ` [PATCH 10/24] Change return type of tui_layout_base::adjust_size Tom Tromey
2020-01-04 18:34 ` [PATCH 06/24] Reimplement "tui reg" command Tom Tromey
2020-01-04 18:34 ` [PATCH 18/24] Remove tui_set_win_focus_to Tom Tromey
2020-01-04 18:34 ` [PATCH 24/24] Fix cast in TUI_DISASM_WIN Tom Tromey
2020-01-04 18:34 ` [PATCH 23/24] Add "usage" text to all TUI command help Tom Tromey
2020-01-04 18:34 ` [PATCH 02/24] Simplify tui_add_win_to_layout Tom Tromey
2020-01-04 18:34 ` [PATCH 21/24] Make some tui_source_window_base members "protected" Tom Tromey
2020-01-04 18:34 ` [PATCH 15/24] Remove tui_delete_invisible_windows and tui_make_all_invisible Tom Tromey
2020-01-04 18:34 ` [PATCH 05/24] Reimplement TUI "C-x 1" binding Tom Tromey
2020-01-04 18:34 ` [PATCH 04/24] Simplify TUI C-x 2 binding Tom Tromey
2020-01-04 18:34 ` [PATCH 19/24] Remove the TUI annotation hack Tom Tromey
2020-01-04 18:34 ` [PATCH 08/24] Add the "tui new-layout" command Tom Tromey
2020-01-04 18:44   ` Eli Zaretskii
2020-01-04 18:54 ` [PATCH 17/24] Change how TUI windows are instantiated Tom Tromey
2020-02-22 20:22 ` [PATCH 00/24] Horizontal TUI layout + windows in Python Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200104183410.17114-13-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).