MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / gen_field_store

Method gen_field_store

tl/generate/tl_writer_cpp.cpp:434–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432}
433
434std::string TD_TL_writer_cpp::gen_field_store(const tl::arg &a, std::vector<tl::var_description> &vars, bool flat,
435 int storer_type) const {
436 std::string field_name = gen_field_name(a.name);
437 std::string res = storer_type == 1 ? " " : " ";
438
439 if (a.type->get_type() == tl::NODE_TYPE_VAR_TYPE) {
440 const tl::tl_tree_var_type *t = static_cast<const tl::tl_tree_var_type *>(a.type);
441 assert(a.flags == tl::FLAG_EXCL);
442
443 assert(a.var_num == -1);
444 assert(a.exist_var_num == -1);
445
446 assert(t->var_num >= 0);
447 assert(!vars[t->var_num].is_stored);
448 vars[t->var_num].is_stored = true;
449 assert(vars[t->var_num].is_type);
450
451 return res + field_name + "->store(s);\n";
452 }
453
454 assert(!(a.flags & tl::FLAG_EXCL));
455
456 if (a.flags & tl::FLAG_OPT_VAR) {
457 assert(false);
458 assert(a.exist_var_num == -1);
459 assert(0 <= a.var_num && a.var_num < static_cast<int>(vars.size()));
460
461 assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
462 assert(static_cast<const tl::tl_tree_type *>(a.type)->type->id == tl::ID_VAR_NUM);
463 assert(vars[a.var_num].is_stored);
464 assert(!vars[a.var_num].is_type);
465 return "";
466 }
467
468 if (a.exist_var_num >= 0) {
469 assert(a.exist_var_num < static_cast<int>(vars.size()));
470 assert(vars[a.exist_var_num].is_stored);
471
472 res += "if (" + gen_var_name(vars[a.exist_var_num]) + " & " + int_to_string(1 << a.exist_var_bit) + ") { ";
473 }
474
475 if (flat) {
476 // TODO
477 // return gen_field_store(const tl::arg &a, std::vector<tl::var_description> &vars, bool flat, int storer_type);
478 }
479
480 if (a.var_num >= 0) {
481 assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
482 assert(static_cast<const tl::tl_tree_type *>(a.type)->type->id == tl::ID_VAR_NUM);
483 assert(a.var_num < static_cast<int>(vars.size()));
484 if (!vars[a.var_num].is_stored) {
485 field_name = "(" + gen_var_name(vars[a.var_num]) + " = " + field_name + ")";
486 vars[a.var_num].is_stored = true;
487 } else {
488 assert(false); // need to check value of stored var
489 field_name = gen_var_name(vars[a.var_num]);
490 }
491 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected