From eaa29e9019ea90e03d079214b23d5288a59b6c6c Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 22 Jan 2015 03:11:13 +0000 Subject: [PATCH] DIBuilder: Extract DIHeaderFieldIterator::getNumber(), NFC Reduce code duplication between `DIBuilder` and `DIExpressionIterator` by implementing a `getNumber()` directly in the iterator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226772 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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; -- 2.34.1