object-introspection/types/cxx11_list_type.toml
Jake Hillion e9d8df0ca4 oil: add support for std::list
Summary:

Remove the now useless `handler` and adds the `traversal_func` and `processor`
entries for `std::list`. This type is a bit weird as most of our sequential
containers don't have any overhead on storing the element. I went for the same
approach we take for maps where we have a shared `[]` element covering the map
overhead and below that a `key` & `value`. As we only have a single element
under it which doesn't have a logical name I went for `*`.

Closes #315.

Test Plan:
- CI
- Copied the relevant `std::vector` tests and updated the existing one.
2023-11-15 14:14:02 +00:00

86 lines
2.1 KiB
TOML

[info]
type_name = "std::__cxx11::list"
stub_template_params = [1]
header = "list"
# Old:
ctype = "LIST_TYPE"
typeName = "std::__cxx11::list"
ns = ["namespace std"]
numTemplateParams = 1
replaceTemplateParamIndex = []
allocatorIndex = 1
[codegen]
decl = """
template<typename T, typename Allocator>
void getSizeType(const %1%<T, Allocator> &container, size_t& returnArg);
"""
func = """
template<typename T, typename Allocator>
void getSizeType(const %1%<T, Allocator> &container, size_t& returnArg)
{
SAVE_SIZE(sizeof(%1%<T>));
SAVE_DATA((uintptr_t)&container);
SAVE_DATA((uintptr_t)container.size());
// The double ampersand is needed otherwise this loop doesn't work with vector<bool>
for (auto&& it: container) {
getSizeType(it, returnArg);
}
}
"""
traversal_func = """
auto tail = returnArg.write((uintptr_t)&container)
.write(container.size());
for (auto&& it : container) {
tail = tail.delegate([&it](auto ret) {
return OIInternal::getSizeType<DB>(it, 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::List<DB, typename TypeHandler<DB, T0>::type>"
func = """
#ifdef __GLIBCXX__
static constexpr size_t element_size = sizeof(std::_List_node<T0>);
#else
static_assert(false && "No known element_size for list. See types/cxx11_list_type.toml");
#endif
static constexpr std::array<inst::Field, 1> child_field{
make_field<DB, T0>("*"),
};
static constexpr inst::Field element{
element_size,
element_size - sizeof(T0),
"[]",
std::array<std::string_view, 0>{},
child_field,
std::array<inst::ProcessorInst, 0>{},
};
static constexpr auto childField = make_field<DB, T0>("[]");
auto list = std::get<ParsedData::List>(d.val);
el.container_stats.emplace(result::Element::ContainerStats{
.capacity = list.length,
.length = list.length,
});
el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0);
stack_ins(inst::Repeat{ list.length, childField });
"""