Remove ALL_OBJFILES_SAFE
[deliverable/binutils-gdb.git] / gdb / objfiles.h
index 7a9087b015817757c155ad433ab3c5b9aca3b513..cb3668aff651f4f2b631d04f0d3202f2d739a557 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for symbol file management in GDB.
 
-   Copyright (C) 1992-2018 Free Software Foundation, Inc.
+   Copyright (C) 1992-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -28,6 +28,8 @@
 #include "registry.h"
 #include "gdb_bfd.h"
 #include <vector>
+#include "common/next-iterator.h"
+#include "common/safe-iterator.h"
 
 struct bcache;
 struct htab;
@@ -565,25 +567,51 @@ extern void default_iterate_over_objfiles_in_search_order
    void *cb_data, struct objfile *current_objfile);
 \f
 
-/* Traverse all object files in the current program space.
-   ALL_OBJFILES_SAFE works even if you delete the objfile during the
-   traversal.  */
+/* An iterarable object that can be used to iterate over all
+   objfiles.  The basic use is in a foreach, like:
 
-/* Traverse all object files in program space SS.  */
+   for (objfile *objf : all_objfiles (pspace)) { ... }  */
 
-#define ALL_PSPACE_OBJFILES(ss, obj)                                   \
-  for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next)
+class all_objfiles : public next_adapter<struct objfile>
+{
+public:
+
+  explicit all_objfiles (struct program_space *pspace)
+    : next_adapter<struct objfile> (pspace->objfiles)
+  {
+  }
+};
+
+/* An iterarable object that can be used to iterate over all
+   objfiles.  The basic use is in a foreach, like:
+
+   for (objfile *objf : all_objfiles_safe (pspace)) { ... }
+
+   This variant uses a basic_safe_iterator so that objfiles can be
+   deleted during iteration.  */
+
+class all_objfiles_safe
+  : public next_adapter<struct objfile,
+                       basic_safe_iterator<next_iterator<objfile>>>
+{
+public:
+
+  explicit all_objfiles_safe (struct program_space *pspace)
+    : next_adapter<struct objfile,
+                  basic_safe_iterator<next_iterator<objfile>>>
+        (pspace->objfiles)
+  {
+  }
+};
+
+
+/* Traverse all object files in the current program space.  */
 
 #define ALL_OBJFILES(obj)                          \
   for ((obj) = current_program_space->objfiles; \
        (obj) != NULL;                              \
        (obj) = (obj)->next)
 
-#define ALL_OBJFILES_SAFE(obj,nxt)                     \
-  for ((obj) = current_program_space->objfiles;        \
-       (obj) != NULL? ((nxt)=(obj)->next,1) :0;        \
-       (obj) = (nxt))
-
 /* Traverse all symtabs in one objfile.  */
 
 #define ALL_OBJFILE_FILETABS(objfile, cu, s) \
This page took 0.025663 seconds and 4 git commands to generate.