mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
592e182e0f
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
55 lines
1.3 KiB
TOML
55 lines
1.3 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);
|
|
}
|
|
}
|
|
"""
|
|
|
|
traversal_func = """
|
|
auto tail = returnArg.write(container.size());
|
|
|
|
for (auto & it: container) {
|
|
tail = tail.delegate([&it](auto ret) {
|
|
return TypeHandler<Ctx, T0>::getSizeType(it, ret);
|
|
});
|
|
}
|
|
|
|
return tail.finish();
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = "types::st::List<DB, typename TypeHandler<Ctx, T0>::type>"
|
|
func = """
|
|
static constexpr auto childField = make_field<Ctx, 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);
|
|
"""
|