[PATCH 35/66] Introduce tui_gen_win_info::name method

Tom Tromey
2019-06-23T23:25:50Z

This removes tui_win_name and replaces it with a method on
tui_gen_win_info, removing another spot that switched on window type.

2019-06-23 Tom Tromey <tom@tromey.com>

* tui/tui-win.c (window_name_completer, tui_set_focus)
(tui_all_windows_info): Use name method.
* tui/tui-data.h (struct tui_gen_win_info)
(struct tui_source_window, struct tui_disasm_window)
(struct tui_data_window, struct tui_cmd_window) <name>: New
method.
(tui_win_name): Don't declare.
* tui/tui-data.c (tui_partial_win_by_name): Use name method.
(tui_win_name): Remove.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/tui/tui-data.c | 31 +------------------------------
gdb/tui/tui-data.h | 27 ++++++++++++++++++++++++++-
gdb/tui/tui-win.c | 8 ++++----
4 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 63afec57141..5bb79156e70 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -337,7 +337,7 @@ tui_partial_win_by_name (const char *name)
{
if (tui_win_list[i] != 0)
{
- const char *cur_name = tui_win_name (tui_win_list[i]);
+ const char *cur_name = tui_win_list[i]->name ();

if (strlen (name) <= strlen (cur_name)
&& startswith (cur_name, name))
@@ -351,35 +351,6 @@ tui_partial_win_by_name (const char *name)
}

-/* Answer the name of the window. */
-const char *
-tui_win_name (const struct tui_gen_win_info *win_info)
-{
- const char *name = NULL;
-
- switch (win_info->type)
- {
- case SRC_WIN:
- name = SRC_NAME;
- break;
- case CMD_WIN:
- name = CMD_NAME;
- break;
- case DISASSEM_WIN:
- name = DISASSEM_NAME;
- break;
- case DATA_WIN:
- name = DATA_NAME;
- break;
- default:
- name = "";
- break;
- }
-
- return name;
-}
-
-
void
tui_initialize_static_data (void)
{
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 78c17102218..01c0f167cde 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -51,6 +51,12 @@ struct tui_gen_win_info
/* Call to refresh this window. */
virtual void refresh_window ();

+ /* Return the name of this type of window. */
+ virtual const char *name () const
+ {
+ return "";
+ }
+
/* Window handle. */
WINDOW *handle = nullptr;
/* Type of window. */
@@ -383,6 +389,11 @@ struct tui_source_window : public tui_source_window_base

DISABLE_COPY_AND_ASSIGN (tui_source_window);

+ const char *name () const override
+ {
+ return SRC_NAME;
+ }
+
protected:

void do_scroll_vertical (enum tui_scroll_direction,
@@ -400,6 +411,11 @@ struct tui_disasm_window : public tui_source_window_base

DISABLE_COPY_AND_ASSIGN (tui_disasm_window);

+ const char *name () const override
+ {
+ return DISASSEM_NAME;
+ }
+
protected:

void do_scroll_vertical (enum tui_scroll_direction,
@@ -423,6 +439,11 @@ struct tui_data_window : public tui_win_info

void refresh_window () override;

+ const char *name () const override
+ {
+ return DATA_NAME;
+ }
+
/* Start of data display content. */
tui_win_content data_content = NULL;
int data_content_count = 0;
@@ -465,6 +486,11 @@ struct tui_cmd_window : public tui_win_info
{
}

+ const char *name () const override
+ {
+ return CMD_NAME;
+ }
+
int start_line = 0;

protected:
@@ -502,7 +528,6 @@ extern void tui_free_win_content (struct tui_gen_win_info *);
extern void tui_free_data_content (tui_win_content, int);
extern void tui_free_all_source_wins_content (void);
extern struct tui_win_info *tui_partial_win_by_name (const char *);
-extern const char *tui_win_name (const struct tui_gen_win_info *);
extern enum tui_layout_type tui_current_layout (void);
extern void tui_set_current_layout_to (enum tui_layout_type);
extern int tui_term_height (void);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index c8fd267f362..33dcb3b2f6c 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -376,7 +376,7 @@ window_name_completer (completion_tracker &tracker,
|| !tui_win_list[win_type]->is_visible)
continue;

- completion_name = tui_win_name (tui_win_list [win_type]);
+ completion_name = tui_win_list[win_type]->name ();
gdb_assert (completion_name != NULL);
completion_name_vec.push_back (completion_name);
}
@@ -869,7 +869,7 @@ The window name specified must be valid and visible.\n"));
TUI_DATA_WIN->refresh_all ();
xfree (buf_ptr);
printf_filtered (_("Focus set to %s window.\n"),
- tui_win_name (tui_win_with_focus ()));
+ tui_win_with_focus ()->name ());
}
else
warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
@@ -896,11 +896,11 @@ tui_all_windows_info (const char *arg, int from_tty)
{
if (win_with_focus == tui_win_list[type])
printf_filtered (" %s\t(%d lines) <has focus>\n",
- tui_win_name (tui_win_list[type]),
+ tui_win_list[type]->name (),
tui_win_list[type]->height);
else
printf_filtered (" %s\t(%d lines)\n",
- tui_win_name (tui_win_list[type]),
+ tui_win_list[type]->name (),
tui_win_list[type]->height);
}
}
--
2.17.2