aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdtl
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2023-06-26 15:56:15 +0300
committerlevlam <levlam@telegram.org>2023-06-26 15:56:15 +0300
commit6e543d3cddf348bfb58520ab5a58a99aa2ffb2b8 (patch)
tree3efd8eb9c44b95de2fb71d45202e6519183a44c2 /tdtl
parent8f9a4dcaa01a063ca274c881d6388ad4f554f383 (diff)
Add get_children_types helper.
Diffstat (limited to 'tdtl')
-rw-r--r--tdtl/td/tl/tl_generate.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp
index 5222dd318..7a61d32f8 100644
--- a/tdtl/td/tl/tl_generate.cpp
+++ b/tdtl/td/tl/tl_generate.cpp
@@ -50,14 +50,13 @@ static bool is_reachable_for_storer(int storer_type, const std::string &name,
return true;
}
-static void write_forward_declaration(tl_outputer &out, const tl_tree *tree, const TL_writer &w,
- std::set<std::string> &existing_forward_declarations) {
+static void get_children_types(const tl_tree *tree, const TL_writer &w, std::map<std::string, bool> &children_types) {
if (tree->get_type() != NODE_TYPE_TYPE) {
return;
}
const tl_tree_type *tree_type = static_cast<const tl_tree_type *>(tree);
for (std::size_t i = 0; i < tree_type->children.size(); i++) {
- write_forward_declaration(out, tree_type->children[i], w, existing_forward_declarations);
+ get_children_types(tree_type->children[i], w, children_types);
}
const tl_type *t = tree_type->type;
@@ -69,20 +68,23 @@ static void write_forward_declaration(tl_outputer &out, const tl_tree *tree, con
assert(t->flags == 0);
if (t->simple_constructors != 1) {
- if (existing_forward_declarations.insert(w.gen_class_name(t->name)).second) {
- out.append(w.gen_forward_class_declaration(w.gen_class_name(t->name), true));
- }
+ children_types.emplace(t->name, true);
} else {
for (std::size_t i = 0; i < t->constructors_num; i++) {
if (w.is_combinator_supported(t->constructors[i])) {
- if (existing_forward_declarations.insert(w.gen_class_name(t->constructors[i]->name)).second) {
- out.append(w.gen_forward_class_declaration(w.gen_class_name(t->constructors[i]->name), false));
- }
+ children_types.emplace(t->constructors[i]->name, false);
}
}
}
}
+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) {
+ out.append(w.gen_forward_class_declaration(w.gen_class_name(it->first), it->second));
+ }
+}
+
static void write_class_constructor(tl_outputer &out, const tl_combinator *t, const std::string &class_name,
bool is_default, const TL_writer &w) {
// std::fprintf(stderr, "Gen constructor %s\n", class_name.c_str());
@@ -276,11 +278,12 @@ 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::set<std::string> existing_forward_declarations;
+ std::map<std::string, bool> children_types;
for (std::size_t i = 0; i < t->args.size(); i++) {
- write_forward_declaration(out, t->args[i].type, w, existing_forward_declarations);
+ get_children_types(t->args[i].type, w, children_types);
}
- write_forward_declaration(out, t->result, w, existing_forward_declarations);
+ get_children_types(t->result, w, children_types);
+ write_forward_declarations(out, children_types, w);
std::string class_name = w.gen_class_name(t->name);
@@ -422,14 +425,15 @@ 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::set<std::string> existing_forward_declarations;
+ 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++) {
- write_forward_declaration(out, t->constructors[i]->args[j].type, w, existing_forward_declarations);
+ get_children_types(t->constructors[i]->args[j].type, w, children_types);
}
}
}
+ write_forward_declarations(out, children_types, w);
std::vector<var_description> empty_vars;
bool optimize_one_constructor = (t->simple_constructors == 1);