Use separate type bytes in generated C++ code.

GitOrigin-RevId: 185d08246caf0dd6050b1c9409a4078746d9091e
This commit is contained in:
levlam 2020-03-24 20:02:03 +03:00
parent 302485d673
commit 6943db4d52
6 changed files with 27 additions and 9 deletions

View File

@ -17,8 +17,9 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
case 'double':
return 'double ';
case 'string':
case 'bytes':
return 'std::string const &';
case 'bytes':
return 'bytes const &';
default:
if (substr($type, 0, 6) === 'vector') {
@ -74,8 +75,9 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
case 'double':
return 'double';
case 'string':
case 'bytes':
return 'std::string';
case 'bytes':
return 'bytes';
case 'bool':
case 'int':
case 'long':
@ -163,6 +165,13 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
* Contains declarations of all functions and types which represent a public TDLib interface.
*/
EOT
);
$this->addDocumentation('using bytes = std::string;', <<<EOT
/**
* This class is used to store arbitrary sequence of bytes.
*/
EOT
);
$this->addDocumentation('using BaseObject', <<<EOT

View File

@ -150,7 +150,7 @@ std::string TD_TL_writer_cpp::gen_fetch_class_name(const tl::tl_tree_type *tree_
return "TlFetchString<" + string_type + ">";
}
if (name == "Bytes") {
return "TlFetchBytes<" + bytes_type + ">";
return "TlFetchBytes<bytes>";
}
if (name == "Vector") {
@ -662,7 +662,7 @@ std::string TD_TL_writer_cpp::gen_constructor_field_init(int field_num, const st
}
std::string move_begin;
std::string move_end;
if ((field_type == bytes_type || field_type.compare(0, 11, "std::vector") == 0 ||
if ((field_type == "bytes" || field_type.compare(0, 11, "std::vector") == 0 ||
field_type.compare(0, 10, "object_ptr") == 0) &&
!is_default) {
move_begin = "std::move(";

View File

@ -56,6 +56,10 @@ std::string TD_TL_writer_h::gen_output_begin() const {
ext_forward_declaration + "namespace " + tl_name +
" {\n\n"
"using bytes = " +
bytes_type +
";\n\n"
"using BaseObject = ::td::TlObject;\n\n"
"template <class Type>\n"

View File

@ -107,7 +107,7 @@ std::string TD_TL_writer_jni_cpp::gen_vector_fetch(std::string field_name, const
template_type = gen_main_class_name(child->type);
}
template_type = "std::vector<" + template_type + ">";
} else if (vector_type == bytes_type) {
} else if (vector_type == "bytes") {
std::fprintf(stderr, "Vector of Bytes is not supported\n");
assert(false);
} else {
@ -262,7 +262,7 @@ std::string TD_TL_writer_jni_cpp::gen_vector_store(const std::string &field_name
"env->DeleteLocalRef(arr_tmp_); "
"} }";
}
if (vector_type == bytes_type) {
if (vector_type == "bytes") {
std::fprintf(stderr, "Vector of Bytes is not supported\n");
assert(false);
}

View File

@ -79,6 +79,10 @@ std::string TD_TL_writer_jni_h::gen_output_begin() const {
tl_name +
" {\n\n"
"using bytes = " +
bytes_type +
";\n\n"
"class " +
gen_base_tl_class_name() +
";\n"

View File

@ -188,7 +188,7 @@ std::string TD_TL_writer::gen_type_name(const tl::tl_tree_type *tree_type) const
return "UInt256";
}
if (name == "Bytes") {
return bytes_type;
return "bytes";
}
if (name == "Vector") {
@ -242,9 +242,10 @@ std::string TD_TL_writer::gen_constructor_parameter(int field_num, const std::st
if (field_type == "bool " || field_type == "std::int32_t " || field_type == "std::int64_t " ||
field_type == "double ") {
res += field_type;
} else if (field_type == "UInt128 " || field_type == "UInt256 " || field_type == string_type + " ") {
} else if (field_type == "UInt128 " || field_type == "UInt256 " || field_type == string_type + " " ||
(string_type == bytes_type && field_type == "bytes ")) {
res += field_type + "const &";
} else if (field_type.compare(0, 11, "std::vector") == 0 || field_type == bytes_type + " ") {
} else if (field_type.compare(0, 11, "std::vector") == 0 || field_type == "bytes ") {
res += field_type + "&&";
} else if (field_type.compare(0, 10, "object_ptr") == 0) {
res += field_type + "&&";