diff options
author | thegeorg <thegeorg@yandex-team.com> | 2023-09-06 12:00:15 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2023-09-06 12:35:38 +0300 |
commit | 23225dd61414039ed8f923ca08c96efecc8894eb (patch) | |
tree | c35c77c85c0bca5f54ba4ceb397f442d9adfdf97 /contrib | |
parent | ee92fee2d806dd933291766e2f42948c481b6398 (diff) | |
download | ydb-23225dd61414039ed8f923ca08c96efecc8894eb.tar.gz |
Update contrib/libs/flatbuffers to 23.5.26
Diffstat (limited to 'contrib')
49 files changed, 720 insertions, 1508 deletions
diff --git a/contrib/libs/flatbuffers/CHANGELOG.md b/contrib/libs/flatbuffers/CHANGELOG.md index 4c627ed365..145c62b109 100644 --- a/contrib/libs/flatbuffers/CHANGELOG.md +++ b/contrib/libs/flatbuffers/CHANGELOG.md @@ -4,6 +4,11 @@ All major or breaking changes will be documented in this file, as well as any new features that should be highlighted. Minor fixes or improvements are not necessarily listed. +## [23.5.26 (May 26 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.26) + +* Mostly bug fixing for 64-bit support +* Adds support for specifying underling type of unions in C++ and TS/JS (#7954) + ## [23.5.9 (May 9 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.9) * 64-bit support for C++ (#7935) diff --git a/contrib/libs/flatbuffers/README.md b/contrib/libs/flatbuffers/README.md index 1fb2fe0c66..875c73bb9c 100644 --- a/contrib/libs/flatbuffers/README.md +++ b/contrib/libs/flatbuffers/README.md @@ -14,6 +14,47 @@ **FlatBuffers** is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility. +## Quick Start + +1. Build the compiler for flatbuffers (`flatc`) + + Use `cmake` to create the build files for your platform and then perform the compliation (Linux example). + + ``` + cmake -G "Unix Makefiles" + make -j + ``` + +2. Define your flatbuffer schema (`.fbs`) + + Write the [schema](https://flatbuffers.dev/flatbuffers_guide_writing_schema.html) to define the data you want to serialize. See [monster.fbs](https://github.com/google/flatbuffers/blob/master/samples/monster.fbs) for an example. + +3. Generate code for your language(s) + + Use the `flatc` compiler to take your schema and generate language-specific code: + + ``` + ./flatc --cpp --rust monster.fbs + ``` + + Which generates `monster_generated.h` and `monster_generated.rs` files. + +4. Serialize data + + Use the generated code, as well as the `FlatBufferBuilder` to construct your serialized buffer. ([`C++` example](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.cpp#L24-L56)) + +5. Transmit/store/save Buffer + + Use your serialized buffer however you want. Send it to someone, save it for later, etc... + +6. Read the data + + Use the generated accessors to read the data from the serialized buffer. + + It doesn't need to be the same language/schema version, FlatBuffers ensures the data is readable across languages and schema versions. See the [`Rust` example](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.rs#L92-L106) reading the data written by `C++`. + +## Documentation + **Go to our [landing page][] to browse our documentation.** ## Supported operating systems @@ -46,7 +87,7 @@ Code generation and runtime libraries for many popular languages. ## Versioning -FlatBuffers does not follow traditional Semver versioning (see [rationale](https://github.com/google/flatbuffers/wiki/Versioning)) but rather uses a format of the date of the release. +FlatBuffers does not follow traditional SemVer versioning (see [rationale](https://github.com/google/flatbuffers/wiki/Versioning)) but rather uses a format of the date of the release. ## Contribution diff --git a/contrib/libs/flatbuffers/flatc/CMakeLists.darwin-x86_64.txt b/contrib/libs/flatbuffers/flatc/CMakeLists.darwin-x86_64.txt index 60468b3dcd..a9bafb3381 100644 --- a/contrib/libs/flatbuffers/flatc/CMakeLists.darwin-x86_64.txt +++ b/contrib/libs/flatbuffers/flatc/CMakeLists.darwin-x86_64.txt @@ -48,7 +48,6 @@ target_sources(libs-flatbuffers-flatc PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lua.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_php.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_python.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_rust.cpp diff --git a/contrib/libs/flatbuffers/flatc/CMakeLists.linux-aarch64.txt b/contrib/libs/flatbuffers/flatc/CMakeLists.linux-aarch64.txt index 8e7b7f0105..19eed0d07d 100644 --- a/contrib/libs/flatbuffers/flatc/CMakeLists.linux-aarch64.txt +++ b/contrib/libs/flatbuffers/flatc/CMakeLists.linux-aarch64.txt @@ -49,7 +49,6 @@ target_sources(libs-flatbuffers-flatc PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lua.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_php.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_python.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_rust.cpp diff --git a/contrib/libs/flatbuffers/flatc/CMakeLists.linux-x86_64.txt b/contrib/libs/flatbuffers/flatc/CMakeLists.linux-x86_64.txt index 8e7b7f0105..19eed0d07d 100644 --- a/contrib/libs/flatbuffers/flatc/CMakeLists.linux-x86_64.txt +++ b/contrib/libs/flatbuffers/flatc/CMakeLists.linux-x86_64.txt @@ -49,7 +49,6 @@ target_sources(libs-flatbuffers-flatc PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lua.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_php.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_python.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_rust.cpp diff --git a/contrib/libs/flatbuffers/flatc/CMakeLists.windows-x86_64.txt b/contrib/libs/flatbuffers/flatc/CMakeLists.windows-x86_64.txt index 60468b3dcd..a9bafb3381 100644 --- a/contrib/libs/flatbuffers/flatc/CMakeLists.windows-x86_64.txt +++ b/contrib/libs/flatbuffers/flatc/CMakeLists.windows-x86_64.txt @@ -48,7 +48,6 @@ target_sources(libs-flatbuffers-flatc PRIVATE ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_lua.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_php.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_python.cpp ${CMAKE_SOURCE_DIR}/contrib/libs/flatbuffers/src/idl_gen_rust.cpp diff --git a/contrib/libs/flatbuffers/flatc/ya.make b/contrib/libs/flatbuffers/flatc/ya.make index 1ed0d49cba..455c519d22 100644 --- a/contrib/libs/flatbuffers/flatc/ya.make +++ b/contrib/libs/flatbuffers/flatc/ya.make @@ -53,7 +53,6 @@ SRCS( src/idl_gen_json_schema.cpp src/idl_gen_kotlin.cpp src/idl_gen_lobster.cpp - src/idl_gen_lua.cpp src/idl_gen_php.cpp src/idl_gen_python.cpp src/idl_gen_rust.cpp diff --git a/contrib/libs/flatbuffers/include/flatbuffers/base.h b/contrib/libs/flatbuffers/include/flatbuffers/base.h index a416bc1b38..506fd545d1 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/base.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/base.h @@ -141,7 +141,7 @@ #define FLATBUFFERS_VERSION_MAJOR 23 #define FLATBUFFERS_VERSION_MINOR 5 -#define FLATBUFFERS_VERSION_REVISION 9 +#define FLATBUFFERS_VERSION_REVISION 26 #define FLATBUFFERS_STRING_EXPAND(X) #X #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) namespace flatbuffers { @@ -279,14 +279,14 @@ namespace flatbuffers { #endif // !FLATBUFFERS_LOCALE_INDEPENDENT // Suppress Undefined Behavior Sanitizer (recoverable only). Usage: -// - __suppress_ubsan__("undefined") -// - __suppress_ubsan__("signed-integer-overflow") +// - FLATBUFFERS_SUPPRESS_UBSAN("undefined") +// - FLATBUFFERS_SUPPRESS_UBSAN("signed-integer-overflow") #if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7)) - #define __suppress_ubsan__(type) __attribute__((no_sanitize(type))) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize(type))) #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) - #define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined)) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize_undefined)) #else - #define __suppress_ubsan__(type) + #define FLATBUFFERS_SUPPRESS_UBSAN(type) #endif // This is constexpr function used for checking compile-time constants. @@ -424,7 +424,7 @@ template<typename T> T EndianScalar(T t) { template<typename T> // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__suppress_ubsan__("alignment") +FLATBUFFERS_SUPPRESS_UBSAN("alignment") T ReadScalar(const void *p) { return EndianScalar(*reinterpret_cast<const T *>(p)); } @@ -438,13 +438,13 @@ T ReadScalar(const void *p) { template<typename T> // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. -__suppress_ubsan__("alignment") +FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, T t) { *reinterpret_cast<T *>(p) = EndianScalar(t); } template<typename T> struct Offset; -template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) { +template<typename T> FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, Offset<T> t) { *reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o); } @@ -455,7 +455,7 @@ template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, O // Computes how many bytes you'd have to pad to be able to write an // "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in // memory). -__suppress_ubsan__("unsigned-integer-overflow") +FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) { return ((~buf_size) + 1) & (scalar_size - 1); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h b/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h index 2c05b7e247..de6ed6ff75 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/code_generator.h @@ -23,6 +23,10 @@ namespace flatbuffers { +struct CodeGenOptions { + std::string output_path; +}; + // A code generator interface for producing converting flatbuffer schema into // code. class CodeGenerator { @@ -44,9 +48,20 @@ class CodeGenerator { virtual Status GenerateCode(const Parser &parser, const std::string &path, const std::string &filename) = 0; + // Generate code from the provided `parser` and place it in the output. + virtual Status GenerateCodeString(const Parser &parser, + const std::string &filename, + std::string &output) { + (void)parser; + (void)filename; + (void)output; + return Status::NOT_IMPLEMENTED; + } + // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0; + virtual Status GenerateCode(const uint8_t *buffer, int64_t length, + const CodeGenOptions &options) = 0; virtual Status GenerateMakeRule(const Parser &parser, const std::string &path, const std::string &filename, diff --git a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h index 0407690616..fa5eb4c1ec 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h @@ -229,6 +229,10 @@ class TypedFloatConstantGenerator : public FloatConstantGenerator { const std::string neg_inf_number_; }; +std::string JavaCSharpMakeRule(const bool java, const Parser &parser, + const std::string &path, + const std::string &file_name); + } // namespace flatbuffers #endif // FLATBUFFERS_CODE_GENERATORS_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h index 4bb2a7222a..f97daa4046 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffer_builder.h @@ -722,9 +722,8 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { /// @param[in] len The number of elements to serialize. /// @return Returns a typed `TOffset` into the serialized data indicating /// where the vector is stored. - template<template<typename...> class OffsetT = Offset, - template<typename...> class VectorT = Vector, - int &...ExplicitArgumentBarrier, typename T> + template<typename T, template<typename...> class OffsetT = Offset, + template<typename...> class VectorT = Vector> OffsetT<VectorT<T>> CreateVector(const T *v, size_t len) { // The type of the length field in the vector. typedef typename VectorT<T>::size_type LenT; @@ -793,7 +792,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { template<template<typename...> class VectorT = Vector64, int &...ExplicitArgumentBarrier, typename T> Offset64<VectorT<T>> CreateVector64(const std::vector<T> &v) { - return CreateVector<Offset64, VectorT>(data(v), v.size()); + return CreateVector<T, Offset64, VectorT>(data(v), v.size()); } // vector<bool> may be implemented using a bit-set, so we can't access it as @@ -1302,11 +1301,6 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { // This will remain 0 if no 64-bit offset types are added to the buffer. size_t length_of_64_bit_region_; - // When true, 64-bit offsets can still be added to the builder. When false, - // only 32-bit offsets can be added, and attempts to add a 64-bit offset will - // raise an assertion. This is typically a compile-time error in ordering the - // serialization of 64-bit offset fields not at the tail of the buffer. - // Ensure objects are not nested. bool nested; @@ -1417,8 +1411,8 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl { // Hack to `FlatBufferBuilder` mean `FlatBufferBuilder<false>` or // `FlatBufferBuilder<>`, where the template < > syntax is required. -typedef FlatBufferBuilderImpl<false> FlatBufferBuilder; -typedef FlatBufferBuilderImpl<true> FlatBufferBuilder64; +using FlatBufferBuilder = FlatBufferBuilderImpl<false>; +using FlatBufferBuilder64 = FlatBufferBuilderImpl<true>; // These are external due to GCC not allowing them in the class. // See: https://stackoverflow.com/q/8061456/868247 diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h index acf1e2c0ea..952ea3bcdf 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h @@ -81,6 +81,17 @@ inline SizeT GetPrefixedSize(const uint8_t *buf) { return ReadScalar<SizeT>(buf); } +// Gets the total length of the buffer given a sized prefixed FlatBuffer. +// +// This includes the size of the prefix as well as the buffer: +// +// [size prefix][flatbuffer] +// |---------length--------| +template<typename SizeT = uoffset_t> +inline SizeT GetSizePrefixedBufferLength(const uint8_t *const buf) { + return ReadScalar<SizeT>(buf) + sizeof(SizeT); +} + // Base class for native objects (FlatBuffer data de-serialized into native // C++ data structures). // Contains no functionality, purely documentative. diff --git a/contrib/libs/flatbuffers/include/flatbuffers/idl.h b/contrib/libs/flatbuffers/include/flatbuffers/idl.h index 1c07254ac3..f65f18a9ab 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/idl.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/idl.h @@ -723,7 +723,7 @@ struct IDLOptions { kRust = 1 << 14, kKotlin = 1 << 15, kSwift = 1 << 16, - kCppYandexMapsIter = 1 << 17, + kCppYandexMapsIter = 1 << 19, kNim = 1 << 17, kProto = 1 << 18, kMAX @@ -1152,6 +1152,7 @@ class Parser : public ParserState { bool SupportsOptionalScalars() const; bool SupportsDefaultVectorsAndStrings() const; bool Supports64BitOffsets() const; + bool SupportsUnionUnderlyingType() const; Namespace *UniqueNamespace(Namespace *ns); FLATBUFFERS_CHECKED_ERROR RecurseError(); @@ -1211,100 +1212,17 @@ class Parser : public ParserState { // if it is less than 0, no linefeeds will be generated either. // See idl_gen_text.cpp. // strict_json adds "quotes" around field names if true. -// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8 -// byte arrays in String values), returns false. -extern const char *GenerateTextFromTable(const Parser &parser, const void *table, - const std::string &tablename, - std::string *text); -extern const char *GenerateText(const Parser &parser, const void *flatbuffer, - std::string *text); -extern const char *GenerateTextFile(const Parser &parser, - const std::string &path, - const std::string &file_name); - -// Generate Json schema to string -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, std::string *json); - -// Generate binary files from a given FlatBuffer, and a given Parser -// object that has been populated with the corresponding schema. -// See code_generators.cpp. -extern bool GenerateBinary(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a C++ header from the definitions in the Parser object. -// See idl_gen_cpp. -extern bool GenerateCPP(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate C# files from the definitions in the Parser object. -// See idl_gen_csharp.cpp. -extern bool GenerateCSharp(const Parser &parser, const std::string &path, - const std::string &file_name); - -extern bool GenerateDart(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Java files from the definitions in the Parser object. -// See idl_gen_java.cpp. -extern bool GenerateJava(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate JavaScript or TypeScript code from the definitions in the Parser -// object. See idl_gen_js. -extern bool GenerateTS(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Go files from the definitions in the Parser object. -// See idl_gen_go.cpp. -extern bool GenerateGo(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Php code from the definitions in the Parser object. -// See idl_gen_php. -extern bool GeneratePhp(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Python files from the definitions in the Parser object. -// See idl_gen_python.cpp. -extern bool GeneratePython(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Lobster files from the definitions in the Parser object. -// See idl_gen_lobster.cpp. -extern bool GenerateLobster(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Lua files from the definitions in the Parser object. -// See idl_gen_lua.cpp. -extern bool GenerateLua(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Rust files from the definitions in the Parser object. -// See idl_gen_rust.cpp. -extern bool GenerateRust(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Json schema file -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, const std::string &path, +// These functions return nullptr on success, or an error string, +// which may happen if the flatbuffer cannot be encoded in JSON (e.g., +// it contains non-UTF-8 byte arrays in String values). +extern const char *GenTextFromTable(const Parser &parser, const void *table, + const std::string &tablename, + std::string *text); +extern const char *GenText(const Parser &parser, const void *flatbuffer, + std::string *text); +extern const char *GenTextFile(const Parser &parser, const std::string &path, const std::string &file_name); -extern bool GenerateKotlin(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate Swift classes. -// See idl_gen_swift.cpp -extern bool GenerateSwift(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a schema file from the internal representation, useful after -// parsing a .proto schema. -extern std::string GenerateFBS(const Parser &parser, - const std::string &file_name, bool no_log); -extern bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name, bool no_log); - // Generate a C++ header for reading with templated file iterator from // the definitions in the Parser object. // See idl_gen_cpp_yandex_maps_iter.cpp. @@ -1314,43 +1232,6 @@ extern bool GenerateCPPYandexMapsIter(const Parser &parser, const std::string &path, const std::string &file_name); -// Generate a make rule for the generated TypeScript code. -// See idl_gen_ts.cpp. -extern std::string TSMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated C++ header. -// See idl_gen_cpp.cpp. -extern std::string CPPMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Dart code -// see idl_gen_dart.cpp -extern std::string DartMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated Rust code. -// See idl_gen_rust.cpp. -extern std::string RustMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for generated Java or C# files. -// See code_generators.cpp. -extern std::string CSharpMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); -extern std::string JavaMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - -// Generate a make rule for the generated text (JSON) files. -// See idl_gen_text.cpp. -extern std::string TextMakeRule(const Parser &parser, const std::string &path, - const std::string &file_names); - -// Generate a make rule for the generated binary files. -// See code_generators.cpp. -extern std::string BinaryMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); - // Generate GRPC Cpp interfaces. // See idl_gen_grpc.cpp. bool GenerateCppGRPC(const Parser &parser, const std::string &path, @@ -1378,9 +1259,6 @@ extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, extern bool GenerateTSGRPC(const Parser &parser, const std::string &path, const std::string &file_name); - -extern bool GenerateRustModuleRootFile(const Parser &parser, - const std::string &path); } // namespace flatbuffers #endif // FLATBUFFERS_IDL_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h index 067222d9dc..4690434db6 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h @@ -10,7 +10,7 @@ // generated, otherwise it may not be compatible. static_assert(FLATBUFFERS_VERSION_MAJOR == 23 && FLATBUFFERS_VERSION_MINOR == 5 && - FLATBUFFERS_VERSION_REVISION == 9, + FLATBUFFERS_VERSION_REVISION == 26, "Non-compatible flatbuffers version included"); namespace reflection { diff --git a/contrib/libs/flatbuffers/include/flatbuffers/table.h b/contrib/libs/flatbuffers/include/flatbuffers/table.h index 9ceafaa143..c5d548c21e 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/table.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/table.h @@ -153,7 +153,7 @@ class Table { return verifier.Check(field_offset != 0) && verifier.VerifyOffset<OffsetT>(data_, field_offset); } - + bool VerifyOffset64(const Verifier &verifier, voffset_t field) const { return VerifyOffset<uoffset64_t>(verifier, field); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/util.h b/contrib/libs/flatbuffers/include/flatbuffers/util.h index 03f61834c0..c781b7e233 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/util.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/util.h @@ -257,7 +257,7 @@ inline void strtoval_impl(double *val, const char *str, char **endptr) { } // UBSAN: double to float is safe if numeric_limits<float>::is_iec559 is true. -__suppress_ubsan__("float-cast-overflow") +FLATBUFFERS_SUPPRESS_UBSAN("float-cast-overflow") inline void strtoval_impl(float *val, const char *str, char **endptr) { *val = __strtof_impl(str, endptr); } @@ -623,7 +623,7 @@ inline bool EscapeString(const char *s, size_t length, std::string *_text, // we previously checked for non-UTF-8, so we shouldn't reach // here. // - // 2) We reached here by someone calling GenerateText() + // 2) We reached here by someone calling GenText() // on a previously-serialized flatbuffer. The data might have // non-UTF-8 Strings, or might be corrupt. // diff --git a/contrib/libs/flatbuffers/include/flatbuffers/vector.h b/contrib/libs/flatbuffers/include/flatbuffers/vector.h index 848e6c0b25..eb67922230 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/vector.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/vector.h @@ -147,12 +147,10 @@ struct VectorReverseIterator : public std::reverse_iterator<Iterator> { // Vector::data() assumes the vector elements start after the length field. template<typename T, typename SizeT = uoffset_t> class Vector { public: - typedef VectorIterator<T, - typename IndirectHelper<T>::mutable_return_type, + typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type, uint8_t *, SizeT> iterator; - typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type, - SizeT> + typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type, SizeT> const_iterator; typedef VectorReverseIterator<iterator> reverse_iterator; typedef VectorReverseIterator<const_iterator> const_reverse_iterator; @@ -171,8 +169,7 @@ template<typename T, typename SizeT = uoffset_t> class Vector { typedef SizeT size_type; typedef typename IndirectHelper<T>::return_type return_type; - typedef typename IndirectHelper<T>::mutable_return_type - mutable_return_type; + typedef typename IndirectHelper<T>::mutable_return_type mutable_return_type; typedef return_type value_type; return_type Get(SizeT i) const { diff --git a/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h b/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h index 7fd2551cfc..2055ce9c7f 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/vector_downward.h @@ -17,9 +17,8 @@ #ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_ #define FLATBUFFERS_VECTOR_DOWNWARD_H_ -#include <cstdint> - #include <algorithm> +#include <cstdint> #include "base.h" #include "default_allocator.h" @@ -167,7 +166,9 @@ template<typename SizeT = uoffset_t> class vector_downward { inline SizeT size() const { return size_; } // The size of the buffer part of the vector that is currently unused. - SizeT unused_buffer_size() const { return static_cast<SizeT>(cur_ - scratch_); } + SizeT unused_buffer_size() const { + return static_cast<SizeT>(cur_ - scratch_); + } // The size of the scratch part of the vector. SizeT scratch_size() const { return static_cast<SizeT>(scratch_ - buf_); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/verifier.h b/contrib/libs/flatbuffers/include/flatbuffers/verifier.h index 86dbcb4eac..3386408465 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/verifier.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/verifier.h @@ -177,8 +177,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS { return true; } - __suppress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart( - const uint8_t *const table) { + FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") + bool VerifyTableStart(const uint8_t *const table) { // Check the vtable offset. const auto tableo = static_cast<size_t>(table - buf_); if (!Verify<soffset_t>(tableo)) return false; @@ -246,7 +246,9 @@ class Verifier FLATBUFFERS_FINAL_CLASS { template<typename T, typename SizeT = uoffset_t> bool VerifySizePrefixedBuffer(const char *const identifier) { return Verify<SizeT>(0U) && - Check(ReadScalar<SizeT>(buf_) == size_ - sizeof(SizeT)) && + // Ensure the prefixed size is within the bounds of the provided + // length. + Check(ReadScalar<SizeT>(buf_) + sizeof(SizeT) <= size_) && VerifyBufferFromStart<T>(identifier, sizeof(SizeT)); } diff --git a/contrib/libs/flatbuffers/src/bfbs_gen.h b/contrib/libs/flatbuffers/src/bfbs_gen.h index ed20dc8965..c1beb0247e 100644 --- a/contrib/libs/flatbuffers/src/bfbs_gen.h +++ b/contrib/libs/flatbuffers/src/bfbs_gen.h @@ -101,15 +101,15 @@ class BaseBfbsGenerator : public CodeGenerator { virtual ~BaseBfbsGenerator() {} BaseBfbsGenerator() : schema_(nullptr) {} - virtual Status GenerateFromSchema( - const reflection::Schema *schema) = 0; + virtual Status GenerateFromSchema(const reflection::Schema *schema, + const CodeGenOptions &options) = 0; virtual uint64_t SupportedAdvancedFeatures() const = 0; // Override of the Generator::GenerateCode method that does the initial // deserialization and verification steps. - Status GenerateCode(const uint8_t *buffer, - int64_t length) FLATBUFFERS_OVERRIDE { + Status GenerateCode(const uint8_t *buffer, int64_t length, + const CodeGenOptions &options) FLATBUFFERS_OVERRIDE { flatbuffers::Verifier verifier(buffer, static_cast<size_t>(length)); if (!reflection::VerifySchemaBuffer(verifier)) { return FAILED_VERIFICATION; @@ -124,7 +124,7 @@ class BaseBfbsGenerator : public CodeGenerator { return FAILED_VERIFICATION; } - Status status = GenerateFromSchema(schema_); + Status status = GenerateFromSchema(schema_, options); schema_ = nullptr; return status; } diff --git a/contrib/libs/flatbuffers/src/bfbs_gen_lua.cpp b/contrib/libs/flatbuffers/src/bfbs_gen_lua.cpp index 8823d912b1..185e859620 100644 --- a/contrib/libs/flatbuffers/src/bfbs_gen_lua.cpp +++ b/contrib/libs/flatbuffers/src/bfbs_gen_lua.cpp @@ -28,6 +28,7 @@ #include "bfbs_namer.h" // The intermediate representation schema. +#include "flatbuffers/code_generator.h" #include "flatbuffers/reflection.h" #include "flatbuffers/reflection_generated.h" @@ -78,7 +79,10 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { flatc_version_(flatc_version), namer_(LuaDefaultConfig(), LuaKeywords()) {} - Status GenerateFromSchema(const r::Schema *schema) FLATBUFFERS_OVERRIDE { + Status GenerateFromSchema(const r::Schema *schema, + const CodeGenOptions &options) + FLATBUFFERS_OVERRIDE { + options_ = options; if (!GenerateEnums(schema->enums())) { return ERROR; } if (!GenerateObjects(schema->objects(), schema->root_table())) { return ERROR; @@ -88,10 +92,9 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { using BaseBfbsGenerator::GenerateCode; - Status GenerateCode(const Parser &parser, const std::string &path, - const std::string &filename) FLATBUFFERS_OVERRIDE { - if (!GenerateLua(parser, path, filename)) { return ERROR; } - return OK; + Status GenerateCode(const Parser &, const std::string &, + const std::string &) override { + return Status::NOT_IMPLEMENTED; } Status GenerateMakeRule(const Parser &parser, const std::string &path, @@ -653,12 +656,15 @@ class LuaBfbsGenerator : public BaseBfbsGenerator { // TODO(derekbailey): figure out a save file without depending on util.h EnsureDirExists(path); - const std::string file_name = path + "/" + namer_.File(name); + const std::string file_name = + options_.output_path + path + "/" + namer_.File(name); SaveFile(file_name.c_str(), code, false); } std::unordered_set<std::string> keywords_; std::map<std::string, std::string> requires_; + CodeGenOptions options_; + const r::Object *current_obj_; const r::Enum *current_enum_; const std::string flatc_version_; diff --git a/contrib/libs/flatbuffers/src/bfbs_gen_nim.cpp b/contrib/libs/flatbuffers/src/bfbs_gen_nim.cpp index 45bd3c33d4..a8f4ee0c74 100644 --- a/contrib/libs/flatbuffers/src/bfbs_gen_nim.cpp +++ b/contrib/libs/flatbuffers/src/bfbs_gen_nim.cpp @@ -28,6 +28,7 @@ #include "bfbs_namer.h" // The intermediate representation schema. +#include "flatbuffers/code_generator.h" #include "flatbuffers/reflection.h" #include "flatbuffers/reflection_generated.h" @@ -95,7 +96,10 @@ class NimBfbsGenerator : public BaseBfbsGenerator { flatc_version_(flatc_version), namer_(NimDefaultConfig(), NimKeywords()) {} - Status GenerateFromSchema(const r::Schema *schema) FLATBUFFERS_OVERRIDE { + Status GenerateFromSchema(const r::Schema *schema, + const CodeGenOptions &options) + FLATBUFFERS_OVERRIDE { + options_ = options; ForAllEnums(schema->enums(), [&](const r::Enum *enum_def) { StartCodeBlock(enum_def); GenerateEnum(enum_def); @@ -671,12 +675,15 @@ class NimBfbsGenerator : public BaseBfbsGenerator { // TODO(derekbailey): figure out a save file without depending on util.h EnsureDirExists(path); - const std::string file_name = path + "/" + namer_.File(name); + const std::string file_name = + options_.output_path + path + "/" + namer_.File(name); SaveFile(file_name.c_str(), code, false); } std::unordered_set<std::string> keywords_; std::map<std::string, std::string> imports_; + CodeGenOptions options_; + const r::Object *current_obj_; const r::Enum *current_enum_; const std::string flatc_version_; diff --git a/contrib/libs/flatbuffers/src/code_generators.cpp b/contrib/libs/flatbuffers/src/code_generators.cpp index c5efb222b1..6a542103ab 100644 --- a/contrib/libs/flatbuffers/src/code_generators.cpp +++ b/contrib/libs/flatbuffers/src/code_generators.cpp @@ -30,9 +30,7 @@ namespace flatbuffers { -namespace { - -static std::string JavaCSharpMakeRule(const bool java, const Parser &parser, +std::string JavaCSharpMakeRule(const bool java, const Parser &parser, const std::string &path, const std::string &file_name) { const std::string file_extension = java ? ".java" : ".cs"; @@ -64,18 +62,6 @@ static std::string JavaCSharpMakeRule(const bool java, const Parser &parser, return make_rule; } - -static std::string BinaryFileName(const Parser &parser, const std::string &path, - const std::string &file_name) { - auto ext = parser.file_extension_.length() ? parser.file_extension_ : "bin"; - return path + file_name + "." + ext; -} - -} // namespace - - - - void CodeWriter::operator+=(std::string text) { if (!ignore_ident_ && !text.empty()) AppendIdent(stream_); @@ -346,48 +332,6 @@ std::string SimpleFloatConstantGenerator::NaN(float v) const { return this->NaN(static_cast<double>(v)); } - -std::string JavaMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { - return JavaCSharpMakeRule(true, parser, path, file_name); -} -std::string CSharpMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { - return JavaCSharpMakeRule(false, parser, path, file_name); -} - -bool GenerateBinary(const Parser &parser, const std::string &path, - const std::string &file_name) { - if (parser.opts.use_flexbuffers) { - auto data_vec = parser.flex_builder_.GetBuffer(); - auto data_ptr = reinterpret_cast<char *>(data(data_vec)); - return !parser.flex_builder_.GetSize() || - flatbuffers::SaveFile( - BinaryFileName(parser, path, file_name).c_str(), data_ptr, - parser.flex_builder_.GetSize(), true); - } - return !parser.builder_.GetSize() || - flatbuffers::SaveFile( - BinaryFileName(parser, path, file_name).c_str(), - reinterpret_cast<char *>(parser.builder_.GetBufferPointer()), - parser.builder_.GetSize(), true); -} - -std::string BinaryMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { - if (!parser.builder_.GetSize()) return ""; - std::string filebase = - flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); - std::string make_rule = - BinaryFileName(parser, path, filebase) + ": " + file_name; - auto included_files = - parser.GetIncludedFilesRecursive(parser.root_struct_def_->file); - for (auto it = included_files.begin(); it != included_files.end(); ++it) { - make_rule += " " + *it; - } - return make_rule; -} - } // namespace flatbuffers #if defined(_MSC_VER) diff --git a/contrib/libs/flatbuffers/src/file_name_saving_file_manager.cpp b/contrib/libs/flatbuffers/src/file_name_saving_file_manager.cpp index fc4a4aa1ec..b43c7b6eb0 100644 --- a/contrib/libs/flatbuffers/src/file_name_saving_file_manager.cpp +++ b/contrib/libs/flatbuffers/src/file_name_saving_file_manager.cpp @@ -37,8 +37,8 @@ class FileNameSavingFileManager : public FileManager { } bool Loadfile(const std::string &absolute_file_name, std::string *content) { - (void) absolute_file_name; - (void) content; + (void)absolute_file_name; + (void)content; return false; } diff --git a/contrib/libs/flatbuffers/src/flatc.cpp b/contrib/libs/flatbuffers/src/flatc.cpp index a1501712e5..202c3d644a 100644 --- a/contrib/libs/flatbuffers/src/flatc.cpp +++ b/contrib/libs/flatbuffers/src/flatc.cpp @@ -866,8 +866,11 @@ std::unique_ptr<Parser> FlatCompiler::GenerateCode(const FlatCOptions &options, // Prefer bfbs generators if present. if (code_generator->SupportsBfbsGeneration()) { - const CodeGenerator::Status status = - code_generator->GenerateCode(bfbs_buffer, bfbs_length); + CodeGenOptions code_gen_options; + code_gen_options.output_path = options.output_path; + + const CodeGenerator::Status status = code_generator->GenerateCode( + bfbs_buffer, bfbs_length, code_gen_options); if (status != CodeGenerator::Status::OK) { Error("Unable to generate " + code_generator->LanguageName() + " for " + filebase + code_generator->status_detail + @@ -968,7 +971,7 @@ int FlatCompiler::Compile(const FlatCOptions &options) { return 0; } - if (options.generators.empty()) { + if (options.generators.empty() && options.conform_to_schema.empty()) { Error("No generator registered"); return -1; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_binary.cpp b/contrib/libs/flatbuffers/src/idl_gen_binary.cpp index feb4e2f55e..7ed0a99ca6 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_binary.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_binary.cpp @@ -31,9 +31,46 @@ #include "flatbuffers/util.h" namespace flatbuffers { - namespace { +static std::string BinaryFileName(const Parser &parser, const std::string &path, + const std::string &file_name) { + auto ext = parser.file_extension_.length() ? parser.file_extension_ : "bin"; + return path + file_name + "." + ext; +} + +static bool GenerateBinary(const Parser &parser, const std::string &path, + const std::string &file_name) { + if (parser.opts.use_flexbuffers) { + auto data_vec = parser.flex_builder_.GetBuffer(); + auto data_ptr = reinterpret_cast<char *>(data(data_vec)); + return !parser.flex_builder_.GetSize() || + flatbuffers::SaveFile( + BinaryFileName(parser, path, file_name).c_str(), data_ptr, + parser.flex_builder_.GetSize(), true); + } + return !parser.builder_.GetSize() || + flatbuffers::SaveFile( + BinaryFileName(parser, path, file_name).c_str(), + reinterpret_cast<char *>(parser.builder_.GetBufferPointer()), + parser.builder_.GetSize(), true); +} + +static std::string BinaryMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { + if (!parser.builder_.GetSize()) return ""; + std::string filebase = + flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); + std::string make_rule = + BinaryFileName(parser, path, filebase) + ": " + file_name; + auto included_files = + parser.GetIncludedFilesRecursive(parser.root_struct_def_->file); + for (auto it = included_files.begin(); it != included_files.end(); ++it) { + make_rule += " " + *it; + } + return make_rule; +} + class BinaryCodeGenerator : public CodeGenerator { public: Status GenerateCode(const Parser &parser, const std::string &path, @@ -44,9 +81,8 @@ class BinaryCodeGenerator : public CodeGenerator { // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_cpp.cpp b/contrib/libs/flatbuffers/src/idl_gen_cpp.cpp index 6e22c9d219..21a21b8370 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_cpp.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_cpp.cpp @@ -377,10 +377,8 @@ class CppGenerator : public BaseGenerator { code_ += "#pragma clang system_header\n\n"; } - code_ += "#include \"flatbuffers/flatbuffers.h\""; - code_ += ""; - GenFlatbuffersVersionCheck(); - code_ += ""; + code_ += "#include <cstddef>"; + code_ += "#include <cstdint>"; SetNameSpace(struct_def.defined_namespace); auto name = Name(struct_def); @@ -779,7 +777,12 @@ class CppGenerator : public BaseGenerator { if (type.enum_def) return WrapInNameSpace(*type.enum_def); if (type.base_type == BASE_TYPE_BOOL) return "bool"; } - return StringOf(type.base_type); + // Get real underlying type for union type + auto base_type = type.base_type; + if (type.base_type == BASE_TYPE_UTYPE && type.enum_def != nullptr) { + base_type = type.enum_def->underlying_type.base_type; + } + return StringOf(base_type); } // Return a C++ pointer type, specialized to the actual struct/table types, @@ -1048,7 +1051,7 @@ class CppGenerator : public BaseGenerator { std::string UnionVectorVerifySignature(const EnumDef &enum_def) { const std::string name = Name(enum_def); - const std::string &type = opts_.scoped_enums ? name : "uint8_t"; + const std::string &type = opts_.scoped_enums ? name : GenTypeBasic(enum_def.underlying_type, false); return "bool Verify" + name + "Vector" + "(::flatbuffers::Verifier &verifier, " + "const ::flatbuffers::Vector<::flatbuffers::Offset<void>> " @@ -3496,12 +3499,13 @@ class CppGenerator : public BaseGenerator { } case BASE_TYPE_UTYPE: { value = StripUnionType(value); + auto underlying_type = GenTypeBasic(vector_type, false); const std::string &type = opts_.scoped_enums ? Name(*field.value.type.enum_def) - : "uint8_t"; + : underlying_type; auto enum_value = "__va->_" + value + "[i].type"; if (!opts_.scoped_enums) - enum_value = "static_cast<uint8_t>(" + enum_value + ")"; + enum_value = "static_cast<" + underlying_type + ">(" + enum_value + ")"; code += "_fbb.CreateVector<" + type + ">(" + value + ".size(), [](size_t i, _VectorArgs *__va) { return " + @@ -4066,8 +4070,8 @@ class CppGenerator : public BaseGenerator { } // namespace cpp -bool GenerateCPP(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateCPP(const Parser &parser, const std::string &path, + const std::string &file_name) { cpp::IDLOptionsCpp opts(parser.opts); // The '--cpp_std' argument could be extended (like ASAN): // Example: "flatc --cpp_std c++17:option1:option2". @@ -4105,8 +4109,8 @@ bool GenerateCPP(const Parser &parser, const std::string &path, return generator.generate(); } -std::string CPPMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { +static std::string CPPMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { const auto filebase = StripPath(StripExtension(file_name)); cpp::CppGenerator geneartor(parser, path, file_name, parser.opts); const auto included_files = parser.GetIncludedFilesRecursive(file_name); @@ -4130,9 +4134,8 @@ class CppCodeGenerator : public CodeGenerator { // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_cpp_yandex_maps_iter.cpp b/contrib/libs/flatbuffers/src/idl_gen_cpp_yandex_maps_iter.cpp index c368428950..5dbb2738d9 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_cpp_yandex_maps_iter.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_cpp_yandex_maps_iter.cpp @@ -748,9 +748,11 @@ class CppIterCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode( + const uint8_t* /* buffer */, + int64_t /* length */, + const CodeGenOptions& /* options */ + ) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_csharp.cpp b/contrib/libs/flatbuffers/src/idl_gen_csharp.cpp index 0dbcd4b927..369460d730 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_csharp.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_csharp.cpp @@ -625,7 +625,8 @@ class CSharpGenerator : public BaseGenerator { } // Get the value of a table verification function start - void GetStartOfTableVerifier(const StructDef &struct_def, std::string *code_ptr) { + void GetStartOfTableVerifier(const StructDef &struct_def, + std::string *code_ptr) { std::string &code = *code_ptr; code += "\n"; code += "static public class " + struct_def.name + "Verify\n"; @@ -645,17 +646,18 @@ class CSharpGenerator : public BaseGenerator { } std::string GetNestedFlatBufferName(const FieldDef &field) { - std::string name; + std::string name; if (field.nested_flatbuffer) { name = NamespacedName(*field.nested_flatbuffer); } else { name = ""; } - return name ; + return name; } // Generate the code to call the appropriate Verify function(s) for a field. - void GenVerifyCall(CodeWriter &code_, const FieldDef &field, const char *prefix) { + void GenVerifyCall(CodeWriter &code_, const FieldDef &field, + const char *prefix) { code_.SetValue("PRE", prefix); code_.SetValue("NAME", ConvertCase(field.name, Case::kUpperCamel)); code_.SetValue("REQUIRED", field.IsRequired() ? "Required" : ""); @@ -663,14 +665,16 @@ class CSharpGenerator : public BaseGenerator { code_.SetValue("TYPE", GenTypeGet(field.value.type)); code_.SetValue("INLINESIZE", NumToString(InlineSize(field.value.type))); code_.SetValue("OFFSET", NumToString(field.value.offset)); - + if (IsScalar(field.value.type.base_type) || IsStruct(field.value.type)) { code_.SetValue("ALIGN", NumToString(InlineAlignment(field.value.type))); code_ += - "{{PRE}} && verifier.VerifyField(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{INLINESIZE}} /*{{TYPE}}*/, {{ALIGN}}, {{REQUIRED_FLAG}})"; + "{{PRE}} && verifier.VerifyField(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{INLINESIZE}} /*{{TYPE}}*/, {{ALIGN}}, " + "{{REQUIRED_FLAG}})"; } else { - // TODO - probably code below should go to this 'else' - code_ += "{{PRE}}VerifyOffset{{REQUIRED}}(verifier, {{OFFSET}})\\"; + // TODO - probably code below should go to this 'else' - code_ += + // "{{PRE}}VerifyOffset{{REQUIRED}}(verifier, {{OFFSET}})\\"; } switch (field.value.type.base_type) { @@ -679,37 +683,47 @@ class CSharpGenerator : public BaseGenerator { code_.SetValue("ENUM_NAME1", field.value.type.enum_def->name); code_.SetValue("ENUM_NAME", union_name); code_.SetValue("SUFFIX", UnionTypeFieldSuffix()); - // Caution: This construction assumes, that UNION type id element has been created just before union data and - // its offset precedes union. Such assumption is common in flatbuffer implementation - code_.SetValue("TYPE_ID_OFFSET", NumToString(field.value.offset - sizeof(voffset_t))); - code_ += "{{PRE}} && verifier.VerifyUnion(tablePos, {{TYPE_ID_OFFSET}}, " - "{{OFFSET}} /*{{NAME}}*/, {{ENUM_NAME}}Verify.Verify, {{REQUIRED_FLAG}})"; + // Caution: This construction assumes, that UNION type id element has + // been created just before union data and its offset precedes union. + // Such assumption is common in flatbuffer implementation + code_.SetValue("TYPE_ID_OFFSET", + NumToString(field.value.offset - sizeof(voffset_t))); + code_ += + "{{PRE}} && verifier.VerifyUnion(tablePos, " + "{{TYPE_ID_OFFSET}}, " + "{{OFFSET}} /*{{NAME}}*/, {{ENUM_NAME}}Verify.Verify, " + "{{REQUIRED_FLAG}})"; break; } case BASE_TYPE_STRUCT: { if (!field.value.type.struct_def->fixed) { - code_ += "{{PRE}} && verifier.VerifyTable(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{TYPE}}Verify.Verify, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyTable(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{TYPE}}Verify.Verify, " + "{{REQUIRED_FLAG}})"; } break; } case BASE_TYPE_STRING: { - code_ += "{{PRE}} && verifier.VerifyString(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyString(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{REQUIRED_FLAG}})"; break; } case BASE_TYPE_VECTOR: { - switch (field.value.type.element) { case BASE_TYPE_STRING: { - code_ += "{{PRE}} && verifier.VerifyVectorOfStrings(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyVectorOfStrings(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{REQUIRED_FLAG}})"; break; } case BASE_TYPE_STRUCT: { if (!field.value.type.struct_def->fixed) { - code_ += "{{PRE}} && verifier.VerifyVectorOfTables(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{TYPE}}Verify.Verify, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyVectorOfTables(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{TYPE}}Verify.Verify, " + "{{REQUIRED_FLAG}})"; } else { code_.SetValue( "VECTOR_ELEM_INLINESIZE", @@ -733,16 +747,22 @@ class CSharpGenerator : public BaseGenerator { if (!nfn.empty()) { code_.SetValue("CPP_NAME", nfn); // FIXME: file_identifier. - code_ += "{{PRE}} && verifier.VerifyNestedBuffer(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{CPP_NAME}}Verify.Verify, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyNestedBuffer(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{CPP_NAME}}Verify.Verify, " + "{{REQUIRED_FLAG}})"; } else if (field.flexbuffer) { - code_ += "{{PRE}} && verifier.VerifyNestedBuffer(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, null, {{REQUIRED_FLAG}})"; + code_ += + "{{PRE}} && verifier.VerifyNestedBuffer(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, null, {{REQUIRED_FLAG}})"; } else { - code_.SetValue("VECTOR_ELEM_INLINESIZE", NumToString(InlineSize(field.value.type.VectorType()))); + code_.SetValue( + "VECTOR_ELEM_INLINESIZE", + NumToString(InlineSize(field.value.type.VectorType()))); code_ += - "{{PRE}} && verifier.VerifyVectorOfData(tablePos, " - "{{OFFSET}} /*{{NAME}}*/, {{VECTOR_ELEM_INLINESIZE}} /*{{TYPE}}*/, {{REQUIRED_FLAG}})"; + "{{PRE}} && verifier.VerifyVectorOfData(tablePos, " + "{{OFFSET}} /*{{NAME}}*/, {{VECTOR_ELEM_INLINESIZE}} " + "/*{{TYPE}}*/, {{REQUIRED_FLAG}})"; } break; } @@ -758,7 +778,7 @@ class CSharpGenerator : public BaseGenerator { // Generate table constructors, conditioned on its members' types. void GenTableVerifier(const StructDef &struct_def, std::string *code_ptr) { CodeWriter code_; - + GetStartOfTableVerifier(struct_def, code_ptr); // Generate struct fields accessors @@ -771,7 +791,7 @@ class CSharpGenerator : public BaseGenerator { } *code_ptr += code_.ToString(); - + GetEndOfTableVerifier(code_ptr); } @@ -787,7 +807,7 @@ class CSharpGenerator : public BaseGenerator { // verification - instead structure size is verified using VerifyField } else { // Create table verification function - GenTableVerifier(struct_def, code_ptr); + GenTableVerifier(struct_def, code_ptr); } } @@ -826,7 +846,7 @@ class CSharpGenerator : public BaseGenerator { // Force compile time error if not using the same version runtime. code += " public static void ValidateVersion() {"; code += " FlatBufferConstants."; - code += "FLATBUFFERS_23_5_9(); "; + code += "FLATBUFFERS_23_5_26(); "; code += "}\n"; // Generate a special accessor for the table that when used as the root @@ -1602,8 +1622,7 @@ class CSharpGenerator : public BaseGenerator { if (union_type.enum_def) { const auto &enum_def = *union_type.enum_def; - auto ret = - "\n\nstatic public class " + enum_def.name + "Verify\n"; + auto ret = "\n\nstatic public class " + enum_def.name + "Verify\n"; ret += "{\n"; ret += " static public bool Verify(Google.FlatBuffers.Verifier verifier, " @@ -1615,25 +1634,26 @@ class CSharpGenerator : public BaseGenerator { ret += " switch((" + enum_def.name + ")typeId)\n"; ret += " {\n"; - for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { + for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); + ++it) { const auto &ev = **it; if (ev.IsZero()) { continue; } ret += " case " + Name(enum_def) + "." + Name(ev) + ":\n"; if (IsString(ev.union_type)) { - ret += - " result = verifier.VerifyUnionString(tablePos);\n"; + ret += " result = verifier.VerifyUnionString(tablePos);\n"; ret += " break;"; } else if (ev.union_type.base_type == BASE_TYPE_STRUCT) { - if (! ev.union_type.struct_def->fixed) { + if (!ev.union_type.struct_def->fixed) { auto type = GenTypeGet(ev.union_type); - ret += " result = " + type + "Verify.Verify(verifier, tablePos);\n"; + ret += " result = " + type + + "Verify.Verify(verifier, tablePos);\n"; } else { ret += " result = verifier.VerifyUnionData(tablePos, " + - NumToString(InlineSize(ev.union_type)) + ", " + - NumToString(InlineAlignment(ev.union_type)) + - ");\n";; + NumToString(InlineSize(ev.union_type)) + ", " + + NumToString(InlineAlignment(ev.union_type)) + ");\n"; + ; } ret += " break;"; } else { @@ -1676,7 +1696,7 @@ class CSharpGenerator : public BaseGenerator { // Type code += " public " + enum_def.name + " Type { get; set; }\n"; // Value - code += " public object " + class_member + " { get; set; }\n"; + code += " public object " + class_member + " { get; set; }\n"; code += "\n"; // Constructor code += " public " + union_name + "() {\n"; @@ -1736,7 +1756,7 @@ class CSharpGenerator : public BaseGenerator { code += "}\n\n"; code += GenUnionVerify(enum_def.underlying_type); - + // JsonConverter if (opts.cs_gen_json_serializer) { if (enum_def.attributes.Lookup("private")) { @@ -1773,7 +1793,7 @@ class CSharpGenerator : public BaseGenerator { " _o, " "Newtonsoft.Json.JsonSerializer serializer) {\n"; code += " if (_o == null) return;\n"; - code += " serializer.Serialize(writer, _o." + class_member + ");\n"; + code += " serializer.Serialize(writer, _o." + class_member + ");\n"; code += " }\n"; code += " public override object ReadJson(Newtonsoft.Json.JsonReader " @@ -2498,8 +2518,8 @@ class CSharpGenerator : public BaseGenerator { }; } // namespace csharp -bool GenerateCSharp(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateCSharp(const Parser &parser, const std::string &path, + const std::string &file_name) { csharp::CSharpGenerator generator(parser, path, file_name); return generator.generate(); } @@ -2514,16 +2534,15 @@ class CSharpCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } Status GenerateMakeRule(const Parser &parser, const std::string &path, const std::string &filename, std::string &output) override { - output = CSharpMakeRule(parser, path, filename); + output = JavaCSharpMakeRule(false, parser, path, filename); return Status::OK; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_dart.cpp b/contrib/libs/flatbuffers/src/idl_gen_dart.cpp index 299409bac2..a4df1f4dfc 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_dart.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_dart.cpp @@ -90,8 +90,8 @@ class DartGenerator : public BaseGenerator { template<typename T> void import_generator(const std::vector<T *> &definitions, - const std::string &included, - std::set<std::string> &imports) { + const std::string &included, + std::set<std::string> &imports) { for (const auto &item : definitions) { if (item->file == included) { std::string component = namer_.Namespace(*item->defined_namespace); @@ -760,9 +760,7 @@ class DartGenerator : public BaseGenerator { std::string getDefaultValue(const Value &value) const { if (!value.constant.empty() && value.constant != "0") { - if (IsBool(value.type.base_type)) { - return "true"; - } + if (IsBool(value.type.base_type)) { return "true"; } if (IsScalar(value.type.base_type)) { if (StringIsFlatbufferNan(value.constant)) { return "double.nan"; @@ -1124,14 +1122,14 @@ class DartGenerator : public BaseGenerator { }; } // namespace dart -bool GenerateDart(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateDart(const Parser &parser, const std::string &path, + const std::string &file_name) { dart::DartGenerator generator(parser, path, file_name); return generator.generate(); } -std::string DartMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { +static std::string DartMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { auto filebase = flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); dart::DartGenerator generator(parser, path, file_name); @@ -1154,9 +1152,8 @@ class DartCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_fbs.cpp b/contrib/libs/flatbuffers/src/idl_gen_fbs.cpp index f71c21f97d..f9844854d4 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_fbs.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_fbs.cpp @@ -28,6 +28,7 @@ #include "flatbuffers/util.h" namespace flatbuffers { +namespace { static std::string GenType(const Type &type, bool underlying = false) { switch (type.base_type) { @@ -252,8 +253,9 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema, } // Generate a flatbuffer schema from the Parser's internal representation. -std::string GenerateFBS(const Parser &parser, const std::string &file_name, - bool no_log = false) { +static std::string GenerateFBS(const Parser &parser, + const std::string &file_name, + bool no_log = false) { // Proto namespaces may clash with table names, escape the ones that were // generated from a table: for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); @@ -374,8 +376,8 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name, return schema; } -bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name, bool no_log = false) { +static bool GenerateFBS(const Parser &parser, const std::string &path, + const std::string &file_name, bool no_log = false) { const std::string fbs = GenerateFBS(parser, file_name, no_log); if (fbs.empty()) { return false; } // TODO: Use LogCompilerWarn @@ -387,8 +389,6 @@ bool GenerateFBS(const Parser &parser, const std::string &path, return SaveFile((path + file_name + ".fbs").c_str(), fbs, false); } -namespace { - class FBSCodeGenerator : public CodeGenerator { public: explicit FBSCodeGenerator(const bool no_log) : no_log_(no_log) {} @@ -399,11 +399,16 @@ class FBSCodeGenerator : public CodeGenerator { return Status::OK; } + Status GenerateCodeString(const Parser &parser, const std::string &filename, + std::string &output) override { + output = GenerateFBS(parser, filename, no_log_); + return Status::OK; + } + // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_go.cpp b/contrib/libs/flatbuffers/src/idl_gen_go.cpp index 0f2882b758..e1e84a0e58 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_go.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_go.cpp @@ -1606,8 +1606,8 @@ class GoGenerator : public BaseGenerator { }; } // namespace go -bool GenerateGo(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateGo(const Parser &parser, const std::string &path, + const std::string &file_name) { go::GoGenerator generator(parser, path, file_name, parser.opts.go_namespace); return generator.generate(); } @@ -1622,9 +1622,8 @@ class GoCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_java.cpp b/contrib/libs/flatbuffers/src/idl_gen_java.cpp index 34895ee9dc..252c60f6d9 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_java.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_java.cpp @@ -69,9 +69,10 @@ static std::set<std::string> JavaKeywords() { }; } -static const TypedFloatConstantGenerator JavaFloatGen("Double.", "Float.", "NaN", - "POSITIVE_INFINITY", - "NEGATIVE_INFINITY"); +static const TypedFloatConstantGenerator JavaFloatGen("Double.", "Float.", + "NaN", + "POSITIVE_INFINITY", + "NEGATIVE_INFINITY"); static const CommentConfig comment_config = { "/**", @@ -79,7 +80,7 @@ static const CommentConfig comment_config = { " */", }; -} // namespace +} // namespace class JavaGenerator : public BaseGenerator { struct FieldArrayLength { @@ -89,16 +90,15 @@ class JavaGenerator : public BaseGenerator { public: JavaGenerator(const Parser &parser, const std::string &path, - const std::string &file_name, - const std::string &package_prefix) + const std::string &file_name, const std::string &package_prefix) : BaseGenerator(parser, path, file_name, "", ".", "java"), - cur_name_space_(nullptr), + cur_name_space_(nullptr), namer_(WithFlagOptions(JavaDefaultConfig(), parser.opts, path), JavaKeywords()) { if (!package_prefix.empty()) { std::istringstream iss(package_prefix); std::string component; - while(std::getline(iss, component, '.')) { + while (std::getline(iss, component, '.')) { package_prefix_ns_.components.push_back(component); } package_prefix_ = package_prefix_ns_.GetFullyQualifiedName("") + "."; @@ -184,10 +184,8 @@ class JavaGenerator : public BaseGenerator { code = "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n"; Namespace combined_ns = package_prefix_ns_; - std::copy( - ns.components.begin(), - ns.components.end(), - std::back_inserter(combined_ns.components)); + std::copy(ns.components.begin(), ns.components.end(), + std::back_inserter(combined_ns.components)); const std::string namespace_name = FullNamespace(".", combined_ns); if (!namespace_name.empty()) { @@ -368,9 +366,9 @@ class JavaGenerator : public BaseGenerator { FLATBUFFERS_ASSERT(value.type.enum_def); auto &enum_def = *value.type.enum_def; auto enum_val = enum_def.FindByValue(value.constant); - return - enum_val ? Prefixed(namer_.NamespacedEnumVariant(enum_def, *enum_val)) - : value.constant; + return enum_val + ? Prefixed(namer_.NamespacedEnumVariant(enum_def, *enum_val)) + : value.constant; } std::string GenDefaultValue(const FieldDef &field) const { @@ -703,7 +701,7 @@ class JavaGenerator : public BaseGenerator { // Force compile time error if not using the same version runtime. code += " public static void ValidateVersion() {"; code += " Constants."; - code += "FLATBUFFERS_23_5_9(); "; + code += "FLATBUFFERS_23_5_26(); "; code += "}\n"; // Generate a special accessor for the table that when used as the root @@ -1653,9 +1651,9 @@ class JavaGenerator : public BaseGenerator { break; case BASE_TYPE_UNION: array_type = "int"; - element_type = - Prefixed(namer_.NamespacedType(*field.value.type.enum_def)) - + "Union"; + element_type = Prefixed(namer_.NamespacedType( + *field.value.type.enum_def)) + + "Union"; to_array = element_type + ".pack(builder, _o." + namer_.Method("get", property_name) + "()[_j])"; break; @@ -2007,8 +2005,7 @@ class JavaGenerator : public BaseGenerator { case BASE_TYPE_UNION: { if (wrap_in_namespace) { - type_name = - Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; + type_name = Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; } else { type_name = namer_.Type(*type.enum_def) + "Union"; } @@ -2042,15 +2039,13 @@ class JavaGenerator : public BaseGenerator { type_name.replace(type_name.length() - type_name_length, type_name_length, new_type_name); } else if (type.element == BASE_TYPE_UNION) { - type_name = - Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; + type_name = Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; } break; } case BASE_TYPE_UNION: { - type_name = - Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; + type_name = Prefixed(namer_.NamespacedType(*type.enum_def)) + "Union"; break; } default: break; @@ -2192,12 +2187,11 @@ class JavaGenerator : public BaseGenerator { std::string package_prefix_; Namespace package_prefix_ns_; - }; } // namespace java -bool GenerateJava(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateJava(const Parser &parser, const std::string &path, + const std::string &file_name) { java::JavaGenerator generator(parser, path, file_name, parser.opts.java_package_prefix); return generator.generate(); @@ -2213,16 +2207,15 @@ class JavaCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } Status GenerateMakeRule(const Parser &parser, const std::string &path, const std::string &filename, std::string &output) override { - output = JavaMakeRule(parser, path, filename); + output = JavaCSharpMakeRule(true, parser, path, filename); return Status::OK; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp b/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp index 3849da856a..ed891ab2e2 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_json_schema.cpp @@ -30,8 +30,7 @@ namespace jsons { namespace { -template<class T> -static std::string GenFullName(const T *enum_def) { +template<class T> static std::string GenFullName(const T *enum_def) { std::string full_name; const auto &name_spaces = enum_def->defined_namespace->components; for (auto ns = name_spaces.cbegin(); ns != name_spaces.cend(); ++ns) { @@ -41,8 +40,7 @@ static std::string GenFullName(const T *enum_def) { return full_name; } -template<class T> -static std::string GenTypeRef(const T *enum_def) { +template<class T> static std::string GenTypeRef(const T *enum_def) { return "\"$ref\" : \"#/definitions/" + GenFullName(enum_def) + "\""; } @@ -144,7 +142,7 @@ static std::string GenType(const Type &type) { } } -} // namespace +} // namespace class JsonSchemaGenerator : public BaseGenerator { private: @@ -319,20 +317,13 @@ class JsonSchemaGenerator : public BaseGenerator { }; } // namespace jsons -bool GenerateJsonSchema(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateJsonSchema(const Parser &parser, const std::string &path, + const std::string &file_name) { jsons::JsonSchemaGenerator generator(parser, path, file_name); if (!generator.generate()) { return false; } return generator.save(); } -bool GenerateJsonSchema(const Parser &parser, std::string *json) { - jsons::JsonSchemaGenerator generator(parser, "", ""); - if (!generator.generate()) { return false; } - *json = generator.getJson(); - return true; -} - namespace { class JsonSchemaCodeGenerator : public CodeGenerator { @@ -343,9 +334,8 @@ class JsonSchemaCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp b/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp index eeaca94854..ecea21edc9 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_kotlin.cpp @@ -70,7 +70,7 @@ static Namer::Config KotlinDefaultConfig() { /*filename_suffix=*/"", /*filename_extension=*/".kt" }; } -} // namespace +} // namespace class KotlinGenerator : public BaseGenerator { public: @@ -524,7 +524,7 @@ class KotlinGenerator : public BaseGenerator { // runtime. GenerateFunOneLine( writer, "validateVersion", "", "", - [&]() { writer += "Constants.FLATBUFFERS_23_5_9()"; }, + [&]() { writer += "Constants.FLATBUFFERS_23_5_26()"; }, options.gen_jvmstatic); GenerateGetRootAsAccessors(namer_.Type(struct_def), writer, options); @@ -1593,8 +1593,8 @@ class KotlinGenerator : public BaseGenerator { }; } // namespace kotlin -bool GenerateKotlin(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateKotlin(const Parser &parser, const std::string &path, + const std::string &file_name) { kotlin::KotlinGenerator generator(parser, path, file_name); return generator.generate(); } @@ -1609,9 +1609,8 @@ class KotlinCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp b/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp index a8b0a6f7a5..37c95e9600 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_lobster.cpp @@ -63,8 +63,10 @@ class LobsterGenerator : public BaseGenerator { std::string GenTypeName(const Type &type) { auto bits = NumToString(SizeOf(type.base_type) * 8); if (IsInteger(type.base_type)) { - if (IsUnsigned(type.base_type)) return "uint" + bits; - else return "int" + bits; + if (IsUnsigned(type.base_type)) + return "uint" + bits; + else + return "int" + bits; } if (IsFloat(type.base_type)) return "float" + bits; if (IsString(type)) return "string"; @@ -120,16 +122,17 @@ class LobsterGenerator : public BaseGenerator { auto defval = field.IsOptional() ? "0" : field.value.constant; acc = "buf_.flatbuffers_field_" + GenTypeName(field.value.type) + "(pos_, " + offsets + ", " + defval + ")"; - if (IsBool(field.value.type.base_type)) - acc = "bool(" + acc + ")"; + if (IsBool(field.value.type.base_type)) acc = "bool(" + acc + ")"; } if (field.value.type.enum_def) acc = NormalizedName(*field.value.type.enum_def) + "(" + acc + ")"; if (field.IsOptional()) { acc += ", buf_.flatbuffers_field_present(pos_, " + offsets + ")"; - code += def + "() -> " + LobsterType(field.value.type) + ", bool:\n return " + acc + "\n"; + code += def + "() -> " + LobsterType(field.value.type) + + ", bool:\n return " + acc + "\n"; } else { - code += def + "() -> " + LobsterType(field.value.type) + ":\n return " + acc + "\n"; + code += def + "() -> " + LobsterType(field.value.type) + + ":\n return " + acc + "\n"; } return; } @@ -150,7 +153,8 @@ class LobsterGenerator : public BaseGenerator { } case BASE_TYPE_STRING: code += def + - "() -> string:\n return buf_.flatbuffers_field_string(pos_, " + + "() -> string:\n return " + "buf_.flatbuffers_field_string(pos_, " + offsets + ")\n"; break; case BASE_TYPE_VECTOR: { @@ -161,7 +165,9 @@ class LobsterGenerator : public BaseGenerator { if (!(vectortype.struct_def->fixed)) { start = "buf_.flatbuffers_indirect(" + start + ")"; } - code += def + "(i:int) -> " + NamespacedName(*field.value.type.struct_def) + ":\n return "; + code += def + "(i:int) -> " + + NamespacedName(*field.value.type.struct_def) + + ":\n return "; code += NamespacedName(*field.value.type.struct_def) + " { buf_, " + start + " }\n"; } else { @@ -169,7 +175,8 @@ class LobsterGenerator : public BaseGenerator { code += def + "(i:int) -> string:\n return "; code += "buf_.flatbuffers_string"; } else { - code += def + "(i:int) -> " + LobsterType(vectortype) + ":\n return "; + code += def + "(i:int) -> " + LobsterType(vectortype) + + ":\n return "; code += "buf_.read_" + GenTypeName(vectortype) + "_le"; } code += "(buf_.flatbuffers_field_vector(pos_, " + offsets + @@ -398,8 +405,8 @@ class LobsterGenerator : public BaseGenerator { } // namespace lobster -bool GenerateLobster(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateLobster(const Parser &parser, const std::string &path, + const std::string &file_name) { lobster::LobsterGenerator generator(parser, path, file_name); return generator.generate(); } @@ -414,9 +421,8 @@ class LobsterCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_lua.cpp b/contrib/libs/flatbuffers/src/idl_gen_lua.cpp deleted file mode 100644 index 551a4b26f8..0000000000 --- a/contrib/libs/flatbuffers/src/idl_gen_lua.cpp +++ /dev/null @@ -1,806 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// independent from idl_parser, since this code is not needed for most clients - -#include "idl_gen_lua.h" - -#include <string> -#include <unordered_set> - -#include "flatbuffers/code_generators.h" -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" -#include "flatbuffers/util.h" - -namespace flatbuffers { -namespace lua { - -// Hardcode spaces per indentation. -const CommentConfig def_comment = { nullptr, "--", nullptr }; -const char *Indent = " "; -const char *Comment = "-- "; -const char *End = "end\n"; -const char *EndFunc = "end\n"; -const char *SelfData = "self.view"; -const char *SelfDataPos = "self.view.pos"; -const char *SelfDataBytes = "self.view.bytes"; - -class LuaGenerator : public BaseGenerator { - public: - LuaGenerator(const Parser &parser, const std::string &path, - const std::string &file_name) - : BaseGenerator(parser, path, file_name, "" /* not used */, - "" /* not used */, "lua") { - static const char *const keywords[] = { - "and", "break", "do", "else", "elseif", "end", "false", "for", - "function", "goto", "if", "in", "local", "nil", "not", "or", - "repeat", "return", "then", "true", "until", "while" - }; - keywords_.insert(std::begin(keywords), std::end(keywords)); - } - - // Most field accessors need to retrieve and test the field offset first, - // this is the prefix code for that. - std::string OffsetPrefix(const FieldDef &field) { - return std::string(Indent) + "local o = " + SelfData + ":Offset(" + - NumToString(field.value.offset) + ")\n" + Indent + - "if o ~= 0 then\n"; - } - - // Begin a class declaration. - void BeginClass(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "local " + NormalizedName(struct_def) + " = {} -- the module\n"; - code += "local " + NormalizedMetaName(struct_def) + - " = {} -- the class metatable\n"; - code += "\n"; - } - - // Begin enum code with a class declaration. - void BeginEnum(const std::string &class_name, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "local " + class_name + " = {\n"; - } - - std::string EscapeKeyword(const std::string &name) const { - return keywords_.find(name) == keywords_.end() ? name : "_" + name; - } - - std::string NormalizedName(const Definition &definition) const { - return EscapeKeyword(definition.name); - } - - std::string NormalizedName(const EnumVal &ev) const { - return EscapeKeyword(ev.name); - } - - std::string NormalizedMetaName(const Definition &definition) const { - return EscapeKeyword(definition.name) + "_mt"; - } - - // A single enum member. - void EnumMember(const EnumDef &enum_def, const EnumVal &ev, - std::string *code_ptr) { - std::string &code = *code_ptr; - code += std::string(Indent) + NormalizedName(ev) + " = " + - enum_def.ToString(ev) + ",\n"; - } - - // End enum code. - void EndEnum(std::string *code_ptr) { - std::string &code = *code_ptr; - code += "}\n"; - } - - void GenerateNewObjectPrototype(const StructDef &struct_def, - std::string *code_ptr) { - std::string &code = *code_ptr; - - code += "function " + NormalizedName(struct_def) + ".New()\n"; - code += std::string(Indent) + "local o = {}\n"; - code += std::string(Indent) + - "setmetatable(o, {__index = " + NormalizedMetaName(struct_def) + - "})\n"; - code += std::string(Indent) + "return o\n"; - code += EndFunc; - } - - // Initialize a new struct or table from existing data. - void NewRootTypeFromBuffer(const StructDef &struct_def, - std::string *code_ptr) { - std::string &code = *code_ptr; - - code += "function " + NormalizedName(struct_def) + ".GetRootAs" + - NormalizedName(struct_def) + "(buf, offset)\n"; - code += std::string(Indent) + "if type(buf) == \"string\" then\n"; - code += std::string(Indent) + Indent + - "buf = flatbuffers.binaryArray.New(buf)\n"; - code += std::string(Indent) + "end\n"; - code += std::string(Indent) + - "local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)\n"; - code += std::string(Indent) + "local o = " + NormalizedName(struct_def) + - ".New()\n"; - code += std::string(Indent) + "o:Init(buf, n + offset)\n"; - code += std::string(Indent) + "return o\n"; - code += EndFunc; - } - - // Initialize an existing object with other data, to avoid an allocation. - void InitializeExisting(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - - GenReceiver(struct_def, code_ptr); - code += "Init(buf, pos)\n"; - code += - std::string(Indent) + SelfData + " = flatbuffers.view.New(buf, pos)\n"; - code += EndFunc; - } - - // Get the length of a vector. - void GetVectorLen(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - - GenReceiver(struct_def, code_ptr); - code += - ConvertCase(NormalizedName(field), Case::kUpperCamel) + "Length()\n"; - code += OffsetPrefix(field); - code += - std::string(Indent) + Indent + "return " + SelfData + ":VectorLen(o)\n"; - code += std::string(Indent) + End; - code += std::string(Indent) + "return 0\n"; - code += EndFunc; - } - - // Get the value of a struct's scalar. - void GetScalarFieldOfStruct(const StructDef &struct_def, - const FieldDef &field, std::string *code_ptr) { - std::string &code = *code_ptr; - std::string getter = GenGetter(field.value.type); - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "()\n"; - code += std::string(Indent) + "return " + getter; - code += std::string(SelfDataPos) + " + " + NumToString(field.value.offset) + - ")\n"; - code += EndFunc; - } - - // Get the value of a table's scalar. - void GetScalarFieldOfTable(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - std::string getter = GenGetter(field.value.type); - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "()\n"; - code += OffsetPrefix(field); - getter += std::string("o + ") + SelfDataPos + ")"; - auto is_bool = field.value.type.base_type == BASE_TYPE_BOOL; - if (is_bool) { getter = "(" + getter + " ~= 0)"; } - code += std::string(Indent) + Indent + "return " + getter + "\n"; - code += std::string(Indent) + End; - std::string default_value; - if (is_bool) { - default_value = field.value.constant == "0" ? "false" : "true"; - } else { - default_value = field.value.constant; - } - code += std::string(Indent) + "return " + default_value + "\n"; - code += EndFunc; - } - - // Get a struct by initializing an existing struct. - // Specific to Struct. - void GetStructFieldOfStruct(const StructDef &struct_def, - const FieldDef &field, std::string *code_ptr) { - std::string &code = *code_ptr; - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "(obj)\n"; - code += std::string(Indent) + "obj:Init(" + SelfDataBytes + ", " + - SelfDataPos + " + "; - code += NumToString(field.value.offset) + ")\n"; - code += std::string(Indent) + "return obj\n"; - code += EndFunc; - } - - // Get a struct by initializing an existing struct. - // Specific to Table. - void GetStructFieldOfTable(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "()\n"; - code += OffsetPrefix(field); - if (field.value.type.struct_def->fixed) { - code += - std::string(Indent) + Indent + "local x = o + " + SelfDataPos + "\n"; - } else { - code += std::string(Indent) + Indent + "local x = " + SelfData + - ":Indirect(o + " + SelfDataPos + ")\n"; - } - code += std::string(Indent) + Indent + "local obj = require('" + - TypeNameWithNamespace(field) + "').New()\n"; - code += - std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n"; - code += std::string(Indent) + Indent + "return obj\n"; - code += std::string(Indent) + End; - code += EndFunc; - } - - // Get the value of a string. - void GetStringField(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "()\n"; - code += OffsetPrefix(field); - code += - std::string(Indent) + Indent + "return " + GenGetter(field.value.type); - code += std::string("o + ") + SelfDataPos + ")\n"; - code += std::string(Indent) + End; - code += EndFunc; - } - - // Get the value of a union from an object. - void GetUnionField(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel) + "()\n"; - code += OffsetPrefix(field); - - // TODO(rw): this works and is not the good way to it: - // bool is_native_table = TypeName(field) == "*flatbuffers.Table"; - // if (is_native_table) { - // code += std::string(Indent) + Indent + "from flatbuffers.table import - // Table\n"; - //} else { - // code += std::string(Indent) + Indent + - // code += "from ." + TypeName(field) + " import " + TypeName(field) + - // "\n"; - //} - code += - std::string(Indent) + Indent + - "local obj = " - "flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)\n"; - code += std::string(Indent) + Indent + GenGetter(field.value.type) + - "obj, o)\n"; - code += std::string(Indent) + Indent + "return obj\n"; - code += std::string(Indent) + End; - code += EndFunc; - } - - // Get the value of a vector's struct member. - void GetMemberOfVectorOfStruct(const StructDef &struct_def, - const FieldDef &field, std::string *code_ptr) { - std::string &code = *code_ptr; - auto vectortype = field.value.type.VectorType(); - - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "(j)\n"; - code += OffsetPrefix(field); - code += - std::string(Indent) + Indent + "local x = " + SelfData + ":Vector(o)\n"; - code += std::string(Indent) + Indent + "x = x + ((j-1) * "; - code += NumToString(InlineSize(vectortype)) + ")\n"; - if (!(vectortype.struct_def->fixed)) { - code += - std::string(Indent) + Indent + "x = " + SelfData + ":Indirect(x)\n"; - } - code += std::string(Indent) + Indent + "local obj = require('" + - TypeNameWithNamespace(field) + "').New()\n"; - code += - std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n"; - code += std::string(Indent) + Indent + "return obj\n"; - code += std::string(Indent) + End; - code += EndFunc; - } - - // Get the value of a vector's non-struct member. Uses a named return - // argument to conveniently set the zero value for the result. - void GetMemberOfVectorOfNonStruct(const StructDef &struct_def, - const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - auto vectortype = field.value.type.VectorType(); - - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "(j)\n"; - code += OffsetPrefix(field); - code += - std::string(Indent) + Indent + "local a = " + SelfData + ":Vector(o)\n"; - code += std::string(Indent) + Indent; - code += "return " + GenGetter(field.value.type); - code += "a + ((j-1) * "; - code += NumToString(InlineSize(vectortype)) + "))\n"; - code += std::string(Indent) + End; - if (IsString(vectortype)) { - code += std::string(Indent) + "return ''\n"; - } else { - code += std::string(Indent) + "return 0\n"; - } - code += EndFunc; - } - - // Access a byte/ubyte vector as a string - void AccessByteVectorAsString(const StructDef &struct_def, - const FieldDef &field, std::string *code_ptr) { - std::string &code = *code_ptr; - GenReceiver(struct_def, code_ptr); - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "AsString(start, stop)\n"; - code += std::string(Indent) + "return " + SelfData + ":VectorAsString(" + - NumToString(field.value.offset) + ", start, stop)\n"; - code += EndFunc; - } - - // Begin the creator function signature. - void BeginBuilderArgs(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - - code += "function " + NormalizedName(struct_def) + ".Create" + - NormalizedName(struct_def); - code += "(builder"; - } - - // Recursively generate arguments for a constructor, to deal with nested - // structs. - void StructBuilderArgs(const StructDef &struct_def, const char *nameprefix, - std::string *code_ptr) { - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto &field = **it; - if (IsStruct(field.value.type)) { - // Generate arguments for a struct inside a struct. To ensure names - // don't clash, and to make it obvious these arguments are constructing - // a nested struct, prefix the name with the field name. - StructBuilderArgs(*field.value.type.struct_def, - (nameprefix + (NormalizedName(field) + "_")).c_str(), - code_ptr); - } else { - std::string &code = *code_ptr; - code += std::string(", ") + nameprefix; - code += ConvertCase(NormalizedName(field), Case::kLowerCamel); - } - } - } - - // End the creator function signature. - void EndBuilderArgs(std::string *code_ptr) { - std::string &code = *code_ptr; - code += ")\n"; - } - - // Recursively generate struct construction statements and instert manual - // padding. - void StructBuilderBody(const StructDef &struct_def, const char *nameprefix, - std::string *code_ptr) { - std::string &code = *code_ptr; - code += std::string(Indent) + "builder:Prep(" + - NumToString(struct_def.minalign) + ", "; - code += NumToString(struct_def.bytesize) + ")\n"; - for (auto it = struct_def.fields.vec.rbegin(); - it != struct_def.fields.vec.rend(); ++it) { - auto &field = **it; - if (field.padding) - code += std::string(Indent) + "builder:Pad(" + - NumToString(field.padding) + ")\n"; - if (IsStruct(field.value.type)) { - StructBuilderBody(*field.value.type.struct_def, - (nameprefix + (NormalizedName(field) + "_")).c_str(), - code_ptr); - } else { - code += - std::string(Indent) + "builder:Prepend" + GenMethod(field) + "("; - code += nameprefix + - ConvertCase(NormalizedName(field), Case::kLowerCamel) + ")\n"; - } - } - } - - void EndBuilderBody(std::string *code_ptr) { - std::string &code = *code_ptr; - code += std::string(Indent) + "return builder:Offset()\n"; - code += EndFunc; - } - - // Get the value of a table's starting offset. - void GetStartOfTable(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "function " + NormalizedName(struct_def) + ".Start"; - code += "(builder) "; - code += "builder:StartObject("; - code += NumToString(struct_def.fields.vec.size()); - code += ") end\n"; - } - - // Set the value of a table's field. - void BuildFieldOfTable(const StructDef &struct_def, const FieldDef &field, - const size_t offset, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "function " + NormalizedName(struct_def) + ".Add" + - ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "(builder, "; - code += ConvertCase(NormalizedName(field), Case::kLowerCamel); - code += ") "; - code += "builder:Prepend"; - code += GenMethod(field) + "Slot("; - code += NumToString(offset) + ", "; - // todo: i don't need to cast in Lua, but am I missing something? - // if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) { - // code += "flatbuffers.N.UOffsetTFlags.py_type"; - // code += "("; - // code += ConvertCase(NormalizedName(field), Case::kLowerCamel) + ")"; - // } else { - code += ConvertCase(NormalizedName(field), Case::kLowerCamel); - // } - code += ", " + field.value.constant; - code += ") end\n"; - } - - // Set the value of one of the members of a table's vector. - void BuildVectorOfTable(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - std::string &code = *code_ptr; - code += "function " + NormalizedName(struct_def) + ".Start"; - code += ConvertCase(NormalizedName(field), Case::kUpperCamel); - code += "Vector(builder, numElems) return builder:StartVector("; - auto vector_type = field.value.type.VectorType(); - auto alignment = InlineAlignment(vector_type); - auto elem_size = InlineSize(vector_type); - code += NumToString(elem_size); - code += ", numElems, " + NumToString(alignment); - code += ") end\n"; - } - - // Get the offset of the end of a table. - void GetEndOffsetOnTable(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "function " + NormalizedName(struct_def) + ".End"; - code += "(builder) "; - code += "return builder:EndObject() end\n"; - } - - // Generate the receiver for function signatures. - void GenReceiver(const StructDef &struct_def, std::string *code_ptr) { - std::string &code = *code_ptr; - code += "function " + NormalizedMetaName(struct_def) + ":"; - } - - // Generate a struct field, conditioned on its child type(s). - void GenStructAccessor(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) { - GenComment(field.doc_comment, code_ptr, &def_comment); - if (IsScalar(field.value.type.base_type)) { - if (struct_def.fixed) { - GetScalarFieldOfStruct(struct_def, field, code_ptr); - } else { - GetScalarFieldOfTable(struct_def, field, code_ptr); - } - } else { - switch (field.value.type.base_type) { - case BASE_TYPE_STRUCT: - if (struct_def.fixed) { - GetStructFieldOfStruct(struct_def, field, code_ptr); - } else { - GetStructFieldOfTable(struct_def, field, code_ptr); - } - break; - case BASE_TYPE_STRING: - GetStringField(struct_def, field, code_ptr); - break; - case BASE_TYPE_VECTOR: { - auto vectortype = field.value.type.VectorType(); - if (vectortype.base_type == BASE_TYPE_STRUCT) { - GetMemberOfVectorOfStruct(struct_def, field, code_ptr); - } else { - GetMemberOfVectorOfNonStruct(struct_def, field, code_ptr); - if (vectortype.base_type == BASE_TYPE_CHAR || - vectortype.base_type == BASE_TYPE_UCHAR) { - AccessByteVectorAsString(struct_def, field, code_ptr); - } - } - break; - } - case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr); break; - default: FLATBUFFERS_ASSERT(0); - } - } - if (IsVector(field.value.type)) { - GetVectorLen(struct_def, field, code_ptr); - } - } - - // Generate table constructors, conditioned on its members' types. - void GenTableBuilders(const StructDef &struct_def, std::string *code_ptr) { - GetStartOfTable(struct_def, code_ptr); - - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto &field = **it; - if (field.deprecated) continue; - - auto offset = it - struct_def.fields.vec.begin(); - BuildFieldOfTable(struct_def, field, offset, code_ptr); - if (IsVector(field.value.type)) { - BuildVectorOfTable(struct_def, field, code_ptr); - } - } - - GetEndOffsetOnTable(struct_def, code_ptr); - } - - // Generate struct or table methods. - void GenStruct(const StructDef &struct_def, std::string *code_ptr) { - if (struct_def.generated) return; - - GenComment(struct_def.doc_comment, code_ptr, &def_comment); - BeginClass(struct_def, code_ptr); - - GenerateNewObjectPrototype(struct_def, code_ptr); - - if (!struct_def.fixed) { - // Generate a special accessor for the table that has been declared as - // the root type. - NewRootTypeFromBuffer(struct_def, code_ptr); - } - - // Generate the Init method that sets the field in a pre-existing - // accessor object. This is to allow object reuse. - InitializeExisting(struct_def, code_ptr); - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto &field = **it; - if (field.deprecated) continue; - - GenStructAccessor(struct_def, field, code_ptr); - } - - if (struct_def.fixed) { - // create a struct constructor function - GenStructBuilder(struct_def, code_ptr); - } else { - // Create a set of functions that allow table construction. - GenTableBuilders(struct_def, code_ptr); - } - } - - // Generate enum declarations. - void GenEnum(const EnumDef &enum_def, std::string *code_ptr) { - if (enum_def.generated) return; - - GenComment(enum_def.doc_comment, code_ptr, &def_comment); - BeginEnum(NormalizedName(enum_def), code_ptr); - for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { - auto &ev = **it; - GenComment(ev.doc_comment, code_ptr, &def_comment, Indent); - EnumMember(enum_def, ev, code_ptr); - } - EndEnum(code_ptr); - } - - // Returns the function name that is able to read a value of the given type. - std::string GenGetter(const Type &type) { - switch (type.base_type) { - case BASE_TYPE_STRING: return std::string(SelfData) + ":String("; - case BASE_TYPE_UNION: return std::string(SelfData) + ":Union("; - case BASE_TYPE_VECTOR: return GenGetter(type.VectorType()); - default: - return std::string(SelfData) + ":Get(flatbuffers.N." + - ConvertCase(GenTypeGet(type), Case::kUpperCamel) + ", "; - } - } - - // Returns the method name for use with add/put calls. - std::string GenMethod(const FieldDef &field) { - return IsScalar(field.value.type.base_type) - ? ConvertCase(GenTypeBasic(field.value.type), Case::kUpperCamel) - : (IsStruct(field.value.type) ? "Struct" : "UOffsetTRelative"); - } - - std::string GenTypeBasic(const Type &type) { - // clang-format off - static const char *ctypename[] = { - #define FLATBUFFERS_TD(ENUM, IDLTYPE, \ - CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, ...) \ - #PTYPE, - FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) - #undef FLATBUFFERS_TD - }; - // clang-format on - return ctypename[type.base_type]; - } - - std::string GenTypePointer(const Type &type) { - switch (type.base_type) { - case BASE_TYPE_STRING: return "string"; - case BASE_TYPE_VECTOR: return GenTypeGet(type.VectorType()); - case BASE_TYPE_STRUCT: return type.struct_def->name; - case BASE_TYPE_UNION: - // fall through - default: return "*flatbuffers.Table"; - } - } - - std::string GenTypeGet(const Type &type) { - return IsScalar(type.base_type) ? GenTypeBasic(type) : GenTypePointer(type); - } - - std::string GetNamespace(const Type &type) { - return type.struct_def->defined_namespace->GetFullyQualifiedName( - type.struct_def->name); - } - - std::string TypeName(const FieldDef &field) { - return GenTypeGet(field.value.type); - } - - std::string TypeNameWithNamespace(const FieldDef &field) { - return GetNamespace(field.value.type); - } - - // Create a struct with a builder and the struct's arguments. - void GenStructBuilder(const StructDef &struct_def, std::string *code_ptr) { - BeginBuilderArgs(struct_def, code_ptr); - StructBuilderArgs(struct_def, "", code_ptr); - EndBuilderArgs(code_ptr); - - StructBuilderBody(struct_def, "", code_ptr); - EndBuilderBody(code_ptr); - } - - bool generate() { - if (!generateEnums()) return false; - if (!generateStructs()) return false; - return true; - } - - private: - bool generateEnums() { - for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end(); - ++it) { - auto &enum_def = **it; - std::string enumcode; - GenEnum(enum_def, &enumcode); - if (!SaveType(enum_def, enumcode, false)) return false; - } - return true; - } - - bool generateStructs() { - for (auto it = parser_.structs_.vec.begin(); - it != parser_.structs_.vec.end(); ++it) { - auto &struct_def = **it; - std::string declcode; - GenStruct(struct_def, &declcode); - if (!SaveType(struct_def, declcode, true)) return false; - } - return true; - } - - // Begin by declaring namespace and imports. - void BeginFile(const std::string &name_space_name, const bool needs_imports, - std::string *code_ptr) { - std::string &code = *code_ptr; - code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n"; - code += std::string(Comment) + "namespace: " + name_space_name + "\n\n"; - if (needs_imports) { - code += "local flatbuffers = require('flatbuffers')\n\n"; - } - } - - // Save out the generated code for a Lua Table type. - bool SaveType(const Definition &def, const std::string &classcode, - bool needs_imports) { - if (!classcode.length()) return true; - - std::string namespace_dir = path_; - auto &namespaces = def.defined_namespace->components; - for (auto it = namespaces.begin(); it != namespaces.end(); ++it) { - if (it != namespaces.begin()) namespace_dir += kPathSeparator; - namespace_dir += *it; - // std::string init_py_filename = namespace_dir + "/__init__.py"; - // SaveFile(init_py_filename.c_str(), "", false); - } - - std::string code = ""; - BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code); - code += classcode; - code += "\n"; - code += - "return " + NormalizedName(def) + " " + Comment + "return the module"; - std::string filename = - NamespaceDir(*def.defined_namespace) + NormalizedName(def) + ".lua"; - return SaveFile(filename.c_str(), code, false); - } - - private: - std::unordered_set<std::string> keywords_; -}; - -} // namespace lua - -bool GenerateLua(const Parser &parser, const std::string &path, - const std::string &file_name) { - lua::LuaGenerator generator(parser, path, file_name); - return generator.generate(); -} - -namespace { - -class LuaCodeGenerator : public CodeGenerator { - public: - Status GenerateCode(const Parser &parser, const std::string &path, - const std::string &filename) override { - if (!GenerateLua(parser, path, filename)) { return Status::ERROR; } - return Status::OK; - } - - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; - return Status::NOT_IMPLEMENTED; - } - - Status GenerateMakeRule(const Parser &parser, const std::string &path, - const std::string &filename, - std::string &output) override { - (void)parser; - (void)path; - (void)filename; - (void)output; - return Status::NOT_IMPLEMENTED; - } - - Status GenerateGrpcCode(const Parser &parser, const std::string &path, - const std::string &filename) override { - (void)parser; - (void)path; - (void)filename; - return Status::NOT_IMPLEMENTED; - } - - Status GenerateRootFile(const Parser &parser, - const std::string &path) override { - (void)parser; - (void)path; - return Status::NOT_IMPLEMENTED; - } - - bool IsSchemaOnly() const override { return true; } - - bool SupportsBfbsGeneration() const override { return true; } - - bool SupportsRootFileGeneration() const override { return false; } - - IDLOptions::Language Language() const override { return IDLOptions::kLua; } - - std::string LanguageName() const override { return "Lua"; } -}; -} // namespace - -std::unique_ptr<CodeGenerator> NewLuaCodeGenerator() { - return std::unique_ptr<LuaCodeGenerator>(new LuaCodeGenerator()); -} - -} // namespace flatbuffers diff --git a/contrib/libs/flatbuffers/src/idl_gen_lua.h b/contrib/libs/flatbuffers/src/idl_gen_lua.h deleted file mode 100644 index 43974a8c33..0000000000 --- a/contrib/libs/flatbuffers/src/idl_gen_lua.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2023 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FLATBUFFERS_IDL_GEN_LUA_H_ -#define FLATBUFFERS_IDL_GEN_LUA_H_ - -#include "flatbuffers/code_generator.h" - -namespace flatbuffers { - -// Constructs a new Lua code generator. -std::unique_ptr<CodeGenerator> NewLuaCodeGenerator(); - -} // namespace flatbuffers - -#endif // FLATBUFFERS_IDL_GEN_LUA_H_ diff --git a/contrib/libs/flatbuffers/src/idl_gen_php.cpp b/contrib/libs/flatbuffers/src/idl_gen_php.cpp index 7bdc6e750d..16ba3385e9 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_php.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_php.cpp @@ -939,8 +939,8 @@ class PhpGenerator : public BaseGenerator { }; } // namespace php -bool GeneratePhp(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GeneratePhp(const Parser &parser, const std::string &path, + const std::string &file_name) { php::PhpGenerator generator(parser, path, file_name); return generator.generate(); } @@ -955,9 +955,8 @@ class PhpCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_python.cpp b/contrib/libs/flatbuffers/src/idl_gen_python.cpp index dc901bb7c4..ff535d1574 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_python.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_python.cpp @@ -74,7 +74,7 @@ static Namer::Config PythonDefaultConfig() { static const CommentConfig def_comment = { nullptr, "#", nullptr }; static const std::string Indent = " "; -} // namespace +} // namespace class PythonGenerator : public BaseGenerator { public: @@ -149,10 +149,11 @@ class PythonGenerator : public BaseGenerator { if (!parser_.opts.python_no_type_prefix_suffix) { // Add an alias with the old name code += Indent + "@classmethod\n"; - code += Indent + "def GetRootAs" + struct_type + "(cls, buf, offset=0):\n"; code += - Indent + Indent + - "\"\"\"This method is deprecated. Please switch to GetRootAs.\"\"\"\n"; + Indent + "def GetRootAs" + struct_type + "(cls, buf, offset=0):\n"; + code += Indent + Indent + + "\"\"\"This method is deprecated. Please switch to " + "GetRootAs.\"\"\"\n"; code += Indent + Indent + "return cls.GetRootAs(buf, offset)\n"; } } @@ -179,16 +180,15 @@ class PythonGenerator : public BaseGenerator { GenReceiver(struct_def, code_ptr); code += namer_.Method(field) + "Length(self)"; - if (parser_.opts.python_typing) { - code += " -> int"; - } + if (parser_.opts.python_typing) { code += " -> int"; } code += ":"; - if(!IsArray(field.value.type)){ - code += OffsetPrefix(field,false); + if (!IsArray(field.value.type)) { + code += OffsetPrefix(field, false); code += GenIndents(3) + "return self._tab.VectorLen(o)"; code += GenIndents(2) + "return 0\n\n"; - }else{ - code += GenIndents(2) + "return "+NumToString(field.value.type.fixed_length)+"\n\n"; + } else { + code += GenIndents(2) + "return " + + NumToString(field.value.type.fixed_length) + "\n\n"; } } @@ -199,17 +199,15 @@ class PythonGenerator : public BaseGenerator { GenReceiver(struct_def, code_ptr); code += namer_.Method(field) + "IsNone(self)"; - if (parser_.opts.python_typing) { - code += " -> bool"; - } + if (parser_.opts.python_typing) { code += " -> bool"; } code += ":"; - if(!IsArray(field.value.type)){ + if (!IsArray(field.value.type)) { code += GenIndents(2) + "o = flatbuffers.number_types.UOffsetTFlags.py_type" + "(self._tab.Offset(" + NumToString(field.value.offset) + "))"; code += GenIndents(2) + "return o == 0"; } else { - //assume that we always have an array as memory is preassigned + // assume that we always have an array as memory is preassigned code += GenIndents(2) + "return False"; } code += "\n\n"; @@ -290,7 +288,8 @@ class PythonGenerator : public BaseGenerator { code += "(self, i):"; } - if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { + if (parser_.opts.include_dependence_headers && + !parser_.opts.python_typing) { code += GenIndents(2); code += "from " + import_entry.first + " import " + import_entry.second + "\n"; @@ -317,8 +316,9 @@ class PythonGenerator : public BaseGenerator { code += NumToString(field.value.offset) + " + i * "; code += NumToString(InlineSize(field.value.type.VectorType())); code += ")) for i in range("; - code += "self."+namer_.Method(field)+"Length()" + ")]"; - code += GenIndents(2) +"elif j >= 0 and j < self."+namer_.Method(field)+"Length():"; + code += "self." + namer_.Method(field) + "Length()" + ")]"; + code += GenIndents(2) + "elif j >= 0 and j < self." + namer_.Method(field) + + "Length():"; code += GenIndents(3) + "return " + GenGetter(field.value.type); code += "self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type("; code += NumToString(field.value.offset) + " + j * "; @@ -355,7 +355,8 @@ class PythonGenerator : public BaseGenerator { code += "x = self._tab.Indirect(o + self._tab.Pos)\n"; } - if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { + if (parser_.opts.include_dependence_headers && + !parser_.opts.python_typing) { code += Indent + Indent + Indent; code += "from " + import_entry.first + " import " + import_entry.second + "\n"; @@ -464,7 +465,8 @@ class PythonGenerator : public BaseGenerator { if (!(vectortype.struct_def->fixed)) { code += Indent + Indent + Indent + "x = self._tab.Indirect(x)\n"; } - if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { + if (parser_.opts.include_dependence_headers && + !parser_.opts.python_typing) { code += Indent + Indent + Indent; code += "from " + import_entry.first + " import " + import_entry.second + "\n"; @@ -519,7 +521,7 @@ class PythonGenerator : public BaseGenerator { GenReceiver(struct_def, code_ptr); code += namer_.Method(field) + "AsNumpy(self):"; - if(!IsArray(field.value.type)){ + if (!IsArray(field.value.type)) { code += OffsetPrefix(field, false); code += GenIndents(3); @@ -533,11 +535,13 @@ class PythonGenerator : public BaseGenerator { } else { code += GenIndents(2) + "return 0\n"; } - }else{ + } else { code += GenIndents(2) + "return "; code += "self._tab.GetArrayAsNumpy(flatbuffers.number_types."; code += namer_.Method(GenTypeGet(field.value.type.VectorType())); - code += "Flags, self._tab.Pos + "+NumToString(field.value.offset)+", "+NumToString("self."+namer_.Method(field)+"Length()")+")\n"; + code += "Flags, self._tab.Pos + " + NumToString(field.value.offset) + + ", " + NumToString("self." + namer_.Method(field) + "Length()") + + ")\n"; } code += "\n"; } @@ -564,9 +568,7 @@ class PythonGenerator : public BaseGenerator { const std::string unqualified_name = nested->constant; std::string qualified_name = NestedFlatbufferType(unqualified_name); - if (qualified_name.empty()) { - qualified_name = nested->constant; - } + if (qualified_name.empty()) { qualified_name = nested->constant; } const ImportMapEntry import_entry = { qualified_name, unqualified_name }; @@ -704,7 +706,9 @@ class PythonGenerator : public BaseGenerator { const auto struct_type = namer_.Type(struct_def); // Generate method with struct name. - const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" : struct_type + "Start"; + const auto name = parser_.opts.python_no_type_prefix_suffix + ? "Start" + : struct_type + "Start"; code += "def " + name; if (parser_.opts.python_typing) { @@ -736,12 +740,14 @@ class PythonGenerator : public BaseGenerator { const std::string field_method = namer_.Method(field); const std::string field_ty = GenFieldTy(field); - const auto name = parser_.opts.python_no_type_prefix_suffix ? "Add" + field_method : namer_.Type(struct_def) + "Add" + field_method; + const auto name = parser_.opts.python_no_type_prefix_suffix + ? "Add" + field_method + : namer_.Type(struct_def) + "Add" + field_method; // Generate method with struct name. code += "def " + name; if (parser_.opts.python_typing) { - code += "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty; + code += "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty; } else { code += "(builder, " + field_var; } @@ -767,9 +773,14 @@ class PythonGenerator : public BaseGenerator { if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def Add" + field_method + "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty + "):\n"; - code += - Indent + namer_.Type(struct_def) + "Add" + field_method; + code += "def Add" + field_method; + if (parser_.opts.python_typing) { + code += "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty; + } else { + code += "(builder, " + field_var; + } + code += "):\n"; + code += Indent + namer_.Type(struct_def) + "Add" + field_method; code += "(builder, "; code += field_var; code += ")\n\n"; @@ -784,7 +795,9 @@ class PythonGenerator : public BaseGenerator { const std::string field_method = namer_.Method(field); // Generate method with struct name. - const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" + field_method : struct_type + "Start" + field_method; + const auto name = parser_.opts.python_no_type_prefix_suffix + ? "Start" + field_method + : struct_type + "Start" + field_method; code += "def " + name; if (parser_.opts.python_typing) { code += "Vector(builder, numElems: int) -> int:\n"; @@ -802,7 +815,8 @@ class PythonGenerator : public BaseGenerator { if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def Start" + field_method + "Vector(builder, numElems: int) -> int:\n"; + code += "def Start" + field_method + + "Vector(builder, numElems: int) -> int:\n"; code += Indent + "return " + struct_type + "Start"; code += field_method + "Vector(builder, numElems)\n\n"; } @@ -849,7 +863,9 @@ class PythonGenerator : public BaseGenerator { std::string *code_ptr) const { auto &code = *code_ptr; - const auto name = parser_.opts.python_no_type_prefix_suffix ? "End" : namer_.Type(struct_def) + "End"; + const auto name = parser_.opts.python_no_type_prefix_suffix + ? "End" + : namer_.Type(struct_def) + "End"; // Generate method with struct name. if (parser_.opts.python_typing) { code += "def " + name + "(builder: flatbuffers.Builder) -> int:\n"; @@ -921,7 +937,9 @@ class PythonGenerator : public BaseGenerator { } break; } - case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr, imports); break; + case BASE_TYPE_UNION: + GetUnionField(struct_def, field, code_ptr, imports); + break; default: FLATBUFFERS_ASSERT(0); } } @@ -1255,14 +1273,15 @@ class PythonGenerator : public BaseGenerator { } void InitializeFromPackedBuf(const StructDef &struct_def, - std::string *code_ptr) const { + std::string *code_ptr) const { auto &code = *code_ptr; const auto struct_var = namer_.Variable(struct_def); const auto struct_type = namer_.Type(struct_def); code += GenIndents(1) + "@classmethod"; code += GenIndents(1) + "def InitFromPackedBuf(cls, buf, pos=0):"; - code += GenIndents(2) + "n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)"; + code += GenIndents(2) + + "n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)"; code += GenIndents(2) + "return cls.InitFromBuf(buf, pos+n)"; code += "\n"; } @@ -1281,20 +1300,21 @@ class PythonGenerator : public BaseGenerator { code += "\n"; } - void GenCompareOperator(const StructDef &struct_def, + void GenCompareOperator(const StructDef &struct_def, std::string *code_ptr) const { auto &code = *code_ptr; code += GenIndents(1) + "def __eq__(self, other):"; code += GenIndents(2) + "return type(self) == type(other)"; for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto &field = **it; - if (field.deprecated) continue; + it != struct_def.fields.vec.end(); ++it) { + auto &field = **it; + if (field.deprecated) continue; - // Wrties the comparison statement for this field. - const auto field_field = namer_.Field(field); - code += " and \\" + GenIndents(3) + "self." + field_field + " == " + "other." + field_field; - } + // Wrties the comparison statement for this field. + const auto field_field = namer_.Field(field); + code += " and \\" + GenIndents(3) + "self." + field_field + + " == " + "other." + field_field; + } code += "\n"; } @@ -1317,8 +1337,9 @@ class PythonGenerator : public BaseGenerator { code += field_type + "()"; } code += ") is not None:"; - code += GenIndents(3) + "self." + field_field + " = " + namer_.ObjectType(field_type) + - + ".InitFromObj(" + struct_var + "." + field_method + "("; + code += GenIndents(3) + "self." + field_field + " = " + + namer_.ObjectType(field_type) + +".InitFromObj(" + struct_var + + "." + field_method + "("; // A struct's accessor requires a struct buf instance. if (struct_def.fixed && field.value.type.base_type == BASE_TYPE_STRUCT) { code += field_type + "()"; @@ -1368,8 +1389,9 @@ class PythonGenerator : public BaseGenerator { "(i) is None:"; code += GenIndents(5) + "self." + field_field + ".append(None)"; code += GenIndents(4) + "else:"; - code += GenIndents(5) + one_instance + " = " + namer_.ObjectType(field_type) + - ".InitFromObj(" + struct_var + "." + field_method + "(i))"; + code += GenIndents(5) + one_instance + " = " + + namer_.ObjectType(field_type) + ".InitFromObj(" + struct_var + "." + + field_method + "(i))"; code += GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")"; } @@ -1399,8 +1421,9 @@ class PythonGenerator : public BaseGenerator { "(i) is None:"; code += GenIndents(5) + "self." + field_field + ".append(None)"; code += GenIndents(4) + "else:"; - code += GenIndents(5) + one_instance + " = " + namer_.ObjectType(field_type) + - ".InitFromObj(" + struct_var + "." + field_method + "(i))"; + code += GenIndents(5) + one_instance + " = " + + namer_.ObjectType(field_type) + ".InitFromObj(" + struct_var + "." + + field_method + "(i))"; code += GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")"; } @@ -1780,9 +1803,7 @@ class PythonGenerator : public BaseGenerator { InitializeFromObjForObject(struct_def, &code); - if (parser_.opts.gen_compare) { - GenCompareOperator(struct_def, &code); - } + if (parser_.opts.gen_compare) { GenCompareOperator(struct_def, &code); } GenUnPack(struct_def, &code); @@ -1891,17 +1912,11 @@ class PythonGenerator : public BaseGenerator { std::string GenFieldTy(const FieldDef &field) const { if (IsScalar(field.value.type.base_type) || IsArray(field.value.type)) { const std::string ty = GenTypeBasic(field.value.type); - if (ty.find("int") != std::string::npos) { - return "int"; - } + if (ty.find("int") != std::string::npos) { return "int"; } - if (ty.find("float") != std::string::npos) { - return "float"; - } + if (ty.find("float") != std::string::npos) { return "float"; } - if (ty == "bool") { - return "bool"; - } + if (ty == "bool") { return "bool"; } return "Any"; } else { @@ -2052,13 +2067,9 @@ class PythonGenerator : public BaseGenerator { } if (parser_.opts.one_file) { - if (!declcode.empty()) { - *one_file_code += declcode + "\n\n"; - } + if (!declcode.empty()) { *one_file_code += declcode + "\n\n"; } - for (auto import_str: imports) { - one_file_imports.insert(import_str); - } + for (auto import_str : imports) { one_file_imports.insert(import_str); } } else { const std::string mod = namer_.File(struct_def, SkipFile::SuffixAndExtension); @@ -2135,8 +2146,8 @@ class PythonGenerator : public BaseGenerator { } // namespace python -bool GeneratePython(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GeneratePython(const Parser &parser, const std::string &path, + const std::string &file_name) { python::PythonGenerator generator(parser, path, file_name); return generator.generate(); } @@ -2151,9 +2162,8 @@ class PythonCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_rust.cpp b/contrib/libs/flatbuffers/src/idl_gen_rust.cpp index ac6097faae..95fa39bdd6 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_rust.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_rust.cpp @@ -277,10 +277,10 @@ static bool IsBitFlagsEnum(const EnumDef &enum_def) { static bool IsOptionalToBuilder(const FieldDef &field) { return field.IsOptional() || !IsScalar(field.value.type.base_type); } -} // namespace +} // namespace -bool GenerateRustModuleRootFile(const Parser &parser, - const std::string &output_dir) { +static bool GenerateRustModuleRootFile(const Parser &parser, + const std::string &output_dir) { if (!parser.opts.rust_module_root_file) { // Don't generate a root file when generating one file. This isn't an error // so return true. @@ -708,7 +708,7 @@ class RustGenerator : public BaseGenerator { // and an enum array of values void GenEnum(const EnumDef &enum_def) { const bool is_private = parser_.opts.no_leak_private_annotations && - (enum_def.attributes.Lookup("private") != nullptr); + (enum_def.attributes.Lookup("private") != nullptr); code_.SetValue("ACCESS_TYPE", is_private ? "pub(crate)" : "pub"); code_.SetValue("ENUM_TY", namer_.Type(enum_def)); code_.SetValue("BASE_TYPE", GetEnumTypeForDecl(enum_def.underlying_type)); @@ -842,15 +842,21 @@ class RustGenerator : public BaseGenerator { code_ += " type Inner = Self;"; code_ += " #[inline]"; code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; - code_ += " let b = flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc);"; + code_ += + " let b = flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc);"; if (IsBitFlagsEnum(enum_def)) { // Safety: - // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size. - // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0 + // This is safe because we know bitflags is implemented with a repr + // transparent uint of the correct size. from_bits_unchecked will be + // replaced by an equivalent but safe from_bits_retain in bitflags 2.0 // https://github.com/bitflags/bitflags/issues/262 code_ += " // Safety:"; - code_ += " // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size."; - code_ += " // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0"; + code_ += + " // This is safe because we know bitflags is implemented with a " + "repr transparent uint of the correct size."; + code_ += + " // from_bits_unchecked will be replaced by an equivalent but " + "safe from_bits_retain in bitflags 2.0"; code_ += " // https://github.com/bitflags/bitflags/issues/262"; code_ += " Self::from_bits_unchecked(b)"; } else { @@ -863,7 +869,9 @@ class RustGenerator : public BaseGenerator { code_ += " type Output = {{ENUM_TY}};"; code_ += " #[inline]"; code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {"; - code_ += " flatbuffers::emplace_scalar::<{{BASE_TYPE}}>(dst, {{INTO_BASE}});"; + code_ += + " flatbuffers::emplace_scalar::<{{BASE_TYPE}}>(dst, " + "{{INTO_BASE}});"; code_ += " }"; code_ += "}"; code_ += ""; @@ -879,12 +887,17 @@ class RustGenerator : public BaseGenerator { code_ += " let b = {{BASE_TYPE}}::from_le(v);"; if (IsBitFlagsEnum(enum_def)) { // Safety: - // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size. - // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0 + // This is safe because we know bitflags is implemented with a repr + // transparent uint of the correct size. from_bits_unchecked will be + // replaced by an equivalent but safe from_bits_retain in bitflags 2.0 // https://github.com/bitflags/bitflags/issues/262 code_ += " // Safety:"; - code_ += " // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size."; - code_ += " // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0"; + code_ += + " // This is safe because we know bitflags is implemented with a " + "repr transparent uint of the correct size."; + code_ += + " // from_bits_unchecked will be replaced by an equivalent but " + "safe from_bits_retain in bitflags 2.0"; code_ += " // https://github.com/bitflags/bitflags/issues/262"; code_ += " unsafe { Self::from_bits_unchecked(b) }"; } else { @@ -1458,7 +1471,8 @@ class RustGenerator : public BaseGenerator { case ftVectorOfBool: case ftVectorOfFloat: { const auto typname = GetTypeBasic(type.VectorType()); - return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + ">"); + return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + + ">"); } case ftVectorOfEnumKey: { const auto typname = WrapInNameSpace(*type.enum_def); @@ -1467,7 +1481,8 @@ class RustGenerator : public BaseGenerator { } case ftVectorOfStruct: { const auto typname = WrapInNameSpace(*type.struct_def); - return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + ">"); + return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + + ">"); } case ftVectorOfTable: { const auto typname = WrapInNameSpace(*type.struct_def); @@ -1585,8 +1600,9 @@ class RustGenerator : public BaseGenerator { : "None"; const std::string unwrap = field.IsOptional() ? "" : ".unwrap()"; - return "unsafe { self._tab.get::<" + typname + ">({{STRUCT_TY}}::" + vt_offset + - ", " + default_value + ")" + unwrap + "}"; + return "unsafe { self._tab.get::<" + typname + + ">({{STRUCT_TY}}::" + vt_offset + ", " + default_value + ")" + + unwrap + "}"; } // Generates a fully-qualified name getter for use with --gen-name-strings @@ -1646,8 +1662,8 @@ class RustGenerator : public BaseGenerator { // Generate an accessor struct, builder struct, and create function for a // table. void GenTable(const StructDef &struct_def) { - - const bool is_private = parser_.opts.no_leak_private_annotations && + const bool is_private = + parser_.opts.no_leak_private_annotations && (struct_def.attributes.Lookup("private") != nullptr); code_.SetValue("ACCESS_TYPE", is_private ? "pub(crate)" : "pub"); code_.SetValue("STRUCT_TY", namer_.Type(struct_def)); @@ -1933,13 +1949,17 @@ class RustGenerator : public BaseGenerator { code_ += " // Safety:"; code_ += " // Created from a valid Table for this object"; code_ += " // Which contains a valid union in this slot"; - code_ += " Some(unsafe { {{U_ELEMENT_TABLE_TYPE}}::init_from_table(u) })"; + code_ += + " Some(unsafe { " + "{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u) })"; } else { - code_ +=" self.{{FIELD}}().map(|t| {"; + code_ += " self.{{FIELD}}().map(|t| {"; code_ += " // Safety:"; code_ += " // Created from a valid Table for this object"; code_ += " // Which contains a valid union in this slot"; - code_ += " unsafe { {{U_ELEMENT_TABLE_TYPE}}::init_from_table(t) }"; + code_ += + " unsafe { {{U_ELEMENT_TABLE_TYPE}}::init_from_table(t) " + "}"; code_ += " })"; } code_ += " } else {"; @@ -2264,7 +2284,8 @@ class RustGenerator : public BaseGenerator { case ftUnionValue: { code_.SetValue("ENUM_METHOD", namer_.Method(*field.value.type.enum_def)); - code_.SetValue("DISCRIMINANT", namer_.LegacyRustUnionTypeMethod(field)); + code_.SetValue("DISCRIMINANT", + namer_.LegacyRustUnionTypeMethod(field)); code_ += " let {{DISCRIMINANT}} = " "self.{{FIELD}}.{{ENUM_METHOD}}_type();"; @@ -2312,10 +2333,10 @@ class RustGenerator : public BaseGenerator { // TODO(cneo): create_vector* should be more generic to avoid // allocations. - MapNativeTableField( - field, - "let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();" - "_fbb.create_vector(&w)"); + MapNativeTableField(field, + "let w: Vec<_> = x.iter().map(|s| " + "_fbb.create_string(s)).collect();" + "_fbb.create_vector(&w)"); return; } case ftVectorOfTable: { @@ -2601,7 +2622,8 @@ class RustGenerator : public BaseGenerator { } // Generate an accessor struct with constructor for a flatbuffers struct. void GenStruct(const StructDef &struct_def) { - const bool is_private = parser_.opts.no_leak_private_annotations && + const bool is_private = + parser_.opts.no_leak_private_annotations && (struct_def.attributes.Lookup("private") != nullptr); code_.SetValue("ACCESS_TYPE", is_private ? "pub(crate)" : "pub"); // Generates manual padding and alignment. @@ -2665,7 +2687,9 @@ class RustGenerator : public BaseGenerator { code_ += " type Output = {{STRUCT_TY}};"; code_ += " #[inline]"; code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {"; - code_ += " let src = ::core::slice::from_raw_parts(self as *const {{STRUCT_TY}} as *const u8, Self::size());"; + code_ += + " let src = ::core::slice::from_raw_parts(self as *const " + "{{STRUCT_TY}} as *const u8, Self::size());"; code_ += " dst.copy_from_slice(src);"; code_ += " }"; code_ += "}"; @@ -2759,7 +2783,9 @@ class RustGenerator : public BaseGenerator { code_ += " // Safety:"; code_ += " // Created from a valid Table for this object"; code_ += " // Which contains a valid array in this slot"; - code_ += " unsafe { flatbuffers::Array::follow(&self.0, {{FIELD_OFFSET}}) }"; + code_ += + " unsafe { flatbuffers::Array::follow(&self.0, {{FIELD_OFFSET}}) " + "}"; } else { code_ += "pub fn {{FIELD}}(&self) -> {{FIELD_TYPE}} {"; code_ += @@ -2772,7 +2798,9 @@ class RustGenerator : public BaseGenerator { code_ += " core::ptr::copy_nonoverlapping("; code_ += " self.0[{{FIELD_OFFSET}}..].as_ptr(),"; code_ += " mem.as_mut_ptr() as *mut u8,"; - code_ += " core::mem::size_of::<<{{FIELD_TYPE}} as EndianScalar>::Scalar>(),"; + code_ += + " core::mem::size_of::<<{{FIELD_TYPE}} as " + "EndianScalar>::Scalar>(),"; code_ += " );"; code_ += " mem.assume_init()"; code_ += " })"; @@ -2827,7 +2855,9 @@ class RustGenerator : public BaseGenerator { code_ += " core::ptr::copy_nonoverlapping("; code_ += " &x_le as *const _ as *const u8,"; code_ += " self.0[{{FIELD_OFFSET}}..].as_mut_ptr(),"; - code_ += " core::mem::size_of::<<{{FIELD_TYPE}} as EndianScalar>::Scalar>(),"; + code_ += + " core::mem::size_of::<<{{FIELD_TYPE}} as " + "EndianScalar>::Scalar>(),"; code_ += " );"; code_ += " }"; } @@ -2989,14 +3019,14 @@ class RustGenerator : public BaseGenerator { } // namespace rust -bool GenerateRust(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateRust(const Parser &parser, const std::string &path, + const std::string &file_name) { rust::RustGenerator generator(parser, path, file_name); return generator.generate(); } -std::string RustMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { +static std::string RustMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { std::string filebase = flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); rust::RustGenerator generator(parser, path, file_name); @@ -3020,9 +3050,8 @@ class RustCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_swift.cpp b/contrib/libs/flatbuffers/src/idl_gen_swift.cpp index 695f5a0d75..17f3bf5fa4 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_swift.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_swift.cpp @@ -148,7 +148,7 @@ static std::string GenArrayMainBody(const std::string &optional) { optional + " { "; } -} // namespace +} // namespace class SwiftGenerator : public BaseGenerator { private: @@ -261,8 +261,7 @@ class SwiftGenerator : public BaseGenerator { code_ += "private var _{{FIELDVAR}}: " + valueType; const auto accessing_value = IsEnum(field.value.type) ? ".value" : ""; const auto base_value = - IsStruct(field.value.type) ? (type + "()") - : SwiftConstant(field); + IsStruct(field.value.type) ? (type + "()") : SwiftConstant(field); main_constructor.push_back("_" + field_var + " = " + field_var + accessing_value); @@ -720,8 +719,7 @@ class SwiftGenerator : public BaseGenerator { if (IsBool(field.value.type.base_type)) { std::string default_value = - field.IsOptional() ? "nil" - : SwiftConstant(field); + field.IsOptional() ? "nil" : SwiftConstant(field); code_.SetValue("CONSTANT", default_value); code_.SetValue("VALUETYPE", "Bool"); code_ += GenReaderMainBody(optional) + "\\"; @@ -984,8 +982,9 @@ class SwiftGenerator : public BaseGenerator { } else if (IsEnum(type) && !field.IsOptional()) { code_.SetValue("CONSTANT", GenEnumDefaultValue(field)); code_ += "if {{FIELDVAR}} != {{CONSTANT}} {"; - } else if (IsFloat(type.base_type) && StringIsFlatbufferNan(field.value.constant)) { - code_ += "if !{{FIELDVAR}}.isNaN {"; + } else if (IsFloat(type.base_type) && + StringIsFlatbufferNan(field.value.constant)) { + code_ += "if !{{FIELDVAR}}.isNaN {"; } else if (IsScalar(type.base_type) && !IsEnum(type) && !IsBool(type.base_type) && !field.IsOptional()) { code_ += "if {{FIELDVAR}} != {{CONSTANT}} {"; @@ -1158,8 +1157,9 @@ class SwiftGenerator : public BaseGenerator { void GenEnum(const EnumDef &enum_def) { if (enum_def.generated) return; - const bool is_private_access = parser_.opts.swift_implementation_only || - enum_def.attributes.Lookup("private") != nullptr; + const bool is_private_access = + parser_.opts.swift_implementation_only || + enum_def.attributes.Lookup("private") != nullptr; code_.SetValue("ENUM_TYPE", enum_def.is_union ? "UnionEnum" : "Enum, Verifiable"); code_.SetValue("ACCESS_TYPE", is_private_access ? "internal" : "public"); @@ -1579,7 +1579,8 @@ class SwiftGenerator : public BaseGenerator { if (IsBool(field.value.type.base_type)) { code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: Bool" + nullable; if (!field.IsOptional()) - base_constructor.push_back(field_var + " = " + SwiftConstant(field)); + base_constructor.push_back(field_var + " = " + + SwiftConstant(field)); } } } @@ -1827,22 +1828,24 @@ class SwiftGenerator : public BaseGenerator { } } - std::string SwiftConstant(const FieldDef& field) { + std::string SwiftConstant(const FieldDef &field) { const auto default_value = - StringIsFlatbufferNan(field.value.constant) ? ".nan" : - StringIsFlatbufferPositiveInfinity(field.value.constant) ? ".infinity" : - StringIsFlatbufferNegativeInfinity(field.value.constant) ? "-.infinity" : - IsBool(field.value.type.base_type) ? ("0" == field.value.constant ? "false" : "true") : - field.value.constant; + StringIsFlatbufferNan(field.value.constant) ? ".nan" + : StringIsFlatbufferPositiveInfinity(field.value.constant) ? ".infinity" + : StringIsFlatbufferNegativeInfinity(field.value.constant) + ? "-.infinity" + : IsBool(field.value.type.base_type) + ? ("0" == field.value.constant ? "false" : "true") + : field.value.constant; return default_value; - } + } std::string GenEnumConstructor(const std::string &at) { return "{{VALUETYPE}}(rawValue: " + GenReader("BASEVALUE", at) + ") "; } std::string ValidateFunc() { - return "static func validateVersion() { FlatBuffersVersion_23_5_9() }"; + return "static func validateVersion() { FlatBuffersVersion_23_5_26() }"; } std::string GenType(const Type &type, @@ -1899,8 +1902,9 @@ class SwiftGenerator : public BaseGenerator { IdlNamer namer_; }; } // namespace swift -bool GenerateSwift(const Parser &parser, const std::string &path, - const std::string &file_name) { + +static bool GenerateSwift(const Parser &parser, const std::string &path, + const std::string &file_name) { swift::SwiftGenerator generator(parser, path, file_name); return generator.generate(); } @@ -1915,9 +1919,8 @@ class SwiftCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_text.cpp b/contrib/libs/flatbuffers/src/idl_gen_text.cpp index 59f6844413..a34667c4b6 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_text.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_text.cpp @@ -30,8 +30,12 @@ namespace flatbuffers { struct PrintScalarTag {}; struct PrintPointerTag {}; -template<typename T> struct PrintTag { typedef PrintScalarTag type; }; -template<> struct PrintTag<const void *> { typedef PrintPointerTag type; }; +template<typename T> struct PrintTag { + typedef PrintScalarTag type; +}; +template<> struct PrintTag<const void *> { + typedef PrintPointerTag type; +}; struct JsonPrinter { // If indentation is less than 0, that indicates we don't want any newlines @@ -104,7 +108,7 @@ struct JsonPrinter { // "[]". template<typename Container, typename SizeT = typename Container::size_type> const char *PrintContainer(PrintScalarTag, const Container &c, SizeT size, - const Type &type, int indent, const uint8_t *) { + const Type &type, int indent, const uint8_t *) { const auto elem_indent = indent + Indent(); text += '['; AddNewLine(); @@ -126,7 +130,8 @@ struct JsonPrinter { // "[]". template<typename Container, typename SizeT = typename Container::size_type> const char *PrintContainer(PrintPointerTag, const Container &c, SizeT size, - const Type &type, int indent, const uint8_t *prev_val) { + const Type &type, int indent, + const uint8_t *prev_val) { const auto is_struct = IsStruct(type); const auto elem_indent = indent + Indent(); text += '['; @@ -152,7 +157,7 @@ struct JsonPrinter { template<typename T, typename SizeT = uoffset_t> const char *PrintVector(const void *val, const Type &type, int indent, - const uint8_t *prev_val) { + const uint8_t *prev_val) { typedef Vector<T, SizeT> Container; typedef typename PrintTag<typename Container::return_type>::type tag; auto &vec = *reinterpret_cast<const Container *>(val); @@ -163,8 +168,8 @@ struct JsonPrinter { // Print an array a sequence of JSON values, comma separated, wrapped in "[]". template<typename T> const char *PrintArray(const void *val, uint16_t size, const Type &type, - - int indent) { + + int indent) { typedef Array<T, 0xFFFF> Container; typedef typename PrintTag<typename Container::return_type>::type tag; auto &arr = *reinterpret_cast<const Container *>(val); @@ -172,7 +177,7 @@ struct JsonPrinter { } const char *PrintOffset(const void *val, const Type &type, int indent, - const uint8_t *prev_val, soffset_t vector_index) { + const uint8_t *prev_val, soffset_t vector_index) { switch (type.base_type) { case BASE_TYPE_UNION: { // If this assert hits, you have an corrupt buffer, a union type field @@ -196,8 +201,8 @@ struct JsonPrinter { indent); case BASE_TYPE_STRING: { auto s = reinterpret_cast<const String *>(val); - bool ok = EscapeString(s->c_str(), s->size(), &text, opts.allow_non_utf8, - opts.natural_utf8); + bool ok = EscapeString(s->c_str(), s->size(), &text, + opts.allow_non_utf8, opts.natural_utf8); return ok ? nullptr : "string contains non-utf8 bytes"; } case BASE_TYPE_VECTOR: { @@ -235,9 +240,7 @@ struct JsonPrinter { // clang-format on return nullptr; } - default: - FLATBUFFERS_ASSERT(0); - return "unknown type"; + default: FLATBUFFERS_ASSERT(0); return "unknown type"; } } @@ -265,15 +268,14 @@ struct JsonPrinter { text += "null"; } } else { - PrintScalar( - table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)), - fd.value.type, indent); + PrintScalar(table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)), + fd.value.type, indent); } } // Generate text for non-scalar field. const char *GenFieldOffset(const FieldDef &fd, const Table *table, bool fixed, - int indent, const uint8_t *prev_val) { + int indent, const uint8_t *prev_val) { const void *val = nullptr; if (fixed) { // The only non-scalar fields in structs are structs or arrays. @@ -372,7 +374,8 @@ struct JsonPrinter { }; static const char *GenerateTextImpl(const Parser &parser, const Table *table, - const StructDef &struct_def, std::string *_text) { + const StructDef &struct_def, + std::string *_text) { JsonPrinter printer(parser, *_text); auto err = printer.GenStruct(struct_def, table, 0); if (err) return err; @@ -381,8 +384,8 @@ static const char *GenerateTextImpl(const Parser &parser, const Table *table, } // Generate a text representation of a flatbuffer in JSON format. -const char *GenerateTextFromTable(const Parser &parser, const void *table, - const std::string &table_name, std::string *_text) { +const char *GenTextFromTable(const Parser &parser, const void *table, + const std::string &table_name, std::string *_text) { auto struct_def = parser.LookupStruct(table_name); if (struct_def == nullptr) { return "unknown struct"; } auto root = static_cast<const Table *>(table); @@ -390,8 +393,8 @@ const char *GenerateTextFromTable(const Parser &parser, const void *table, } // Generate a text representation of a flatbuffer in JSON format. -const char *GenerateText(const Parser &parser, const void *flatbuffer, - std::string *_text) { +const char *GenText(const Parser &parser, const void *flatbuffer, + std::string *_text) { FLATBUFFERS_ASSERT(parser.root_struct_def_); // call SetRootType() auto root = parser.opts.size_prefixed ? GetSizePrefixedRoot<Table>(flatbuffer) : GetRoot<Table>(flatbuffer); @@ -403,7 +406,7 @@ static std::string TextFileName(const std::string &path, return path + file_name + ".json"; } -const char *GenerateTextFile(const Parser &parser, const std::string &path, +const char *GenTextFile(const Parser &parser, const std::string &path, const std::string &file_name) { if (parser.opts.use_flexbuffers) { std::string json; @@ -415,7 +418,7 @@ const char *GenerateTextFile(const Parser &parser, const std::string &path, } if (!parser.builder_.GetSize() || !parser.root_struct_def_) return nullptr; std::string text; - auto err = GenerateText(parser, parser.builder_.GetBufferPointer(), &text); + auto err = GenText(parser, parser.builder_.GetBufferPointer(), &text); if (err) return err; return flatbuffers::SaveFile(TextFileName(path, file_name).c_str(), text, false) @@ -423,8 +426,8 @@ const char *GenerateTextFile(const Parser &parser, const std::string &path, : "SaveFile failed"; } -std::string TextMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { +static std::string TextMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { if (!parser.builder_.GetSize() || !parser.root_struct_def_) return ""; std::string filebase = flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); @@ -443,7 +446,7 @@ class TextCodeGenerator : public CodeGenerator { public: Status GenerateCode(const Parser &parser, const std::string &path, const std::string &filename) override { - auto err = GenerateTextFile(parser, path, filename); + auto err = GenTextFile(parser, path, filename); if (err) { status_detail = " (" + std::string(err) + ")"; return Status::ERROR; @@ -453,9 +456,8 @@ class TextCodeGenerator : public CodeGenerator { // Generate code from the provided `buffer` of given `length`. The buffer is a // serialized reflection.fbs. - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_gen_ts.cpp b/contrib/libs/flatbuffers/src/idl_gen_ts.cpp index ca072f1c41..acd2a4febe 100644 --- a/contrib/libs/flatbuffers/src/idl_gen_ts.cpp +++ b/contrib/libs/flatbuffers/src/idl_gen_ts.cpp @@ -408,7 +408,7 @@ class TsGenerator : public BaseGenerator { switch (type.base_type) { case BASE_TYPE_BOOL: case BASE_TYPE_CHAR: return "Int8"; - case BASE_TYPE_UTYPE: + case BASE_TYPE_UTYPE: return GenType(GetUnionUnderlyingType(type)); case BASE_TYPE_UCHAR: return "Uint8"; case BASE_TYPE_SHORT: return "Int16"; case BASE_TYPE_USHORT: return "Uint16"; @@ -477,10 +477,9 @@ class TsGenerator : public BaseGenerator { EnumVal *val = value.type.enum_def->FindByValue(value.constant); if (val == nullptr) val = const_cast<EnumVal *>(value.type.enum_def->MinValue()); - return AddImport(imports, *value.type.enum_def, - *value.type.enum_def) - .name + - "." + namer_.Variant(*val); + return AddImport(imports, *value.type.enum_def, *value.type.enum_def) + .name + + "." + namer_.Variant(*val); } } } @@ -563,11 +562,26 @@ class TsGenerator : public BaseGenerator { } } + static Type GetUnionUnderlyingType(const Type &type) + { + if (type.enum_def != nullptr && + type.enum_def->underlying_type.base_type != type.base_type) { + return type.enum_def->underlying_type; + } else { + return Type(BASE_TYPE_UCHAR); + } + } + + static Type GetUnderlyingVectorType(const Type &vector_type) + { + return (vector_type.base_type == BASE_TYPE_UTYPE) ? GetUnionUnderlyingType(vector_type) : vector_type; + } + // Returns the method name for use with add/put calls. std::string GenWriteMethod(const Type &type) { // Forward to signed versions since unsigned versions don't exist switch (type.base_type) { - case BASE_TYPE_UTYPE: + case BASE_TYPE_UTYPE: return GenWriteMethod(GetUnionUnderlyingType(type)); case BASE_TYPE_UCHAR: return GenWriteMethod(Type(BASE_TYPE_CHAR)); case BASE_TYPE_USHORT: return GenWriteMethod(Type(BASE_TYPE_SHORT)); case BASE_TYPE_UINT: return GenWriteMethod(Type(BASE_TYPE_INT)); @@ -850,8 +864,8 @@ class TsGenerator : public BaseGenerator { } if (enum_def.is_union) { - symbols_expression += ", unionTo" + name; - symbols_expression += ", unionListTo" + name; + symbols_expression += (", " + namer_.Function("unionTo" + name)); + symbols_expression += (", " + namer_.Function("unionListTo" + name)); } return symbols_expression; @@ -1764,7 +1778,8 @@ class TsGenerator : public BaseGenerator { auto vectortype = field.value.type.VectorType(); auto vectortypename = GenTypeName(imports, struct_def, vectortype, false); - auto inline_size = InlineSize(vectortype); + auto type = GetUnderlyingVectorType(vectortype); + auto inline_size = InlineSize(type); auto index = GenBBAccess() + ".__vector(this.bb_pos + offset) + index" + MaybeScale(inline_size); @@ -1995,8 +2010,9 @@ class TsGenerator : public BaseGenerator { if (IsVector(field.value.type)) { auto vector_type = field.value.type.VectorType(); - auto alignment = InlineAlignment(vector_type); - auto elem_size = InlineSize(vector_type); + auto type = GetUnderlyingVectorType(vector_type); + auto alignment = InlineAlignment(type); + auto elem_size = InlineSize(type); // Generate a method to create a vector from a JavaScript array if (!IsStruct(vector_type)) { @@ -2161,14 +2177,14 @@ class TsGenerator : public BaseGenerator { }; // namespace ts } // namespace ts -bool GenerateTS(const Parser &parser, const std::string &path, - const std::string &file_name) { +static bool GenerateTS(const Parser &parser, const std::string &path, + const std::string &file_name) { ts::TsGenerator generator(parser, path, file_name); return generator.generate(); } -std::string TSMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { +static std::string TSMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name) { std::string filebase = flatbuffers::StripPath(flatbuffers::StripExtension(file_name)); ts::TsGenerator generator(parser, path, file_name); @@ -2192,9 +2208,8 @@ class TsCodeGenerator : public CodeGenerator { return Status::OK; } - Status GenerateCode(const uint8_t *buffer, int64_t length) override { - (void)buffer; - (void)length; + Status GenerateCode(const uint8_t *, int64_t, + const CodeGenOptions &) override { return Status::NOT_IMPLEMENTED; } diff --git a/contrib/libs/flatbuffers/src/idl_namer.h b/contrib/libs/flatbuffers/src/idl_namer.h index 7f89433da6..337ac920b5 100644 --- a/contrib/libs/flatbuffers/src/idl_namer.h +++ b/contrib/libs/flatbuffers/src/idl_namer.h @@ -146,7 +146,8 @@ class IdlNamer : public Namer { std::string LegacyRustUnionTypeMethod(const FieldDef &d) { // assert d is a union - return Method(d.name + "_type"); + // d should convert case but not escape keywords due to historical reasons + return ConvertCase(d.name, config_.fields, Case::kLowerCamel) + "_type"; } private: diff --git a/contrib/libs/flatbuffers/src/idl_parser.cpp b/contrib/libs/flatbuffers/src/idl_parser.cpp index bddc736a5f..8b4f116854 100644 --- a/contrib/libs/flatbuffers/src/idl_parser.cpp +++ b/contrib/libs/flatbuffers/src/idl_parser.cpp @@ -947,8 +947,12 @@ CheckedError Parser::ParseField(StructDef &struct_def) { if (type.base_type == BASE_TYPE_UNION) { // For union fields, add a second auto-generated field to hold the type, // with a special suffix. - ECHECK(AddField(struct_def, name + UnionTypeFieldSuffix(), - type.enum_def->underlying_type, &typefield)); + + // To ensure compatibility with many codes that rely on the BASE_TYPE_UTYPE value to identify union type fields. + Type union_type(type.enum_def->underlying_type); + union_type.base_type = BASE_TYPE_UTYPE; + ECHECK(AddField(struct_def, name + UnionTypeFieldSuffix(),union_type, &typefield)); + } else if (IsVector(type) && type.element == BASE_TYPE_UNION) { advanced_features_ |= reflection::AdvancedUnionFeatures; // Only cpp, js and ts supports the union vector feature so far. @@ -2368,8 +2372,12 @@ template<typename T> void EnumDef::ChangeEnumValue(EnumVal *ev, T new_value) { } namespace EnumHelper { -template<BaseType E> struct EnumValType { typedef int64_t type; }; -template<> struct EnumValType<BASE_TYPE_ULONG> { typedef uint64_t type; }; +template<BaseType E> struct EnumValType { + typedef int64_t type; +}; +template<> struct EnumValType<BASE_TYPE_ULONG> { + typedef uint64_t type; +}; } // namespace EnumHelper struct EnumValBuilder { @@ -2478,23 +2486,39 @@ CheckedError Parser::ParseEnum(const bool is_union, EnumDef **dest, &GetPooledString(RelativeToRootPath(opts.project_root, filename)); } enum_def->doc_comment = enum_comment; - if (!is_union && !opts.proto_mode) { + if (!opts.proto_mode) { // Give specialized error message, since this type spec used to // be optional in the first FlatBuffers release. + bool explicit_underlying_type = false; if (!Is(':')) { - return Error( - "must specify the underlying integer type for this" - " enum (e.g. \': short\', which was the default)."); + // Enum is forced to have an explicit underlying type in declaration. + if (!is_union) { + return Error( + "must specify the underlying integer type for this" + " enum (e.g. \': short\', which was the default)."); + } } else { + // Union underlying type is only supported for cpp + if (is_union && !SupportsUnionUnderlyingType()) { + return Error( + "Underlying type for union is not yet supported in at least one of " + "the specified programming languages."); + } NEXT(); + explicit_underlying_type = true; } - // Specify the integer type underlying this enum. - ECHECK(ParseType(enum_def->underlying_type)); - if (!IsInteger(enum_def->underlying_type.base_type) || - IsBool(enum_def->underlying_type.base_type)) - return Error("underlying enum type must be integral"); - // Make this type refer back to the enum it was derived from. - enum_def->underlying_type.enum_def = enum_def; + + if (explicit_underlying_type) { + // Specify the integer type underlying this enum. + ECHECK(ParseType(enum_def->underlying_type)); + if (!IsInteger(enum_def->underlying_type.base_type) || IsBool(enum_def->underlying_type.base_type)) { + return Error("underlying " + std::string(is_union ? "union" : "enum") + "type must be integral"); + } + + // Make this type refer back to the enum it was derived from. + enum_def->underlying_type.enum_def = enum_def; + } + } ECHECK(ParseMetaData(&enum_def->attributes)); const auto underlying_type = enum_def->underlying_type.base_type; @@ -2693,6 +2717,10 @@ bool Parser::Supports64BitOffsets() const { ~(IDLOptions::kCpp | IDLOptions::kJson | IDLOptions::kBinary)) == 0; } +bool Parser::SupportsUnionUnderlyingType() const { + return (opts.lang_to_generate & ~(IDLOptions::kCpp | IDLOptions::kTs)) == 0; +} + Namespace *Parser::UniqueNamespace(Namespace *ns) { for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) { if (ns->components == (*it)->components) { @@ -4424,6 +4452,10 @@ std::string Parser::ConformTo(const Parser &base) { return "values differ for enum: " + enum_val.name; } } + // Check underlying type changes + if (enum_def_base->underlying_type.base_type != enum_def.underlying_type.base_type) { + return "underlying type differ for " + std::string(enum_def.is_union ? "union: " : "enum: ") + qualified_name; + } } return ""; } diff --git a/contrib/libs/flatbuffers/src/reflection.cpp b/contrib/libs/flatbuffers/src/reflection.cpp index 0d0814ef62..f064c1c6bd 100644 --- a/contrib/libs/flatbuffers/src/reflection.cpp +++ b/contrib/libs/flatbuffers/src/reflection.cpp @@ -24,17 +24,18 @@ namespace flatbuffers { namespace { -static void CopyInline(FlatBufferBuilder &fbb, const reflection::Field &fielddef, - const Table &table, size_t align, size_t size) { +static void CopyInline(FlatBufferBuilder &fbb, + const reflection::Field &fielddef, const Table &table, + size_t align, size_t size) { fbb.Align(align); fbb.PushBytes(table.GetStruct<const uint8_t *>(fielddef.offset()), size); fbb.TrackField(fielddef.offset(), fbb.GetSize()); } static bool VerifyStruct(flatbuffers::Verifier &v, - const flatbuffers::Table &parent_table, - voffset_t field_offset, const reflection::Object &obj, - bool required) { + const flatbuffers::Table &parent_table, + voffset_t field_offset, const reflection::Object &obj, + bool required) { auto offset = parent_table.GetOptionalFieldOffset(field_offset); if (required && !offset) { return false; } @@ -44,9 +45,10 @@ static bool VerifyStruct(flatbuffers::Verifier &v, } static bool VerifyVectorOfStructs(flatbuffers::Verifier &v, - const flatbuffers::Table &parent_table, - voffset_t field_offset, - const reflection::Object &obj, bool required) { + const flatbuffers::Table &parent_table, + voffset_t field_offset, + const reflection::Object &obj, + bool required) { auto p = parent_table.GetPointer<const uint8_t *>(field_offset); if (required && !p) { return false; } @@ -54,13 +56,15 @@ static bool VerifyVectorOfStructs(flatbuffers::Verifier &v, } // forward declare to resolve cyclic deps between VerifyObject and VerifyVector -static bool VerifyObject(flatbuffers::Verifier &v, const reflection::Schema &schema, - const reflection::Object &obj, - const flatbuffers::Table *table, bool required); - -static bool VerifyUnion(flatbuffers::Verifier &v, const reflection::Schema &schema, - uint8_t utype, const uint8_t *elem, - const reflection::Field &union_field) { +static bool VerifyObject(flatbuffers::Verifier &v, + const reflection::Schema &schema, + const reflection::Object &obj, + const flatbuffers::Table *table, bool required); + +static bool VerifyUnion(flatbuffers::Verifier &v, + const reflection::Schema &schema, uint8_t utype, + const uint8_t *elem, + const reflection::Field &union_field) { if (!utype) return true; // Not present. auto fb_enum = schema.enums()->Get(union_field.type()->index()); if (utype >= fb_enum->values()->size()) return false; @@ -83,9 +87,10 @@ static bool VerifyUnion(flatbuffers::Verifier &v, const reflection::Schema &sche } } -static bool VerifyVector(flatbuffers::Verifier &v, const reflection::Schema &schema, - const flatbuffers::Table &table, - const reflection::Field &vec_field) { +static bool VerifyVector(flatbuffers::Verifier &v, + const reflection::Schema &schema, + const flatbuffers::Table &table, + const reflection::Field &vec_field) { FLATBUFFERS_ASSERT(vec_field.type()->base_type() == reflection::Vector); if (!table.VerifyField<uoffset_t>(v, vec_field.offset(), sizeof(uoffset_t))) return false; @@ -161,9 +166,10 @@ static bool VerifyVector(flatbuffers::Verifier &v, const reflection::Schema &sch } } -static bool VerifyObject(flatbuffers::Verifier &v, const reflection::Schema &schema, - const reflection::Object &obj, - const flatbuffers::Table *table, bool required) { +static bool VerifyObject(flatbuffers::Verifier &v, + const reflection::Schema &schema, + const reflection::Object &obj, + const flatbuffers::Table *table, bool required) { if (!table) return !required; if (!table->VerifyTableStart(v)) return false; for (uoffset_t i = 0; i < obj.fields()->size(); i++) { @@ -251,8 +257,7 @@ static bool VerifyObject(flatbuffers::Verifier &v, const reflection::Schema &sch return true; } - -} // namespace +} // namespace int64_t GetAnyValueI(reflection::BaseType type, const uint8_t *data) { // clang-format off @@ -618,9 +623,6 @@ const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf, return flatbuf.data() + insertion_point + root_offset; } - - - Offset<const Table *> CopyTable(FlatBufferBuilder &fbb, const reflection::Schema &schema, const reflection::Object &objectdef, @@ -691,7 +693,7 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb, FLATBUFFERS_FALLTHROUGH(); // fall thru default: { // Scalars and structs. auto element_size = GetTypeSize(element_base_type); - auto element_alignment = element_size; // For primitive elements + auto element_alignment = element_size; // For primitive elements if (elemobjectdef && elemobjectdef->is_struct()) element_size = elemobjectdef->bytesize(); fbb.StartVector(vec->size(), element_size, element_alignment); @@ -746,7 +748,6 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb, } } - bool Verify(const reflection::Schema &schema, const reflection::Object &root, const uint8_t *const buf, const size_t length, const uoffset_t max_depth, const uoffset_t max_tables) { diff --git a/contrib/libs/flatbuffers/src/util.cpp b/contrib/libs/flatbuffers/src/util.cpp index 38d8536c09..b201246fd7 100644 --- a/contrib/libs/flatbuffers/src/util.cpp +++ b/contrib/libs/flatbuffers/src/util.cpp @@ -90,13 +90,12 @@ static std::string ToCamelCase(const std::string &input, bool is_upper) { std::string s; for (size_t i = 0; i < input.length(); i++) { if (!i && input[i] == '_') { - s += input[i]; - // we ignore leading underscore but make following - // alphabet char upper. - if (i + 1 < input.length() && is_alpha(input[i + 1])) - s += CharToUpper(input[++i]); - } - else if (!i) + s += input[i]; + // we ignore leading underscore but make following + // alphabet char upper. + if (i + 1 < input.length() && is_alpha(input[i + 1])) + s += CharToUpper(input[++i]); + } else if (!i) s += is_upper ? CharToUpper(input[i]) : CharToLower(input[i]); else if (input[i] == '_' && i + 1 < input.length()) s += CharToUpper(input[++i]); @@ -116,7 +115,10 @@ static std::string ToSnakeCase(const std::string &input, bool screaming) { } else if (!islower(input[i])) { // Prevent duplicate underscores for Upper_Snake_Case strings // and UPPERCASE strings. - if (islower(input[i - 1]) || (isdigit(input[i-1]) && !isdigit(input[i]))) { s += '_'; } + if (islower(input[i - 1]) || + (isdigit(input[i - 1]) && !isdigit(input[i]))) { + s += '_'; + } s += screaming ? CharToUpper(input[i]) : CharToLower(input[i]); } else { s += screaming ? CharToUpper(input[i]) : input[i]; @@ -126,7 +128,7 @@ static std::string ToSnakeCase(const std::string &input, bool screaming) { } std::string ToAll(const std::string &input, - std::function<char(const char)> transform) { + std::function<char(const char)> transform) { std::string s; for (size_t i = 0; i < input.length(); i++) { s += transform(input[i]); } return s; @@ -142,7 +144,10 @@ std::string CamelToSnake(const std::string &input) { } else if (!islower(input[i])) { // Prevent duplicate underscores for Upper_Snake_Case strings // and UPPERCASE strings. - if (islower(input[i - 1]) || (isdigit(input[i-1]) && !isdigit(input[i]))) { s += '_'; } + if (islower(input[i - 1]) || + (isdigit(input[i - 1]) && !isdigit(input[i]))) { + s += '_'; + } s += CharToLower(input[i]); } else { s += input[i]; @@ -184,7 +189,6 @@ std::string ToDasher(const std::string &input) { return s; } - // Converts foo_bar_123baz_456 to foo_bar123_baz456 std::string SnakeToSnake2(const std::string &s) { if (s.length() <= 1) return s; @@ -206,8 +210,7 @@ std::string SnakeToSnake2(const std::string &s) { return result; } -} // namespace - +} // namespace bool LoadFile(const char *name, bool binary, std::string *buf) { FLATBUFFERS_ASSERT(g_load_file_function); diff --git a/contrib/libs/flatbuffers/ya.make b/contrib/libs/flatbuffers/ya.make index 64d620e2c7..2d46dbe7e4 100644 --- a/contrib/libs/flatbuffers/ya.make +++ b/contrib/libs/flatbuffers/ya.make @@ -2,9 +2,9 @@ LIBRARY() -VERSION(23.5.9) +VERSION(23.5.26) -ORIGINAL_SOURCE(https://github.com/google/flatbuffers/archive/v23.5.9.tar.gz) +ORIGINAL_SOURCE(https://github.com/google/flatbuffers/archive/v23.5.26.tar.gz) LICENSE(Apache-2.0) |