diff options
| -rw-r--r-- | SplitSource.php | 4 | ||||
| -rw-r--r-- | td/generate/CMakeLists.txt | 22 | ||||
| -rw-r--r-- | td/generate/generate_common.cpp | 19 | ||||
| -rw-r--r-- | tdtl/td/tl/tl_generate.cpp | 79 | ||||
| -rw-r--r-- | tdtl/td/tl/tl_generate.h | 3 |
5 files changed, 115 insertions, 12 deletions
diff --git a/SplitSource.php b/SplitSource.php index 627af478b..75b53aa9a 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -513,9 +513,7 @@ $files = array('td/telegram/ChatManager' => 10, 'td/telegram/StoryManager' => 10, 'td/telegram/UpdatesManager' => 10, 'td/telegram/UserManager' => 10, - 'td/generate/auto/td/telegram/td_api' => 10, - 'td/generate/auto/td/telegram/td_api_json' => 10, - 'td/generate/auto/td/telegram/telegram_api' => 10); + 'td/generate/auto/td/telegram/td_api_json' => 10); foreach ($files as $file => $chunks) { split_file($file, $chunks, $undo); diff --git a/td/generate/CMakeLists.txt b/td/generate/CMakeLists.txt index 1277a16ef..b117da0be 100644 --- a/td/generate/CMakeLists.txt +++ b/td/generate/CMakeLists.txt @@ -22,7 +22,16 @@ set(TL_MTPROTO_AUTO_SOURCE ) set(TL_TD_AUTO_SOURCE - ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_0.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_1.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_2.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_3.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_4.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_5.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_6.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_7.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_8.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api_9.cpp ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api.h ${TD_AUTO_INCLUDE_DIR}/telegram/telegram_api.hpp ${TD_AUTO_INCLUDE_DIR}/telegram/secret_api.cpp @@ -39,7 +48,16 @@ set(TL_E2E_AUTO_SOURCE ) set(TL_TD_API_AUTO_SOURCE - ${TD_AUTO_INCLUDE_DIR}/telegram/td_api.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_0.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_1.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_2.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_3.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_4.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_5.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_6.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_7.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_8.cpp + ${TD_AUTO_INCLUDE_DIR}/telegram/td_api_9.cpp ${TD_AUTO_INCLUDE_DIR}/telegram/td_api.h ${TD_AUTO_INCLUDE_DIR}/telegram/td_api.hpp PARENT_SCOPE diff --git a/td/generate/generate_common.cpp b/td/generate/generate_common.cpp index 0865e790b..79445eeab 100644 --- a/td/generate/generate_common.cpp +++ b/td/generate/generate_common.cpp @@ -16,14 +16,19 @@ #include <string> #include <vector> -template <bool generate_multiple_headers = false, class WriterCpp = td::TD_TL_writer_cpp, +template <int multiple_source_count = 0, bool generate_multiple_headers = false, class WriterCpp = td::TD_TL_writer_cpp, class WriterH = td::TD_TL_writer_h, class WriterHpp = td::TD_TL_writer_hpp> static void generate_cpp(const std::string &directory, const std::string &tl_name, const std::string &string_type, const std::string &bytes_type, const std::vector<std::string> &ext_cpp_includes, const std::vector<std::string> &ext_h_includes) { std::string path = directory + "/" + tl_name; td::tl::tl_config config = td::tl::read_tl_config_from_file("tlo/" + tl_name + ".tlo"); - td::tl::write_tl_to_file(config, path + ".cpp", WriterCpp(tl_name, string_type, bytes_type, ext_cpp_includes)); + if (multiple_source_count > 0) { + td::tl::write_tl_to_fixed_file_count(config, path, ".cpp", multiple_source_count, + WriterCpp(tl_name, string_type, bytes_type, ext_cpp_includes)); + } else { + td::tl::write_tl_to_file(config, path + ".cpp", WriterCpp(tl_name, string_type, bytes_type, ext_cpp_includes)); + } if (generate_multiple_headers) { td::tl::write_tl_to_multiple_files(config, path, ".h", WriterH(tl_name, string_type, bytes_type, ext_h_includes)); } else { @@ -33,9 +38,9 @@ static void generate_cpp(const std::string &directory, const std::string &tl_nam } int main() { - generate_cpp<>("td/telegram", "telegram_api", "std::string", "BufferSlice", - {"\"td/tl/tl_object_parse.h\"", "\"td/tl/tl_object_store.h\""}, - {"\"td/utils/buffer.h\"", "\"td/utils/UInt.h\""}); + generate_cpp<10>("td/telegram", "telegram_api", "std::string", "BufferSlice", + {"\"td/tl/tl_object_parse.h\"", "\"td/tl/tl_object_store.h\""}, + {"\"td/utils/buffer.h\"", "\"td/utils/UInt.h\""}); generate_cpp<>("td/telegram", "secret_api", "std::string", "BufferSlice", {"\"td/tl/tl_object_parse.h\"", "\"td/tl/tl_object_store.h\""}, {"\"td/utils/buffer.h\""}); @@ -44,9 +49,9 @@ int main() { {"\"td/tl/tl_object_parse.h\"", "\"td/tl/tl_object_store.h\""}, {"\"td/utils/UInt.h\""}); #ifdef TD_ENABLE_JNI - generate_cpp<false, td::TD_TL_writer_jni_cpp, td::TD_TL_writer_jni_h>( + generate_cpp<10, false, td::TD_TL_writer_jni_cpp, td::TD_TL_writer_jni_h>( "td/telegram", "td_api", "std::string", "std::string", {"\"td/tl/tl_jni_object.h\""}, {"<string>"}); #else - generate_cpp<>("td/telegram", "td_api", "std::string", "std::string", {}, {"<string>"}); + generate_cpp<10>("td/telegram", "td_api", "std::string", "std::string", {}, {"<string>"}); #endif } diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp index 20113857e..ea5fb7c86 100644 --- a/tdtl/td/tl/tl_generate.cpp +++ b/tdtl/td/tl/tl_generate.cpp @@ -899,6 +899,85 @@ bool write_tl_to_file(const tl_config &config, const std::string &file_name, con return put_file_contents(file_name, out.get_result(), w.is_documentation_generated()); } +bool write_tl_to_fixed_file_count(const tl_config &config, const std::string &file_name_prefix, + const std::string &file_name_suffix, int file_count, const TL_writer &w) { + assert(file_count > 0); + find_complex_types(config, w); + + std::map<std::string, tl_string_outputer> outs; + + int file_num = 0; + tl_string_outputer *out = nullptr; + for (int i = 0; i < file_count; i++) { + outs[TL_writer::int_to_string(i)].append(w.gen_output_begin(std::string())); + } + outs["0"].append(w.gen_output_begin_once()); + + std::set<std::string> request_types; + std::set<std::string> result_types; + for (std::size_t function = 0; function < config.get_function_count(); function++) { + const tl_combinator *t = config.get_function_by_num(function); + dfs_combinator(t, request_types, w); + dfs_tree(t->result, result_types, w); + } + + std::map<std::string, bool> object_types; + for (std::size_t type = 0; type < config.get_type_count(); type++) { + tl_type *t = config.get_type_by_num(type); + if (t->constructors_num == 0 || w.is_built_in_simple_type(t->name) || + w.is_built_in_complex_type(t->name)) { // built-in dummy or complex types + continue; + } + + if (t->flags & FLAG_COMPLEX) { + std::fprintf(stderr, "Can't generate class %s\n", t->name.c_str()); + continue; + } + + object_types[w.gen_main_class_name(t)] = (t->simple_constructors != 1); + file_num = (file_num + 1) % file_count; + out = &outs[TL_writer::int_to_string(file_num)]; + write_class(*out, t, request_types, result_types, w); + } + + std::map<std::string, bool> function_types; + for (std::size_t function = 0; function < config.get_function_count(); function++) { + tl_combinator *t = config.get_function_by_num(function); + if (!w.is_combinator_supported(t)) { + // std::fprintf(stderr, "Function %s is too hard to store\n", t->name.c_str()); + continue; + } + + function_types[w.gen_class_name(t->name)] = false; + file_num = (file_num + 1) % file_count; + out = &outs[TL_writer::int_to_string(file_num)]; + write_function(*out, t, request_types, result_types, w); + } + + for (std::size_t type = 0; type < config.get_type_count(); type++) { + tl_type *t = config.get_type_by_num(type); + if (t->flags & FLAG_COMPLEX) { + t->flags &= ~FLAG_COMPLEX; // remove temporary flag + } + } + + write_base_object_classes(config, outs["0"], request_types, result_types, w); + write_base_function_class(config, outs["0"], request_types, result_types, w); + + for (int i = 0; i < file_count; i++) { + outs[TL_writer::int_to_string(i)].append(w.gen_output_end()); + } + + for (std::map<std::string, tl_string_outputer>::const_iterator it = outs.begin(); it != outs.end(); ++it) { + std::string file_name = file_name_prefix + "_" + it->first + file_name_suffix; + if (!put_file_contents(file_name, it->second.get_result(), w.is_documentation_generated())) { + return false; + } + } + + return true; +} + static std::string get_additional_imports(const std::map<std::string, bool> &types, const std::string base_class_name, const std::string &file_name_prefix, const std::string &file_name_suffix, const TL_writer &w) { diff --git a/tdtl/td/tl/tl_generate.h b/tdtl/td/tl/tl_generate.h index aed64c579..b48847cfc 100644 --- a/tdtl/td/tl/tl_generate.h +++ b/tdtl/td/tl/tl_generate.h @@ -21,6 +21,9 @@ tl_config read_tl_config_from_file(const std::string &file_name); bool write_tl_to_file(const tl_config &config, const std::string &file_name, const TL_writer &w); +bool write_tl_to_fixed_file_count(const tl_config &config, const std::string &file_name_prefix, + const std::string &file_name_suffix, int file_count, const TL_writer &w); + bool write_tl_to_multiple_files(const tl_config &config, const std::string &file_name_prefix, const std::string &file_name_suffix, const TL_writer &w); |
