mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 19:19:05 +01:00
d71307cb43
Summary: Previously on large types OIL would have problems with corrupting the `std::stack<exporter::inst::Inst>` that is passed to the processors. This change hides the implementation of the stack from the processors by wrapping the call to emplace in a `std::function` written by the non-generated code, which solves the test case I've seen for this crashing. It also allows us to easily change the stack implementation in future - I plan to change it to a `std::stack<T, std::vector<T>>` in a follow up. Reviewed By: tyroguru Differential Revision: D49273116
113 lines
2.9 KiB
TOML
113 lines
2.9 KiB
TOML
[info]
|
|
type_name = "std::unique_ptr"
|
|
ctype = "UNIQ_PTR_TYPE"
|
|
header = "memory"
|
|
stub_template_params = [1]
|
|
|
|
# Old:
|
|
typeName = "std::unique_ptr"
|
|
ns = ["namespace std"]
|
|
numTemplateParams = 1
|
|
replaceTemplateParamIndex = []
|
|
|
|
[codegen]
|
|
decl = """
|
|
template<typename T, class Deleter>
|
|
void getSizeType(const %1%<T,Deleter> &container, size_t& returnArg);
|
|
"""
|
|
|
|
func = """
|
|
template<typename T, class Deleter>
|
|
void getSizeType(const %1%<T,Deleter> &u_ptr, size_t& returnArg)
|
|
{
|
|
SAVE_SIZE(sizeof(%1%<T,Deleter>));
|
|
|
|
if constexpr (!std::is_void<T>::value) {
|
|
SAVE_DATA((uintptr_t)(u_ptr.get()));
|
|
|
|
if (u_ptr && pointers.add((uintptr_t)(u_ptr.get()))) {
|
|
SAVE_DATA(1);
|
|
getSizeType(*(u_ptr.get()), returnArg);
|
|
} else {
|
|
SAVE_DATA(0);
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|
|
handler = """
|
|
template <typename DB, typename T0, typename T1>
|
|
struct TypeHandler<DB, %1%<T0,T1>> {
|
|
using type = typename std::conditional<
|
|
std::is_void<T0>::value,
|
|
types::st::Unit<DB>,
|
|
types::st::Pair<DB,
|
|
types::st::VarInt<DB>,
|
|
types::st::Sum<DB,
|
|
types::st::Unit<DB>,
|
|
typename TypeHandler<DB, T0>::type
|
|
>>>::type;
|
|
|
|
static types::st::Unit<DB> getSizeType(
|
|
const %1%<T0,T1>& container,
|
|
typename TypeHandler<DB, %1%<T0,T1>>::type returnArg) {
|
|
if constexpr (!std::is_void<T0>::value) {
|
|
auto r0 = returnArg.write((uintptr_t)(container.get()));
|
|
if (container && pointers.add((uintptr_t)(container.get()))) {
|
|
return r0.template delegate<1>([&container](auto ret) {
|
|
return OIInternal::getSizeType<DB>(*(container.get()), ret);
|
|
});
|
|
} else {
|
|
return r0.template delegate<0>(std::identity());
|
|
}
|
|
} else {
|
|
return returnArg;
|
|
}
|
|
}
|
|
};
|
|
"""
|
|
|
|
traversal_func = """
|
|
auto tail = returnArg.write((uintptr_t)container.get());
|
|
|
|
if constexpr (std::is_void<T0>::value) {
|
|
return tail.template delegate<0>(std::identity());
|
|
} else {
|
|
bool do_visit = container && pointers.add((uintptr_t)container.get());
|
|
if (!do_visit)
|
|
return tail.template delegate<0>(std::identity());
|
|
|
|
return tail.template delegate<1>([&container](auto ret) {
|
|
return OIInternal::getSizeType<DB>(*container, ret);
|
|
});
|
|
}
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = "types::st::VarInt<DB>"
|
|
func = """
|
|
el.pointer = std::get<ParsedData::VarInt>(d.val).value;
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = """
|
|
types::st::Sum<DB,
|
|
types::st::Unit<DB>,
|
|
typename TypeHandler<DB, T0>::type>
|
|
"""
|
|
func = """
|
|
auto sum = std::get<ParsedData::Sum>(d.val);
|
|
el.container_stats.emplace(result::Element::ContainerStats {
|
|
.capacity = 1,
|
|
.length = sum.index, // 0 for empty containers/void, 1 otherwise
|
|
});
|
|
|
|
// Must be in a `if constexpr` or the compiler will complain about make_field<DB, void>
|
|
if constexpr (!std::is_void<T0>::value) {
|
|
if (sum.index == 1) {
|
|
static constexpr auto element = make_field<DB, T0>("ptr_val");
|
|
stack_ins(element);
|
|
}
|
|
}
|
|
"""
|