mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
Implement Container V2 for F14NodeMap
This commit is contained in:
parent
d2a40b4f45
commit
b8e2770e2c
78
test/integration/folly_f14_node_map.toml
Normal file
78
test/integration/folly_f14_node_map.toml
Normal file
@ -0,0 +1,78 @@
|
||||
includes = ["folly/container/F14Map.h"]
|
||||
definitions = '''
|
||||
struct Bar {
|
||||
float a, b;
|
||||
};
|
||||
|
||||
struct Foo {
|
||||
folly::F14NodeMap<int, int> m1;
|
||||
folly::F14NodeMap<int, Bar> m2;
|
||||
folly::F14NodeMap<int, int> m3;
|
||||
folly::F14NodeMap<int, int> m4;
|
||||
};
|
||||
'''
|
||||
|
||||
[cases]
|
||||
[cases.a]
|
||||
param_types = ["const Foo&"]
|
||||
setup = '''
|
||||
Foo foo;
|
||||
|
||||
foo.m1.reserve(3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
foo.m1.emplace(i, i);
|
||||
}
|
||||
|
||||
foo.m2.reserve(5);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
foo.m2.emplace(i, Bar{0.0f, 0.0f});
|
||||
}
|
||||
|
||||
foo.m3.reserve(7);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
foo.m3.emplace(i, i);
|
||||
}
|
||||
|
||||
foo.m4.reserve(9);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
foo.m4.emplace(i, i);
|
||||
}
|
||||
|
||||
return {foo};
|
||||
'''
|
||||
expect_json = '''[{
|
||||
"staticSize":96,
|
||||
"dynamicSize":500,
|
||||
"members":[
|
||||
{"name":"m1", "staticSize":24, "dynamicSize":72, "length":3, "capacity":3, "elementStaticSize":8},
|
||||
{
|
||||
"name":"m2",
|
||||
"staticSize":24,
|
||||
"dynamicSize":124,
|
||||
"length":5,
|
||||
"capacity":5,
|
||||
"elementStaticSize":12,
|
||||
"members":[
|
||||
{"staticSize": 4},
|
||||
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
|
||||
{"staticSize": 4},
|
||||
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
|
||||
{"staticSize": 4},
|
||||
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
|
||||
{"staticSize": 4},
|
||||
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]},
|
||||
{"staticSize": 4},
|
||||
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]}
|
||||
]},
|
||||
{"name":"m3", "staticSize":24, "dynamicSize":136, "length":7, "capacity":7, "elementStaticSize":8},
|
||||
{"name":"m4", "staticSize":24, "dynamicSize":168, "length":9, "capacity":9, "elementStaticSize":8}
|
||||
]}]'''
|
||||
expect_json_v2 = '''[{
|
||||
"staticSize":96,
|
||||
"exclusiveSize": 0,
|
||||
"members":[
|
||||
{"name":"m1", "staticSize":24, "exclusiveSize": 24, "length": 3, "capacity": 3},
|
||||
{"name":"m2", "staticSize":24, "exclusiveSize": 24, "length": 5, "capacity": 5},
|
||||
{"name":"m3", "staticSize":24, "exclusiveSize": 24, "length": 7, "capacity": 7},
|
||||
{"name":"m4", "staticSize":24, "exclusiveSize": 24, "length": 9, "capacity": 9}
|
||||
]}]'''
|
@ -35,3 +35,87 @@ void getSizeType(const %1%<Key, Mapped, Hasher, KeyEqual, Alloc> &container, siz
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
handler = """
|
||||
template <typename DB, typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
struct TypeHandler<DB, %1%<T0, T1, T2, T3, T4>> {
|
||||
using type = types::st::Pair<DB,
|
||||
types::st::VarInt<DB>,
|
||||
types::st::Pair<DB,
|
||||
types::st::VarInt<DB>,
|
||||
types::st::List<DB, types::st::Pair<DB,
|
||||
typename TypeHandler<DB, T0>::type,
|
||||
typename TypeHandler<DB, T1>::type>>>>;
|
||||
|
||||
static types::st::Unit<DB> getSizeType(
|
||||
const %1%<T0, T1, T2, T3, T4>& container,
|
||||
typename TypeHandler<DB, %1%<T0, T1, T2, T3, T4>>::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([&key = entry.first, &value = entry.second](auto ret) {
|
||||
auto next = ret.delegate([&key](typename TypeHandler<DB, T0>::type ret) {
|
||||
return OIInternal::getSizeType<DB>(key, ret);
|
||||
});
|
||||
return OIInternal::getSizeType<DB>(value, next);
|
||||
});
|
||||
}
|
||||
|
||||
return tail.finish();
|
||||
}
|
||||
};
|
||||
"""
|
||||
|
||||
traversal_func = """
|
||||
auto tail = returnArg
|
||||
.write((uintptr_t)&container)
|
||||
.write(container.size());
|
||||
|
||||
for (auto &&entry: container) {
|
||||
tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) {
|
||||
auto next = ret.delegate([&key](typename TypeHandler<DB, T0>::type ret) {
|
||||
return OIInternal::getSizeType<DB>(key, ret);
|
||||
});
|
||||
return OIInternal::getSizeType<DB>(value, next);
|
||||
});
|
||||
}
|
||||
|
||||
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, types::st::Pair<DB,
|
||||
typename TypeHandler<DB, T0>::type,
|
||||
typename TypeHandler<DB, T1>::type>>
|
||||
"""
|
||||
func = """
|
||||
auto list = std::get<ParsedData::List>(d.val);
|
||||
el.container_stats.emplace(result::Element::ContainerStats {
|
||||
.capacity = list.length,
|
||||
.length = list.length,
|
||||
});
|
||||
|
||||
static constexpr std::array<inst::Field, 2> element_fields{
|
||||
make_field<DB, T0>("key"),
|
||||
make_field<DB, T1>("value"),
|
||||
};
|
||||
|
||||
static constexpr inst::Field element{
|
||||
0, 0, "[]",
|
||||
std::array<std::string_view, 0>{},
|
||||
element_fields,
|
||||
std::array<inst::ProcessorInst, 0>{},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < list.length; i++)
|
||||
ins.emplace(element);
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user