Improve parameter names.

GitOrigin-RevId: 9eb8a512d2f908ef5cb725eed74b1d979ead9ef2
This commit is contained in:
levlam 2019-11-22 18:21:13 +03:00
parent 1823cad280
commit 003c93f0d6
14 changed files with 66 additions and 63 deletions

View File

@ -335,7 +335,7 @@ class TlWriterCCommon : public tl::TL_writer {
return "";
}
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override {
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override {
if (!is_default || is_header_ == -1 || class_name == "") {
return "";
}
@ -344,7 +344,7 @@ class TlWriterCCommon : public tl::TL_writer {
ss << "};\n";
}
ss << "struct Td" + gen_class_name(class_name) + " *TdCreateObject" + gen_class_name(class_name) + " (" +
(fields_num ? "" : "void");
(field_count ? "" : "void");
return ss.str();
}
std::string gen_constructor_parameter(int field_num, const std::string &class_name, const tl::arg &a,
@ -362,7 +362,7 @@ class TlWriterCCommon : public tl::TL_writer {
bool is_default) const override {
return "";
}
std::string gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const override {
std::string gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const override {
if (!is_default || is_header_ == -1) {
return "";
}
@ -1029,11 +1029,11 @@ class TlWriterCCommon : public tl::TL_writer {
}
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override {
return "";
}
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override {
return "";
}

View File

@ -506,7 +506,7 @@ std::string TD_TL_writer_cpp::gen_function_result_type(const tl::tl_tree *result
}
std::string TD_TL_writer_cpp::gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const {
for (std::size_t i = 0; i < vars.size(); i++) {
assert(vars[i].is_stored == false);
@ -521,7 +521,7 @@ std::string TD_TL_writer_cpp::gen_fetch_function_begin(const std::string &parser
" &p) {\n"
" return make_tl_object<" +
class_name + ">(";
if (field_num == 0) {
if (field_count == 0) {
result += ");\n";
} else {
result +=
@ -540,7 +540,7 @@ std::string TD_TL_writer_cpp::gen_fetch_function_begin(const std::string &parser
(parser_type == -1 ? "" : " " + fetched_type + "res = make_tl_object<" + class_name + ">();\n");
}
std::string TD_TL_writer_cpp::gen_fetch_function_end(bool has_parent, int field_num,
std::string TD_TL_writer_cpp::gen_fetch_function_end(bool has_parent, int field_count,
const std::vector<tl::var_description> &vars,
int parser_type) const {
for (std::size_t i = 0; i < vars.size(); i++) {
@ -548,7 +548,7 @@ std::string TD_TL_writer_cpp::gen_fetch_function_end(bool has_parent, int field_
}
if (parser_type == 0) {
if (field_num == 0) {
if (field_count == 0) {
return "}\n";
}
return "#undef FAIL\n"
@ -649,7 +649,7 @@ std::string TD_TL_writer_cpp::gen_fetch_switch_end() const {
" }\n";
}
std::string TD_TL_writer_cpp::gen_constructor_begin(int fields_num, const std::string &class_name,
std::string TD_TL_writer_cpp::gen_constructor_begin(int field_count, const std::string &class_name,
bool is_default) const {
return "\n" + class_name + "::" + class_name + "(";
}
@ -673,8 +673,8 @@ std::string TD_TL_writer_cpp::gen_constructor_field_init(int field_num, const st
(is_default ? "" : gen_field_name(a.name)) + move_end + ")\n";
}
std::string TD_TL_writer_cpp::gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const {
if (fields_num == 0) {
std::string TD_TL_writer_cpp::gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const {
if (field_count == 0) {
return ") {\n"
"}\n";
}

View File

@ -77,9 +77,9 @@ class TD_TL_writer_cpp : public TD_TL_writer {
std::string gen_function_result_type(const tl::tl_tree *result) const override;
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override;
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override;
std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,
@ -97,10 +97,10 @@ class TD_TL_writer_cpp : public TD_TL_writer {
std::string gen_fetch_switch_case(const tl::tl_combinator *t, int arity) const override;
std::string gen_fetch_switch_end() const override;
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const override;
};
} // namespace td

View File

@ -270,7 +270,7 @@ class TlWriterDotNet : public TL_writer {
return "";
}
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override {
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override {
std::stringstream ss;
ss << "\n";
ss << (is_header_ ? " " : gen_class_name(class_name) + "::") << gen_class_name(class_name) << "(";
@ -312,12 +312,12 @@ class TlWriterDotNet : public TL_writer {
return ss.str();
}
std::string gen_constructor_end(const tl_combinator *t, int fields_num, bool is_default) const override {
std::string gen_constructor_end(const tl_combinator *t, int field_count, bool is_default) const override {
if (is_header_) {
return ");\n";
}
std::stringstream ss;
if (fields_num == 0) {
if (field_count == 0) {
ss << ") {\n";
}
ss << "}\n";
@ -471,11 +471,11 @@ class TlWriterDotNet : public TL_writer {
}
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<var_description> &vars, int parser_type) const override {
return "";
}
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<var_description> &vars,
int parser_type) const override {
return "";
}

View File

@ -253,7 +253,7 @@ std::string TD_TL_writer_h::gen_function_result_type(const tl::tl_tree *result)
}
std::string TD_TL_writer_h::gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const {
std::string returned_type = "object_ptr<" + parent_class_name + "> ";
@ -262,9 +262,11 @@ std::string TD_TL_writer_h::gen_fetch_function_begin(const std::string &parser_n
"\n"
" static " +
returned_type + "fetch(" + parser_name + " &p);\n";
if (field_num != 0) {
result += "\n"
" explicit " + class_name + "(" + parser_name + " &p);\n";
if (field_count != 0) {
result +=
"\n"
" explicit " +
class_name + "(" + parser_name + " &p);\n";
}
return result;
}
@ -275,7 +277,7 @@ std::string TD_TL_writer_h::gen_fetch_function_begin(const std::string &parser_n
returned_type + "fetch(" + parser_name + " &p);\n";
}
std::string TD_TL_writer_h::gen_fetch_function_end(bool has_parent, int field_num,
std::string TD_TL_writer_h::gen_fetch_function_end(bool has_parent, int field_count,
const std::vector<tl::var_description> &vars,
int parser_type) const {
return "";
@ -331,11 +333,11 @@ std::string TD_TL_writer_h::gen_fetch_switch_end() const {
return "";
}
std::string TD_TL_writer_h::gen_constructor_begin(int fields_num, const std::string &class_name,
std::string TD_TL_writer_h::gen_constructor_begin(int field_count, const std::string &class_name,
bool is_default) const {
return "\n"
" " +
std::string(fields_num == 1 ? "explicit " : "") + class_name + "(";
std::string(field_count == 1 ? "explicit " : "") + class_name + "(";
}
std::string TD_TL_writer_h::gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
@ -343,7 +345,7 @@ std::string TD_TL_writer_h::gen_constructor_field_init(int field_num, const std:
return "";
}
std::string TD_TL_writer_h::gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const {
std::string TD_TL_writer_h::gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const {
return ");\n";
}

View File

@ -63,9 +63,9 @@ class TD_TL_writer_h : public TD_TL_writer {
std::string gen_function_result_type(const tl::tl_tree *result) const override;
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override;
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override;
std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,
@ -83,10 +83,10 @@ class TD_TL_writer_h : public TD_TL_writer {
std::string gen_fetch_switch_case(const tl::tl_combinator *t, int arity) const override;
std::string gen_fetch_switch_end() const override;
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const override;
};
} // namespace td

View File

@ -138,12 +138,12 @@ std::string TD_TL_writer_hpp::gen_function_result_type(const tl::tl_tree *result
}
std::string TD_TL_writer_hpp::gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_end(bool has_parent, int field_num,
std::string TD_TL_writer_hpp::gen_fetch_function_end(bool has_parent, int field_count,
const std::vector<tl::var_description> &vars,
int parser_type) const {
return "";
@ -247,7 +247,7 @@ std::string TD_TL_writer_hpp::gen_additional_proxy_function_end(const std::strin
"}\n\n";
}
std::string TD_TL_writer_hpp::gen_constructor_begin(int fields_num, const std::string &class_name,
std::string TD_TL_writer_hpp::gen_constructor_begin(int field_count, const std::string &class_name,
bool is_default) const {
return "";
}
@ -262,7 +262,7 @@ std::string TD_TL_writer_hpp::gen_constructor_field_init(int field_num, const st
return "";
}
std::string TD_TL_writer_hpp::gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const {
std::string TD_TL_writer_hpp::gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const {
return "";
}

View File

@ -64,9 +64,9 @@ class TD_TL_writer_hpp : public TD_TL_writer {
std::string gen_function_result_type(const tl::tl_tree *result) const override;
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override;
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override;
std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,
@ -84,12 +84,12 @@ class TD_TL_writer_hpp : public TD_TL_writer {
std::string gen_fetch_switch_case(const tl::tl_combinator *t, int arity) const override;
std::string gen_fetch_switch_end() const override;
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_parameter(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const override;
std::string gen_additional_function(const std::string &function_name, const tl::tl_combinator *t,
bool is_function) const override;

View File

@ -346,12 +346,13 @@ std::string TD_TL_writer_java::gen_function_result_type(const tl::tl_tree *resul
}
std::string TD_TL_writer_java::gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
std::vector<tl::var_description> &vars, int parser_type) const {
const std::string &parent_class_name, int arity,
int field_count, std::vector<tl::var_description> &vars,
int parser_type) const {
return "";
}
std::string TD_TL_writer_java::gen_fetch_function_end(bool has_parent, int field_num,
std::string TD_TL_writer_java::gen_fetch_function_end(bool has_parent, int field_count,
const std::vector<tl::var_description> &vars,
int parser_type) const {
return "";
@ -402,7 +403,7 @@ std::string TD_TL_writer_java::gen_fetch_switch_end() const {
return "";
}
std::string TD_TL_writer_java::gen_constructor_begin(int fields_num, const std::string &class_name,
std::string TD_TL_writer_java::gen_constructor_begin(int field_count, const std::string &class_name,
bool is_default) const {
return "\n"
" public " +
@ -442,8 +443,8 @@ std::string TD_TL_writer_java::gen_constructor_field_init(int field_num, const s
gen_field_name(a.name) + ";\n";
}
std::string TD_TL_writer_java::gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const {
if (fields_num == 0) {
std::string TD_TL_writer_java::gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const {
if (field_count == 0) {
return ") {\n"
" }\n";
}

View File

@ -88,9 +88,9 @@ class TD_TL_writer_java : public tl::TL_writer {
std::string gen_function_result_type(const tl::tl_tree *result) const override;
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override;
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override;
std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,
@ -108,12 +108,12 @@ class TD_TL_writer_java : public tl::TL_writer {
std::string gen_fetch_switch_case(const tl::tl_combinator *t, int arity) const override;
std::string gen_fetch_switch_end() const override;
std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const override;
std::string gen_constructor_parameter(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const override;
std::string gen_constructor_end(const tl::tl_combinator *t, int field_count, bool is_default) const override;
};
} // namespace td

View File

@ -380,7 +380,7 @@ std::string TD_TL_writer_jni_cpp::gen_get_id(const std::string &class_name, std:
std::string TD_TL_writer_jni_cpp::gen_fetch_function_begin(const std::string &parser_name,
const std::string &class_name,
const std::string &parent_class_name, int arity,
int field_num, std::vector<tl::var_description> &vars,
int field_count, std::vector<tl::var_description> &vars,
int parser_type) const {
for (std::size_t i = 0; i < vars.size(); i++) {
assert(vars[i].is_stored == false);
@ -399,7 +399,7 @@ std::string TD_TL_writer_jni_cpp::gen_fetch_function_begin(const std::string &pa
fetched_type + "res = make_object<" + class_name + ">();\n");
}
std::string TD_TL_writer_jni_cpp::gen_fetch_function_end(bool has_parent, int field_num,
std::string TD_TL_writer_jni_cpp::gen_fetch_function_end(bool has_parent, int field_count,
const std::vector<tl::var_description> &vars,
int parser_type) const {
for (std::size_t i = 0; i < vars.size(); i++) {

View File

@ -74,9 +74,9 @@ class TD_TL_writer_jni_cpp : public TD_TL_writer_cpp {
std::string gen_get_id(const std::string &class_name, std::int32_t id, bool is_proxy) const override;
std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<tl::var_description> &vars, int parser_type) const override;
std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<tl::var_description> &vars,
std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<tl::var_description> &vars,
int parser_type) const override;
std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,

View File

@ -53,12 +53,12 @@ static bool is_reachable_for_storer(int storer_type, const std::string &name,
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());
int fields_num = 0;
int field_count = 0;
for (std::size_t i = 0; i < t->args.size(); i++) {
fields_num += !w.gen_constructor_parameter(fields_num, class_name, t->args[i], is_default).empty();
field_count += !w.gen_constructor_parameter(field_count, class_name, t->args[i], is_default).empty();
}
out.append(w.gen_constructor_begin(fields_num, class_name, is_default));
out.append(w.gen_constructor_begin(field_count, class_name, is_default));
int field_num = 0;
for (std::size_t i = 0; i < t->args.size(); i++) {
std::string parameter_init = w.gen_constructor_parameter(field_num, class_name, t->args[i], is_default);
@ -67,7 +67,7 @@ static void write_class_constructor(tl_outputer &out, const tl_combinator *t, co
field_num++;
}
}
assert(field_num == fields_num);
assert(field_num == field_count);
field_num = 0;
for (std::size_t i = 0; i < t->args.size(); i++) {

View File

@ -120,9 +120,9 @@ class TL_writer {
virtual std::string gen_function_result_type(const tl_tree *result) const = 0;
virtual std::string gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity, int field_num,
const std::string &parent_class_name, int arity, int field_count,
std::vector<var_description> &vars, int parser_type) const = 0;
virtual std::string gen_fetch_function_end(bool has_parent, int field_num, const std::vector<var_description> &vars,
virtual std::string gen_fetch_function_end(bool has_parent, int field_count, const std::vector<var_description> &vars,
int parser_type) const = 0;
virtual std::string gen_fetch_function_result_begin(const std::string &parser_name, const std::string &class_name,
@ -140,12 +140,12 @@ class TL_writer {
virtual std::string gen_fetch_switch_case(const tl_combinator *t, int arity) const = 0;
virtual std::string gen_fetch_switch_end() const = 0;
virtual std::string gen_constructor_begin(int fields_num, const std::string &class_name, bool is_default) const = 0;
virtual std::string gen_constructor_begin(int field_count, const std::string &class_name, bool is_default) const = 0;
virtual std::string gen_constructor_parameter(int field_num, const std::string &class_name, const arg &a,
bool is_default) const = 0;
virtual std::string gen_constructor_field_init(int field_num, const std::string &class_name, const arg &a,
bool is_default) const = 0;
virtual std::string gen_constructor_end(const tl_combinator *t, int fields_num, bool is_default) const = 0;
virtual std::string gen_constructor_end(const tl_combinator *t, int field_count, bool is_default) const = 0;
virtual std::string gen_additional_function(const std::string &function_name, const tl_combinator *t,
bool is_function) const;