diff --git a/oi/CodeGen.cpp b/oi/CodeGen.cpp index f69af71..65ea981 100644 --- a/oi/CodeGen.cpp +++ b/oi/CodeGen.cpp @@ -985,6 +985,22 @@ void addStandardTypeHandlers(TypeGraph& typeGraph, } )"; + if (features[Feature::TreeBuilderV2]) { + code += R"( +template +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::names, + TypeHandler::fields, + TypeHandler::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 used{}; diff --git a/types/array_type.toml b/types/array_type.toml index f8d62bb..0eb26c7 100644 --- a/types/array_type.toml +++ b/types/array_type.toml @@ -65,13 +65,7 @@ traversal_func = """ [[codegen.processor]] type = "types::st::List::type>" func = """ -static constexpr inst::Field childField{ - sizeof(T0), - "[]", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, -}; +static constexpr auto childField = make_field("[]"); size_t size = std::get(d.val).length; el.exclusive_size = N0 == 0 ? 1 : 0; diff --git a/types/map_seq_type.toml b/types/map_seq_type.toml index 6a19340..5e6c6de 100644 --- a/types/map_seq_type.toml +++ b/types/map_seq_type.toml @@ -103,23 +103,10 @@ func = ''' using element_type = std::pair; static constexpr std::array entryFields{ - inst::Field{ - sizeof(T0), - "key", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, - inst::Field{ - sizeof(T1), - "value", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, + make_field("key"), + make_field("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); ''' diff --git a/types/multi_map_type.toml b/types/multi_map_type.toml index ee1ed7f..550025e 100644 --- a/types/multi_map_type.toml +++ b/types/multi_map_type.toml @@ -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 element_fields{ - inst::Field { - sizeof(T0), - "key", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, - inst::Field { - sizeof(T1), - "value", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, +static constexpr std::array elementFields{ + make_field("key"), + make_field("value"), }; static constexpr auto element = inst::Field { element_size, element_size - sizeof(T0) - sizeof(T1), "[]", std::array{}, - element_fields, + elementFields, std::array{}, }; diff --git a/types/multi_set_type.toml b/types/multi_set_type.toml index 4654cd4..68010bd 100644 --- a/types/multi_set_type.toml +++ b/types/multi_set_type.toml @@ -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::names, - TypeHandler::fields, - TypeHandler::processors, -}; +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats { diff --git a/types/pair_type.toml b/types/pair_type.toml index ad2ca7e..af4a4cf 100644 --- a/types/pair_type.toml +++ b/types/pair_type.toml @@ -58,20 +58,8 @@ traversal_func = """ [[codegen.processor]] type = "types::st::Pair::type, typename TypeHandler::type>" func = """ -static constexpr auto firstField = inst::Field{ - sizeof(T0), - "first", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, -}; -static constexpr auto secondField = inst::Field{ - sizeof(T1), - "second", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, -}; +static constexpr auto firstField = make_field("first"); +static constexpr auto secondField = make_field("second"); el.exclusive_size = sizeof(std::pair) - sizeof(T0) - sizeof(T1); ins.emplace(secondField); diff --git a/types/seq_type.toml b/types/seq_type.toml index b730461..6b04973 100644 --- a/types/seq_type.toml +++ b/types/seq_type.toml @@ -95,13 +95,7 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get [[codegen.processor]] type = "types::st::List::type>" func = """ -static constexpr auto childField = inst::Field{ - sizeof(T0), - "[]", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, -}; +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats->length = list.length; diff --git a/types/set_type.toml b/types/set_type.toml index a24a936..7512bb6 100644 --- a/types/set_type.toml +++ b/types/set_type.toml @@ -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::names, - TypeHandler::fields, - TypeHandler::processors, -}; +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats { diff --git a/types/std_map_type.toml b/types/std_map_type.toml index bcaa8b7..43b3da7 100644 --- a/types/std_map_type.toml +++ b/types/std_map_type.toml @@ -144,22 +144,10 @@ static_assert(false && "No known element_size for sets. See types/std_map_type.t #endif static constexpr std::array element_fields{ - inst::Field { - sizeof(T0), - "key", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, - inst::Field { - sizeof(T1), - "value", - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, - }, + make_field("key"), + make_field("value"), }; -static constexpr auto element = inst::Field { +static constexpr inst::Field element{ element_size, element_size - sizeof(T0) - sizeof(T1), "[]",