object-introspection/types/shrd_ptr_type.toml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.4 KiB
TOML
Raw Normal View History

2022-12-19 14:37:51 +00:00
[info]
type_name = "std::shared_ptr"
2022-12-19 14:37:51 +00:00
ctype = "SHRD_PTR_TYPE"
header = "memory"
# Old:
typeName = "std::shared_ptr"
2022-12-19 14:37:51 +00:00
ns = ["namespace std"]
numTemplateParams = 1
2022-12-19 14:37:51 +00:00
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>) {
2023-04-05 20:55:40 +01:00
SAVE_DATA((uintptr_t)(s_ptr.get()));
2022-12-19 14:37:51 +00:00
if (s_ptr && ctx.pointers.add((uintptr_t)(s_ptr.get()))) {
2023-04-05 20:55:40 +01:00
SAVE_DATA(1);
getSizeType(*(s_ptr.get()), returnArg);
} else {
SAVE_DATA(0);
}
2022-12-19 14:37:51 +00:00
}
}
"""
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
});
tbv2: replace DB template param with Ctx (#409) Summary: tbv2: replace DB template param with Ctx TreeBuilder v2 adds a DB template parameter to every function. This is used as part of the static type to decide what type of DataBuffer is being used: currently `BackInserterDataBuffer<std::vector<uint8_t>>` for OIL and it would be `DataSegmentDataBuffer` for OID. This change replaces the `DB` template parameter with a more general `Ctx`. Due to issues with dependent naming it also adds a `using DB` to each `TypeHandler` which has the same function as before. This allows us to add more "static context" (typedefs and constants) to functions without changing this signature again, because changing the signature of everything is a massive pain. Currently this change achieves nothing because Ctx contains only DB in a static wrapper. In the next change I'm going to pass a reference of type Ctx around to add a "dynamic context" to invocations which will contain the pointer array. In future we'll then be able to add either static or dynamic context without any signature adjustments. Test Plan: - CI --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebookexperimental/object-introspection/pull/409). * https://github.com/facebookexperimental/object-introspection/issues/410 * __->__ https://github.com/facebookexperimental/object-introspection/issues/409 Reviewed By: ajor Differential Revision: D51352092 Pulled By: JakeHillion
2023-11-15 19:28:21 +00:00
// 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) {
tbv2: replace DB template param with Ctx (#409) Summary: tbv2: replace DB template param with Ctx TreeBuilder v2 adds a DB template parameter to every function. This is used as part of the static type to decide what type of DataBuffer is being used: currently `BackInserterDataBuffer<std::vector<uint8_t>>` for OIL and it would be `DataSegmentDataBuffer` for OID. This change replaces the `DB` template parameter with a more general `Ctx`. Due to issues with dependent naming it also adds a `using DB` to each `TypeHandler` which has the same function as before. This allows us to add more "static context" (typedefs and constants) to functions without changing this signature again, because changing the signature of everything is a massive pain. Currently this change achieves nothing because Ctx contains only DB in a static wrapper. In the next change I'm going to pass a reference of type Ctx around to add a "dynamic context" to invocations which will contain the pointer array. In future we'll then be able to add either static or dynamic context without any signature adjustments. Test Plan: - CI --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebookexperimental/object-introspection/pull/409). * https://github.com/facebookexperimental/object-introspection/issues/410 * __->__ https://github.com/facebookexperimental/object-introspection/issues/409 Reviewed By: ajor Differential Revision: D51352092 Pulled By: JakeHillion
2023-11-15 19:28:21 +00:00
static constexpr auto element = make_field<Ctx, T0>("ptr_val");
stack_ins(element);
}
}
"""