mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
add support for std::optional in treebuilder v2
This commit is contained in:
parent
2699b4a665
commit
a95d6f2187
@ -20,6 +20,7 @@
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <iostream> // TODO: remove
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool always_false_v = false;
|
||||
@ -48,6 +49,7 @@ IntrospectionResult::const_iterator::operator++() {
|
||||
using T = std::decay_t<decltype(ty)>;
|
||||
|
||||
if constexpr (std::is_same_v<T, exporters::inst::Field>) {
|
||||
std::cerr << "ty.name = " << ty.name << std::endl;
|
||||
type_path_.emplace_back(ty.name);
|
||||
stack_.emplace(exporters::inst::PopTypePath{});
|
||||
next_ = result::Element{
|
||||
|
@ -1,7 +1,6 @@
|
||||
includes = ["optional", "cstdint", "vector"]
|
||||
[cases]
|
||||
[cases.uint64_empty]
|
||||
oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/312
|
||||
param_types = ["std::optional<std::uint64_t>&"]
|
||||
setup = "return std::nullopt;"
|
||||
expect_json = '''
|
||||
@ -17,7 +16,6 @@ includes = ["optional", "cstdint", "vector"]
|
||||
]
|
||||
'''
|
||||
[cases.uint64_present]
|
||||
oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/312
|
||||
param_types = ["std::optional<std::uint64_t>&"]
|
||||
setup = "return 64;"
|
||||
expect_json = '''
|
||||
@ -33,7 +31,6 @@ includes = ["optional", "cstdint", "vector"]
|
||||
]
|
||||
'''
|
||||
[cases.vector_empty]
|
||||
oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/312
|
||||
param_types = ["std::optional<std::vector<std::uint64_t>>&"]
|
||||
setup = "return std::nullopt;"
|
||||
expect_json = '''
|
||||
@ -49,7 +46,6 @@ includes = ["optional", "cstdint", "vector"]
|
||||
]
|
||||
'''
|
||||
[cases.vector_present]
|
||||
oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/312
|
||||
param_types = ["std::optional<std::vector<std::uint64_t>>&"]
|
||||
setup = "return {{{1,2,3,4,5}}};"
|
||||
expect_json = '''
|
||||
|
@ -39,13 +39,40 @@ struct TypeHandler<DB, %1%<T0>> {
|
||||
static types::st::Unit<DB> getSizeType(
|
||||
const %1%<T0>& container,
|
||||
typename TypeHandler<DB, %1%<T0>>::type returnArg) {
|
||||
if (container) {
|
||||
return returnArg.template delegate<1>([&container](auto ret) {
|
||||
return OIInternal::getSizeType<DB>(*container, ret);
|
||||
});
|
||||
} else {
|
||||
return returnArg.template delegate<0>(std::identity());
|
||||
}
|
||||
}
|
||||
};
|
||||
"""
|
||||
|
||||
traversal_func = """
|
||||
if (container.has_value()) {
|
||||
return returnArg.template delegate<1>([&container](auto ret) {
|
||||
return OIInternal::getSizeType<DB>(*container, ret);
|
||||
});
|
||||
} else {
|
||||
return returnArg.template delegate<0>(std::identity());
|
||||
}
|
||||
"""
|
||||
|
||||
[[codegen.processor]]
|
||||
type = "types::st::Sum<DB, types::st::Unit<DB>, typename TypeHandler<DB, T0>::type>"
|
||||
func = """
|
||||
static constexpr std::array<std::string_view, 1> names{"TODO"};
|
||||
static constexpr auto elementField = inst::Field{
|
||||
sizeof(T0),
|
||||
"el",
|
||||
names,
|
||||
TypeHandler<DB, T0>::fields,
|
||||
TypeHandler<DB, T0>::processors,
|
||||
};
|
||||
|
||||
auto sum = std::get<ParsedData::Sum>(d.val);
|
||||
|
||||
el.container_stats = result::Element::ContainerStats {
|
||||
.capacity = 1,
|
||||
.length = sum.index,
|
||||
};
|
||||
|
||||
if (sum.index == 1) {
|
||||
el.exclusive_size -= sizeof(T0);
|
||||
ins.emplace(elementField);
|
||||
}
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user