DebugInfo: Remove special iterators from DIExpression

Remove special iterators from `DIExpression` in favour of same in
`MDExpression`.  There should be no functionality change here.

Note that the APIs are slightly different: `getArg(unsigned)` counts
from 0, not 1, in the `MDExpression` version of the iterator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234285 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-04-07 03:45:57 +00:00
parent ad8a6b66d9
commit fb2e97e4aa
7 changed files with 27 additions and 83 deletions

View File

@@ -872,66 +872,6 @@ public:
uint64_t getBitPieceOffset() const;
/// \brief Return the size of this piece in bits.
uint64_t getBitPieceSize() const;
class iterator;
/// \brief A lightweight wrapper around an element of a DIExpression.
class Operand {
friend class iterator;
MDExpression::element_iterator I;
Operand() {}
Operand(MDExpression::element_iterator I) : I(I) {}
public:
/// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
/// Argument 0 is the operand itself.
uint64_t getArg(unsigned N) const {
MDExpression::element_iterator In = I;
std::advance(In, N);
return *In;
}
operator uint64_t () const { return *I; }
/// \brief Returns underlying MDExpression::element_iterator.
const MDExpression::element_iterator &getBase() const { return I; }
/// \brief Returns the next operand.
iterator getNext() const;
};
/// \brief An iterator for DIExpression elements.
class iterator : public std::iterator<std::input_iterator_tag, StringRef,
unsigned, const Operand*, Operand> {
friend class Operand;
MDExpression::element_iterator I;
Operand Tmp;
public:
iterator(MDExpression::element_iterator I) : I(I) {}
const Operand &operator*() { return Tmp = Operand(I); }
const Operand *operator->() { return &(Tmp = Operand(I)); }
iterator &operator++() {
increment();
return *this;
}
iterator operator++(int) {
iterator X(*this);
increment();
return X;
}
bool operator==(const iterator &X) const { return I == X.I; }
bool operator!=(const iterator &X) const { return !(*this == X); }
private:
void increment() {
switch (**this) {
case dwarf::DW_OP_bit_piece: std::advance(I, 3); break;
case dwarf::DW_OP_plus: std::advance(I, 2); break;
case dwarf::DW_OP_deref: std::advance(I, 1); break;
default:
llvm_unreachable("unsupported operand");
}
}
};
iterator begin() const { return get()->elements_begin(); }
iterator end() const { return get()->elements_end(); }
};
/// \brief This object holds location information.

View File

@@ -1885,6 +1885,13 @@ public:
return T;
}
/// \brief Get the next iterator.
///
/// \a std::next() doesn't work because this is technically an
/// input_iterator, but it's a perfectly valid operation. This is an
/// accessor to provide the same functionality.
expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
bool operator==(const expr_op_iterator &X) const {
return getBase() == X.getBase();
}