#ifndef LLVM_ADT_DEPTHFIRSTITERATOR_H
#define LLVM_ADT_DEPTHFIRSTITERATOR_H
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/iterator_range.h"
#include <iterator>
#include <optional>
#include <utility>
#include <vector>
namespace llvm {
template<class SetType, bool External>
class df_iterator_storage { … };
df_iterator_storage<SetType, true>;
template <typename NodeRef, unsigned SmallSize=8>
struct df_iterator_default_set : public SmallPtrSet<NodeRef, SmallSize> { … };
template <class GraphT,
class SetType =
df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
class df_iterator : public df_iterator_storage<SetType, ExtStorage> {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = typename GT::NodeRef;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = const value_type &;
private:
using NodeRef = typename GT::NodeRef;
using ChildItTy = typename GT::ChildIteratorType;
using StackElement = std::pair<NodeRef, std::optional<ChildItTy>>;
std::vector<StackElement> VisitStack;
inline df_iterator(NodeRef Node) { … }
inline df_iterator() = default;
inline df_iterator(NodeRef Node, SetType &S)
: … { … }
inline df_iterator(SetType &S)
: … { … }
inline void toNext() { … }
public:
static df_iterator begin(const GraphT &G) { … }
static df_iterator end(const GraphT &G) { … }
static df_iterator begin(const GraphT &G, SetType &S) { … }
static df_iterator end(const GraphT &G, SetType &S) { … }
bool operator==(const df_iterator &x) const { … }
bool operator!=(const df_iterator &x) const { … }
reference operator*() const { … }
NodeRef operator->() const { … }
df_iterator &operator++() { … }
df_iterator &skipChildren() { … }
df_iterator operator++(int) { … }
bool nodeVisited(NodeRef Node) const { … }
unsigned getPathLength() const { … }
NodeRef getPath(unsigned n) const { … }
};
template <class T>
df_iterator<T> df_begin(const T& G) { … }
template <class T>
df_iterator<T> df_end(const T& G) { … }
template <class T>
iterator_range<df_iterator<T>> depth_first(const T& G) { … }
template <class T, class SetTy = df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
struct df_ext_iterator : public df_iterator<T, SetTy, true> {
df_ext_iterator(const df_iterator<T, SetTy, true> &V)
: … { … }
};
template <class T, class SetTy>
df_ext_iterator<T, SetTy> df_ext_begin(const T& G, SetTy &S) { … }
template <class T, class SetTy>
df_ext_iterator<T, SetTy> df_ext_end(const T& G, SetTy &S) { … }
template <class T, class SetTy>
iterator_range<df_ext_iterator<T, SetTy>> depth_first_ext(const T& G,
SetTy &S) { … }
template <class T,
class SetTy =
df_iterator_default_set<typename GraphTraits<T>::NodeRef>,
bool External = false>
struct idf_iterator : public df_iterator<Inverse<T>, SetTy, External> { … };
template <class T>
idf_iterator<T> idf_begin(const T& G) { … }
template <class T>
idf_iterator<T> idf_end(const T& G){ … }
template <class T>
iterator_range<idf_iterator<T>> inverse_depth_first(const T& G) { … }
template <class T, class SetTy = df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
struct idf_ext_iterator : public idf_iterator<T, SetTy, true> {
idf_ext_iterator(const idf_iterator<T, SetTy, true> &V)
: … { … }
idf_ext_iterator(const df_iterator<Inverse<T>, SetTy, true> &V)
: … { … }
};
template <class T, class SetTy>
idf_ext_iterator<T, SetTy> idf_ext_begin(const T& G, SetTy &S) { … }
template <class T, class SetTy>
idf_ext_iterator<T, SetTy> idf_ext_end(const T& G, SetTy &S) { … }
template <class T, class SetTy>
iterator_range<idf_ext_iterator<T, SetTy>> inverse_depth_first_ext(const T& G,
SetTy &S) { … }
}
#endif