forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtl_writer_hpp.cpp
294 lines (244 loc) · 11.1 KB
/
tl_writer_hpp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "tl_writer_hpp.h"
#include <cassert>
namespace td {
bool TD_TL_writer_hpp::is_documentation_generated() const {
return true;
}
int TD_TL_writer_hpp::get_additional_function_type(const std::string &additional_function_name) const {
assert(additional_function_name == "downcast_call" || additional_function_name == "downcast_construct");
return 2;
}
std::vector<std::string> TD_TL_writer_hpp::get_additional_functions() const {
std::vector<std::string> additional_functions;
additional_functions.push_back("downcast_call");
additional_functions.push_back("downcast_construct");
return additional_functions;
}
std::string TD_TL_writer_hpp::gen_base_type_class_name(int arity) const {
assert(arity == 0);
return "Object";
}
std::string TD_TL_writer_hpp::gen_base_tl_class_name() const {
return "BaseObject";
}
std::string TD_TL_writer_hpp::gen_output_begin() const {
return "#pragma once\n"
"\n"
"#include \"" +
tl_name +
".h\"\n"
"\n"
"namespace ton {\n"
"namespace " +
tl_name + " {\n\n";
}
std::string TD_TL_writer_hpp::gen_output_end() const {
return "} // namespace " + tl_name +
"\n"
"} // namespace ton \n";
}
std::string TD_TL_writer_hpp::gen_field_definition(const std::string &class_name, const std::string &type_name,
const std::string &field_name) const {
return "";
}
std::string TD_TL_writer_hpp::gen_vars(const tl::tl_combinator *t, const tl::tl_tree_type *result_type,
std::vector<tl::var_description> &vars) const {
return "";
}
std::string TD_TL_writer_hpp::gen_function_vars(const tl::tl_combinator *t,
std::vector<tl::var_description> &vars) const {
return "";
}
std::string TD_TL_writer_hpp::gen_uni(const tl::tl_tree_type *result_type, std::vector<tl::var_description> &vars,
bool check_negative) const {
return "";
}
std::string TD_TL_writer_hpp::gen_constructor_id_store(std::int32_t id, int storer_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_field_fetch(int field_num, const tl::arg &a, std::vector<tl::var_description> &vars,
bool flat, int parser_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_field_store(const tl::arg &a, std::vector<tl::var_description> &vars, bool flat,
int storer_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_type_fetch(const std::string &field_name, const tl::tl_tree_type *tree_type,
const std::vector<tl::var_description> &vars, int parser_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_type_store(const std::string &field_name, const tl::tl_tree_type *tree_type,
const std::vector<tl::var_description> &vars, int storer_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_var_type_fetch(const tl::arg &a) const {
assert(false);
return "";
}
std::string TD_TL_writer_hpp::gen_forward_class_declaration(const std::string &class_name, bool is_proxy) const {
return "";
}
std::string TD_TL_writer_hpp::gen_class_begin(const std::string &class_name, const std::string &base_class_name,
bool is_proxy) const {
return "";
}
std::string TD_TL_writer_hpp::gen_class_end() const {
return "";
}
std::string TD_TL_writer_hpp::gen_class_alias(const std::string &class_name, const std::string &alias_name) const {
return "";
}
std::string TD_TL_writer_hpp::gen_get_id(const std::string &class_name, std::int32_t id, bool is_proxy) const {
return "";
}
std::string TD_TL_writer_hpp::gen_function_result_type(const tl::tl_tree *result) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_begin(const std::string &parser_name, const std::string &class_name,
const std::string &parent_class_name, int arity,
std::vector<tl::var_description> &vars, int parser_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_end(bool has_parent, int field_num,
const std::vector<tl::var_description> &vars,
int parser_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_result_begin(const std::string &parser_name,
const std::string &class_name,
const tl::tl_tree *result) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_result_end() const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_result_any_begin(const std::string &parser_name,
const std::string &class_name, bool is_proxy) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_function_result_any_end(bool is_proxy) const {
return "";
}
std::string TD_TL_writer_hpp::gen_store_function_begin(const std::string &storer_name, const std::string &class_name,
int arity, std::vector<tl::var_description> &vars,
int storer_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_store_function_end(const std::vector<tl::var_description> &vars,
int storer_type) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_switch_begin() const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_switch_case(const tl::tl_combinator *t, int arity) const {
return "";
}
std::string TD_TL_writer_hpp::gen_fetch_switch_end() const {
return "";
}
std::string TD_TL_writer_hpp::gen_additional_function(const std::string &function_name, const tl::tl_combinator *t,
bool is_function) const {
assert(function_name == "downcast_call" || function_name == "downcast_construct");
return "";
}
std::string TD_TL_writer_hpp::gen_additional_proxy_function_begin(const std::string &function_name,
const tl::tl_type *type,
const std::string &class_name, int arity,
bool is_function) const {
if (function_name == "downcast_call") {
return "/**\n"
" * Calls specified function object with the specified object downcasted to the most-derived type.\n"
" * \\param[in] obj Object to pass as an argument to the function object.\n"
" * \\param[in] func Function object to which the object will be passed.\n"
" * \\returns whether function object call has happened. Should always return true for correct parameters.\n"
" */\n"
"template <class T>\n"
"bool downcast_call(" +
class_name +
" &obj, const T &func) {\n"
" switch (obj.get_id()) {\n";
}
if (function_name == "downcast_construct") {
return "/**\n"
"* Constructs tl_object_ptr with the object of the same type as the specified object, calls the specified "
"function.\n"
" * \\param[in] obj Object to get the type from.\n"
" * \\param[in] func Function object to which the new object will be passed.\n"
" * \\returns whether function object call has happened. Should always return true for correct parameters.\n"
"*/"
"template <class T>\n"
"bool downcast_construct(" +
class_name +
" &obj, const T &func) {\n"
"switch (obj.get_id()) {";
}
assert(false);
}
std::string TD_TL_writer_hpp::gen_additional_proxy_function_case(const std::string &function_name,
const tl::tl_type *type, const std::string &class_name,
int arity) const {
//assert(function_name == "downcast_call");
assert(false);
return "";
}
std::string TD_TL_writer_hpp::gen_additional_proxy_function_case(const std::string &function_name,
const tl::tl_type *type, const tl::tl_combinator *t,
int arity, bool is_function) const {
if (function_name == "downcast_call") {
return " case " + gen_class_name(t->name) +
"::ID:\n"
" func(static_cast<" +
gen_class_name(t->name) +
" &>(obj));\n"
" return true;\n";
}
if (function_name == "downcast_construct") {
return " case " + gen_class_name(t->name) +
"::ID:\n"
" func(create_tl_object<" +
gen_class_name(t->name) +
">());\n"
" return true;\n";
}
assert(false);
}
std::string TD_TL_writer_hpp::gen_additional_proxy_function_end(const std::string &function_name,
const tl::tl_type *type, bool is_function) const {
assert(function_name == "downcast_call" || function_name == "downcast_construct");
return " default:\n"
" return false;\n"
" }\n"
"}\n\n";
}
std::string TD_TL_writer_hpp::gen_constructor_begin(int fields_num, const std::string &class_name,
bool is_default) const {
return "";
}
std::string TD_TL_writer_hpp::gen_constructor_parameter(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const {
return "";
}
std::string TD_TL_writer_hpp::gen_constructor_field_init(int field_num, const std::string &class_name, const tl::arg &a,
bool is_default) const {
return "";
}
std::string TD_TL_writer_hpp::gen_constructor_end(const tl::tl_combinator *t, int fields_num, bool is_default) const {
return "";
}
} // namespace td