This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 40/66] Remove tui_scroll_direction enum


The tui_scroll_direction enum is not really needed, because it's
simple to adapt the various scrolling methods to use the sign of their
argument as the direction in which to scroll.

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

	* tui/tui-winsource.c
	(tui_source_window_base::do_scroll_horizontal): Remove direction
	parameter.
	* tui/tui-windata.c (tui_data_window::do_scroll_vertical): Remove
	direction parameter.
	* tui/tui-win.c (tui_win_info::forward_scroll)
	(tui_win_info::backward_scroll, tui_win_info::left_scroll)
	(tui_win_info::right_scroll): Update.
	* tui/tui-source.c (tui_source_window::do_scroll_vertical): Remove
	direction parameter.
	* tui/tui-disasm.c (tui_disasm_window::do_scroll_vertical): Remove
	direction parameter.
	* tui/tui-data.h (enum tui_scroll_direction): Remove.
	(struct tui_win_info) <do_scroll_vertical, do_scroll_horizontal>:
	Remove direction parameter.
	(struct tui_source_window_base, struct tui_source_window)
	(struct tui_disasm_window, struct tui_data_window)
	(struct tui_cmd_window): Update.
---
 gdb/ChangeLog           | 21 +++++++++++++++++++++
 gdb/tui/tui-data.h      | 37 +++++++++----------------------------
 gdb/tui/tui-disasm.c    | 13 ++++++-------
 gdb/tui/tui-source.c    | 29 ++++++++++-------------------
 gdb/tui/tui-win.c       |  8 ++++----
 gdb/tui/tui-windata.c   |  8 ++------
 gdb/tui/tui-winsource.c | 16 ++++------------
 7 files changed, 56 insertions(+), 76 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 01c0f167cde..92bfb39fe86 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -122,16 +122,6 @@ struct tui_gen_win_info
 #define MAX_TARGET_WIDTH  10
 #define MAX_PID_WIDTH     19
 
-/* Scroll direction enum.  */
-enum tui_scroll_direction
-{
-  FORWARD_SCROLL,
-  BACKWARD_SCROLL,
-  LEFT_SCROLL,
-  RIGHT_SCROLL
-};
-
-
 /* The kinds of layouts available.  */
 enum tui_layout_type
 {
@@ -264,13 +254,11 @@ protected:
 
   /* Scroll the contents vertically.  This is only called via
      forward_scroll and backward_scroll.  */
-  virtual void do_scroll_vertical (enum tui_scroll_direction,
-				   int num_to_scroll) = 0;
+  virtual void do_scroll_vertical (int num_to_scroll) = 0;
 
   /* Scroll the contents horizontally.  This is only called via
      left_scroll and right_scroll.  */
-  virtual void do_scroll_horizontal (enum tui_scroll_direction,
-				     int num_to_scroll) = 0;
+  virtual void do_scroll_horizontal (int num_to_scroll) = 0;
 
 public:
 
@@ -337,8 +325,7 @@ protected:
   ~tui_source_window_base () override;
   DISABLE_COPY_AND_ASSIGN (tui_source_window_base);
 
-  void do_scroll_horizontal (enum tui_scroll_direction,
-			     int num_to_scroll) override;
+  void do_scroll_horizontal (int num_to_scroll) override;
 
 public:
 
@@ -396,8 +383,7 @@ struct tui_source_window : public tui_source_window_base
 
 protected:
 
-  void do_scroll_vertical (enum tui_scroll_direction,
-			   int num_to_scroll) override;
+  void do_scroll_vertical (int num_to_scroll) override;
 };
 
 /* A TUI disassembly window.  */
@@ -418,8 +404,7 @@ struct tui_disasm_window : public tui_source_window_base
 
 protected:
 
-  void do_scroll_vertical (enum tui_scroll_direction,
-			   int num_to_scroll) override;
+  void do_scroll_vertical (int num_to_scroll) override;
 };
 
 struct tui_data_window : public tui_win_info
@@ -457,10 +442,8 @@ struct tui_data_window : public tui_win_info
 
 protected:
 
-  void do_scroll_vertical (enum tui_scroll_direction,
-			   int num_to_scroll) override;
-  void do_scroll_horizontal (enum tui_scroll_direction,
-			     int num_to_scroll) override
+  void do_scroll_vertical (int num_to_scroll) override;
+  void do_scroll_horizontal (int num_to_scroll) override
   {
   }
 };
@@ -495,13 +478,11 @@ struct tui_cmd_window : public tui_win_info
 
 protected:
 
-  void do_scroll_vertical (enum tui_scroll_direction,
-			   int num_to_scroll) override
+  void do_scroll_vertical (int num_to_scroll) override
   {
   }
 
-  void do_scroll_horizontal (enum tui_scroll_direction,
-			     int num_to_scroll) override
+  void do_scroll_horizontal (int num_to_scroll) override
   {
   }
 };
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 0bc7c642bcd..b3d39ea8031 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -371,22 +371,21 @@ tui_get_low_disassembly_address (struct gdbarch *gdbarch,
 
 /* Scroll the disassembly forward or backward vertically.  */
 void
-tui_disasm_window::do_scroll_vertical
-  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
+tui_disasm_window::do_scroll_vertical (int num_to_scroll)
 {
   if (content != NULL)
     {
       CORE_ADDR pc;
       struct tui_line_or_address val;
-      int dir;
 
       pc = content[0]->which_element.source.line_or_addr.u.addr;
-      num_to_scroll++;
-      dir = (scroll_direction == FORWARD_SCROLL)
-	? num_to_scroll : -num_to_scroll;
+      if (num_to_scroll >= 0)
+	num_to_scroll++;
+      else
+	--num_to_scroll;
 
       val.loa = LOA_ADDRESS;
-      val.u.addr = tui_find_disassembly_address (gdbarch, pc, dir);
+      val.u.addr = tui_find_disassembly_address (gdbarch, pc, num_to_scroll);
       tui_update_source_window_as_is (this, gdbarch,
 				      NULL, val, FALSE);
     }
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 39abe81a870..54e53cf8dbd 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -308,8 +308,7 @@ tui_source_is_displayed (const char *fullname)
 
 /* Scroll the source forward or backward vertically.  */
 void
-tui_source_window::do_scroll_vertical
-  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
+tui_source_window::do_scroll_vertical (int num_to_scroll)
 {
   if (content != NULL)
     {
@@ -323,23 +322,15 @@ tui_source_window::do_scroll_vertical
 	s = cursal.symtab;
 
       l.loa = LOA_LINE;
-      if (scroll_direction == FORWARD_SCROLL)
-	{
-	  l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
-	    + num_to_scroll;
-	  if (l.u.line_no > s->nlines)
-	    /* line = s->nlines - win_info->content_size + 1; */
-	    /* elz: fix for dts 23398.  */
-	    l.u.line_no
-	      = content[0]->which_element.source.line_or_addr.u.line_no;
-	}
-      else
-	{
-	  l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
-	    - num_to_scroll;
-	  if (l.u.line_no <= 0)
-	    l.u.line_no = 1;
-	}
+      l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
+	+ num_to_scroll;
+      if (l.u.line_no > s->nlines)
+	/* line = s->nlines - win_info->content_size + 1; */
+	/* elz: fix for dts 23398.  */
+	l.u.line_no
+	  = content[0]->which_element.source.line_or_addr.u.line_no;
+      if (l.u.line_no <= 0)
+	l.u.line_no = 1;
 
       print_source_lines (s, l.u.line_no, l.u.line_no + 1, 0);
     }
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 33dcb3b2f6c..b92eb505b31 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -475,7 +475,7 @@ tui_win_info::forward_scroll (int num_to_scroll)
   if (num_to_scroll == 0)
     num_to_scroll = height - 3;
 
-  do_scroll_vertical (FORWARD_SCROLL, num_to_scroll);
+  do_scroll_vertical (num_to_scroll);
 }
 
 void
@@ -484,7 +484,7 @@ tui_win_info::backward_scroll (int num_to_scroll)
   if (num_to_scroll == 0)
     num_to_scroll = height - 3;
 
-  do_scroll_vertical (BACKWARD_SCROLL, num_to_scroll);
+  do_scroll_vertical (- num_to_scroll);
 }
 
 
@@ -494,7 +494,7 @@ tui_win_info::left_scroll (int num_to_scroll)
   if (num_to_scroll == 0)
     num_to_scroll = 1;
 
-  do_scroll_horizontal (LEFT_SCROLL, num_to_scroll);
+  do_scroll_horizontal (num_to_scroll);
 }
 
 
@@ -504,7 +504,7 @@ tui_win_info::right_scroll (int num_to_scroll)
   if (num_to_scroll == 0)
     num_to_scroll = 1;
 
-  do_scroll_horizontal (RIGHT_SCROLL, num_to_scroll);
+  do_scroll_horizontal (- num_to_scroll);
 }
 
 
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 739272a5d03..c5593454580 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -243,8 +243,7 @@ tui_check_data_values (struct frame_info *frame)
 
 /* Scroll the data window vertically forward or backward.  */
 void
-tui_data_window::do_scroll_vertical
-  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
+tui_data_window::do_scroll_vertical (int num_to_scroll)
 {
   int first_element_no;
   int first_line = (-1);
@@ -259,10 +258,7 @@ tui_data_window::do_scroll_vertical
 
   if (first_line >= 0)
     {
-      if (scroll_direction == FORWARD_SCROLL)
-	first_line += num_to_scroll;
-      else
-	first_line -= num_to_scroll;
+      first_line += num_to_scroll;
       tui_erase_data_content (NULL);
       tui_delete_data_content_windows ();
       tui_display_data_from_line (first_line);
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index e55ce40a206..e56fbcb76d6 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -332,21 +332,13 @@ tui_source_window_base::refill ()
 /* Scroll the source forward or backward horizontally.  */
 
 void
-tui_source_window_base::do_scroll_horizontal
-  (enum tui_scroll_direction direction, int num_to_scroll)
+tui_source_window_base::do_scroll_horizontal (int num_to_scroll)
 {
   if (content != NULL)
     {
-      int offset;
-
-      if (direction == LEFT_SCROLL)
-	offset = horizontal_offset + num_to_scroll;
-      else
-	{
-	  offset = horizontal_offset - num_to_scroll;
-	  if (offset < 0)
-	    offset = 0;
-	}
+      int offset = horizontal_offset + num_to_scroll;
+      if (offset < 0)
+	offset = 0;
       horizontal_offset = offset;
       refill ();
     }
-- 
2.17.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]