diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 13fa23c8fd6..fc4d95cfc14 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -99,6 +99,16 @@ public: return Header.slice(Current.end() - Header.begin() + 1, StringRef::npos); } + /// \brief Get the current field as a number. + /// + /// Convert the current field into a number. Return \c 0 on error. + template T getNumber() const { + T Int; + if (getCurrent().getAsInteger(0, Int)) + return 0; + return Int; + } + private: void increment() { assert(Current.data() != nullptr && "Cannot increment past the end"); @@ -204,10 +214,7 @@ public: } template T getHeaderFieldAs(unsigned Index) const { - T Int; - if (getHeaderField(Index).getAsInteger(0, Int)) - return 0; - return Int; + return getHeaderIterator(Index).getNumber(); } uint16_t getTag() const { return getHeaderFieldAs(0); } @@ -883,12 +890,7 @@ public: DIExpressionIterator() {} DIExpressionIterator(const DIExpression Expr) : I(Expr.getHeader()) { ++I; } - uint64_t operator*() const { - uint64_t UInt; - if (I->getAsInteger(0, UInt)) - return 0; - return UInt; - } + uint64_t operator*() const { return I.getNumber(); } DIExpressionIterator &operator++() { increment(); return *this;