mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-18 18:59:04 +01:00
db289c1a1a
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.
81 lines
1.9 KiB
TOML
81 lines
1.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 (oi_is_complete<T>) {
|
|
SAVE_DATA((uintptr_t)(u_ptr.get()));
|
|
|
|
if (u_ptr && ctx.pointers.add((uintptr_t)(u_ptr.get()))) {
|
|
SAVE_DATA(1);
|
|
getSizeType(*(u_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 = """
|
|
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);
|
|
}
|
|
}
|
|
"""
|