Support additional headers in gen_output_begin.

This commit is contained in:
levlam 2023-06-26 17:01:19 +03:00
parent 6e543d3cdd
commit f4b4893124
14 changed files with 22 additions and 21 deletions

View File

@ -222,7 +222,7 @@ class TlWriterCCommon final : public tl::TL_writer {
std::string gen_type_name(const tl::tl_tree_type *tree_type) const final {
return gen_type_name(tree_type, false);
}
std::string gen_output_begin() const final {
std::string gen_output_begin(const std::string &additional_imports) const final {
if (is_header_ == 1) {
return "#pragma once\n"
"#ifdef __cplusplus\n"
@ -236,12 +236,13 @@ class TlWriterCCommon final : public tl::TL_writer {
"\n";
}
if (is_header_ == -1) {
return "#pragma once\n" + gen_import_declaration("td/telegram/td_tdc_api.h", false) +
gen_import_declaration("td/telegram/td_api.h", false);
return "#pragma once\n\n" + gen_import_declaration("td/telegram/td_tdc_api.h", false) +
gen_import_declaration("td/telegram/td_api.h", false) + "\n" + additional_imports;
}
return gen_import_declaration("td/telegram/td_tdc_api_inner.h", false) + "\n" +
gen_import_declaration("td/utils/format.h", false) + gen_import_declaration("td/utils/logging.h", false) +
gen_import_declaration("td/utils/misc.h", false) + gen_import_declaration("td/utils/Slice.h", false) + "\n";
gen_import_declaration("td/utils/misc.h", false) + gen_import_declaration("td/utils/Slice.h", false) + "\n" +
additional_imports;
}
std::string gen_output_begin_once() const final {

View File

@ -10,7 +10,7 @@
namespace td {
std::string TD_TL_writer_cpp::gen_output_begin() const {
std::string TD_TL_writer_cpp::gen_output_begin(const std::string &additional_imports) const {
std::string ext_include_str;
for (auto &it : ext_include) {
ext_include_str += "#include " + it + "\n";
@ -26,7 +26,8 @@ std::string TD_TL_writer_cpp::gen_output_begin() const {
"#include \"td/utils/SliceBuilder.h\"\n"
"#include \"td/utils/tl_parsers.h\"\n"
"#include \"td/utils/tl_storers.h\"\n"
"#include \"td/utils/TlStorerToString.h\"\n\n"
"#include \"td/utils/TlStorerToString.h\"\n\n" +
additional_imports +
"namespace td {\n"
"namespace " +
tl_name + " {\n\n";

View File

@ -41,7 +41,7 @@ class TD_TL_writer_cpp : public TD_TL_writer {
: TD_TL_writer(tl_name, string_type, bytes_type), ext_include(ext_include) {
}
std::string gen_output_begin() const override;
std::string gen_output_begin(const std::string &additional_imports) const override;
std::string gen_output_begin_once() const override;
std::string gen_output_end() const override;

View File

@ -181,9 +181,8 @@ class TlWriterDotNet final : public TL_writer {
return gen_main_class_name(t) + "^";
}
std::string gen_output_begin(void) const final {
return prefix_ +
"#include \"td/tl/tl_dotnet_object.h\"\n\n"
std::string gen_output_begin(const std::string &additional_imports) const final {
return prefix_ + "#include \"td/tl/tl_dotnet_object.h\"\n\n" + additional_imports +
"namespace Telegram {\n"
"namespace Td {\n"
"namespace Api {\n";

View File

@ -28,7 +28,7 @@ std::string TD_TL_writer_h::forward_declaration(std::string type) {
return "";
}
std::string TD_TL_writer_h::gen_output_begin() const {
std::string TD_TL_writer_h::gen_output_begin(const std::string &additional_imports) const {
std::string ext_include_str;
for (auto &it : ext_include) {
ext_include_str += "#include " + it + "\n";

View File

@ -28,7 +28,7 @@ class TD_TL_writer_h : public TD_TL_writer {
: TD_TL_writer(tl_name, string_type, bytes_type), ext_include(ext_include) {
}
std::string gen_output_begin() const override;
std::string gen_output_begin(const std::string &additional_imports) const override;
std::string gen_output_begin_once() const override;
std::string gen_output_end() const override;

View File

@ -38,7 +38,7 @@ std::string TD_TL_writer_hpp::gen_base_tl_class_name() const {
return "BaseObject";
}
std::string TD_TL_writer_hpp::gen_output_begin() const {
std::string TD_TL_writer_hpp::gen_output_begin(const std::string &additional_imports) const {
return "#pragma once\n"
"\n"
#ifndef DISABLE_HPP_DOCUMENTATION

View File

@ -28,7 +28,7 @@ class TD_TL_writer_hpp final : public TD_TL_writer {
std::string gen_base_type_class_name(int arity) const final;
std::string gen_base_tl_class_name() const final;
std::string gen_output_begin() const final;
std::string gen_output_begin(const std::string &additional_imports) const final;
std::string gen_output_begin_once() const final;
std::string gen_output_end() const final;

View File

@ -190,8 +190,8 @@ std::string TD_TL_writer_java::gen_int_const(const tl::tl_tree *tree_c,
return std::string();
}
std::string TD_TL_writer_java::gen_output_begin() const {
return "package " + package_name + ";\n\n";
std::string TD_TL_writer_java::gen_output_begin(const std::string &additional_imports) const {
return "package " + package_name + ";\n\n" + additional_imports;
}
std::string TD_TL_writer_java::gen_output_begin_once() const {

View File

@ -53,7 +53,7 @@ class TD_TL_writer_java final : public tl::TL_writer {
std::string gen_int_const(const tl::tl_tree *tree_c, const std::vector<tl::var_description> &vars) const final;
std::string gen_output_begin() const final;
std::string gen_output_begin(const std::string &additional_imports) const final;
std::string gen_output_begin_once() const final;
std::string gen_output_end() const final;

View File

@ -58,7 +58,7 @@ std::string TD_TL_writer_jni_h::gen_base_tl_class_name() const {
return "Object";
}
std::string TD_TL_writer_jni_h::gen_output_begin() const {
std::string TD_TL_writer_jni_h::gen_output_begin(const std::string &additional_imports) const {
std::string ext_include_str;
for (auto &it : ext_include) {
ext_include_str += "#include " + it + "\n";

View File

@ -32,7 +32,7 @@ class TD_TL_writer_jni_h final : public TD_TL_writer_h {
std::string gen_base_type_class_name(int arity) const final;
std::string gen_base_tl_class_name() const final;
std::string gen_output_begin() const final;
std::string gen_output_begin(const std::string &additional_imports) const final;
std::string gen_output_begin_once() const final;
std::string gen_class_begin(const std::string &class_name, const std::string &base_class_name, bool is_proxy,

View File

@ -819,7 +819,7 @@ static void write_base_function_class(const tl_config &config, tl_outputer &out,
void write_tl(const tl_config &config, tl_outputer &out, const TL_writer &w) {
find_complex_types(config, w);
out.append(w.gen_output_begin());
out.append(w.gen_output_begin(std::string()));
out.append(w.gen_output_begin_once());
std::set<std::string> request_types;

View File

@ -83,7 +83,7 @@ class TL_writer {
virtual std::string gen_int_const(const tl_tree *tree_c, const std::vector<var_description> &vars) const = 0;
virtual std::string gen_output_begin() const = 0;
virtual std::string gen_output_begin(const std::string &additional_imports) const = 0;
virtual std::string gen_output_begin_once() const = 0;
virtual std::string gen_output_end() const = 0;