summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/DumpDataExtractor.cpp
diff options
context:
space:
mode:
authorAlex Langford <apl@fb.com>2019-08-26 21:09:57 +0000
committerAlex Langford <apl@fb.com>2019-08-26 21:09:57 +0000
commit5e777e1ed2889953153c02caa2fbf2b1979dc21f (patch)
tree6060bcb8b777187ae614a21067d32a38de33f183 /lldb/source/Core/DumpDataExtractor.cpp
parent90e00bd8f3e1e03a9390c2531b90117498d2c78f (diff)
downloadbcm5719-llvm-5e777e1ed2889953153c02caa2fbf2b1979dc21f.tar.gz
bcm5719-llvm-5e777e1ed2889953153c02caa2fbf2b1979dc21f.zip
[Core] GetAPInt should return an Optional
The current implementation returns a bool for indicating success and whether or not the APInt passed by reference was populated. Instead of doing that, I think it makes more sense to return an Optional<APInt>. llvm-svn: 369970
Diffstat (limited to 'lldb/source/Core/DumpDataExtractor.cpp')
-rw-r--r--lldb/source/Core/DumpDataExtractor.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index aa84370e223..d13d7dc99ea 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -20,6 +20,7 @@
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Log.h"
#include "lldb/Utility/Stream.h"
#include "clang/AST/ASTContext.h"
@@ -28,6 +29,7 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include <limits>
@@ -64,8 +66,9 @@ static float half2float(uint16_t half) {
return u.f * ldexpf(1, -112);
}
-static bool GetAPInt(const DataExtractor &data, lldb::offset_t *offset_ptr,
- lldb::offset_t byte_size, llvm::APInt &result) {
+static llvm::Optional<llvm::APInt> GetAPInt(const DataExtractor &data,
+ lldb::offset_t *offset_ptr,
+ lldb::offset_t byte_size) {
llvm::SmallVector<uint64_t, 2> uint64_array;
lldb::offset_t bytes_left = byte_size;
uint64_t u64;
@@ -81,8 +84,7 @@ static bool GetAPInt(const DataExtractor &data, lldb::offset_t *offset_ptr,
}
uint64_array.push_back(u64);
}
- result = llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
- return true;
+ return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
} else if (byte_order == lldb::eByteOrderBig) {
lldb::offset_t be_offset = *offset_ptr + byte_size;
lldb::offset_t temp_offset;
@@ -101,18 +103,17 @@ static bool GetAPInt(const DataExtractor &data, lldb::offset_t *offset_ptr,
uint64_array.push_back(u64);
}
*offset_ptr += byte_size;
- result = llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
- return true;
+ return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
}
- return false;
+ return llvm::None;
}
static lldb::offset_t DumpAPInt(Stream *s, const DataExtractor &data,
lldb::offset_t offset, lldb::offset_t byte_size,
bool is_signed, unsigned radix) {
- llvm::APInt apint;
- if (GetAPInt(data, &offset, byte_size, apint)) {
- std::string apint_str(apint.toString(radix, is_signed));
+ llvm::Optional<llvm::APInt> apint = GetAPInt(data, &offset, byte_size);
+ if (apint.hasValue()) {
+ std::string apint_str(apint.getValue().toString(radix, is_signed));
switch (radix) {
case 2:
s->Write("0b", 2);
@@ -572,10 +573,11 @@ lldb::offset_t lldb_private::DumpDataExtractor(
apint);
apfloat.toString(sv, format_precision, format_max_padding);
} else if (item_bit_size == ast->getTypeSize(ast->DoubleTy)) {
- llvm::APInt apint;
- if (GetAPInt(DE, &offset, item_byte_size, apint)) {
+ llvm::Optional<llvm::APInt> apint =
+ GetAPInt(DE, &offset, item_byte_size);
+ if (apint.hasValue()) {
llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->DoubleTy),
- apint);
+ apint.getValue());
apfloat.toString(sv, format_precision, format_max_padding);
}
} else if (item_bit_size == ast->getTypeSize(ast->LongDoubleTy)) {
@@ -586,9 +588,10 @@ lldb::offset_t lldb_private::DumpDataExtractor(
if (&semantics == &llvm::APFloatBase::x87DoubleExtended())
byte_size = (llvm::APFloat::getSizeInBits(semantics) + 7) / 8;
- llvm::APInt apint;
- if (GetAPInt(DE, &offset, byte_size, apint)) {
- llvm::APFloat apfloat(semantics, apint);
+ llvm::Optional<llvm::APInt> apint =
+ GetAPInt(DE, &offset, byte_size);
+ if (apint.hasValue()) {
+ llvm::APFloat apfloat(semantics, apint.getValue());
apfloat.toString(sv, format_precision, format_max_padding);
}
} else if (item_bit_size == ast->getTypeSize(ast->HalfTy)) {
OpenPOWER on IntegriCloud