Two simplifications in tui-layout.c
authorTom Tromey <tom@tromey.com>
Fri, 5 Jul 2019 18:34:31 +0000 (12:34 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 13 Aug 2019 20:52:09 +0000 (14:52 -0600)
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.

gdb/ChangeLog
gdb/tui/tui-layout.c

index f300180289f1d0db4c37d8eed01eae9708789ec4..ea3c0777c9970a2a798461ff0832c637abc64405 100644 (file)
@@ -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>
 
        * tui/tui-wingeneral.c (make_all_visible): Remove.
index 3ee3354b2ff4625ab10cab376c54952f6207382c..91db38404b30abdbf0190b8d884f62f9ea40b271 100644 (file)
@@ -83,33 +83,29 @@ show_layout (enum tui_layout_type layout)
       /* First make the current layout be invisible.  */
       tui_make_all_invisible ();
       tui_locator_win_info_ptr ()->make_visible (false);
-      if (layout == SRC_DATA_COMMAND 
-         || layout == DISASSEM_DATA_COMMAND)
+      switch (layout)
        {
+       case SRC_DATA_COMMAND:
+       case DISASSEM_DATA_COMMAND:
          show_data (layout);
          tui_refresh_all ();
-       }
-      else
-       {
-         switch (layout)
-           {
-             /* Now show the new layout.  */
-           case SRC_COMMAND:
-             show_source_command ();
-             tui_add_to_source_windows (TUI_SRC_WIN);
-             break;
-           case DISASSEM_COMMAND:
-             show_disasm_command ();
-             tui_add_to_source_windows (TUI_DISASM_WIN);
-             break;
-           case SRC_DISASSEM_COMMAND:
-             show_source_disasm_command ();
-             tui_add_to_source_windows (TUI_SRC_WIN);
-             tui_add_to_source_windows (TUI_DISASM_WIN);
-             break;
-           default:
-             break;
-           }
+         break;
+         /* Now show the new layout.  */
+       case SRC_COMMAND:
+         show_source_command ();
+         tui_add_to_source_windows (TUI_SRC_WIN);
+         break;
+       case DISASSEM_COMMAND:
+         show_disasm_command ();
+         tui_add_to_source_windows (TUI_DISASM_WIN);
+         break;
+       case SRC_DISASSEM_COMMAND:
+         show_source_disasm_command ();
+         tui_add_to_source_windows (TUI_SRC_WIN);
+         tui_add_to_source_windows (TUI_DISASM_WIN);
+         break;
+       default:
+         break;
        }
     }
 }
@@ -500,59 +496,56 @@ show_disasm_command (void)
 static 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)
-       cmd_height = TUI_CMD_WIN->height;
-      else
-       cmd_height = tui_term_height () / 3;
+  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) / 2;
-      asm_height = tui_term_height () - (src_height + cmd_height);
+  src_height = (tui_term_height () - cmd_height) / 2;
+  asm_height = tui_term_height () - (src_height + cmd_height);
 
-      if (TUI_SRC_WIN == NULL)
-       tui_win_list[SRC_WIN] = new tui_source_window ();
-      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 */ ,
+  if (TUI_SRC_WIN == NULL)
+    tui_win_list[SRC_WIN] = new tui_source_window ();
+  TUI_SRC_WIN->reset (src_height,
                      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;
-    }
+                     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 (),
+                 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
 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;
-      int src_height, cmd_height;
-      struct tui_locator_window *locator = tui_locator_win_info_ptr ();
-      gdb_assert (locator != nullptr);
+      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;
+    }
 
-      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;
+  locator->reset (2 /* 1 */ ,
+                 tui_term_width (),
+                 0,
+                 src_height - 1);
+  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 (),
                      0,
-                     src_height - 1);
-      win_info->reset (src_height - 1,
-                      tui_term_width (),
-                      0,
-                      0);
-      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;
-    }
+                     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;
 }