object-introspection/types/shrd_ptr_type.toml
Jake Hillion db289c1a1a tbv2: use std::decay_t with smart pointers
CodeGen v2 permits template parameters to be qualified. This means that if we
call `make_field` with a template parameter it will be qualified. However, we
don't qualify the types when generating meta functions such as `NameProvider`
and `TypeHandler`. This means these qualified types don't match up with the
expected type.

Use `std::decay_t` when forwarding the type to `NameProvider` and `TypeHandler`
so they're always the base type that they were generated with. Most of this is
covered by `make_field`, but there are direct references to `TypeHandler<Ctx,
T>` in a lot of `TypeHandler::type` fields. Fix the problematic types manually
for now, there may need to be a better solution with meta functions for this in
the future.

Test Plan:
- CI
- Added a test for `std::unique_ptr<const uint64_t>` to exercise this. Failed
  before, passes after.
- Added a test for `std::unique_ptr<const std::vector<uint64_t>>` to test a
  non-primitive type. Failed before, passes after.
2024-01-31 17:27:04 +00:00

95 lines
2.4 KiB
TOML

[info]
type_name = "std::shared_ptr"
ctype = "SHRD_PTR_TYPE"
header = "memory"
# Old:
typeName = "std::shared_ptr"
ns = ["namespace std"]
numTemplateParams = 1
replaceTemplateParamIndex = []
[codegen]
decl = """
template<typename T>
void getSizeType(const %1%<T> &s_ptr, size_t& returnArg);
"""
func = """
template<typename T>
void getSizeType(const %1%<T> &s_ptr, size_t& returnArg)
{
SAVE_SIZE(sizeof(%1%<T>));
if constexpr (oi_is_complete<T>) {
SAVE_DATA((uintptr_t)(s_ptr.get()));
if (s_ptr && ctx.pointers.add((uintptr_t)(s_ptr.get()))) {
SAVE_DATA(1);
getSizeType(*(s_ptr.get()), returnArg);
} else {
SAVE_DATA(0);
}
}
}
"""
traversal_func = """
auto tail = returnArg.write((uintptr_t)container.get());
if constexpr (!oi_is_complete<T0>) {
return tail.template delegate<0>(std::identity());
} else {
bool do_visit = container && ctx.pointers.add((uintptr_t)container.get());
if (!do_visit)
return tail.template delegate<0>(std::identity());
return tail.template delegate<1>([&ctx, &container](auto ret) {
return OIInternal::getSizeType<Ctx>(ctx, *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<Ctx, std::decay_t<T0>>::type>
"""
func = """
#ifdef __GLIBCXX__
// TODO: Accurately report the control block overhead
// accounting for both in-place and non-in-place
// _Sp_counted_base (_Atomic_word, _Atomic_word)
// _Sp_counted_ptr : _Sp_counted_base (_Ptr)
// _Sp_counted_ptr_inplace : _Sp_counted_base (_Tp)
// _Sp_counted_deleter : _Sp_counted_base (_Ptr)
// _Sp_counted_array : _Sp_counted_base (_Ptr)
#elif _LIBCPP_VERSION
static_assert(false && "libc++ is currently not supported");
#else
static_assert(false && "No known element_size for sets. See types/set_type.toml");
#endif
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<Ctx, void>
if constexpr (oi_is_complete<T0>) {
if (sum.index == 1) {
static constexpr auto element = make_field<Ctx, T0>("ptr_val");
stack_ins(element);
}
}
"""