From 8898bfa6557d843604bb493688b6036d2fd5b543 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Mar 2020 21:14:47 +0300 Subject: [PATCH] Add typedefs for other integer and string types in generated C++ code. GitOrigin-RevId: d6494c0aaaf10719c9bbb24ba4d259d7cde25060 --- .../DoxygenTlDocumentationGenerator.php | 35 +++++++++++++++---- td/generate/tl_writer_cpp.cpp | 2 +- td/generate/tl_writer_h.cpp | 8 ++++- td/generate/tl_writer_jni_cpp.cpp | 10 +++--- td/generate/tl_writer_jni_h.cpp | 8 ++++- td/generate/tl_writer_td.cpp | 16 ++++----- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/td/generate/DoxygenTlDocumentationGenerator.php b/td/generate/DoxygenTlDocumentationGenerator.php index 0a87e363..641c1a12 100644 --- a/td/generate/DoxygenTlDocumentationGenerator.php +++ b/td/generate/DoxygenTlDocumentationGenerator.php @@ -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;', <<addDocumentation('using int53 = std::int64_t;', <<addDocumentation('using int64 = std::int64_t;', <<addDocumentation('using string = std::string;', <<addDocumentation('using bytes = std::string;', <<"; + return "TlFetchString"; } if (name == "Bytes") { return "TlFetchBytes"; diff --git a/td/generate/tl_writer_h.cpp b/td/generate/tl_writer_h.cpp index 1716a2c1..2404d7f6 100644 --- a/td/generate/tl_writer_h.cpp +++ b/td/generate/tl_writer_h.cpp @@ -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 + diff --git a/td/generate/tl_writer_jni_cpp.cpp b/td/generate/tl_writer_jni_cpp.cpp index c08efd2e..4fe2300a 100644 --- a/td/generate/tl_writer_jni_cpp.cpp +++ b/td/generate/tl_writer_jni_cpp.cpp @@ -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(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, " + diff --git a/td/generate/tl_writer_jni_h.cpp b/td/generate/tl_writer_jni_h.cpp index d8722b96..d050edae 100644 --- a/td/generate/tl_writer_jni_h.cpp +++ b/td/generate/tl_writer_jni_h.cpp @@ -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 + diff --git a/td/generate/tl_writer_td.cpp b/td/generate/tl_writer_td.cpp index 6b5949a1..1a9cdb43 100644 --- a/td/generate/tl_writer_td.cpp +++ b/td/generate/tl_writer_td.cpp @@ -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 ") {