mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
d71307cb43
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
68 lines
1.7 KiB
TOML
68 lines
1.7 KiB
TOML
[info]
|
|
type_name = "std::pair"
|
|
ctype = "PAIR_TYPE"
|
|
header = "utility"
|
|
|
|
# Old:
|
|
typeName = "std::pair<"
|
|
ns = ["namespace std"]
|
|
numTemplateParams = 2
|
|
replaceTemplateParamIndex = []
|
|
|
|
[codegen]
|
|
decl = """
|
|
template<typename P, typename Q>
|
|
void getSizeType(const %1%<P,Q> &container, size_t& returnArg);
|
|
"""
|
|
|
|
func = """
|
|
template<typename P, typename Q>
|
|
void getSizeType(const %1%<P,Q> &container, size_t& returnArg)
|
|
{
|
|
SAVE_SIZE(sizeof(%1%<P,Q>) - sizeof(P) - sizeof(Q));
|
|
|
|
getSizeType(container.first, returnArg);
|
|
getSizeType(container.second, returnArg);
|
|
}
|
|
"""
|
|
|
|
handler = """
|
|
template <typename DB, typename T0, typename T1>
|
|
struct TypeHandler<DB, %1%<T0, T1>> {
|
|
using type = types::st::Pair<DB,
|
|
typename TypeHandler<DB, T0>::type,
|
|
typename TypeHandler<DB, T1>::type>;
|
|
|
|
static types::st::Unit<DB> getSizeType(
|
|
const %1%<T0, T1> & container,
|
|
typename TypeHandler<DB, %1%<T0, T1>>::type returnArg) {
|
|
return OIInternal::getSizeType<DB>(
|
|
container.second,
|
|
returnArg.delegate([&container](auto ret) {
|
|
return OIInternal::getSizeType<DB>(container.first, ret);
|
|
})
|
|
);
|
|
}
|
|
};
|
|
"""
|
|
|
|
traversal_func = """
|
|
return OIInternal::getSizeType<DB>(
|
|
container.second,
|
|
returnArg.delegate([&container](auto ret) {
|
|
return OIInternal::getSizeType<DB>(container.first, ret);
|
|
})
|
|
);
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = "types::st::Pair<DB, typename TypeHandler<DB, T0>::type, typename TypeHandler<DB, T1>::type>"
|
|
func = """
|
|
static constexpr auto firstField = make_field<DB, T0>("first");
|
|
static constexpr auto secondField = make_field<DB, T1>("second");
|
|
|
|
el.exclusive_size = sizeof(std::pair<T0, T1>) - sizeof(T0) - sizeof(T1);
|
|
stack_ins(secondField);
|
|
stack_ins(firstField);
|
|
"""
|