mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
tbv2: use std::decay_t in make_field
CodeGen v2 permits template parameters to be qualified. This means that if we call `make_field` with a template parameter it will be qualified. However, we don't qualify the types when generating meta functions such as `NameProvider` and `TypeHandler`. This means these qualified types don't match up with the expected type. Use `std::decay_t` when forwarding the type to `NameProvider` and `TypeHandler` so they're always the base type that they were generated with. Test Plan: - CI - Added a test for `std::unique_ptr<const Foo>` to exercise this. Failed before, passes after.
This commit is contained in:
parent
beb404e41c
commit
5984e59961
@ -1060,7 +1060,7 @@ void addStandardTypeHandlers(TypeGraph& typeGraph,
|
||||
getSizeType(Ctx& ctx, const T &t, typename TypeHandler<Ctx, T>::type returnArg) {
|
||||
JLOG("obj @");
|
||||
JLOGPTR(&t);
|
||||
return TypeHandler<Ctx, T>::getSizeType(ctx, t, returnArg);
|
||||
return TypeHandler<Ctx, std::decay_t<T>>::getSizeType(ctx, t, returnArg);
|
||||
}
|
||||
)";
|
||||
|
||||
@ -1072,9 +1072,9 @@ constexpr inst::Field make_field(std::string_view name) {
|
||||
sizeof(T),
|
||||
ExclusiveSizeProvider<T>::size,
|
||||
name,
|
||||
NameProvider<T>::names,
|
||||
TypeHandler<Ctx, T>::fields,
|
||||
TypeHandler<Ctx, T>::processors,
|
||||
NameProvider<std::decay_t<T>>::names,
|
||||
TypeHandler<Ctx, std::decay_t<T>>::fields,
|
||||
TypeHandler<Ctx, std::decay_t<T>>::processors,
|
||||
};
|
||||
}
|
||||
)";
|
||||
|
@ -31,6 +31,31 @@ definitions = '''
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.unique_ptr_const_uint64_empty]
|
||||
param_types = ["std::unique_ptr<const std::uint64_t>&"]
|
||||
setup = "return {nullptr};"
|
||||
expect_json = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 8,
|
||||
"dynamicSize": 0,
|
||||
"exclusiveSize": 8,
|
||||
"length": 0,
|
||||
"capacity": 1,
|
||||
"elementStaticSize": 8
|
||||
}
|
||||
]
|
||||
'''
|
||||
expect_json_v2 = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 8,
|
||||
"exclusiveSize": 8,
|
||||
"length": 0,
|
||||
"capacity": 1
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.unique_ptr_uint64_present]
|
||||
param_types = ["std::unique_ptr<std::uint64_t>&"]
|
||||
setup = "return {std::make_unique<std::uint64_t>(64)};"
|
||||
@ -79,6 +104,30 @@ definitions = '''
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.unique_ptr_const_vector_empty]
|
||||
param_types = ["std::unique_ptr<const std::vector<std::uint64_t>>&"]
|
||||
setup = "return {nullptr};"
|
||||
expect_json = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 8,
|
||||
"dynamicSize": 0,
|
||||
"length": 0,
|
||||
"capacity": 1,
|
||||
"elementStaticSize": 24
|
||||
}
|
||||
]
|
||||
'''
|
||||
expect_json_v2 = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 8,
|
||||
"exclusiveSize": 8,
|
||||
"length": 0,
|
||||
"capacity": 1
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.unique_ptr_vector_present]
|
||||
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}))};"
|
||||
@ -181,6 +230,30 @@ definitions = '''
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.shared_ptr_const_uint64_empty]
|
||||
param_types = ["std::shared_ptr<const std::uint64_t>&"]
|
||||
setup = "return {nullptr};"
|
||||
expect_json = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 16,
|
||||
"dynamicSize": 0,
|
||||
"length": 0,
|
||||
"capacity": 1,
|
||||
"elementStaticSize": 8
|
||||
}
|
||||
]
|
||||
'''
|
||||
expect_json_v2 = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 16,
|
||||
"exclusiveSize": 16,
|
||||
"length": 0,
|
||||
"capacity": 1
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.shared_ptr_uint64_present]
|
||||
param_types = ["std::shared_ptr<std::uint64_t>&"]
|
||||
setup = "return std::make_shared<std::uint64_t>(64);"
|
||||
@ -232,6 +305,30 @@ definitions = '''
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.shared_ptr_const_vector_empty]
|
||||
param_types = ["std::shared_ptr<const std::vector<std::uint64_t>>&"]
|
||||
setup = "return {nullptr};"
|
||||
expect_json = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 16,
|
||||
"dynamicSize": 0,
|
||||
"length": 0,
|
||||
"capacity": 1,
|
||||
"elementStaticSize": 24
|
||||
}
|
||||
]
|
||||
'''
|
||||
expect_json_v2 = '''
|
||||
[
|
||||
{
|
||||
"staticSize": 16,
|
||||
"exclusiveSize": 16,
|
||||
"length": 0,
|
||||
"capacity": 1
|
||||
}
|
||||
]
|
||||
'''
|
||||
[cases.shared_ptr_vector_present]
|
||||
param_types = ["std::shared_ptr<std::vector<std::uint64_t>>&"]
|
||||
setup = "return std::make_shared<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}));"
|
||||
|
@ -60,7 +60,7 @@ el.pointer = std::get<ParsedData::VarInt>(d.val).value;
|
||||
type = """
|
||||
types::st::Sum<DB,
|
||||
types::st::Unit<DB>,
|
||||
typename TypeHandler<Ctx, T0>::type>
|
||||
typename TypeHandler<Ctx, std::decay_t<T0>>::type>
|
||||
"""
|
||||
func = """
|
||||
#ifdef __GLIBCXX__
|
||||
|
@ -61,7 +61,7 @@ el.pointer = std::get<ParsedData::VarInt>(d.val).value;
|
||||
type = """
|
||||
types::st::Sum<DB,
|
||||
types::st::Unit<DB>,
|
||||
typename TypeHandler<Ctx, T0>::type>
|
||||
typename TypeHandler<Ctx, std::decay_t<T0>>::type>
|
||||
"""
|
||||
func = """
|
||||
auto sum = std::get<ParsedData::Sum>(d.val);
|
||||
|
Loading…
Reference in New Issue
Block a user