aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdtl
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2019-07-01 10:43:31 +0200
committerArseny Smirnov <arseny30@gmail.com>2019-07-01 10:43:31 +0200
commit620e4221f3b748d341fb3deff6241518bf3d8440 (patch)
treeb31de5091afc98dc2db3975dd41fb1523b0b2cb9 /tdtl
parentd22a6751dbdbdc357f1a473dc6a93559964baaad (diff)
tl json: support tl::TL_writer::Mode
GitOrigin-RevId: db6769e80f43f5fa2eedac5414cd2a44f8dcaf3c
Diffstat (limited to 'tdtl')
-rw-r--r--tdtl/td/tl/tl_simple.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/tdtl/td/tl/tl_simple.h b/tdtl/td/tl/tl_simple.h
index 2b51fda97..ea53a0620 100644
--- a/tdtl/td/tl/tl_simple.h
+++ b/tdtl/td/tl/tl_simple.h
@@ -16,6 +16,8 @@
#include <string>
#include <vector>
+#include <iostream>
+
namespace td {
namespace tl {
namespace simple {
@@ -63,6 +65,9 @@ struct Constructor {
struct CustomType {
std::string name;
std::vector<const Constructor *> constructors;
+
+ mutable bool is_result_{false};
+ mutable bool is_query_{false};
};
struct Function {
@@ -91,6 +96,23 @@ class Schema {
auto *from_function = config.get_function_by_num(function_num);
functions.push_back(get_function(from_function));
}
+ for (auto &function : functions_) {
+ mark_result(function->type);
+ for (auto &arg : function->args) {
+ mark_query(arg.type);
+ }
+ }
+
+ //for (auto custom_type : custom_types) {
+ //std::cerr << custom_type->name;
+ //if (custom_type->is_result_) {
+ //std::cerr << " result";
+ //}
+ //if (custom_type->is_query_) {
+ //std::cerr << " query";
+ //}
+ //std::cerr << std::endl;
+ //}
}
std::vector<const CustomType *> custom_types;
@@ -107,6 +129,32 @@ class Schema {
std::map<std::int32_t, Constructor *> constructor_by_id;
std::map<std::int32_t, Function *> function_by_id;
+ void mark_result(const Type *type) {
+ do_mark(type, true);
+ }
+ void mark_query(const Type *type) {
+ do_mark(type, false);
+ }
+ void do_mark(const Type *type, bool is_result) {
+ if (type->type == Type::Vector) {
+ return do_mark(type->vector_value_type, is_result);
+ }
+ if (type->type != Type::Custom) {
+ return;
+ }
+ auto *custom = type->custom;
+ auto &was = is_result ? custom->is_result_ : custom->is_query_;
+ if (was) {
+ return;
+ }
+ was = true;
+ for (auto constructor : custom->constructors) {
+ for (auto &arg : constructor->args) {
+ do_mark(arg.type, is_result);
+ }
+ }
+ }
+
const Type *get_type(const tl_type *from_type) {
auto &type = type_by_id[from_type->id];
if (!type) {