Do not generate empty fetch functions and empty constructors.

GitOrigin-RevId: 65f0f7e37f5af8d6e256b6c7b7c07241354b7b45
This commit is contained in:
levlam 2019-11-21 18:42:22 +03:00
parent 6d53f3a85a
commit 0c4433621e
3 changed files with 29 additions and 16 deletions

View File

@ -517,16 +517,22 @@ 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 +
std::string result = "\n" + returned_type + class_name + "::fetch(" + parser_name +
" &p) {\n"
" return make_tl_object<" +
class_name +
">(p);\n"
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 +
" &p) {\n"
@ -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) {

View File

@ -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"
std::string result =
"\n"
" static " +
returned_type + "fetch(" + parser_name + " &p);\n\n" + " explicit " + class_name + "(" + parser_name +
" &p);\n";
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);

View File

@ -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 {