Two simplifications in tui-layout.c

This patch simplifies some code in tui-layout.c.

In show_layout, all the layout settings can be handled by a single
switch statement.  In show_source_disasm_command and
show_source_or_disasm_and_command, there is no need to check the
current layout, as the caller has already done so.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_layout): Unify all layout cases into a
	single switch.
	(show_source_disasm_command, show_source_or_disasm_and_command):
	Don't check current layout.
This commit is contained in:
Tom Tromey
2019-07-05 12:34:31 -06:00
parent 3f3ffe54e2
commit cc0c3ffbc9
2 changed files with 115 additions and 118 deletions

@ -1,3 +1,10 @@
2019-08-13 Tom Tromey <tom@tromey.com>
* tui/tui-layout.c (show_layout): Unify all layout cases into a
single switch.
(show_source_disasm_command, show_source_or_disasm_and_command):
Don't check current layout.
2019-08-13 Tom Tromey <tom@tromey.com> 2019-08-13 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.c (make_all_visible): Remove. * tui/tui-wingeneral.c (make_all_visible): Remove.

@ -83,33 +83,29 @@ show_layout (enum tui_layout_type layout)
/* First make the current layout be invisible. */ /* First make the current layout be invisible. */
tui_make_all_invisible (); tui_make_all_invisible ();
tui_locator_win_info_ptr ()->make_visible (false); tui_locator_win_info_ptr ()->make_visible (false);
if (layout == SRC_DATA_COMMAND switch (layout)
|| layout == DISASSEM_DATA_COMMAND)
{ {
case SRC_DATA_COMMAND:
case DISASSEM_DATA_COMMAND:
show_data (layout); show_data (layout);
tui_refresh_all (); tui_refresh_all ();
} break;
else /* Now show the new layout. */
{ case SRC_COMMAND:
switch (layout) show_source_command ();
{ tui_add_to_source_windows (TUI_SRC_WIN);
/* Now show the new layout. */ break;
case SRC_COMMAND: case DISASSEM_COMMAND:
show_source_command (); show_disasm_command ();
tui_add_to_source_windows (TUI_SRC_WIN); tui_add_to_source_windows (TUI_DISASM_WIN);
break; break;
case DISASSEM_COMMAND: case SRC_DISASSEM_COMMAND:
show_disasm_command (); show_source_disasm_command ();
tui_add_to_source_windows (TUI_DISASM_WIN); tui_add_to_source_windows (TUI_SRC_WIN);
break; tui_add_to_source_windows (TUI_DISASM_WIN);
case SRC_DISASSEM_COMMAND: break;
show_source_disasm_command (); default:
tui_add_to_source_windows (TUI_SRC_WIN); break;
tui_add_to_source_windows (TUI_DISASM_WIN);
break;
default:
break;
}
} }
} }
} }
@ -500,59 +496,56 @@ show_disasm_command (void)
static void static void
show_source_disasm_command (void) show_source_disasm_command (void)
{ {
if (tui_current_layout () != SRC_DISASSEM_COMMAND) int cmd_height, src_height, asm_height;
{
int cmd_height, src_height, asm_height;
if (TUI_CMD_WIN != NULL) if (TUI_CMD_WIN != NULL)
cmd_height = TUI_CMD_WIN->height; cmd_height = TUI_CMD_WIN->height;
else else
cmd_height = tui_term_height () / 3; cmd_height = tui_term_height () / 3;
src_height = (tui_term_height () - cmd_height) / 2; src_height = (tui_term_height () - cmd_height) / 2;
asm_height = tui_term_height () - (src_height + cmd_height); asm_height = tui_term_height () - (src_height + cmd_height);
if (TUI_SRC_WIN == NULL) if (TUI_SRC_WIN == NULL)
tui_win_list[SRC_WIN] = new tui_source_window (); tui_win_list[SRC_WIN] = new tui_source_window ();
TUI_SRC_WIN->reset (src_height, TUI_SRC_WIN->reset (src_height,
tui_term_width (),
0,
0);
TUI_SRC_WIN->make_visible (true);
TUI_SRC_WIN->m_has_locator = false;
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
gdb_assert (locator != nullptr);
tui_show_source_content (TUI_SRC_WIN);
if (TUI_DISASM_WIN == NULL)
tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
TUI_DISASM_WIN->reset (asm_height,
tui_term_width (),
0,
src_height - 1);
TUI_DISASM_WIN->make_visible (true);
locator->reset (2 /* 1 */ ,
tui_term_width (), tui_term_width (),
0, 0,
(src_height + asm_height) - 1); 0);
TUI_SRC_WIN->m_has_locator = false; TUI_SRC_WIN->make_visible (true);
TUI_DISASM_WIN->m_has_locator = true; TUI_SRC_WIN->m_has_locator = false;
locator->make_visible (true);
tui_show_locator_content ();
tui_show_source_content (TUI_DISASM_WIN);
if (TUI_CMD_WIN == NULL) struct tui_locator_window *locator = tui_locator_win_info_ptr ();
tui_win_list[CMD_WIN] = new tui_cmd_window (); gdb_assert (locator != nullptr);
TUI_CMD_WIN->reset (cmd_height,
tui_term_width (), tui_show_source_content (TUI_SRC_WIN);
0, if (TUI_DISASM_WIN == NULL)
tui_term_height () - cmd_height); tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
/* FIXME tui_cmd_window won't recreate the handle on TUI_DISASM_WIN->reset (asm_height,
make_visible, so we need this instead. */ tui_term_width (),
tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW); 0,
current_layout = SRC_DISASSEM_COMMAND; src_height - 1);
} TUI_DISASM_WIN->make_visible (true);
locator->reset (2 /* 1 */ ,
tui_term_width (),
0,
(src_height + asm_height) - 1);
TUI_SRC_WIN->m_has_locator = false;
TUI_DISASM_WIN->m_has_locator = true;
locator->make_visible (true);
tui_show_locator_content ();
tui_show_source_content (TUI_DISASM_WIN);
if (TUI_CMD_WIN == NULL)
tui_win_list[CMD_WIN] = new tui_cmd_window ();
TUI_CMD_WIN->reset (cmd_height,
tui_term_width (),
0,
tui_term_height () - cmd_height);
/* FIXME tui_cmd_window won't recreate the handle on
make_visible, so we need this instead. */
tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW);
current_layout = SRC_DISASSEM_COMMAND;
} }
@ -630,57 +623,54 @@ tui_gen_win_info::reset (int height_, int width_,
static void static void
show_source_or_disasm_and_command (enum tui_layout_type layout_type) show_source_or_disasm_and_command (enum tui_layout_type layout_type)
{ {
if (tui_current_layout () != layout_type) struct tui_source_window_base *win_info;
int src_height, cmd_height;
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
gdb_assert (locator != nullptr);
if (TUI_CMD_WIN != NULL)
cmd_height = TUI_CMD_WIN->height;
else
cmd_height = tui_term_height () / 3;
src_height = tui_term_height () - cmd_height;
if (layout_type == SRC_COMMAND)
{ {
struct tui_source_window_base *win_info; if (tui_win_list[SRC_WIN] == nullptr)
int src_height, cmd_height; tui_win_list[SRC_WIN] = new tui_source_window ();
struct tui_locator_window *locator = tui_locator_win_info_ptr (); win_info = TUI_SRC_WIN;
gdb_assert (locator != nullptr); }
else
{
if (tui_win_list[DISASSEM_WIN] == nullptr)
tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
win_info = TUI_DISASM_WIN;
}
if (TUI_CMD_WIN != NULL) locator->reset (2 /* 1 */ ,
cmd_height = TUI_CMD_WIN->height; tui_term_width (),
else 0,
cmd_height = tui_term_height () / 3; src_height - 1);
src_height = tui_term_height () - cmd_height; win_info->reset (src_height - 1,
tui_term_width (),
0,
0);
win_info->make_visible (true);
if (layout_type == SRC_COMMAND)
{
if (tui_win_list[SRC_WIN] == nullptr)
tui_win_list[SRC_WIN] = new tui_source_window ();
win_info = TUI_SRC_WIN;
}
else
{
if (tui_win_list[DISASSEM_WIN] == nullptr)
tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
win_info = TUI_DISASM_WIN;
}
locator->reset (2 /* 1 */ , win_info->m_has_locator = true;
locator->make_visible (true);
tui_show_locator_content ();
tui_show_source_content (win_info);
if (TUI_CMD_WIN == NULL)
tui_win_list[CMD_WIN] = new tui_cmd_window ();
TUI_CMD_WIN->reset (cmd_height,
tui_term_width (), tui_term_width (),
0, 0,
src_height - 1); src_height);
win_info->reset (src_height - 1, /* FIXME tui_cmd_window won't recreate the handle on
tui_term_width (), make_visible, so we need this instead. */
0, tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW);
0); current_layout = layout_type;
win_info->make_visible (true);
win_info->m_has_locator = true;
locator->make_visible (true);
tui_show_locator_content ();
tui_show_source_content (win_info);
if (TUI_CMD_WIN == NULL)
tui_win_list[CMD_WIN] = new tui_cmd_window ();
TUI_CMD_WIN->reset (cmd_height,
tui_term_width (),
0,
src_height);
/* FIXME tui_cmd_window won't recreate the handle on
make_visible, so we need this instead. */
tui_make_window (TUI_CMD_WIN, DONT_BOX_WINDOW);
current_layout = layout_type;
}
} }