diff options
Diffstat (limited to 'source/Utility/DataEncoder.cpp')
-rw-r--r-- | source/Utility/DataEncoder.cpp | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/source/Utility/DataEncoder.cpp b/source/Utility/DataEncoder.cpp index c26c0fa63ab3..13c505e34e82 100644 --- a/source/Utility/DataEncoder.cpp +++ b/source/Utility/DataEncoder.cpp @@ -1,9 +1,8 @@ //===-- DataEncoder.cpp -----------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -25,29 +24,24 @@ using namespace lldb; using namespace lldb_private; using namespace llvm::support::endian; -//---------------------------------------------------------------------- // Default constructor. -//---------------------------------------------------------------------- DataEncoder::DataEncoder() : m_start(nullptr), m_end(nullptr), m_byte_order(endian::InlHostByteOrder()), m_addr_size(sizeof(void *)), m_data_sp() {} -//---------------------------------------------------------------------- // This constructor allows us to use data that is owned by someone else. The // data must stay around as long as this object is valid. -//---------------------------------------------------------------------- DataEncoder::DataEncoder(void *data, uint32_t length, ByteOrder endian, uint8_t addr_size) - : m_start((uint8_t *)data), m_end((uint8_t *)data + length), - m_byte_order(endian), m_addr_size(addr_size), m_data_sp() {} + : m_start(static_cast<uint8_t *>(data)), + m_end(static_cast<uint8_t *>(data) + length), m_byte_order(endian), + m_addr_size(addr_size), m_data_sp() {} -//---------------------------------------------------------------------- // Make a shared pointer reference to the shared data in "data_sp" and set the // endian swapping setting to "swap", and the address size to "addr_size". The // shared data reference will ensure the data lives as long as any DataEncoder // objects exist that have a reference to this data. -//---------------------------------------------------------------------- DataEncoder::DataEncoder(const DataBufferSP &data_sp, ByteOrder endian, uint8_t addr_size) : m_start(nullptr), m_end(nullptr), m_byte_order(endian), @@ -57,10 +51,8 @@ DataEncoder::DataEncoder(const DataBufferSP &data_sp, ByteOrder endian, DataEncoder::~DataEncoder() = default; -//------------------------------------------------------------------ // Clears the object contents back to a default invalid state, and release any // references to shared data that this object may contain. -//------------------------------------------------------------------ void DataEncoder::Clear() { m_start = nullptr; m_end = nullptr; @@ -69,10 +61,8 @@ void DataEncoder::Clear() { m_data_sp.reset(); } -//------------------------------------------------------------------ // If this object contains shared data, this function returns the offset into // that shared data. Else zero is returned. -//------------------------------------------------------------------ size_t DataEncoder::GetSharedDataOffset() const { if (m_start != nullptr) { const DataBuffer *data = m_data_sp.get(); @@ -87,7 +77,6 @@ size_t DataEncoder::GetSharedDataOffset() const { return 0; } -//---------------------------------------------------------------------- // Set the data with which this object will extract from to data starting at // BYTES and set the length of the data to LENGTH bytes long. The data is // externally owned must be around at least as long as this object points to @@ -95,7 +84,6 @@ size_t DataEncoder::GetSharedDataOffset() const { // and can extract from it. If this object refers to any shared data upon // entry, the reference to that data will be released. Is SWAP is set to true, // any data extracted will be endian swapped. -//---------------------------------------------------------------------- uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { m_byte_order = endian; m_data_sp.reset(); @@ -103,13 +91,12 @@ uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { m_start = nullptr; m_end = nullptr; } else { - m_start = (uint8_t *)bytes; + m_start = static_cast<uint8_t *>(bytes); m_end = m_start + length; } return GetByteSize(); } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange of the shared data in // "data_sp" starting "data_offset" bytes into "data_sp" and ending // "data_length" bytes later. If "data_offset" is not a valid offset into @@ -121,7 +108,6 @@ uint32_t DataEncoder::SetData(void *bytes, uint32_t length, ByteOrder endian) { // starting at "data_offset") to ensure the data stays around as long as it is // needed. The address size and endian swap settings will remain unchanged from // their current settings. -//---------------------------------------------------------------------- uint32_t DataEncoder::SetData(const DataBufferSP &data_sp, uint32_t data_offset, uint32_t data_length) { m_start = m_end = nullptr; @@ -153,12 +139,10 @@ uint32_t DataEncoder::SetData(const DataBufferSP &data_sp, uint32_t data_offset, return new_size; } -//---------------------------------------------------------------------- // Extract a single unsigned char from the binary data and update the offset // pointed to by "offset_ptr". // // RETURNS the byte that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataEncoder::PutU8(uint32_t offset, uint8_t value) { if (ValidOffset(offset)) { m_start[offset] = value; @@ -203,7 +187,6 @@ uint32_t DataEncoder::PutU64(uint32_t offset, uint64_t value) { return UINT32_MAX; } -//---------------------------------------------------------------------- // Extract a single integer value from the data and update the offset pointed // to by "offset_ptr". The size of the extracted integer is specified by the // "byte_size" argument. "byte_size" should have a value >= 1 and <= 8 since @@ -212,7 +195,6 @@ uint32_t DataEncoder::PutU64(uint32_t offset, uint64_t value) { // returned. // // RETURNS the integer value that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataEncoder::PutMaxU64(uint32_t offset, uint32_t byte_size, uint64_t value) { switch (byte_size) { |