From eabbe074490485fd30ce41bb0a540a1ab5fe9492 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 23 Jan 2015 23:40:47 +0000 Subject: [PATCH] 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 --- include/llvm/IR/DebugInfo.h | 50 ++++++++++++---------- lib/CodeGen/AsmPrinter/DwarfExpression.cpp | 14 +++--- lib/IR/DebugInfo.cpp | 13 ++++-- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 9292f4b5c35..539025f0df2 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -59,7 +59,7 @@ class DIObjCProperty; typedef DenseMap DITypeIdentifierMap; class DIHeaderFieldIterator - : public std::iterator { StringRef Header; StringRef Current; @@ -867,17 +867,40 @@ public: /// \brief Return the size of this piece in bytes. uint64_t getPieceSize() const; - class Operand; + class iterator; + /// \brief A lightweight wrapper around an element of a DIExpression. + class Operand { + friend class iterator; + DIHeaderFieldIterator I; + Operand() {} + Operand(DIHeaderFieldIterator 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 { + DIHeaderFieldIterator In = I; + std::advance(In, N); + return In.getNumber(); + } + operator uint64_t () const { return I.getNumber(); } + /// \brief Returns underlying DIHeaderFieldIterator. + const DIHeaderFieldIterator &getBase() const { return I; } + /// \brief Returns the next operand. + const Operand &getNext() const; + }; /// \brief An iterator for DIExpression elements. - class iterator : public std::iterator { + class iterator : public std::iterator { + friend class Operand; DIHeaderFieldIterator I; + Operand Tmp; iterator(DIHeaderFieldIterator I) : I(I) {} public: iterator() {} iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {} - Operand operator*() const { return Operand(I); } + const Operand &operator*() { return Tmp = Operand(I); } + const Operand *operator->() { return &(Tmp = Operand(I)); } iterator &operator++() { increment(); return *this; @@ -890,7 +913,6 @@ public: bool operator==(const iterator &X) const { return I == X.I; } bool operator!=(const iterator &X) const { return !(*this == X); } - const DIHeaderFieldIterator &getBase() const { return I; } private: void increment() { switch (**this) { @@ -905,22 +927,6 @@ public: iterator begin() const; iterator end() const; - - /// \brief A lightweight wrapper around an element of a DIExpression. - class Operand { - DIHeaderFieldIterator I; - public: - Operand(DIHeaderFieldIterator I) : I(I) {} - /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments. - /// Argument 0 is the operand itself. - uint64_t getArg(unsigned N) const { - DIHeaderFieldIterator In = I; - std::advance(In, N); - return In.getNumber(); - } - - operator uint64_t () const { return I.getNumber(); } - }; }; /// \brief This object holds location information. diff --git a/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/lib/CodeGen/AsmPrinter/DwarfExpression.cpp index 8515dd020c8..f3d3fb45bb2 100644 --- a/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -210,16 +210,16 @@ bool DwarfExpression::AddMachineRegExpression(DIExpression Expr, switch (*I) { case dwarf::DW_OP_piece: { unsigned SizeOfByte = 8; - unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte; - unsigned SizeInBits = (*I).getArg(2) * SizeOfByte; + unsigned OffsetInBits = I->getArg(1) * SizeOfByte; + unsigned SizeInBits = I->getArg(2) * SizeOfByte; // Piece always comes at the end of the expression. return AddMachineRegPiece(MachineReg, SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits)); } case dwarf::DW_OP_plus: // [DW_OP_reg,Offset,DW_OP_plus,DW_OP_deref] --> [DW_OP_breg,Offset]. - if (*std::next(I) == dwarf::DW_OP_deref) { - unsigned Offset = (*I).getArg(1); + if (I->getNext() == dwarf::DW_OP_deref) { + unsigned Offset = I->getArg(1); ValidReg = AddMachineRegIndirect(MachineReg, Offset); std::advance(I, 2); break; @@ -248,14 +248,14 @@ void DwarfExpression::AddExpression(DIExpression::iterator I, switch (*I) { case dwarf::DW_OP_piece: { unsigned SizeOfByte = 8; - unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte; - unsigned SizeInBits = (*I).getArg(2) * SizeOfByte; + unsigned OffsetInBits = I->getArg(1) * SizeOfByte; + unsigned SizeInBits = I->getArg(2) * SizeOfByte; AddOpPiece(SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits)); break; } case dwarf::DW_OP_plus: EmitOp(dwarf::DW_OP_plus_uconst); - EmitUnsigned((*I).getArg(1)); + EmitUnsigned(I->getArg(1)); break; case dwarf::DW_OP_deref: EmitOp(dwarf::DW_OP_deref); diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 095fcbffde3..9b5a9c3da47 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -170,6 +170,11 @@ DIExpression::iterator DIExpression::end() const { return DIExpression::iterator(); } +const DIExpression::Operand &DIExpression::Operand::getNext() const { + iterator it(I); + return *(++it); +} + //===----------------------------------------------------------------------===// // Predicates //===----------------------------------------------------------------------===// @@ -606,13 +611,13 @@ bool DIExpression::Verify() const { if (!(isExpression() && DbgNode->getNumOperands() == 1)) return false; - for (auto E = end(), I = begin(); I != E; ++I) - switch (*I) { + for (auto Op : *this) + switch (Op) { case DW_OP_piece: // Must be the last element of the expression. - return std::distance(I.getBase(), DIHeaderFieldIterator()) == 3; + return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3; case DW_OP_plus: - if (std::distance(I.getBase(), DIHeaderFieldIterator()) < 2) + if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2) return false; break; case DW_OP_deref: -- 2.34.1