From 014f880e41f6eec000881f6fdfdc462264d371df Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 26 Jun 2023 17:10:04 +0300 Subject: [PATCH] Simplify get_children_types usage. --- tdtl/td/tl/tl_generate.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp index 73b9a3711..84637d23c 100644 --- a/tdtl/td/tl/tl_generate.cpp +++ b/tdtl/td/tl/tl_generate.cpp @@ -78,6 +78,27 @@ static void get_children_types(const tl_tree *tree, const TL_writer &w, std::map } } +static std::map get_children_types(const tl_combinator *t, const TL_writer &w) { + std::map children_types; + for (std::size_t i = 0; i < t->args.size(); i++) { + get_children_types(t->args[i].type, w, children_types); + } + get_children_types(t->result, w, children_types); + return children_types; +} + +static std::map get_children_types(const tl_type *t, const TL_writer &w) { + std::map children_types; + for (std::size_t i = 0; i < t->constructors_num; i++) { + if (w.is_combinator_supported(t->constructors[i])) { + for (std::size_t j = 0; j < t->constructors[i]->args.size(); j++) { + get_children_types(t->constructors[i]->args[j].type, w, children_types); + } + } + } + return children_types; +} + static void write_forward_declarations(tl_outputer &out, const std::map &children_types, const TL_writer &w) { for (std::map::const_iterator it = children_types.begin(); it != children_types.end(); ++it) { @@ -278,12 +299,7 @@ static void write_function(tl_outputer &out, const tl_combinator *t, const std:: const std::set &result_types, const TL_writer &w) { assert(w.is_combinator_supported(t)); - std::map children_types; - for (std::size_t i = 0; i < t->args.size(); i++) { - get_children_types(t->args[i].type, w, children_types); - } - get_children_types(t->result, w, children_types); - write_forward_declarations(out, children_types, w); + write_forward_declarations(out, get_children_types(t, w), w); std::string class_name = w.gen_class_name(t->name); @@ -425,15 +441,7 @@ static void write_class(tl_outputer &out, const tl_type *t, const std::setarity); const std::string class_name = w.gen_class_name(t->name); - std::map children_types; - for (std::size_t i = 0; i < t->constructors_num; i++) { - if (w.is_combinator_supported(t->constructors[i])) { - for (std::size_t j = 0; j < t->constructors[i]->args.size(); j++) { - get_children_types(t->constructors[i]->args[j].type, w, children_types); - } - } - } - write_forward_declarations(out, children_types, w); + write_forward_declarations(out, get_children_types(t, w), w); std::vector empty_vars; bool optimize_one_constructor = (t->simple_constructors == 1);