Run clang-format -i **/*.cpp (#8865)

This commit is contained in:
Derek Bailey
2025-12-19 10:42:57 -08:00
committed by GitHub
parent d9fde67eb5
commit fb55e0c9de
24 changed files with 213 additions and 192 deletions

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
#include "flatbuffers/file_manager.h"
#include <fstream>
#include <set>
#include <string>
#include "flatbuffers/file_manager.h"
namespace flatbuffers {
bool RealFileSaver::SaveFile(const char* name, const char* buf, size_t len,

View File

@@ -652,19 +652,23 @@ class CSharpGenerator : public BaseGenerator {
// Get the getter for the key of the struct.
if (IsString(key_field->value.type)) {
return "string.CompareOrdinal(" +
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
"builder.DataBuffer.Length - o1.Value") +
", " +
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
"builder.DataBuffer.Length - o2.Value") +
")";
GenGetterForLookupByKey(struct_def, key_field,
"builder.DataBuffer",
"builder.DataBuffer.Length - o1.Value") +
", " +
GenGetterForLookupByKey(struct_def, key_field,
"builder.DataBuffer",
"builder.DataBuffer.Length - o2.Value") +
")";
} else {
return GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
"builder.DataBuffer.Length - o1.Value") +
".CompareTo(" +
GenGetterForLookupByKey(struct_def, key_field, "builder.DataBuffer",
"builder.DataBuffer.Length - o2.Value") +
")";
return GenGetterForLookupByKey(struct_def, key_field,
"builder.DataBuffer",
"builder.DataBuffer.Length - o1.Value") +
".CompareTo(" +
GenGetterForLookupByKey(struct_def, key_field,
"builder.DataBuffer",
"builder.DataBuffer.Length - o2.Value") +
")";
}
}
@@ -1596,7 +1600,8 @@ class CSharpGenerator : public BaseGenerator {
code += " obj_.__assign(tableOffset, bb);\n";
if (IsString(key_field->value.type)) {
code += " int comp = string.CompareOrdinal(obj_." + name + ", key);\n";
code +=
" int comp = string.CompareOrdinal(obj_." + name + ", key);\n";
} else {
code += " int comp = obj_." + name + ".CompareTo(key);\n";
}

View File

@@ -56,16 +56,16 @@ static Namer::Config JavaDefaultConfig() {
static std::set<std::string> JavaKeywords() {
return {
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements","import",
"instanceof","int", "interface", "long", "native",
"new", "notify", "package", "private", "protected",
"public", "return", "short", "static", "strictfp",
"super", "switch", "synchronized","this", "throw",
"throws", "transient","try", "void", "volatile",
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "notify", "package", "private", "protected",
"public", "return", "short", "static", "strictfp",
"super", "switch", "synchronized", "this", "throw",
"throws", "transient", "try", "void", "volatile",
"while",
};
}
@@ -1468,7 +1468,8 @@ class JavaGenerator : public BaseGenerator {
" " + variable_name + "Type = " + field_name + "Type(" +
type_params + ");\n";
code += indent + variable_name + ".setType(" + variable_name + "Type);\n";
code += indent + "com.google.flatbuffers.Table " + variable_name + "Value;\n";
code +=
indent + "com.google.flatbuffers.Table " + variable_name + "Value;\n";
code += indent + "switch (" + variable_name + "Type) {\n";
for (auto eit = enum_def.Vals().begin(); eit != enum_def.Vals().end();
++eit) {

View File

@@ -1216,8 +1216,8 @@ class KotlinGenerator : public BaseGenerator {
// fun inventoryInByteBuffer(_bb: Bytebuffer):
// ByteBuffer? = __vector_as_bytebuffer(_bb, 14, 1)
GenerateFunOneLine(
writer, field_name + "InByteBuffer", "_bb: ByteBuffer",
buffer_type, [&]() {
writer, field_name + "InByteBuffer", "_bb: ByteBuffer", buffer_type,
[&]() {
writer.SetValue("end", end_idx);
writer += "__vector_in_bytebuffer(_bb, {{offset}}, {{end}})";
});

View File

@@ -2885,8 +2885,7 @@ class PythonGenerator : public BaseGenerator {
EnsureDirExists(directories);
for (size_t i = directories.find(kPathSeparator, path_.size());
i != std::string::npos;
i = directories.find(kPathSeparator, i + 1)) {
i != std::string::npos; i = directories.find(kPathSeparator, i + 1)) {
const std::string init_py =
directories.substr(0, i) + kPathSeparator + "__init__.py";
parser_.opts.file_saver->SaveFile(init_py.c_str(), "", false);
@@ -2904,7 +2903,7 @@ class PythonGenerator : public BaseGenerator {
} // namespace python
static const char* GeneratePython(const Parser& parser, const std::string& path,
const std::string& file_name) {
const std::string& file_name) {
python::Version version{parser.opts.python_version};
if (!version.IsValid()) return "The provided Python version is not valid";
@@ -2913,7 +2912,8 @@ static const char* GeneratePython(const Parser& parser, const std::string& path,
if (parser.opts.python_typing) {
python::PythonStubGenerator stub_generator(parser, path, version);
if (!stub_generator.Generate()) return "could not generate Python type stubs";
if (!stub_generator.Generate())
return "could not generate Python type stubs";
}
return nullptr;
}
@@ -2948,7 +2948,8 @@ class PythonCodeGenerator : public CodeGenerator {
Status GenerateGrpcCode(const Parser& parser, const std::string& path,
const std::string& filename) override {
if (!GeneratePythonGRPC(parser, path, filename)) { // TODO add status GeneratePythonGRPC
if (!GeneratePythonGRPC(parser, path,
filename)) { // TODO add status GeneratePythonGRPC
return Status::ERROR;
}
return Status::OK;

View File

@@ -1347,7 +1347,8 @@ class SwiftGenerator : public BaseGenerator {
}
void GenerateObjectAPIStructConstructor(const StructDef& struct_def) {
code_ += "{{ACCESS_TYPE}} init(_ _t: borrowing {{STRUCTNAME}}" + Mutable() + ") {";
code_ += "{{ACCESS_TYPE}} init(_ _t: borrowing {{STRUCTNAME}}" + Mutable() +
") {";
Indent();
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) {
@@ -1393,8 +1394,9 @@ class SwiftGenerator : public BaseGenerator {
base_constructor);
}
code_ += "";
BuildObjectConstructor(buffer_constructor,
"_ _t: borrowing " + namer_.NamespacedType(struct_def));
BuildObjectConstructor(
buffer_constructor,
"_ _t: borrowing " + namer_.NamespacedType(struct_def));
BuildObjectConstructor(base_constructor);
if (!struct_def.fixed)
code_ +=
@@ -1960,7 +1962,7 @@ class SwiftGenerator : public BaseGenerator {
std::string GenType(const Type& type,
const bool should_consider_suffix = false) const {
return IsScalar(type.base_type) ? GenTypeBasic(type)
: IsArray(type) ? GenType(type.VectorType())
: IsArray(type) ? GenType(type.VectorType())
: GenTypePointer(type, should_consider_suffix);
}

View File

@@ -339,8 +339,7 @@ class TsGenerator : public BaseGenerator {
for (auto it = dc.begin(); it != dc.end(); ++it) {
if (indent) code += indent;
std::string safe = *it;
for (size_t pos = 0;
(pos = safe.find("*/", pos)) != std::string::npos;) {
for (size_t pos = 0; (pos = safe.find("*/", pos)) != std::string::npos;) {
safe.replace(pos, 2, "*\\/");
pos += 3;
}