1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

updated func/fift

- updated func/fift
- updated liteclient/liteserver
- bugfixes
This commit is contained in:
ton 2019-12-29 12:14:12 +03:00
parent d41ce55305
commit acf16718e6
45 changed files with 1360 additions and 185 deletions

View file

@ -3257,6 +3257,31 @@ void generate_type_constants(std::ostream& os, int mode) {
}
}
void generate_register_function(std::ostream& os, int mode) {
os << "\n// " << (mode ? "definition" : "declaration") << " of type name registration function\n";
if (!mode) {
os << "extern bool register_simple_types(std::function<bool(const char*, const TLB*)> func);\n";
return;
}
os << "bool register_simple_types(std::function<bool(const char*, const TLB*)> func) {\n";
os << " return ";
int k = 0;
for (int i = builtin_types_num; i < types_num; i++) {
Type& type = types[i];
CppTypeCode& cc = *cpp_type[i];
if (!cc.cpp_type_var_name.empty() && type.type_name) {
if (k++) {
os << "\n && ";
}
os << "func(\"" << type.get_name() << "\", &" << cc.cpp_type_var_name << ")";
}
}
if (!k) {
os << "true";
}
os << ";\n}\n\n";
}
void assign_const_type_cpp_idents() {
const_type_expr_cpp_idents.resize(const_type_expr_num + 1, "");
const_type_expr_simple.resize(const_type_expr_num + 1, false);
@ -3389,6 +3414,7 @@ void generate_cpp_output_to(std::ostream& os, int options = 0, std::vector<std::
cc.generate(os, (options & -4) | pass);
}
generate_type_constants(os, pass - 1);
generate_register_function(os, pass - 1);
}
}
for (auto it = cpp_namespace_list.rbegin(); it != cpp_namespace_list.rend(); ++it) {

View file

@ -346,3 +346,24 @@ bool PrettyPrinter::fetch_uint256_field(vm::CellSlice& cs, int n, std::string na
}
} // namespace tlb
namespace tlb {
bool TypenameLookup::register_types(typename TypenameLookup::register_func_t func) {
return func([this](const char* name, const TLB* tp) { return register_type(name, tp); });
}
bool TypenameLookup::register_type(const char* name, const TLB* tp) {
if (!name || !tp) {
return false;
}
auto res = types.emplace(name, tp);
return res.second;
}
const TLB* TypenameLookup::lookup(std::string str) const {
auto it = types.find(str);
return it != types.end() ? it->second : nullptr;
}
} // namespace tlb

View file

@ -18,6 +18,7 @@
*/
#pragma once
#include <iostream>
#include <map>
#include "vm/cellslice.h"
namespace tlb {
@ -268,6 +269,30 @@ struct TLB_Complex : TLB {
}
};
class TlbTypeHolder : public td::CntObject {
const TLB* type{nullptr};
char* data{nullptr};
public:
TlbTypeHolder() = default;
TlbTypeHolder(const TLB* _type) : type(_type), data(nullptr) {
}
TlbTypeHolder(const TLB* _type, char* _data) : type(_type), data(_data) {
}
~TlbTypeHolder() override {
free(data);
}
const TLB* get() const {
return type;
}
const TLB& operator*() const {
return *type;
}
const TLB* operator->() const {
return type;
}
};
static inline bool add_chk(int x, int y, int z) {
return x + y == z && z >= 0;
}
@ -508,6 +533,25 @@ struct PrettyPrinter {
namespace tlb {
class TypenameLookup {
std::map<std::string, const TLB*> types;
public:
typedef std::function<bool(const char*, const TLB*)> simple_register_func_t;
typedef std::function<bool(simple_register_func_t)> register_func_t;
TypenameLookup() = default;
TypenameLookup(register_func_t func) {
register_types(func);
}
bool register_type(const char* name, const TLB* tp);
bool register_types(register_func_t func);
const TLB* lookup(std::string str) const;
};
} // namespace tlb
namespace tlb {
struct False final : TLB {
int get_size(const vm::CellSlice& cs) const override {
return -1;