From 0c4433621e82c8c1692e0d469e2bf6353c06e130 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Nov 2019 18:42:22 +0300 Subject: [PATCH] Do not generate empty fetch functions and empty constructors. GitOrigin-RevId: 65f0f7e37f5af8d6e256b6c7b7c07241354b7b45 --- td/generate/tl_writer_cpp.cpp | 30 +++++++++++++++++++----------- td/generate/tl_writer_h.cpp | 13 +++++++++---- td/generate/tl_writer_td.cpp | 2 +- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/td/generate/tl_writer_cpp.cpp b/td/generate/tl_writer_cpp.cpp index 738f13b9..b2b5c5f5 100644 --- a/td/generate/tl_writer_cpp.cpp +++ b/td/generate/tl_writer_cpp.cpp @@ -517,15 +517,21 @@ std::string TD_TL_writer_cpp::gen_fetch_function_begin(const std::string &parser assert(arity == 0); if (parser_type == 0) { - return "\n" + returned_type + class_name + "::fetch(" + parser_name + - " &p) {\n" - " return make_tl_object<" + - class_name + - ">(p);\n" - "}\n\n" + - class_name + "::" + class_name + "(" + parser_name + - " &p)\n" - "#define FAIL(error) p.set_error(error)\n"; + std::string result = "\n" + returned_type + class_name + "::fetch(" + parser_name + + " &p) {\n" + " return make_tl_object<" + + class_name + ">("; + if (field_num == 0) { + result += ");\n"; + } else { + result += + "p);\n" + "}\n\n" + + class_name + "::" + class_name + "(" + parser_name + + " &p)\n" + "#define FAIL(error) p.set_error(error)\n"; + } + return result; } return "\n" + returned_type + class_name + "::fetch(" + parser_name + @@ -542,9 +548,11 @@ std::string TD_TL_writer_cpp::gen_fetch_function_end(bool has_parent, int field_ } if (parser_type == 0) { + if (field_num == 0) { + return "}\n"; + } return "#undef FAIL\n" - "{" + - (field_num == 0 ? "\n (void)p;\n" : std::string()) + "}\n"; + "{}\n"; } if (parser_type == -1) { diff --git a/td/generate/tl_writer_h.cpp b/td/generate/tl_writer_h.cpp index 1bae4887..5b07b350 100644 --- a/td/generate/tl_writer_h.cpp +++ b/td/generate/tl_writer_h.cpp @@ -258,10 +258,15 @@ std::string TD_TL_writer_h::gen_fetch_function_begin(const std::string &parser_n std::string returned_type = "object_ptr<" + parent_class_name + "> "; if (parser_type == 0) { - return "\n" - " static " + - returned_type + "fetch(" + parser_name + " &p);\n\n" + " explicit " + class_name + "(" + parser_name + - " &p);\n"; + std::string result = + "\n" + " static " + + returned_type + "fetch(" + parser_name + " &p);\n"; + if (field_num != 0) { + result += "\n" + " explicit " + class_name + "(" + parser_name + " &p);\n"; + } + return result; } assert(arity == 0); diff --git a/td/generate/tl_writer_td.cpp b/td/generate/tl_writer_td.cpp index 93f16749..4877fc2b 100644 --- a/td/generate/tl_writer_td.cpp +++ b/td/generate/tl_writer_td.cpp @@ -50,7 +50,7 @@ bool TD_TL_writer::is_combinator_supported(const tl::tl_combinator *constructor) } bool TD_TL_writer::is_default_constructor_generated(const tl::tl_combinator *t) const { - return tl_name == "td_api" || t->var_count > 0 || t->args.empty(); + return tl_name == "td_api" || t->var_count > 0; } int TD_TL_writer::get_storer_type(const tl::tl_combinator *t, const std::string &storer_name) const {