aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdtl
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2023-06-26 17:10:04 +0300
committerlevlam <levlam@telegram.org>2023-06-26 17:10:04 +0300
commit014f880e41f6eec000881f6fdfdc462264d371df (patch)
treeb2eee5d9e31e8fc70e9314c6529411d0a28c5f46 /tdtl
parentf4b4893124f0b8f24fb4cdf764acbfa8d8ab1b61 (diff)
Simplify get_children_types usage.
Diffstat (limited to 'tdtl')
-rw-r--r--tdtl/td/tl/tl_generate.cpp38
1 files 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<std::string, bool> get_children_types(const tl_combinator *t, const TL_writer &w) {
+ std::map<std::string, bool> 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<std::string, bool> get_children_types(const tl_type *t, const TL_writer &w) {
+ std::map<std::string, bool> 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<std::string, bool> &children_types,
const TL_writer &w) {
for (std::map<std::string, bool>::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<std::string> &result_types, const TL_writer &w) {
assert(w.is_combinator_supported(t));
- std::map<std::string, bool> 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::set<std::
const std::string base_class = w.gen_base_type_class_name(t->arity);
const std::string class_name = w.gen_class_name(t->name);
- std::map<std::string, bool> 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<var_description> empty_vars;
bool optimize_one_constructor = (t->simple_constructors == 1);