mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-29 16:38:05 +08:00
Introduce TUI window iterator
This introduces an iterator class and a range adapter to make it simpler to iterate over TUI windows. One explicit iteration remains, in tui-win.c, because that spot is deleting windows as well. gdb/ChangeLog 2019-07-17 Tom Tromey <tom@tromey.com> * tui/tui-wingeneral.h (tui_refresh_all): Update. * tui/tui-wingeneral.c (make_all_visible): Use foreach. (tui_refresh_all): Remove "list" parameter. Use foreach. * tui/tui-win.c (window_name_completer): Use foreach. (tui_refresh_all_win, tui_rehighlight_all, tui_all_windows_info) (update_tab_width): Likewise. * tui/tui-layout.c (show_layout): Update. * tui/tui-data.h (class tui_window_iterator): New. (struct all_tui_windows): New. * tui/tui-data.c (tui_partial_win_by_name): Use foreach.
This commit is contained in:
@ -1,3 +1,16 @@
|
|||||||
|
2019-07-17 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* tui/tui-wingeneral.h (tui_refresh_all): Update.
|
||||||
|
* tui/tui-wingeneral.c (make_all_visible): Use foreach.
|
||||||
|
(tui_refresh_all): Remove "list" parameter. Use foreach.
|
||||||
|
* tui/tui-win.c (window_name_completer): Use foreach.
|
||||||
|
(tui_refresh_all_win, tui_rehighlight_all, tui_all_windows_info)
|
||||||
|
(update_tab_width): Likewise.
|
||||||
|
* tui/tui-layout.c (show_layout): Update.
|
||||||
|
* tui/tui-data.h (class tui_window_iterator): New.
|
||||||
|
(struct all_tui_windows): New.
|
||||||
|
* tui/tui-data.c (tui_partial_win_by_name): Use foreach.
|
||||||
|
|
||||||
2019-07-17 Tom Tromey <tom@tromey.com>
|
2019-07-17 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* tui/tui-regs.c (tui_reg_next, tui_reg_prev): Add "current_group"
|
* tui/tui-regs.c (tui_reg_next, tui_reg_prev): Add "current_group"
|
||||||
|
@ -294,27 +294,19 @@ tui_prev_win (struct tui_win_info *cur_win)
|
|||||||
struct tui_win_info *
|
struct tui_win_info *
|
||||||
tui_partial_win_by_name (const char *name)
|
tui_partial_win_by_name (const char *name)
|
||||||
{
|
{
|
||||||
struct tui_win_info *win_info = NULL;
|
|
||||||
|
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
{
|
{
|
||||||
int i = 0;
|
for (tui_win_info *item : all_tui_windows ())
|
||||||
|
|
||||||
while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
|
|
||||||
{
|
{
|
||||||
if (tui_win_list[i] != 0)
|
const char *cur_name = item->name ();
|
||||||
{
|
|
||||||
const char *cur_name = tui_win_list[i]->name ();
|
|
||||||
|
|
||||||
if (strlen (name) <= strlen (cur_name)
|
if (strlen (name) <= strlen (cur_name)
|
||||||
&& startswith (cur_name, name))
|
&& startswith (cur_name, name))
|
||||||
win_info = tui_win_list[i];
|
return item;
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return win_info;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -601,6 +601,75 @@ 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_DATA_WIN ((tui_data_window *) tui_win_list[DATA_WIN])
|
||||||
#define TUI_CMD_WIN ((tui_cmd_window *) tui_win_list[CMD_WIN])
|
#define TUI_CMD_WIN ((tui_cmd_window *) tui_win_list[CMD_WIN])
|
||||||
|
|
||||||
|
/* An iterator that iterates over all windows. */
|
||||||
|
|
||||||
|
class tui_window_iterator
|
||||||
|
{
|
||||||
|
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 ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Data Manipulation Functions. */
|
/* Data Manipulation Functions. */
|
||||||
extern void tui_initialize_static_data (void);
|
extern void tui_initialize_static_data (void);
|
||||||
extern struct tui_win_info *tui_partial_win_by_name (const char *);
|
extern struct tui_win_info *tui_partial_win_by_name (const char *);
|
||||||
|
@ -86,7 +86,7 @@ show_layout (enum tui_layout_type layout)
|
|||||||
|| layout == DISASSEM_DATA_COMMAND)
|
|| layout == DISASSEM_DATA_COMMAND)
|
||||||
{
|
{
|
||||||
show_data (layout);
|
show_data (layout);
|
||||||
tui_refresh_all (tui_win_list);
|
tui_refresh_all ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -364,18 +364,16 @@ window_name_completer (completion_tracker &tracker,
|
|||||||
const char *text, const char *word)
|
const char *text, const char *word)
|
||||||
{
|
{
|
||||||
std::vector<const char *> completion_name_vec;
|
std::vector<const char *> completion_name_vec;
|
||||||
int win_type;
|
|
||||||
|
|
||||||
for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
{
|
{
|
||||||
const char *completion_name = NULL;
|
const char *completion_name = NULL;
|
||||||
|
|
||||||
/* We can't focus on an invisible window. */
|
/* We can't focus on an invisible window. */
|
||||||
if (tui_win_list[win_type] == NULL
|
if (!win_info->is_visible)
|
||||||
|| !tui_win_list[win_type]->is_visible)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
completion_name = tui_win_list[win_type]->name ();
|
completion_name = win_info->name ();
|
||||||
gdb_assert (completion_name != NULL);
|
gdb_assert (completion_name != NULL);
|
||||||
completion_name_vec.push_back (completion_name);
|
completion_name_vec.push_back (completion_name);
|
||||||
}
|
}
|
||||||
@ -518,14 +516,12 @@ tui_source_window_base::refresh_all ()
|
|||||||
void
|
void
|
||||||
tui_refresh_all_win (void)
|
tui_refresh_all_win (void)
|
||||||
{
|
{
|
||||||
int type;
|
|
||||||
|
|
||||||
clearok (curscr, TRUE);
|
clearok (curscr, TRUE);
|
||||||
tui_refresh_all (tui_win_list);
|
tui_refresh_all ();
|
||||||
for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
{
|
{
|
||||||
if (tui_win_list[type] && tui_win_list[type]->is_visible)
|
if (win_info->is_visible)
|
||||||
tui_win_list[type]->refresh_all ();
|
win_info->refresh_all ();
|
||||||
}
|
}
|
||||||
tui_show_locator_content ();
|
tui_show_locator_content ();
|
||||||
}
|
}
|
||||||
@ -533,10 +529,8 @@ tui_refresh_all_win (void)
|
|||||||
void
|
void
|
||||||
tui_rehighlight_all (void)
|
tui_rehighlight_all (void)
|
||||||
{
|
{
|
||||||
int type;
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
|
tui_check_and_display_highlight_if_needed (win_info);
|
||||||
for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
|
|
||||||
tui_check_and_display_highlight_if_needed (tui_win_list[type]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resize all the windows based on the terminal size. This function
|
/* Resize all the windows based on the terminal size. This function
|
||||||
@ -885,21 +879,19 @@ tui_set_focus_command (const char *arg, int from_tty)
|
|||||||
static void
|
static void
|
||||||
tui_all_windows_info (const char *arg, int from_tty)
|
tui_all_windows_info (const char *arg, int from_tty)
|
||||||
{
|
{
|
||||||
int type;
|
|
||||||
struct tui_win_info *win_with_focus = tui_win_with_focus ();
|
struct tui_win_info *win_with_focus = tui_win_with_focus ();
|
||||||
|
|
||||||
for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
if (tui_win_list[type]
|
if (win_info->is_visible)
|
||||||
&& tui_win_list[type]->is_visible)
|
|
||||||
{
|
{
|
||||||
if (win_with_focus == tui_win_list[type])
|
if (win_with_focus == win_info)
|
||||||
printf_filtered (" %s\t(%d lines) <has focus>\n",
|
printf_filtered (" %s\t(%d lines) <has focus>\n",
|
||||||
tui_win_list[type]->name (),
|
win_info->name (),
|
||||||
tui_win_list[type]->height);
|
win_info->height);
|
||||||
else
|
else
|
||||||
printf_filtered (" %s\t(%d lines)\n",
|
printf_filtered (" %s\t(%d lines)\n",
|
||||||
tui_win_list[type]->name (),
|
win_info->name (),
|
||||||
tui_win_list[type]->height);
|
win_info->height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,11 +932,10 @@ tui_source_window_base::update_tab_width ()
|
|||||||
static void
|
static void
|
||||||
update_tab_width ()
|
update_tab_width ()
|
||||||
{
|
{
|
||||||
for (int win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
{
|
{
|
||||||
if (tui_win_list[win_type] != NULL
|
if (win_info->is_visible)
|
||||||
&& tui_win_list[win_type]->is_visible)
|
win_info->update_tab_width ();
|
||||||
tui_win_list[win_type]->update_tab_width ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,15 +212,8 @@ tui_source_window_base::make_visible (bool visible)
|
|||||||
static void
|
static void
|
||||||
make_all_visible (bool visible)
|
make_all_visible (bool visible)
|
||||||
{
|
{
|
||||||
int i;
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
|
win_info->make_visible (visible);
|
||||||
for (i = 0; i < MAX_MAJOR_WINDOWS; i++)
|
|
||||||
{
|
|
||||||
if (tui_win_list[i] != NULL)
|
|
||||||
tui_win_list[i]->make_visible (visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -257,15 +250,14 @@ tui_source_window_base::refresh ()
|
|||||||
/* Function to refresh all the windows currently displayed. */
|
/* Function to refresh all the windows currently displayed. */
|
||||||
|
|
||||||
void
|
void
|
||||||
tui_refresh_all (struct tui_win_info **list)
|
tui_refresh_all ()
|
||||||
{
|
{
|
||||||
int type;
|
|
||||||
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
|
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
|
||||||
|
|
||||||
for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
|
for (tui_win_info *win_info : all_tui_windows ())
|
||||||
{
|
{
|
||||||
if (list[type] && list[type]->is_visible)
|
if (win_info->is_visible)
|
||||||
list[type]->refresh ();
|
win_info->refresh ();
|
||||||
}
|
}
|
||||||
if (locator->is_visible)
|
if (locator->is_visible)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ extern struct tui_win_info *tui_copy_win (struct tui_win_info *);
|
|||||||
extern void tui_box_win (struct tui_gen_win_info *, int);
|
extern void tui_box_win (struct tui_gen_win_info *, int);
|
||||||
extern void tui_highlight_win (struct tui_win_info *);
|
extern void tui_highlight_win (struct tui_win_info *);
|
||||||
extern void tui_check_and_display_highlight_if_needed (struct tui_win_info *);
|
extern void tui_check_and_display_highlight_if_needed (struct tui_win_info *);
|
||||||
extern void tui_refresh_all (struct tui_win_info **);
|
extern void tui_refresh_all ();
|
||||||
extern void tui_delete_win (WINDOW *window);
|
extern void tui_delete_win (WINDOW *window);
|
||||||
|
|
||||||
#endif /* TUI_TUI_WINGENERAL_H */
|
#endif /* TUI_TUI_WINGENERAL_H */
|
||||||
|
Reference in New Issue
Block a user