mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
Implement Container V2 for std::unique_ptr
This commit is contained in:
parent
36452a2471
commit
2699b4a665
@ -7,7 +7,6 @@ definitions = '''
|
|||||||
'''
|
'''
|
||||||
[cases]
|
[cases]
|
||||||
[cases.unique_ptr_uint64_empty]
|
[cases.unique_ptr_uint64_empty]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<std::uint64_t>&"]
|
param_types = ["std::unique_ptr<std::uint64_t>&"]
|
||||||
setup = "return {nullptr};"
|
setup = "return {nullptr};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -22,8 +21,17 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 8,
|
||||||
|
"exclusiveSize": 8,
|
||||||
|
"length": 0,
|
||||||
|
"capacity": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.unique_ptr_uint64_present]
|
[cases.unique_ptr_uint64_present]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<std::uint64_t>&"]
|
param_types = ["std::unique_ptr<std::uint64_t>&"]
|
||||||
setup = "return {std::make_unique<std::uint64_t>(64)};"
|
setup = "return {std::make_unique<std::uint64_t>(64)};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -37,8 +45,17 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 8,
|
||||||
|
"exclusiveSize": 8,
|
||||||
|
"length": 1,
|
||||||
|
"capacity": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.unique_ptr_vector_empty]
|
[cases.unique_ptr_vector_empty]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<std::vector<std::uint64_t>>&"]
|
param_types = ["std::unique_ptr<std::vector<std::uint64_t>>&"]
|
||||||
setup = "return {nullptr};"
|
setup = "return {nullptr};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -52,8 +69,17 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 8,
|
||||||
|
"exclusiveSize": 8,
|
||||||
|
"length": 0,
|
||||||
|
"capacity": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.unique_ptr_vector_present]
|
[cases.unique_ptr_vector_present]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<std::vector<std::uint64_t>>&"]
|
param_types = ["std::unique_ptr<std::vector<std::uint64_t>>&"]
|
||||||
setup = "return {std::make_unique<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}))};"
|
setup = "return {std::make_unique<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}))};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -75,8 +101,25 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 8,
|
||||||
|
"exclusiveSize": 8,
|
||||||
|
"length": 1,
|
||||||
|
"capacity": 1,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"staticSize": 24,
|
||||||
|
"exclusiveSize": 24,
|
||||||
|
"length": 5,
|
||||||
|
"capacity": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.unique_ptr_void_empty]
|
[cases.unique_ptr_void_empty]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<void, decltype(&void_int_deleter)>&"]
|
param_types = ["std::unique_ptr<void, decltype(&void_int_deleter)>&"]
|
||||||
setup = "return {std::unique_ptr<void, decltype(&void_int_deleter)>(nullptr, &void_int_deleter)};"
|
setup = "return {std::unique_ptr<void, decltype(&void_int_deleter)>(nullptr, &void_int_deleter)};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -87,8 +130,15 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 16,
|
||||||
|
"exclusiveSize": 16
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.unique_ptr_void_present]
|
[cases.unique_ptr_void_present]
|
||||||
oil_skip = "std::unique_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/299
|
|
||||||
param_types = ["std::unique_ptr<void, decltype(&void_int_deleter)>&"]
|
param_types = ["std::unique_ptr<void, decltype(&void_int_deleter)>&"]
|
||||||
setup = "return {std::unique_ptr<void, decltype(&void_int_deleter)>(new int, &void_int_deleter)};"
|
setup = "return {std::unique_ptr<void, decltype(&void_int_deleter)>(new int, &void_int_deleter)};"
|
||||||
expect_json = '''
|
expect_json = '''
|
||||||
@ -99,6 +149,14 @@ definitions = '''
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
expect_json_v2 = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"staticSize": 16,
|
||||||
|
"exclusiveSize": 16
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
[cases.shared_ptr_uint64_empty]
|
[cases.shared_ptr_uint64_empty]
|
||||||
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
|
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
|
||||||
param_types = ["std::shared_ptr<std::uint64_t>&"]
|
param_types = ["std::shared_ptr<std::uint64_t>&"]
|
||||||
|
@ -66,3 +66,47 @@ struct TypeHandler<DB, %1%<T0,T1>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
traversal_func = """
|
||||||
|
auto tail = returnArg.write((uintptr_t)container.get());
|
||||||
|
|
||||||
|
if constexpr (std::is_void<T0>::value) {
|
||||||
|
return tail.template delegate<0>(std::identity());
|
||||||
|
} else {
|
||||||
|
bool do_visit = container && pointers.add((uintptr_t)container.get());
|
||||||
|
if (!do_visit)
|
||||||
|
return tail.template delegate<0>(std::identity());
|
||||||
|
|
||||||
|
return tail.template delegate<1>([&container](auto ret) {
|
||||||
|
return OIInternal::getSizeType<DB>(*container, ret);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
[[codegen.processor]]
|
||||||
|
type = "types::st::VarInt<DB>"
|
||||||
|
func = """
|
||||||
|
el.pointer = std::get<ParsedData::VarInt>(d.val).value;
|
||||||
|
"""
|
||||||
|
|
||||||
|
[[codegen.processor]]
|
||||||
|
type = """
|
||||||
|
types::st::Sum<DB,
|
||||||
|
types::st::Unit<DB>,
|
||||||
|
typename TypeHandler<DB, T0>::type>
|
||||||
|
"""
|
||||||
|
func = """
|
||||||
|
auto sum = std::get<ParsedData::Sum>(d.val);
|
||||||
|
el.container_stats.emplace(result::Element::ContainerStats {
|
||||||
|
.capacity = 1,
|
||||||
|
.length = sum.index, // 0 for empty containers/void, 1 otherwise
|
||||||
|
});
|
||||||
|
|
||||||
|
// Must be in a `if constexpr` or the compiler will complain about make_field<DB, void>
|
||||||
|
if constexpr (!std::is_void<T0>::value) {
|
||||||
|
if (sum.index == 1) {
|
||||||
|
static constexpr auto element = make_field<DB, T0>("ptr_val");
|
||||||
|
ins.emplace(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user