object-introspection/types/array_type.toml
Jake Hillion d71307cb43 oil: change std::stack reference to a std::function (#345)
Summary:

Previously on large types OIL would have problems with corrupting the `std::stack<exporter::inst::Inst>` that is passed to the processors. This change hides the implementation of the stack from the processors by wrapping the call to emplace in a `std::function` written by the non-generated code, which solves the test case I've seen for this crashing. It also allows us to easily change the stack implementation in future - I plan to change it to a `std::stack<T, std::vector<T>>` in a follow up.

Reviewed By: tyroguru

Differential Revision: D49273116
2023-09-14 16:57:45 +01:00

76 lines
1.9 KiB
TOML

[info]
type_name = "std::array"
ctype = "ARRAY_TYPE"
header = "array"
# Old:
numTemplateParams = 1
ns = ["namespace std"]
typeName = "std::array<"
[codegen]
decl = """
template<typename T, long unsigned int N>
void getSizeType(const %1%<T, N> &container, size_t& returnArg);
"""
func = """
template<typename T, long unsigned int N>
void getSizeType(const %1%<T,N> &container, size_t& returnArg)
{
SAVE_DATA((uintptr_t)container.size());
SAVE_SIZE(sizeof(container));
for (auto & it: container) {
// undo the static size that has already been added per-element
SAVE_SIZE(-sizeof(it));
getSizeType(it, returnArg);
}
}
"""
handler = """
template<typename DB, typename T0, long unsigned int N>
struct TypeHandler<DB, %1%<T0, N>> {
using type = types::st::List<DB, typename TypeHandler<DB, T0>::type>;
static types::st::Unit<DB> getSizeType(
const %1%<T0, N> &container,
typename TypeHandler<DB, %1%<T0,N>>::type returnArg) {
auto tail = returnArg.write(container.size());
for (auto & it: container) {
tail = tail.delegate([&it](auto ret) {
return TypeHandler<DB, T0>::getSizeType(it, ret);
});
}
return tail.finish();
}
};
"""
traversal_func = """
auto tail = returnArg.write(container.size());
for (auto & it: container) {
tail = tail.delegate([&it](auto ret) {
return TypeHandler<DB, T0>::getSizeType(it, ret);
});
}
return tail.finish();
"""
[[codegen.processor]]
type = "types::st::List<DB, typename TypeHandler<DB, T0>::type>"
func = """
static constexpr auto childField = make_field<DB, T0>("[]");
size_t size = std::get<ParsedData::List>(d.val).length;
el.exclusive_size = N0 == 0 ? 1 : 0;
el.container_stats.emplace(result::Element::ContainerStats{ .capacity = size, .length = size });
for (size_t i = 0; i < size; i++)
stack_ins(childField);
"""