diff --git a/include/oi/exporters/inst.h b/include/oi/exporters/inst.h index 3d9170e..db8856f 100644 --- a/include/oi/exporters/inst.h +++ b/include/oi/exporters/inst.h @@ -23,8 +23,8 @@ #include #include +#include #include -#include #include #include @@ -34,7 +34,9 @@ struct PopTypePath; struct Field; using Inst = std::variant>; -using Processor = void (*)(result::Element&, std::stack&, ParsedData); +using Processor = void (*)(result::Element&, + std::function, + ParsedData); using ProcessorInst = std::pair; struct PopTypePath {}; diff --git a/oi/CodeGen.cpp b/oi/CodeGen.cpp index 35f66b0..14c3f52 100644 --- a/oi/CodeGen.cpp +++ b/oi/CodeGen.cpp @@ -948,7 +948,8 @@ void genContainerTypeHandler(FeatureSet features, code += " static void processor_"; code += std::to_string(count++); code += - "(result::Element& el, std::stack& ins, ParsedData d) {\n"; + "(result::Element& el, std::function stack_ins, " + "ParsedData d) {\n"; code += pr.func; // bad indentation code += " }\n"; } diff --git a/oi/FuncGen.cpp b/oi/FuncGen.cpp index 9117a37..f299bc1 100644 --- a/oi/FuncGen.cpp +++ b/oi/FuncGen.cpp @@ -726,10 +726,10 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { )"; if (features[Feature::TreeBuilderV2]) { code += R"(private: - static void process_pointer(result::Element& el, std::stack& ins, ParsedData d) { + static void process_pointer(result::Element& el, std::function stack_ins, ParsedData d) { el.pointer = std::get(d.val).value; } - static void process_pointer_content(result::Element& el, std::stack& ins, ParsedData d) { + static void process_pointer_content(result::Element& el, std::function stack_ins, ParsedData d) { static constexpr std::array names{"TODO"}; static constexpr auto childField = inst::Field{ sizeof(T), @@ -747,7 +747,7 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { return; el.container_stats->length = 1; - ins.emplace(childField); + stack_ins(childField); } static constexpr auto choose_fields() { @@ -862,7 +862,7 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = N0, .len auto list = std::get(d.val); // assert(list.length == N0); for (size_t i = 0; i < N0; i++) - ins.emplace(childField); + stack_ins(childField); )", }); diff --git a/oi/IntrospectionResult.cpp b/oi/IntrospectionResult.cpp index cd09806..9c5c844 100644 --- a/oi/IntrospectionResult.cpp +++ b/oi/IntrospectionResult.cpp @@ -62,7 +62,8 @@ IntrospectionResult::const_iterator::operator++() { for (const auto& [dy, handler] : ty.processors) { auto parsed = exporters::ParsedData::parse(data_, dy); - handler(*next_, stack_, parsed); + handler( + *next_, [this](auto i) { stack_.emplace(i); }, parsed); } for (auto it = ty.fields.rbegin(); it != ty.fields.rend(); ++it) { stack_.emplace(*it); diff --git a/types/array_type.toml b/types/array_type.toml index 0eb26c7..92e72ca 100644 --- a/types/array_type.toml +++ b/types/array_type.toml @@ -71,5 +71,5 @@ size_t size = std::get(d.val).length; el.exclusive_size = N0 == 0 ? 1 : 0; el.container_stats.emplace(result::Element::ContainerStats{ .capacity = size, .length = size }); for (size_t i = 0; i < size; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/f14_fast_map.toml b/types/f14_fast_map.toml index bf0d65b..1dd58c7 100644 --- a/types/f14_fast_map.toml +++ b/types/f14_fast_map.toml @@ -120,5 +120,5 @@ static constexpr inst::Field element{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/f14_fast_set.toml b/types/f14_fast_set.toml index 8854101..d8377f9 100644 --- a/types/f14_fast_set.toml +++ b/types/f14_fast_set.toml @@ -99,5 +99,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/f14_node_map.toml b/types/f14_node_map.toml index ef11936..bab3147 100644 --- a/types/f14_node_map.toml +++ b/types/f14_node_map.toml @@ -120,5 +120,5 @@ static constexpr inst::Field element{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/f14_node_set.toml b/types/f14_node_set.toml index 1595f69..4a05137 100644 --- a/types/f14_node_set.toml +++ b/types/f14_node_set.toml @@ -99,5 +99,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/f14_value_map.toml b/types/f14_value_map.toml index bf8511c..6d77a85 100644 --- a/types/f14_value_map.toml +++ b/types/f14_value_map.toml @@ -120,5 +120,5 @@ static constexpr inst::Field element{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/f14_value_set.toml b/types/f14_value_set.toml index f5c07e6..b883ed4 100644 --- a/types/f14_value_set.toml +++ b/types/f14_value_set.toml @@ -99,5 +99,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/f14_vector_map.toml b/types/f14_vector_map.toml index a07bd62..594c066 100644 --- a/types/f14_vector_map.toml +++ b/types/f14_vector_map.toml @@ -120,5 +120,5 @@ static constexpr inst::Field element{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/f14_vector_set.toml b/types/f14_vector_set.toml index 2e4c073..772bf95 100644 --- a/types/f14_vector_set.toml +++ b/types/f14_vector_set.toml @@ -99,5 +99,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/map_seq_type.toml b/types/map_seq_type.toml index 5e6c6de..e19e14d 100644 --- a/types/map_seq_type.toml +++ b/types/map_seq_type.toml @@ -120,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(entry); + stack_ins(entry); ''' diff --git a/types/multi_map_type.toml b/types/multi_map_type.toml index 550025e..f29eb8d 100644 --- a/types/multi_map_type.toml +++ b/types/multi_map_type.toml @@ -155,5 +155,5 @@ el.container_stats.emplace(result::Element::ContainerStats { }); for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/multi_set_type.toml b/types/multi_set_type.toml index 68010bd..aab9fd7 100644 --- a/types/multi_set_type.toml +++ b/types/multi_set_type.toml @@ -138,5 +138,5 @@ el.container_stats.emplace(result::Element::ContainerStats { el.exclusive_size += el.container_stats->length * (element_size - sizeof(T0)); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/optional_type.toml b/types/optional_type.toml index 1e417d9..d153537 100644 --- a/types/optional_type.toml +++ b/types/optional_type.toml @@ -81,6 +81,6 @@ el.container_stats = result::Element::ContainerStats { if (sum.index == 1) { el.exclusive_size -= sizeof(T0); - ins.emplace(elementField); + stack_ins(elementField); } """ diff --git a/types/pair_type.toml b/types/pair_type.toml index af4a4cf..e904db8 100644 --- a/types/pair_type.toml +++ b/types/pair_type.toml @@ -62,6 +62,6 @@ 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); -ins.emplace(firstField); +stack_ins(secondField); +stack_ins(firstField); """ diff --git a/types/seq_type.toml b/types/seq_type.toml index 6b04973..495fa7c 100644 --- a/types/seq_type.toml +++ b/types/seq_type.toml @@ -102,5 +102,5 @@ el.container_stats->length = list.length; el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/set_type.toml b/types/set_type.toml index 7512bb6..bd22ad6 100644 --- a/types/set_type.toml +++ b/types/set_type.toml @@ -142,5 +142,5 @@ el.container_stats.emplace(result::Element::ContainerStats { el.exclusive_size += el.container_stats->length * (element_size - sizeof(T0)); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/shrd_ptr_type.toml b/types/shrd_ptr_type.toml index 2f142cb..3154fe4 100644 --- a/types/shrd_ptr_type.toml +++ b/types/shrd_ptr_type.toml @@ -120,7 +120,7 @@ el.container_stats.emplace(result::Element::ContainerStats { if constexpr (!std::is_void::value) { if (sum.index == 1) { static constexpr auto element = make_field("ptr_val"); - ins.emplace(element); + stack_ins(element); } } """ diff --git a/types/small_vec_type.toml b/types/small_vec_type.toml index 4014c10..0bdd1dd 100644 --- a/types/small_vec_type.toml +++ b/types/small_vec_type.toml @@ -126,5 +126,5 @@ if (uses_intern_storage) { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/std_map_type.toml b/types/std_map_type.toml index 43b3da7..3e0406d 100644 --- a/types/std_map_type.toml +++ b/types/std_map_type.toml @@ -163,5 +163,5 @@ el.container_stats.emplace(result::Element::ContainerStats { }); for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/std_unordered_map_type.toml b/types/std_unordered_map_type.toml index f9c7bc7..d883dff 100644 --- a/types/std_unordered_map_type.toml +++ b/types/std_unordered_map_type.toml @@ -160,5 +160,5 @@ static constexpr auto element = inst::Field{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/std_unordered_multimap_type.toml b/types/std_unordered_multimap_type.toml index 619cb94..2782118 100644 --- a/types/std_unordered_multimap_type.toml +++ b/types/std_unordered_multimap_type.toml @@ -160,5 +160,5 @@ static constexpr auto element = inst::Field{ }; for (size_t i = 0; i < list.length; i++) - ins.emplace(element); + stack_ins(element); """ diff --git a/types/uniq_ptr_type.toml b/types/uniq_ptr_type.toml index 9f6fd9e..eb3be12 100644 --- a/types/uniq_ptr_type.toml +++ b/types/uniq_ptr_type.toml @@ -106,7 +106,7 @@ el.container_stats.emplace(result::Element::ContainerStats { if constexpr (!std::is_void::value) { if (sum.index == 1) { static constexpr auto element = make_field("ptr_val"); - ins.emplace(element); + stack_ins(element); } } """ diff --git a/types/unordered_multiset_type.toml b/types/unordered_multiset_type.toml index b04e936..bf6e86f 100644 --- a/types/unordered_multiset_type.toml +++ b/types/unordered_multiset_type.toml @@ -133,5 +133,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """ diff --git a/types/unordered_set_type.toml b/types/unordered_set_type.toml index 9e88396..8f085c4 100644 --- a/types/unordered_set_type.toml +++ b/types/unordered_set_type.toml @@ -133,5 +133,5 @@ el.container_stats.emplace(result::Element::ContainerStats { static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) - ins.emplace(childField); + stack_ins(childField); """