[BOLT] Stop using std::iterator (NFC)

Without this patch, I get warnings like:

  bolt/include/bolt/Core/BinaryContext.h:108:19: error:
  'iterator<std::bidirectional_iterator_tag,
  llvm::bolt::BinarySection>' is deprecated
  [-Werror,-Wdeprecated-declarations]

This patch fixes those warnings by defining iterator_category,
value_type, etc.

This patch intentionally leaves duplicate types like FilterIterator::T
and FilterIterator::PointerT intact to avoid mixing the fix and the
cleanup.

Differential Revision: https://reviews.llvm.org/D133650
This commit is contained in:
Kazu Hirata 2022-09-13 14:14:23 -07:00
parent 81f8788528
commit 588628de3e
3 changed files with 22 additions and 7 deletions

View File

@ -104,9 +104,8 @@ inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
/// Filter iterator.
template <typename ItrType,
typename PredType = std::function<bool(const ItrType &)>>
class FilterIterator
: public std::iterator<std::bidirectional_iterator_tag,
typename std::iterator_traits<ItrType>::value_type> {
class FilterIterator {
using inner_traits = std::iterator_traits<ItrType>;
using Iterator = FilterIterator;
using T = typename std::iterator_traits<ItrType>::reference;
using PointerT = typename std::iterator_traits<ItrType>::pointer;
@ -128,6 +127,12 @@ class FilterIterator
}
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = typename inner_traits::value_type;
using difference_type = typename inner_traits::difference_type;
using pointer = typename inner_traits::pointer;
using reference = typename inner_traits::reference;
Iterator &operator++() { next(); return *this; }
Iterator &operator--() { prev(); return *this; }
Iterator operator++(int) { auto Tmp(Itr); next(); return Tmp; }

View File

@ -164,9 +164,14 @@ protected:
void setTailCall(MCInst &Inst);
public:
class InstructionIterator
: public std::iterator<std::bidirectional_iterator_tag, MCInst> {
class InstructionIterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = MCInst;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = value_type &;
class Impl {
public:
virtual Impl *Copy() const = 0;

View File

@ -439,13 +439,18 @@ public:
/// Define an iterator for navigating the expressions calculated by a
/// dataflow analysis at each program point, when they are backed by a
/// BitVector.
class ExprIterator
: public std::iterator<std::forward_iterator_tag, const MCInst *> {
class ExprIterator {
const BitVector *BV;
const std::vector<MCInst *> &Expressions;
int Idx;
public:
using iterator_category = std::forward_iterator_tag;
using value_type = const MCInst *;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = value_type &;
ExprIterator &operator++() {
assert(Idx != -1 && "Iterator already at the end");
Idx = BV->find_next(Idx);