[03/66] Create subclasses for different window types

Message ID 20190623224329.16060-4-tom@tromey.com
State New
Headers show
Series
  • Clean up the TUI
Related show

Commit Message

Tom Tromey June 23, 2019, 10:42 p.m.
This changes the TUI so that each different major window type has its
own subclass.

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

	* tui/tui-data.h (struct tui_win_info): Make constructor
	protected.  Make destructor virtual.  Add initializers.
	(tui_source_window, tui_data_window, tui_cmd_window): New
	classes.
	* tui/tui-data.c (tui_win_info): Rename from init_win_info.  Now a
	constructor.  Add "type" parameter.
	(tui_source_window, tui_data_window, tui_cmd_window): New
	constructors.
	(tui_alloc_win_info): Instantiate the appropriate subclass.
---
 gdb/ChangeLog      | 12 ++++++++
 gdb/tui/tui-data.c | 76 +++++++++++++++++++++++++++-------------------
 gdb/tui/tui-data.h | 38 ++++++++++++++++++-----
 3 files changed, 86 insertions(+), 40 deletions(-)

-- 
2.17.2

Comments

Pedro Alves June 24, 2019, 10:21 p.m. | #1
On 6/23/19 11:42 PM, Tom Tromey wrote:
> +protected:

>  

> +  tui_win_info (enum tui_win_type type);


I forgot to mention in the earlier pass that I thought that
these ctors should be explicit?

Fine with me to leave it as is, and then fix it all up
in a follow up patch, if that's easier.

Thanks,
Pedro Alves
Tom Tromey June 25, 2019, 1:51 p.m. | #2
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:


Pedro> On 6/23/19 11:42 PM, Tom Tromey wrote:
>> +protected:

>> 

>> +  tui_win_info (enum tui_win_type type);


Pedro> I forgot to mention in the earlier pass that I thought that
Pedro> these ctors should be explicit?

Yes, thanks.  I went through and added them where it seemed appropriate.

Tom

Patch

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 1c96fc1c077..3320b4fc62a 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -495,47 +495,59 @@  init_content_element (struct tui_win_element *element,
     }
 }
 
-static void
-init_win_info (struct tui_win_info *win_info)
+tui_win_info::tui_win_info (enum tui_win_type type)
 {
-  tui_init_generic_part (&win_info->generic);
-  win_info->can_highlight =
-    win_info->is_highlighted = FALSE;
-  switch (win_info->generic.type)
-    {
-    case SRC_WIN:
-    case DISASSEM_WIN:
-      win_info->detail.source_info.execution_info = NULL;
-      win_info->detail.source_info.has_locator = FALSE;
-      win_info->detail.source_info.horizontal_offset = 0;
-      win_info->detail.source_info.gdbarch = NULL;
-      win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
-      win_info->detail.source_info.start_line_or_addr.u.addr = 0;
-      win_info->detail.source_info.fullname = NULL;
-      break;
-    case DATA_WIN:
-      win_info->detail.data_display_info.data_content = NULL;
-      win_info->detail.data_display_info.data_content_count = 0;
-      win_info->detail.data_display_info.regs_content = NULL;
-      win_info->detail.data_display_info.regs_content_count = 0;
-      win_info->detail.data_display_info.regs_column_count = 1;
-      win_info->detail.data_display_info.display_regs = FALSE;
-      win_info->detail.data_display_info.current_group = 0;
-      break;
-    case CMD_WIN:
-      break;
-    }
+  generic.type = type;
+  tui_init_generic_part (&generic);
 }
 
+tui_source_window::tui_source_window (enum tui_win_type type)
+  : tui_win_info (type)
+{
+  gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
+  detail.source_info.execution_info = NULL;
+  detail.source_info.has_locator = FALSE;
+  detail.source_info.horizontal_offset = 0;
+  detail.source_info.gdbarch = NULL;
+  detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
+  detail.source_info.start_line_or_addr.u.addr = 0;
+  detail.source_info.fullname = NULL;
+}
+
+tui_data_window::tui_data_window ()
+  : tui_win_info (DATA_WIN)
+{
+  detail.data_display_info.data_content = (tui_win_content) NULL;
+  detail.data_display_info.data_content_count = 0;
+  detail.data_display_info.regs_content = (tui_win_content) NULL;
+  detail.data_display_info.regs_content_count = 0;
+  detail.data_display_info.regs_column_count = 1;
+  detail.data_display_info.display_regs = FALSE;
+  detail.data_display_info.current_group = 0;
+}
+
+tui_cmd_window::tui_cmd_window ()
+  : tui_win_info (CMD_WIN)
+{
+}
 
 struct tui_win_info *
 tui_alloc_win_info (enum tui_win_type type)
 {
-  struct tui_win_info *win_info = new struct tui_win_info (type);
+  switch (type)
+    {
+    case SRC_WIN:
+    case DISASSEM_WIN:
+      return new tui_source_window (type);
 
-  init_win_info (win_info);
+    case DATA_WIN:
+      return new tui_data_window ();
 
-  return win_info;
+    case CMD_WIN:
+      return new tui_cmd_window ();
+    }
+
+  gdb_assert_not_reached (_("Unhandled window type"));
 }
 
 
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index ef20c02df2b..2c873c26a2f 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -271,15 +271,15 @@  struct tui_command_info
 /* This defines information about each logical window.  */
 struct tui_win_info
 {
-  tui_win_info (enum tui_win_type type)
-  {
-    generic.type = type;
-  }
-
-  ~tui_win_info ();
+protected:
 
+  tui_win_info (enum tui_win_type type);
   DISABLE_COPY_AND_ASSIGN (tui_win_info);
 
+public:
+
+  virtual ~tui_win_info ();
+
   struct tui_gen_win_info generic;	/* General window information.  */
   union
   {
@@ -288,8 +288,30 @@  struct tui_win_info
     struct tui_command_info command_info;
   }
   detail;
-  int can_highlight;	/* Can this window ever be highlighted?  */
-  int is_highlighted;	/* Is this window highlighted?  */
+
+  /* Can this window ever be highlighted?  */
+  int can_highlight = 0;
+
+  /* Is this window highlighted?  */
+  int is_highlighted = 0;
+};
+
+struct tui_source_window : public tui_win_info
+{
+  tui_source_window (enum tui_win_type type);
+  DISABLE_COPY_AND_ASSIGN (tui_source_window);
+};
+
+struct tui_data_window : public tui_win_info
+{
+  tui_data_window ();
+  DISABLE_COPY_AND_ASSIGN (tui_data_window);
+};
+
+struct tui_cmd_window : public tui_win_info
+{
+  tui_cmd_window ();
+  DISABLE_COPY_AND_ASSIGN (tui_cmd_window);
 };
 
 extern int tui_win_is_source_type (enum tui_win_type win_type);