Add typedefs for other integer and string types in generated C++ code.

GitOrigin-RevId: d6494c0aaaf10719c9bbb24ba4d259d7cde25060
This commit is contained in:
levlam 2020-03-24 21:14:47 +03:00
parent 24a4104ac2
commit 8898bfa655
6 changed files with 56 additions and 23 deletions

View File

@ -10,15 +10,15 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
case 'Bool':
return 'bool ';
case 'int32':
return 'std::int32_t ';
return 'int32 ';
case 'int53':
return 'int53 ';
case 'int64':
return 'std::int64_t ';
return 'int64 ';
case 'double':
return 'double ';
case 'string':
return 'std::string const &';
return 'string const &';
case 'bytes':
return 'bytes const &';
@ -69,15 +69,15 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
case 'Bool':
return 'bool';
case 'int32':
return 'std::int32_t';
return 'int32';
case 'int53':
return 'int53';
case 'int64':
return 'std::int64_t';
return 'int64';
case 'double':
return 'double';
case 'string':
return 'std::string';
return 'string';
case 'bytes':
return 'bytes';
case 'bool':
@ -167,6 +167,13 @@ class DoxygenTlDocumentationGenerator extends TlDocumentationGenerator
* Contains declarations of all functions and types which represent a public TDLib interface.
*/
EOT
);
$this->addDocumentation('using int32 = std::int32_t;', <<<EOT
/**
* This type is used to store 32-bit signed integers, which can be represented as Number in JSON.
*/
EOT
);
$this->addDocumentation('using int53 = std::int64_t;', <<<EOT
@ -174,11 +181,25 @@ EOT
* This type is used to store 53-bit signed integers, which can be represented as Number in JSON.
*/
EOT
);
$this->addDocumentation('using int64 = std::int64_t;', <<<EOT
/**
* This type is used to store 64-bit signed integers, which can't be represented as Number in JSON and are represented as String instead.
*/
EOT
);
$this->addDocumentation('using string = std::string;', <<<EOT
/**
* This type is used to store UTF-8 strings.
*/
EOT
);
$this->addDocumentation('using bytes = std::string;', <<<EOT
/**
* This type is used to store arbitrary sequence of bytes.
* This type is used to store arbitrary sequences of bytes. In JSON interface the bytes are base64-encoded.
*/
EOT
);

View File

@ -147,7 +147,7 @@ std::string TD_TL_writer_cpp::gen_fetch_class_name(const tl::tl_tree_type *tree_
return "TlFetch" + name;
}
if (name == "String") {
return "TlFetchString<" + string_type + ">";
return "TlFetchString<string>";
}
if (name == "Bytes") {
return "TlFetchBytes<bytes>";

View File

@ -56,7 +56,13 @@ std::string TD_TL_writer_h::gen_output_begin() const {
ext_forward_declaration + "namespace " + tl_name +
" {\n\n"
"using int53 = std::int64_t;\n\n"
"using int32 = std::int32_t;\n"
"using int53 = std::int64_t;\n"
"using int64 = std::int64_t;\n\n"
"using string = " +
string_type +
";\n\n"
"using bytes = " +
bytes_type +

View File

@ -83,10 +83,10 @@ std::string TD_TL_writer_jni_cpp::gen_vector_fetch(std::string field_name, const
std::string fetch_object = "jni::fetch_object(env, p, " + field_name + "fieldID)";
std::string array_type;
if (vector_type == "std::int32_t") {
if (vector_type == "int32") {
array_type = "jintArray";
}
if (vector_type == "int53" || vector_type == "std::int64_t") {
if (vector_type == "int53" || vector_type == "int64") {
array_type = "jlongArray";
}
if (vector_type == "double") {
@ -98,7 +98,7 @@ std::string TD_TL_writer_jni_cpp::gen_vector_fetch(std::string field_name, const
}
std::string template_type;
if (vector_type == string_type) {
if (vector_type == "string") {
template_type = "std::string";
} else if (vector_type.compare(0, 11, "std::vector") == 0) {
const tl::tl_tree_type *child = static_cast<const tl::tl_tree_type *>(t->children[0]);
@ -248,8 +248,8 @@ std::string TD_TL_writer_jni_cpp::gen_vector_store(const std::string &field_name
if (vector_type == "bool") {
assert(false); // TODO
}
if (vector_type == "std::int32_t" || vector_type == "int53" || vector_type == "std::int64_t" ||
vector_type == "double" || vector_type == string_type || vector_type.compare(0, 11, "std::vector") == 0 ||
if (vector_type == "int32" || vector_type == "int53" || vector_type == "int64" || vector_type == "double" ||
vector_type == "string" || vector_type.compare(0, 11, "std::vector") == 0 ||
vector_type.compare(0, 10, "object_ptr") == 0) {
return "{ "
"auto arr_tmp_ = jni::store_vector(env, " +

View File

@ -79,7 +79,13 @@ std::string TD_TL_writer_jni_h::gen_output_begin() const {
tl_name +
" {\n\n"
"using int53 = std::int64_t;\n\n"
"using int32 = std::int32_t;\n"
"using int53 = std::int64_t;\n"
"using int64 = std::int64_t;\n\n"
"using string = " +
string_type +
";\n\n"
"using bytes = " +
bytes_type +

View File

@ -121,7 +121,7 @@ std::string TD_TL_writer::gen_class_name(std::string name) const {
assert(false);
}
if (name == "#") {
return "std::int32_t";
return "int32";
}
for (std::size_t i = 0; i < name.size(); i++) {
if (!is_alnum(name[i])) {
@ -161,7 +161,7 @@ std::string TD_TL_writer::gen_type_name(const tl::tl_tree_type *tree_type) const
const std::string &name = t->name;
if (name == "#") {
return "std::int32_t";
return "int32";
}
if (name == "True") {
return "bool";
@ -170,19 +170,19 @@ std::string TD_TL_writer::gen_type_name(const tl::tl_tree_type *tree_type) const
return "bool";
}
if (name == "Int" || name == "Int32") {
return "std::int32_t";
return "int32";
}
if (name == "Int53") {
return "int53";
}
if (name == "Long" || name == "Int64") {
return "std::int64_t";
return "int64";
}
if (name == "Double") {
return "double";
}
if (name == "String") {
return string_type;
return "string";
}
if (name == "Int128") {
return "UInt128";
@ -242,10 +242,10 @@ std::string TD_TL_writer::gen_constructor_parameter(int field_num, const std::st
}
std::string res = (field_num == 0 ? "" : ", ");
if (field_type == "bool " || field_type == "std::int32_t " || field_type == "int53 " ||
field_type == "std::int64_t " || field_type == "double ") {
if (field_type == "bool " || field_type == "int32 " || field_type == "int53 " || field_type == "int64 " ||
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 " ||
(string_type == bytes_type && field_type == "bytes ")) {
res += field_type + "const &";
} else if (field_type.compare(0, 11, "std::vector") == 0 || field_type == "bytes ") {