[09/15] Turn tui_erase_source_content into a method

Message ID 20190814162132.31424-10-tom@tromey.com
State New
Headers show
Series
  • Another round of TUI refactoring
Related show

Commit Message

Tom Tromey Aug. 14, 2019, 4:21 p.m.
This changes tui_erase_source_content into a method on
tui_source_window_base.  The bulk of the work is moved into a helper
method, so that the callers can each pass the string appropriate to
the particular window class.

2019-08-14  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<do_erase_source_content>: New method.
	<erase_source_content>: New method.
	(tui_erase_source_content): Don't declare.
	* tui/tui-winsource.c (tui_clear_source_content): Update.
	(tui_source_window_base::do_erase_source_content): Rename from
	tui_erase_source_content.
	(tui_source_window_base::show_source_content): Update.
	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Update.
	* tui/tui-source.h (struct tui_source_window)
	<erase_source_content>: New method.
	* tui/tui-disasm.h (struct tui_disasm_window)
	<erase_source_content>: New method.
---
 gdb/ChangeLog           | 16 ++++++++++++++++
 gdb/tui/tui-disasm.h    |  5 +++++
 gdb/tui/tui-source.h    |  5 +++++
 gdb/tui/tui-win.c       | 10 +++++-----
 gdb/tui/tui-winsource.c | 40 ++++++++++++++++------------------------
 gdb/tui/tui-winsource.h |  7 ++++++-
 6 files changed, 53 insertions(+), 30 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index 71b911182f8..24073e1dc19 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -48,6 +48,11 @@  struct tui_disasm_window : public tui_source_window_base
 		     int line_no, CORE_ADDR addr)
     override;
 
+  void erase_source_content () override
+  {
+    do_erase_source_content (NO_DISASSEM_STRING);
+  }
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 42338790947..2926777ab3f 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -51,6 +51,11 @@  struct tui_source_window : public tui_source_window_base
 		     int line_no, CORE_ADDR addr)
     override;
 
+  void erase_source_content () override
+  {
+    do_erase_source_content (NO_SRC_STRING);
+  }
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index ff4f2ee5b39..7210f6c4119 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -595,7 +595,7 @@  tui_resize_all (void)
 	  first_win->make_visible_with_new_height ();
 	  TUI_CMD_WIN->make_visible_with_new_height ();
 	  if (src_win->content.empty ())
-	    tui_erase_source_content (src_win);
+	    src_win->erase_source_content ();
 	  break;
 	default:
 	  if (cur_layout == SRC_DISASSEM_COMMAND)
@@ -659,7 +659,7 @@  tui_resize_all (void)
 	  second_win->make_visible_with_new_height ();
 	  TUI_CMD_WIN->make_visible_with_new_height ();
 	  if (src_win->content.empty ())
-	    tui_erase_source_content (src_win);
+	    src_win->erase_source_content ();
 	  break;
 	}
 
@@ -1065,7 +1065,7 @@  tui_adjust_win_heights (struct tui_win_info *primary_win_info,
 		  tui_source_window_base *src_base
 		    = (tui_source_window_base *) src_win_info;
 		  if (src_base->content.empty ())
-		    tui_erase_source_content (src_base);
+		    src_base->erase_source_content ();
 		}
 	    }
 	  else
@@ -1169,9 +1169,9 @@  tui_adjust_win_heights (struct tui_win_info *primary_win_info,
 	      second_win->make_visible_with_new_height ();
 	      first_win->make_visible_with_new_height ();
 	      if (src1 != nullptr && src1->content.empty ())
-		tui_erase_source_content (src1);
+		src1->erase_source_content ();
 	      if (second_win->content.empty ())
-		tui_erase_source_content (second_win);
+		second_win->erase_source_content ();
 	    }
 	}
     }
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 121f19abd8b..d955efcd575 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -198,7 +198,7 @@  tui_clear_source_content (struct tui_source_window_base *win_info)
     {
       int i;
 
-      tui_erase_source_content (win_info);
+      win_info->erase_source_content ();
       for (i = 0; i < win_info->content.size (); i++)
 	{
 	  struct tui_source_element *element = &win_info->content[i];
@@ -211,38 +211,30 @@  tui_clear_source_content (struct tui_source_window_base *win_info)
 
 
 void
-tui_erase_source_content (struct tui_source_window_base *win_info)
+tui_source_window_base::do_erase_source_content (const char *str)
 {
   int x_pos;
-  int half_width = (win_info->width - 2) / 2;
+  int half_width = (width - 2) / 2;
 
-  if (win_info->handle != NULL)
+  if (handle != NULL)
     {
-      werase (win_info->handle);
-      win_info->check_and_display_highlight_if_needed ();
+      werase (handle);
+      check_and_display_highlight_if_needed ();
 
-      const char *no_src_str;
-
-      if (win_info->type == SRC_WIN)
-	no_src_str = NO_SRC_STRING;
-      else
-	no_src_str = NO_DISASSEM_STRING;
-      if (strlen (no_src_str) >= half_width)
+      if (strlen (str) >= half_width)
 	x_pos = 1;
       else
-	x_pos = half_width - strlen (no_src_str);
-      mvwaddstr (win_info->handle,
-		 (win_info->height / 2),
+	x_pos = half_width - strlen (str);
+      mvwaddstr (handle,
+		 (height / 2),
 		 x_pos,
-		 (char *) no_src_str);
-
-      win_info->content.clear ();
-      win_info->refresh_window ();
+		 (char *) str);
 
-      struct tui_gen_win_info *exec_info = win_info->execution_info;
+      content.clear ();
+      refresh_window ();
 
-      werase (exec_info->handle);
-      exec_info->refresh_window ();
+      werase (execution_info->handle);
+      execution_info->refresh_window ();
     }
 }
 
@@ -284,7 +276,7 @@  tui_source_window_base::show_source_content ()
         tui_show_source_line (this, lineno);
     }
   else
-    tui_erase_source_content (this);
+    erase_source_content ();
 
   check_and_display_highlight_if_needed ();
   refresh_window ();
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 320c8370166..60031d3bdb0 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -100,6 +100,9 @@  protected:
   void do_scroll_horizontal (int num_to_scroll) override;
   void do_make_visible_with_new_height () override;
 
+  /* Erase the content and display STRING.  */
+  void do_erase_source_content (const char *string);
+
 public:
 
   void clear_detail ();
@@ -131,6 +134,9 @@  public:
   virtual void maybe_update (struct frame_info *fi, symtab_and_line sal,
 			     int line_no, CORE_ADDR addr) = 0;
 
+  /* Erase the source content.  */
+  virtual void erase_source_content () = 0;
+
   /* Does the locator belong to this window?  */
   bool m_has_locator = false;
   /* Execution information window.  */
@@ -180,7 +186,6 @@  extern void tui_update_source_windows_with_addr (struct gdbarch *, CORE_ADDR);
 extern void tui_update_source_windows_with_line (struct symtab *, 
 						 int);
 extern void tui_clear_source_content (struct tui_source_window_base *);
-extern void tui_erase_source_content (struct tui_source_window_base *);
 
 /* Constant definitions. */
 #define SCROLL_THRESHOLD 2	/* Threshold for lazy scroll.  */