Remove ALL_OBJFILE_FILETABS
[deliverable/binutils-gdb.git] / gdb / objfiles.h
index 8d7a3c35e11ae6e19006c1e7a7e7fabf535cbde7..33acb20e7a18d690c9b5a4813723478f5fea5f73 100644 (file)
@@ -29,6 +29,7 @@
 #include "gdb_bfd.h"
 #include <vector>
 #include "common/next-iterator.h"
+#include "common/safe-iterator.h"
 
 struct bcache;
 struct htab;
@@ -581,63 +582,136 @@ public:
   }
 };
 
+/* 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 the current program space.
-   ALL_OBJFILES_SAFE works even if you delete the objfile during the
-   traversal.  */
+   for (objfile *objf : all_objfiles_safe (pspace)) { ... }
 
-/* Traverse all object files in program space SS.  */
+   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:
 
-#define ALL_PSPACE_OBJFILES(ss, obj)                                   \
-  for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next)
+  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))
+/* A range adapter that makes it possible to iterate over all
+   compunits in one objfile.  */
 
-/* Traverse all symtabs in one objfile.  */
-
-#define ALL_OBJFILE_FILETABS(objfile, cu, s) \
-  ALL_OBJFILE_COMPUNITS (objfile, cu) \
-    ALL_COMPUNIT_FILETABS (cu, s)
+class objfile_compunits : public next_adapter<struct compunit_symtab>
+{
+public:
 
-/* Traverse all compunits in one objfile.  */
+  explicit objfile_compunits (struct objfile *objfile)
+    : next_adapter<struct compunit_symtab> (objfile->compunit_symtabs)
+  {
+  }
+};
 
-#define ALL_OBJFILE_COMPUNITS(objfile, cu) \
-  for ((cu) = (objfile) -> compunit_symtabs; (cu) != NULL; (cu) = (cu) -> next)
+/* A range adapter that makes it possible to iterate over all
+   minimal symbols of an objfile.  */
 
-/* Traverse all minimal symbols in one objfile.  */
+class objfile_msymbols
+{
+public:
 
-#define        ALL_OBJFILE_MSYMBOLS(objfile, m)        \
-    for ((m) = (objfile)->per_bfd->msymbols;   \
-        MSYMBOL_LINKAGE_NAME (m) != NULL;      \
-        (m)++)
+  explicit objfile_msymbols (struct objfile *objfile)
+    : m_objfile (objfile)
+  {
+  }
 
-/* Traverse all symtabs in all objfiles in the current symbol
-   space.  */
+  struct iterator
+  {
+    typedef iterator self_type;
+    typedef struct minimal_symbol *value_type;
+    typedef struct minimal_symbol *&reference;
+    typedef struct minimal_symbol **pointer;
+    typedef std::forward_iterator_tag iterator_category;
+    typedef int difference_type;
+
+    explicit iterator (struct objfile *objfile)
+      : m_msym (objfile->per_bfd->msymbols)
+    {
+      /* Make sure to properly handle the case where there are no
+        minsyms.  */
+      if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
+       m_msym = nullptr;
+    }
+
+    iterator ()
+      : m_msym (nullptr)
+    {
+    }
+    
+    value_type operator* () const
+    {
+      return m_msym;
+    }
+
+    bool operator== (const self_type &other) const
+    {
+      return m_msym == other.m_msym;
+    }
+
+    bool operator!= (const self_type &other) const
+    {
+      return m_msym != other.m_msym;
+    }
+
+    self_type &operator++ ()
+    {
+      if (m_msym != nullptr)
+       {
+         ++m_msym;
+         if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
+           m_msym = nullptr;
+       }
+      return *this;
+    }
+
+  private:
+    struct minimal_symbol *m_msym;
+  };
+
+  iterator begin () const
+  {
+    return iterator (m_objfile);
+  }
 
-#define ALL_FILETABS(objfile, ps, s)           \
-  ALL_OBJFILES (objfile)                       \
-    ALL_OBJFILE_FILETABS (objfile, ps, s)
+  iterator end () const
+  {
+    return iterator ();
+  }
 
-/* Traverse all compunits in all objfiles in the current program space.  */
+private:
 
-#define ALL_COMPUNITS(objfile, cu)     \
-  ALL_OBJFILES (objfile)               \
-    ALL_OBJFILE_COMPUNITS (objfile, cu)
+  struct objfile *m_objfile;
+};
 
-/* Traverse all minimal symbols in all objfiles in the current symbol
+/* Traverse all symtabs in all objfiles in the current symbol
    space.  */
 
-#define        ALL_MSYMBOLS(objfile, m) \
-  ALL_OBJFILES (objfile)        \
-    ALL_OBJFILE_MSYMBOLS (objfile, m)
+#define ALL_FILETABS(objfile, ps, s)                                   \
+  ALL_OBJFILES (objfile)                                               \
+    for (compunit_symtab *ps : objfile_compunits (objfile))    \
+      for (symtab *s : compunit_filetabs (cu))
 
 #define ALL_OBJFILE_OSECTIONS(objfile, osect)  \
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
This page took 0.026407 seconds and 4 git commands to generate.