Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed May 6, 2024
1 parent 530313b commit 1b7989d
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 138 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2024-05-06 12:34:28+01:00 - build 6331

1. Refactoring.

--------------------------------------------------------------------------------
drkns 2024-05-05 18:00:54+01:00 - build 6330

Expand Down
20 changes: 8 additions & 12 deletions far/common/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void copy_memory(detail::void_or_trivially_copyable auto const* const Source, de
namespace detail
{
template<typename T, typename void_type> requires std::same_as<std::remove_const_t<void_type>, void>
decltype(auto) cast_as(void_type* const BaseAddress, intptr_t const Offset)
constexpr decltype(auto) cast_as(void_type* const BaseAddress, intptr_t const Offset)
{
constexpr auto IsConst = std::is_const_v<void_type>;

Expand All @@ -359,10 +359,6 @@ namespace detail
}
}

}

namespace detail
{
template<typename T>
concept buffer_type = std::same_as<std::remove_const_t<T>, void> || std::is_trivially_copyable_v<T>;

Expand All @@ -371,45 +367,45 @@ namespace detail
}

template<typename T>
decltype(auto) view_as(detail::buffer_type auto const* const BaseAddress, intptr_t const Offset = 0)
constexpr decltype(auto) view_as(detail::buffer_type auto const* const BaseAddress, intptr_t const Offset = 0)
{
return detail::cast_as<T>(static_cast<void const*>(BaseAddress), Offset);
}

template<typename T>
decltype(auto) view_as(unsigned long long const Address)
constexpr decltype(auto) view_as(unsigned long long const Address)
{
return view_as<T>(static_cast<void const*>(nullptr), Address);
}

template<typename T>
decltype(auto) edit_as(detail::writable_buffer_type auto* const BaseAddress, intptr_t const Offset = 0)
constexpr decltype(auto) edit_as(detail::writable_buffer_type auto* const BaseAddress, intptr_t const Offset = 0)
{
return detail::cast_as<T>(static_cast<void*>(BaseAddress), Offset);
}

template<typename T>
decltype(auto) edit_as(unsigned long long const Address)
constexpr decltype(auto) edit_as(unsigned long long const Address)
{
return edit_as<T>(static_cast<void*>(nullptr), Address);
}

template<typename T> requires std::is_trivially_copyable_v<T>
auto view_as_opt(detail::buffer_type auto const* const Begin, detail::buffer_type auto const* const End, size_t const Offset = 0)
constexpr auto view_as_opt(detail::buffer_type auto const* const Begin, detail::buffer_type auto const* const End, size_t const Offset = 0)
{
return static_cast<char const*>(static_cast<void const*>(Begin)) + Offset + sizeof(T) <= static_cast<char const*>(static_cast<void const*>(End))?
view_as<T const*>(Begin, Offset) :
nullptr;
}

template<typename T> requires std::is_trivially_copyable_v<T>
auto view_as_opt(detail::buffer_type auto const* const Buffer, size_t const Size, size_t const Offset = 0)
constexpr auto view_as_opt(detail::buffer_type auto const* const Buffer, size_t const Size, size_t const Offset = 0)
{
return view_as_opt<T>(Buffer, static_cast<char const*>(static_cast<void const*>(Buffer)) + Size, Offset);
}

template<typename T> requires std::is_trivially_copyable_v<T>
auto view_as_opt(std::ranges::contiguous_range auto const& Buffer, size_t const Offset = 0)
constexpr auto view_as_opt(std::ranges::contiguous_range auto const& Buffer, size_t const Offset = 0)
{
static_assert(detail::buffer_type<std::ranges::range_value_t<decltype(Buffer)>>);
return view_as_opt<T>(std::ranges::cdata(Buffer), std::ranges::size(Buffer), Offset);
Expand Down
52 changes: 52 additions & 0 deletions far/far.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,56 @@
</Expand>
</Type>

<Type Name="memcheck::memory_block">
<DisplayString Condition="AllocationType == allocation_type::scalar">{{ scalar, {DataSize} bytes }}</DisplayString>
<DisplayString Condition="AllocationType == allocation_type::vector">{{ vector, {DataSize} bytes }}</DisplayString>
<Expand>
<Item Name="Type">AllocationType</Item>
<Synthetic Name="Data (char)">
<DisplayString>{{ {DataSize} bytes }}</DisplayString>
<StringView>(unsigned char*)this + HeaderSize,[DataSize]na</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">DataSize</Item>
<ArrayItems>
<Size>DataSize</Size>
<ValuePointer>(unsigned char const*)this + HeaderSize</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
<Synthetic Name="Data (wchar_t)">
<DisplayString>{{ {DataSize} bytes }}</DisplayString>
<StringView>(wchar_t const*)((unsigned char const*)this + HeaderSize),[DataSize / sizeof(wchar_t)]na</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">DataSize / sizeof(wchar_t)</Item>
<ArrayItems>
<Size>DataSize / sizeof(wchar_t)</Size>
<ValuePointer>(wchar_t const*)((unsigned char const*)this + HeaderSize)</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
<Synthetic Name="Stack">
<DisplayString>{{ {sizeof(Stack) / sizeof(Stack[0])} frames }}</DisplayString>
<Expand>
<ArrayItems>
<Size>sizeof(Stack) / sizeof(Stack[0])</Size>
<ValuePointer>Stack, na</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

<Type Name="memcheck::blocks_list">
<DisplayString>{{Count = {m_Size}}}</DisplayString>
<Expand>
<Item Name="Count">m_Size</Item>
<LinkedListItems>
<Size>m_Size</Size>
<HeadPointer>m_First</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this,na</ValueNode>
</LinkedListItems>
</Expand>
</Type>

</AutoVisualizer>
Loading

0 comments on commit 1b7989d

Please sign in to comment.