mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-11 09:18:40 +12:00
Avoid transitive include of vm_ref.h
Add forward declarations of vm::_ref_base Remove default AT = u32 in _ptr_base and _ref_base (doesn't play well).
This commit is contained in:
parent
cfa1416d64
commit
c01f1a8968
6 changed files with 33 additions and 24 deletions
|
@ -1,17 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "Utilities/types.h"
|
||||
#include "vm_ref.h"
|
||||
#include "Utilities/BEType.h"
|
||||
#include "vm.h"
|
||||
|
||||
class ppu_thread;
|
||||
|
||||
namespace vm
|
||||
{
|
||||
template <typename T, typename AT>
|
||||
class _ref_base;
|
||||
|
||||
// SFINAE helper type for vm::_ptr_base comparison operators (enables comparison between equal types and between any type and void*)
|
||||
template<typename T1, typename T2, typename RT = void>
|
||||
using if_comparable_t = std::enable_if_t<std::is_void<T1>::value || std::is_void<T2>::value || std::is_same<std::remove_cv_t<T1>, std::remove_cv_t<T2>>::value, RT>;
|
||||
|
||||
template<typename T, typename AT = u32>
|
||||
template <typename T, typename AT>
|
||||
class _ptr_base
|
||||
{
|
||||
AT m_addr;
|
||||
|
@ -61,28 +65,28 @@ namespace vm
|
|||
|
||||
// Get vm pointer to a struct member
|
||||
template <typename MT, typename T2, typename = if_comparable_t<T, T2>>
|
||||
_ptr_base<MT> ptr(MT T2::*const mptr) const
|
||||
_ptr_base<MT, u32> ptr(MT T2::*const mptr) const
|
||||
{
|
||||
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr));
|
||||
}
|
||||
|
||||
// Get vm pointer to a struct member with array subscription
|
||||
template <typename MT, typename T2, typename ET = std::remove_extent_t<MT>, typename = if_comparable_t<T, T2>>
|
||||
_ptr_base<ET> ptr(MT T2::*const mptr, u32 index) const
|
||||
_ptr_base<ET, u32> ptr(MT T2::*const mptr, u32 index) const
|
||||
{
|
||||
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr) + u32{sizeof(ET)} * index);
|
||||
}
|
||||
|
||||
// Get vm reference to a struct member
|
||||
template <typename MT, typename T2, typename = if_comparable_t<T, T2>>
|
||||
_ref_base<MT> ref(MT T2::*const mptr) const
|
||||
_ref_base<MT, u32> ref(MT T2::*const mptr) const
|
||||
{
|
||||
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr));
|
||||
}
|
||||
|
||||
// Get vm reference to a struct member with array subscription
|
||||
template <typename MT, typename T2, typename ET = std::remove_extent_t<MT>, typename = if_comparable_t<T, T2>>
|
||||
_ref_base<ET> ref(MT T2::*const mptr, u32 index) const
|
||||
_ref_base<ET, u32> ref(MT T2::*const mptr, u32 index) const
|
||||
{
|
||||
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr) + u32{sizeof(ET)} * index);
|
||||
}
|
||||
|
@ -296,14 +300,14 @@ namespace vm
|
|||
|
||||
// Perform static_cast (for example, vm::ptr<void> to vm::ptr<char>)
|
||||
template<typename CT, typename T, typename AT, typename = decltype(static_cast<to_be_t<CT>*>(std::declval<T*>()))>
|
||||
inline _ptr_base<to_be_t<CT>> static_ptr_cast(const _ptr_base<T, AT>& other)
|
||||
inline _ptr_base<to_be_t<CT>, u32> static_ptr_cast(const _ptr_base<T, AT>& other)
|
||||
{
|
||||
return vm::cast(other.addr(), HERE);
|
||||
}
|
||||
|
||||
// Perform const_cast (for example, vm::cptr<char> to vm::ptr<char>)
|
||||
template<typename CT, typename T, typename AT, typename = decltype(const_cast<to_be_t<CT>*>(std::declval<T*>()))>
|
||||
inline _ptr_base<to_be_t<CT>> const_ptr_cast(const _ptr_base<T, AT>& other)
|
||||
inline _ptr_base<to_be_t<CT>, u32> const_ptr_cast(const _ptr_base<T, AT>& other)
|
||||
{
|
||||
return vm::cast(other.addr(), HERE);
|
||||
}
|
||||
|
@ -441,7 +445,7 @@ struct to_se<vm::_ptr_base<T, AT>, Se>
|
|||
template<typename T, typename AT>
|
||||
struct fmt_unveil<vm::_ptr_base<T, AT>, void>
|
||||
{
|
||||
using type = vm::_ptr_base<T>; // Use only T, ignoring AT
|
||||
using type = vm::_ptr_base<T, u32>; // Use only T, ignoring AT
|
||||
|
||||
static inline auto get(const vm::_ptr_base<T, AT>& arg)
|
||||
{
|
||||
|
@ -449,26 +453,26 @@ struct fmt_unveil<vm::_ptr_base<T, AT>, void>
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt_class_string<vm::_ptr_base<const void>, void>
|
||||
template <>
|
||||
struct fmt_class_string<vm::_ptr_base<const void, u32>, void>
|
||||
{
|
||||
static void format(std::string& out, u64 arg);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct fmt_class_string<vm::_ptr_base<T>, void> : fmt_class_string<vm::_ptr_base<const void>, void>
|
||||
template <typename T>
|
||||
struct fmt_class_string<vm::_ptr_base<T, u32>, void> : fmt_class_string<vm::_ptr_base<const void, u32>, void>
|
||||
{
|
||||
// Classify all pointers as const void*
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt_class_string<vm::_ptr_base<const char>, void>
|
||||
template <>
|
||||
struct fmt_class_string<vm::_ptr_base<const char, u32>, void>
|
||||
{
|
||||
static void format(std::string& out, u64 arg);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt_class_string<vm::_ptr_base<char>, void> : fmt_class_string<vm::_ptr_base<const char>>
|
||||
template <>
|
||||
struct fmt_class_string<vm::_ptr_base<char, u32>, void> : fmt_class_string<vm::_ptr_base<const char, u32>>
|
||||
{
|
||||
// Classify char* as const char*
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue