Simplify code by using Optional::getValueOr()

llvm-svn: 351264
This commit is contained in:
Adrian Prantl 2019-01-15 22:30:01 +00:00
parent 76cb3089de
commit 222474b9ff
4 changed files with 5 additions and 10 deletions

View File

@ -112,9 +112,7 @@ uint64_t ValueObjectVariable::GetByteSize() {
if (!type.IsValid())
return 0;
llvm::Optional<uint64_t> size =
type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
return size ? *size : 0;
return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()).getValueOr(0);
}
lldb::ValueType ValueObjectVariable::GetValueType() const {

View File

@ -577,8 +577,7 @@ private:
ReturnValueExtractor(Thread &thread, CompilerType &type,
RegisterContext *reg_ctx, ProcessSP process_sp)
: m_thread(thread), m_type(type),
m_byte_size(m_type.GetByteSize(nullptr) ? *m_type.GetByteSize(nullptr)
: 0),
m_byte_size(m_type.GetByteSize(nullptr).getValueOr(0)),
m_data_ap(new DataBufferHeap(m_byte_size, 0)), m_reg_ctx(reg_ctx),
m_process_sp(process_sp), m_byte_order(process_sp->GetByteOrder()),
m_addr_size(

View File

@ -337,9 +337,7 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
if (log)
log->Printf("Creating a new result global: \"%s\" with size 0x%" PRIx64,
m_result_name.GetCString(),
m_result_type.GetByteSize(nullptr)
? *m_result_type.GetByteSize(nullptr)
: 0);
m_result_type.GetByteSize(nullptr).getValueOr(0));
// Construct a new result global and set up its metadata

View File

@ -513,11 +513,11 @@ void ClassDescriptorV2::iVarsStorage::fill(AppleObjCRuntimeV2 &runtime,
CompilerType ivar_type =
encoding_to_type_sp->RealizeType(type, for_expression);
if (ivar_type) {
llvm::Optional<uint64_t> ivar_size = ivar_type.GetByteSize(nullptr);
LLDB_LOGV(log,
"name = {0}, encoding = {1}, offset_ptr = {2:x}, size = "
"{3}, type_size = {4}",
name, type, offset_ptr, size, ivar_size ? *ivar_size : 0);
name, type, offset_ptr, size,
ivar_type.GetByteSize(nullptr).getValueOr(0));
Scalar offset_scalar;
Status error;
const int offset_ptr_size = 4;