Remove ALL_UIS

Message ID 20200509180259.23282-1-tom@tromey.com
State New
Headers show
Series
  • Remove ALL_UIS
Related show

Commit Message

Tom Tromey May 9, 2020, 6:02 p.m.
Continuing my goal of removing the "ALL_*" iterator macros, this
removes ALL_UIS, replacing it with an iterator adaptor.

gdb/ChangeLog
2020-05-09  Tom Tromey  <tom@tromey.com>

	* top.c (quit_force): Update.
	* infrun.c (handle_no_resumed): Update.
	* top.h (all_uis): New function.
	(ALL_UIS): Remove.
---
 gdb/ChangeLog |  7 +++++++
 gdb/infrun.c  |  3 +--
 gdb/top.c     |  3 +--
 gdb/top.h     | 10 +++++++---
 4 files changed, 16 insertions(+), 7 deletions(-)

-- 
2.17.2

Comments

Tom Tromey May 16, 2020, 3:56 p.m. | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:


Tom> Continuing my goal of removing the "ALL_*" iterator macros, this
Tom> removes ALL_UIS, replacing it with an iterator adaptor.

I'm checking this in.

Tom

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3c6b201a9fc..2d37603a38a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4930,10 +4930,9 @@  handle_no_resumed (struct execution_control_state *ecs)
 {
   if (target_can_async_p ())
     {
-      struct ui *ui;
       int any_sync = 0;
 
-      ALL_UIS (ui)
+      for (ui *ui : all_uis ())
 	{
 	  if (ui->prompt_state == PROMPT_BLOCKED)
 	    {
diff --git a/gdb/top.c b/gdb/top.c
index 9fb9d5cb5c7..48f9586c9e1 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1782,12 +1782,11 @@  quit_force (int *exit_arg, int from_tty)
     {
       if (write_history_p && history_filename)
 	{
-	  struct ui *ui;
 	  int save = 0;
 
 	  /* History is currently shared between all UIs.  If there's
 	     any UI with a terminal, save history.  */
-	  ALL_UIS (ui)
+	  for (ui *ui : all_uis ())
 	    {
 	      if (input_interactive_p (ui))
 		{
diff --git a/gdb/top.h b/gdb/top.h
index 0cbb244c551..ccb7d08fbcf 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -22,6 +22,7 @@ 
 
 #include "gdbsupport/buffer.h"
 #include "gdbsupport/event-loop.h"
+#include "gdbsupport/next-iterator.h"
 #include "value.h"
 
 struct tl_interp_info;
@@ -206,9 +207,12 @@  class switch_thru_all_uis
 #define SWITCH_THRU_ALL_UIS()		\
   for (switch_thru_all_uis stau_state; !stau_state.done (); stau_state.next ())
 
-/* Traverse over all UIs.  */
-#define ALL_UIS(UI)				\
-  for (UI = ui_list; UI; UI = UI->next)		\
+/* An adapter that can be used to traverse over all UIs.  */
+static inline
+next_adapter<ui> all_uis ()
+{
+  return next_adapter<ui> (ui_list);
+}
 
 /* Register the UI's input file descriptor in the event loop.  */
 extern void ui_register_input_event_handler (struct ui *ui);