tbv2: add make_field helper

This commit is contained in:
Jake Hillion 2023-08-25 10:36:42 -07:00 committed by Jake Hillion
parent d009f02ecb
commit 6b90401f51
9 changed files with 33 additions and 90 deletions

View File

@ -985,6 +985,22 @@ void addStandardTypeHandlers(TypeGraph& typeGraph,
}
)";
if (features[Feature::TreeBuilderV2]) {
code += R"(
template <typename DB, typename T>
constexpr inst::Field make_field(std::string_view name) {
return inst::Field{
sizeof(T),
sizeof(T), // TODO: this is incorrect for excl size
name,
NameProvider<T>::names,
TypeHandler<DB, T>::fields,
TypeHandler<DB, T>::processors,
};
}
)";
}
// TODO: bit of a hack - making ContainerInfo a node in the type graph and
// traversing for it would remove the need for this set altogether.
std::unordered_set<const ContainerInfo*> used{};

View File

@ -65,13 +65,7 @@ traversal_func = """
[[codegen.processor]]
type = "types::st::List<DB, typename TypeHandler<DB, T0>::type>"
func = """
static constexpr inst::Field childField{
sizeof(T0),
"[]",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
};
static constexpr auto childField = make_field<DB, T0>("[]");
size_t size = std::get<ParsedData::List>(d.val).length;
el.exclusive_size = N0 == 0 ? 1 : 0;

View File

@ -103,23 +103,10 @@ func = '''
using element_type = std::pair<T0, T1>;
static constexpr std::array<inst::Field, 2> entryFields{
inst::Field{
sizeof(T0),
"key",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
},
inst::Field{
sizeof(T1),
"value",
NameProvider<T1>::names,
TypeHandler<DB, T1>::fields,
TypeHandler<DB, T1>::processors,
},
make_field<DB, T0>("key"),
make_field<DB, T1>("value"),
};
static constexpr auto entryField = inst::Field {
static constexpr auto entry = inst::Field {
sizeof(element_type),
sizeof(element_type) - sizeof(T0) - sizeof(T1),
"[]",
@ -133,5 +120,5 @@ el.container_stats->length = list.length;
el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(element_type);
for (size_t i = 0; i < list.length; i++)
ins.emplace(entryField);
ins.emplace(entry);
'''

View File

@ -135,28 +135,16 @@ static constexpr size_t element_size = sizeof(OI__tree_node);
static_assert(false && "No known element_size for sets. See types/multi_map_type.toml");
#endif
static constexpr std::array<inst::Field, 2> element_fields{
inst::Field {
sizeof(T0),
"key",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
},
inst::Field {
sizeof(T1),
"value",
NameProvider<T1>::names,
TypeHandler<DB, T1>::fields,
TypeHandler<DB, T1>::processors,
},
static constexpr std::array<inst::Field, 2> elementFields{
make_field<DB, T0>("key"),
make_field<DB, T1>("value"),
};
static constexpr auto element = inst::Field {
element_size,
element_size - sizeof(T0) - sizeof(T1),
"[]",
std::array<std::string_view, 0>{},
element_fields,
elementFields,
std::array<inst::ProcessorInst, 0>{},
};

View File

@ -128,13 +128,7 @@ static constexpr size_t element_size = sizeof(OI__tree_node);
static_assert(false && "No known element_size for multisets. See types/multi_set_type.toml");
#endif
static constexpr auto childField = inst::Field{
sizeof(T0),
"[]",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
};
static constexpr auto childField = make_field<DB, T0>("[]");
auto list = std::get<ParsedData::List>(d.val);
el.container_stats.emplace(result::Element::ContainerStats {

View File

@ -58,20 +58,8 @@ traversal_func = """
[[codegen.processor]]
type = "types::st::Pair<DB, typename TypeHandler<DB, T0>::type, typename TypeHandler<DB, T1>::type>"
func = """
static constexpr auto firstField = inst::Field{
sizeof(T0),
"first",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
};
static constexpr auto secondField = inst::Field{
sizeof(T1),
"second",
NameProvider<T1>::names,
TypeHandler<DB, T1>::fields,
TypeHandler<DB, T1>::processors,
};
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);
ins.emplace(secondField);

View File

@ -95,13 +95,7 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get
[[codegen.processor]]
type = "types::st::List<DB, typename TypeHandler<DB, T0>::type>"
func = """
static constexpr auto childField = inst::Field{
sizeof(T0),
"[]",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
};
static constexpr auto childField = make_field<DB, T0>("[]");
auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;

View File

@ -132,13 +132,7 @@ static constexpr size_t element_size = sizeof(OI__tree_node);
static_assert(false && "No known element_size for sets. See types/set_type.toml");
#endif
static constexpr auto childField = inst::Field{
sizeof(T0),
"[]",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
};
static constexpr auto childField = make_field<DB, T0>("[]");
auto list = std::get<ParsedData::List>(d.val);
el.container_stats.emplace(result::Element::ContainerStats {

View File

@ -144,22 +144,10 @@ static_assert(false && "No known element_size for sets. See types/std_map_type.t
#endif
static constexpr std::array<inst::Field, 2> element_fields{
inst::Field {
sizeof(T0),
"key",
NameProvider<T0>::names,
TypeHandler<DB, T0>::fields,
TypeHandler<DB, T0>::processors,
},
inst::Field {
sizeof(T1),
"value",
NameProvider<T1>::names,
TypeHandler<DB, T1>::fields,
TypeHandler<DB, T1>::processors,
},
make_field<DB, T0>("key"),
make_field<DB, T1>("value"),
};
static constexpr auto element = inst::Field {
static constexpr inst::Field element{
element_size,
element_size - sizeof(T0) - sizeof(T1),
"[]",