object-introspection/types/f14_value_set.toml
2023-10-09 10:41:34 -06:00

112 lines
2.9 KiB
TOML

[info]
type_name = "folly::F14ValueSet"
stub_template_params = [1,2,3]
ctype = "F14_SET"
header = "folly/container/F14Set.h"
# Old:
typeName = "folly::F14ValueSet<"
ns = ["folly::F14ValueSet"]
numTemplateParams = 1
replaceTemplateParamIndex = [1, 2]
allocatorIndex = 3
[codegen]
decl = """
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
void getSizeType(const %1%<Key, Hasher, KeyEqual, Alloc> &container, size_t& returnArg);
"""
func = """
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
void getSizeType(const %1%<Key, Hasher, KeyEqual, Alloc> &container, size_t& returnArg)
{
size_t memorySize = container.getAllocatedMemorySize();
SAVE_SIZE(sizeof(%1%<Key, Hasher, KeyEqual, Alloc>) + memorySize);
SAVE_DATA(memorySize);
SAVE_DATA(container.bucket_count());
SAVE_DATA(container.size());
// The double ampersand is needed otherwise this loop doesn't work with vector<bool>
for (auto&& it: container) {
getSizeType(it, returnArg);
}
}
"""
handler = """
template <typename DB, typename T0, typename T1, typename T2, typename T3>
struct TypeHandler<DB, %1%<T0, T1, T2, T3>> {
using type = types::st::Pair<DB,
types::st::VarInt<DB>,
types::st::Pair<DB,
types::st::VarInt<DB>,
types::st::List<DB,
typename TypeHandler<DB, T0>::type>>>;
static types::st::Unit<DB> getSizeType(
const %1%<T0, T1, T2, T3>& container,
typename TypeHandler<DB, %1%<T0, T1, T2, T3>>::type returnArg) {
size_t memorySize = container.getAllocatedMemorySize();
auto tail = returnArg
.write(memorySize)
.write(container.bucket_count())
.write(container.size());
for (auto &&entry: container) {
tail = tail.delegate([&entry](auto ret) {
return OIInternal::getSizeType<DB>(entry, ret);
});
}
return tail.finish();
}
};
"""
traversal_func = """
auto tail = returnArg
.write((uintptr_t)container.getAllocatedMemorySize())
.write((uintptr_t)container.bucket_count())
.write(container.size());
for (auto &&entry: container) {
tail = tail.delegate([&entry](auto ret) {
return OIInternal::getSizeType<DB>(entry, ret);
});
}
return tail.finish();
"""
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = "el.pointer = std::get<ParsedData::VarInt>(d.val).value;"
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = """
el.container_stats.emplace(result::Element::ContainerStats {
.capacity = std::get<ParsedData::VarInt>(d.val).value,
});
"""
[[codegen.processor]]
type = """
types::st::List<DB, typename TypeHandler<DB, T0>::type>
"""
func = """
auto allocationSize = el.pointer.value();
el.pointer.reset();
auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;
el.exclusive_size += allocationSize - list.length * sizeof(T0);
static constexpr auto childField = make_field<DB, T0>("[]");
for (size_t i = 0; i < list.length; i++)
stack_ins(childField);
"""