llvm.org GIT mirror llvm / eabbe07
Address more review comments for DIExpression::iterator. - input_iterator - define an operator-> - make constructors private were possible git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226967 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
3 changed file(s) with 44 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
5858 typedef DenseMap DITypeIdentifierMap;
5959
6060 class DIHeaderFieldIterator
61 : public std::iteratorforward_iterator_tag, StringRef, std::ptrdiff_t,
61 : public std::iteratorinput_iterator_tag, StringRef, std::ptrdiff_t,
6262 const StringRef *, StringRef> {
6363 StringRef Header;
6464 StringRef Current;
866866 /// \brief Return the size of this piece in bytes.
867867 uint64_t getPieceSize() const;
868868
869 class Operand;
869 class iterator;
870 /// \brief A lightweight wrapper around an element of a DIExpression.
871 class Operand {
872 friend class iterator;
873 DIHeaderFieldIterator I;
874 Operand() {}
875 Operand(DIHeaderFieldIterator I) : I(I) {}
876 public:
877 /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
878 /// Argument 0 is the operand itself.
879 uint64_t getArg(unsigned N) const {
880 DIHeaderFieldIterator In = I;
881 std::advance(In, N);
882 return In.getNumber();
883 }
884 operator uint64_t () const { return I.getNumber(); }
885 /// \brief Returns underlying DIHeaderFieldIterator.
886 const DIHeaderFieldIterator &getBase() const { return I; }
887 /// \brief Returns the next operand.
888 const Operand &getNext() const;
889 };
870890
871891 /// \brief An iterator for DIExpression elements.
872 class iterator : public std::iterator
873 unsigned, const uint64_t *, uint64_t> {
892 class iterator : public std::iterator
893 unsigned, const Operand*, Operand> {
894 friend class Operand;
874895 DIHeaderFieldIterator I;
896 Operand Tmp;
875897 iterator(DIHeaderFieldIterator I) : I(I) {}
876898 public:
877899 iterator() {}
878900 iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {}
879 Operand operator*() const { return Operand(I); }
901 const Operand &operator*() { return Tmp = Operand(I); }
902 const Operand *operator->() { return &(Tmp = Operand(I)); }
880903 iterator &operator++() {
881904 increment();
882905 return *this;
889912 bool operator==(const iterator &X) const { return I == X.I; }
890913 bool operator!=(const iterator &X) const { return !(*this == X); }
891914
892 const DIHeaderFieldIterator &getBase() const { return I; }
893915 private:
894916 void increment() {
895917 switch (**this) {
904926
905927 iterator begin() const;
906928 iterator end() const;
907
908 /// \brief A lightweight wrapper around an element of a DIExpression.
909 class Operand {
910 DIHeaderFieldIterator I;
911 public:
912 Operand(DIHeaderFieldIterator I) : I(I) {}
913 /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
914 /// Argument 0 is the operand itself.
915 uint64_t getArg(unsigned N) const {
916 DIHeaderFieldIterator In = I;
917 std::advance(In, N);
918 return In.getNumber();
919 }
920
921 operator uint64_t () const { return I.getNumber(); }
922 };
923929 };
924930
925931 /// \brief This object holds location information.
209209 switch (*I) {
210210 case dwarf::DW_OP_piece: {
211211 unsigned SizeOfByte = 8;
212 unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte;
213 unsigned SizeInBits = (*I).getArg(2) * SizeOfByte;
212 unsigned OffsetInBits = I->getArg(1) * SizeOfByte;
213 unsigned SizeInBits = I->getArg(2) * SizeOfByte;
214214 // Piece always comes at the end of the expression.
215215 return AddMachineRegPiece(MachineReg, SizeInBits,
216216 getOffsetOrZero(OffsetInBits, PieceOffsetInBits));
217217 }
218218 case dwarf::DW_OP_plus:
219219 // [DW_OP_reg,Offset,DW_OP_plus,DW_OP_deref] --> [DW_OP_breg,Offset].
220 if (*std::next(I) == dwarf::DW_OP_deref) {
221 unsigned Offset = (*I).getArg(1);
220 if (I->getNext() == dwarf::DW_OP_deref) {
221 unsigned Offset = I->getArg(1);
222222 ValidReg = AddMachineRegIndirect(MachineReg, Offset);
223223 std::advance(I, 2);
224224 break;
247247 switch (*I) {
248248 case dwarf::DW_OP_piece: {
249249 unsigned SizeOfByte = 8;
250 unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte;
251 unsigned SizeInBits = (*I).getArg(2) * SizeOfByte;
250 unsigned OffsetInBits = I->getArg(1) * SizeOfByte;
251 unsigned SizeInBits = I->getArg(2) * SizeOfByte;
252252 AddOpPiece(SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits));
253253 break;
254254 }
255255 case dwarf::DW_OP_plus:
256256 EmitOp(dwarf::DW_OP_plus_uconst);
257 EmitUnsigned((*I).getArg(1));
257 EmitUnsigned(I->getArg(1));
258258 break;
259259 case dwarf::DW_OP_deref:
260260 EmitOp(dwarf::DW_OP_deref);
167167
168168 DIExpression::iterator DIExpression::end() const {
169169 return DIExpression::iterator();
170 }
171
172 const DIExpression::Operand &DIExpression::Operand::getNext() const {
173 iterator it(I);
174 return *(++it);
170175 }
171176
172177 //===----------------------------------------------------------------------===//
605610 if (!(isExpression() && DbgNode->getNumOperands() == 1))
606611 return false;
607612
608 for (auto E = end(), I = begin(); I != E; ++I)
609 switch (*I) {
613 for (auto Op : *this)
614 switch (Op) {
610615 case DW_OP_piece:
611616 // Must be the last element of the expression.
612 return std::distance(I.getBase(), DIHeaderFieldIterator()) == 3;
617 return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3;
613618 case DW_OP_plus:
614 if (std::distance(I.getBase(), DIHeaderFieldIterator()) < 2)
619 if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2)
615620 return false;
616621 break;
617622 case DW_OP_deref: