From 8398a6f19d2e10ffe21b1ae7e602303921b6a615 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 31 Jul 2021 09:21:12 +0300 Subject: [PATCH] Remove more default constructors of telegram_api classes. --- td/generate/tl_writer_td.cpp | 5 +++-- td/generate/tl_writer_td.h | 3 ++- tdtl/td/tl/tl_generate.cpp | 34 ++++++++++++++++++++++++++++++---- tdtl/td/tl/tl_writer.cpp | 2 +- tdtl/td/tl/tl_writer.h | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/td/generate/tl_writer_td.cpp b/td/generate/tl_writer_td.cpp index f56622ddf..30c232541 100644 --- a/td/generate/tl_writer_td.cpp +++ b/td/generate/tl_writer_td.cpp @@ -49,8 +49,9 @@ bool TD_TL_writer::is_combinator_supported(const tl::tl_combinator *constructor) return true; } -bool TD_TL_writer::is_default_constructor_generated(const tl::tl_combinator *t, bool is_function) const { - return tl_name == "td_api" || tl_name == "TdApi" || (t->var_count > 0 && !is_function); +bool TD_TL_writer::is_default_constructor_generated(const tl::tl_combinator *t, bool can_be_parsed, + bool can_be_stored) const { + return tl_name == "td_api" || tl_name == "TdApi" || (t->var_count > 0 && can_be_parsed); } int TD_TL_writer::get_storer_type(const tl::tl_combinator *t, const std::string &storer_name) const { diff --git a/td/generate/tl_writer_td.h b/td/generate/tl_writer_td.h index cef02ca0d..b958df605 100644 --- a/td/generate/tl_writer_td.h +++ b/td/generate/tl_writer_td.h @@ -35,7 +35,8 @@ class TD_TL_writer : public tl::TL_writer { bool is_built_in_complex_type(const std::string &name) const override; bool is_type_bare(const tl::tl_type *t) const override; bool is_combinator_supported(const tl::tl_combinator *constructor) const override; - bool is_default_constructor_generated(const tl::tl_combinator *t, bool is_function) const override; + bool is_default_constructor_generated(const tl::tl_combinator *t, bool can_be_parsed, + bool can_be_stored) const override; int get_storer_type(const tl::tl_combinator *t, const std::string &storer_name) const override; Mode get_parser_mode(int type) const override; diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp index 84478aae3..95e87947e 100644 --- a/tdtl/td/tl/tl_generate.cpp +++ b/tdtl/td/tl/tl_generate.cpp @@ -253,7 +253,7 @@ static void write_function(tl_outputer &out, const tl_combinator *t, const std:: std::vector vars(t->var_count); out.append(w.gen_function_vars(t, vars)); - if (w.is_default_constructor_generated(t, true)) { + if (w.is_default_constructor_generated(t, false, true)) { write_class_constructor(out, t, class_name, true, w); } if (required_args) { @@ -306,7 +306,35 @@ static void write_constructor(tl_outputer &out, const tl_combinator *t, const st int required_args = gen_field_definitions(out, t, class_name, w); out.append(w.gen_flags_definitions(t)); - if (w.is_default_constructor_generated(t, false)) { + bool can_be_parsed = false; + bool is_can_be_parsed_inited = false; + std::vector parsers = w.get_parsers(); + for (std::size_t i = 0; i < parsers.size(); i++) { + int parser_type = w.get_parser_type(t, parsers[i]); + if (w.get_parser_mode(parser_type) != TL_writer::All) { + can_be_parsed |= is_reachable_for_parser(parser_type, t->name, request_types, result_types, w); + is_can_be_parsed_inited = true; + } + } + if (!is_can_be_parsed_inited) { + can_be_parsed = true; + } + + bool can_be_stored = false; + bool is_can_be_stored_inited = false; + std::vector storers = w.get_storers(); + for (std::size_t i = 0; i < storers.size(); i++) { + int storer_type = w.get_storer_type(t, storers[i]); + if (w.get_storer_mode(storer_type) != TL_writer::All) { + can_be_stored |= is_reachable_for_storer(storer_type, t->name, request_types, result_types, w); + is_can_be_stored_inited = true; + } + } + if (!is_can_be_stored_inited) { + can_be_stored = true; + } + + if (w.is_default_constructor_generated(t, can_be_parsed, can_be_stored)) { write_class_constructor(out, t, class_name, true, w); } if (required_args) { @@ -319,7 +347,6 @@ static void write_constructor(tl_outputer &out, const tl_combinator *t, const st assert(t->result->get_type() == NODE_TYPE_TYPE); const tl_tree_type *result_type = static_cast(t->result); - std::vector parsers = w.get_parsers(); for (std::size_t i = 0; i < parsers.size(); i++) { write_constructor_fetch(out, parsers[i], t, class_name, parent_class, result_type, required_args == 1 && result_type->type->simple_constructors == 1, request_types, @@ -327,7 +354,6 @@ static void write_constructor(tl_outputer &out, const tl_combinator *t, const st } // STORER - std::vector storers = w.get_storers(); for (std::size_t i = 0; i < storers.size(); i++) { write_constructor_store(out, storers[i], t, class_name, result_type, required_args == 1 && result_type->type->simple_constructors == 1, request_types, diff --git a/tdtl/td/tl/tl_writer.cpp b/tdtl/td/tl/tl_writer.cpp index f965a4b04..965dfdef1 100644 --- a/tdtl/td/tl/tl_writer.cpp +++ b/tdtl/td/tl/tl_writer.cpp @@ -135,7 +135,7 @@ bool TL_writer::is_documentation_generated() const { return false; } -bool TL_writer::is_default_constructor_generated(const tl_combinator *t, bool is_function) const { +bool TL_writer::is_default_constructor_generated(const tl_combinator *t, bool can_be_parsed, bool can_be_stored) const { return true; } diff --git a/tdtl/td/tl/tl_writer.h b/tdtl/td/tl/tl_writer.h index f8e6e71ba..b2ccf55af 100644 --- a/tdtl/td/tl/tl_writer.h +++ b/tdtl/td/tl/tl_writer.h @@ -56,7 +56,7 @@ class TL_writer { virtual bool is_type_bare(const tl_type *t) const = 0; virtual bool is_combinator_supported(const tl_combinator *constructor) const; virtual bool is_documentation_generated() const; - virtual bool is_default_constructor_generated(const tl_combinator *t, bool is_function) const; + virtual bool is_default_constructor_generated(const tl_combinator *t, bool can_be_parsed, bool can_be_stored) const; virtual int get_parser_type(const tl_combinator *t, const std::string &parser_name) const; virtual int get_storer_type(const tl_combinator *t, const std::string &storer_name) const;