From ef0eb3701d9d765f4f0955d6f48ac07eb89bd8a4 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Sat, 15 May 2021 12:54:08 -0700 Subject: [PATCH] Ran clang-format-all.sh. Removed default --style=file parameter (#6639) * Ran clang-format-all.sh. Removed default --style=file parameter * Moved scripts to scripts/ location --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .travis/format_check.sh | 2 +- Formatters.md | 2 +- include/flatbuffers/flexbuffers.h | 10 +++--- include/flatbuffers/idl.h | 12 ++----- scripts/clang-format-all.sh | 6 ++++ {src => scripts}/clang-format-git.sh | 2 +- src/clang-format-all.sh | 6 ---- src/idl_gen_cpp.cpp | 7 ++-- src/idl_gen_csharp.cpp | 9 +++-- src/idl_gen_python.cpp | 49 +++++++++++++++------------- src/idl_gen_ts.cpp | 6 ++-- src/util.cpp | 4 ++- tests/test.cpp | 15 +++++---- 14 files changed, 65 insertions(+), 67 deletions(-) create mode 100644 scripts/clang-format-all.sh rename {src => scripts}/clang-format-git.sh (94%) delete mode 100644 src/clang-format-all.sh diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 949e76fff..db9f09a26 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -13,7 +13,7 @@ If your PR includes C++ code, please adhere to the Google C++ Style Guide, and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3), so only some C++11 support is available. -For any C++ changes, please make sure to run `sh src/clang-format-git.sh` +For any C++ changes, please make sure to run `sh scripts/clang-format-git.sh` Include other details as appropriate. diff --git a/.travis/format_check.sh b/.travis/format_check.sh index c96d8db80..cbd1d9b0b 100644 --- a/.travis/format_check.sh +++ b/.travis/format_check.sh @@ -21,7 +21,7 @@ source ~/.nvm/nvm.sh nvm alias default node nvm use default -sh src/clang-format-git.sh +sh scripts/clang-format-git.sh # Check formatting for go lang diff --git a/Formatters.md b/Formatters.md index 18a51c4c5..877c5f201 100644 --- a/Formatters.md +++ b/Formatters.md @@ -11,7 +11,7 @@ If you are interesting in contributing to the flatbuffers project, please take a ## C++ -C++ uses `clang-format` as it's formatter. Run the following script `sh src/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html). +C++ uses `clang-format` as it's formatter. Run the following script `sh scripts/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html). ## Swift diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index c71928e8a..3268eabf4 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -1397,12 +1397,10 @@ class Builder FLATBUFFERS_FINAL_CLASS { template static Type GetScalarType() { static_assert(flatbuffers::is_scalar::value, "Unrelated types"); - return flatbuffers::is_floating_point::value - ? FBT_FLOAT - : flatbuffers::is_same::value - ? FBT_BOOL - : (flatbuffers::is_unsigned::value ? FBT_UINT - : FBT_INT); + return flatbuffers::is_floating_point::value ? FBT_FLOAT + : flatbuffers::is_same::value + ? FBT_BOOL + : (flatbuffers::is_unsigned::value ? FBT_UINT : FBT_INT); } public: diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 29bf62153..7e2a4e293 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -307,15 +307,9 @@ struct FieldDef : public Definition { bool IsScalarOptional() const { return IsScalar(value.type.base_type) && IsOptional(); } - bool IsOptional() const { - return presence == kOptional; - } - bool IsRequired() const { - return presence == kRequired; - } - bool IsDefault() const { - return presence == kDefault; - } + bool IsOptional() const { return presence == kOptional; } + bool IsRequired() const { return presence == kRequired; } + bool IsDefault() const { return presence == kDefault; } Value value; bool deprecated; // Field is allowed to be present in old data, but can't be. diff --git a/scripts/clang-format-all.sh b/scripts/clang-format-all.sh new file mode 100644 index 000000000..d8aa7be6a --- /dev/null +++ b/scripts/clang-format-all.sh @@ -0,0 +1,6 @@ +# Running it twice corrects some bugs in clang-format. +for run in {1..2} +do + clang-format -i include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp +done +git checkout include/flatbuffers/reflection_generated.h diff --git a/src/clang-format-git.sh b/scripts/clang-format-git.sh similarity index 94% rename from src/clang-format-git.sh rename to scripts/clang-format-git.sh index 0611cbba2..b962d6161 100644 --- a/src/clang-format-git.sh +++ b/scripts/clang-format-git.sh @@ -1,6 +1,6 @@ # Running it twice corrects some bugs in clang-format. for run in {1..2} do - git clang-format HEAD^ -- include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp + git clang-format HEAD^ -- include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp -f done git checkout include/flatbuffers/reflection_generated.h diff --git a/src/clang-format-all.sh b/src/clang-format-all.sh deleted file mode 100644 index 3fd9e3375..000000000 --- a/src/clang-format-all.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Running it twice corrects some bugs in clang-format. -for run in {1..2} -do - clang-format -i -style=file include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp -done -git checkout include/flatbuffers/reflection_generated.h diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 210a38f7a..005e01d66 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1009,10 +1009,9 @@ class CppGenerator : public BaseGenerator { ? bt - BASE_TYPE_UTYPE + ET_UTYPE : ET_SEQUENCE; int ref_idx = -1; - std::string ref_name = - type.struct_def - ? WrapInNameSpace(*type.struct_def) - : type.enum_def ? WrapInNameSpace(*type.enum_def) : ""; + std::string ref_name = type.struct_def ? WrapInNameSpace(*type.struct_def) + : type.enum_def ? WrapInNameSpace(*type.enum_def) + : ""; if (!ref_name.empty()) { auto rit = type_refs.begin(); for (; rit != type_refs.end(); ++rit) { diff --git a/src/idl_gen_csharp.cpp b/src/idl_gen_csharp.cpp index 681ab6d64..fd70c4c06 100644 --- a/src/idl_gen_csharp.cpp +++ b/src/idl_gen_csharp.cpp @@ -1515,11 +1515,10 @@ class CSharpGenerator : public BaseGenerator { case BASE_TYPE_ARRAY: { auto type_name = GenTypeGet_ObjectAPI(field.value.type, opts); auto length_str = NumToString(field.value.type.fixed_length); - auto unpack_method = field.value.type.struct_def == nullptr - ? "" - : field.value.type.struct_def->fixed - ? ".UnPack()" - : "?.UnPack()"; + auto unpack_method = field.value.type.struct_def == nullptr ? "" + : field.value.type.struct_def->fixed + ? ".UnPack()" + : "?.UnPack()"; code += start + "new " + type_name.substr(0, type_name.length() - 1) + length_str + "];\n"; code += " for (var _j = 0; _j < " + length_str + "; ++_j) { _o." + diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index b3f394ebf..e7d6c3c81 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -141,7 +141,9 @@ class PythonGenerator : public BaseGenerator { code += Indent + "def GetRootAs"; code += NormalizedName(struct_def); code += "(cls, buf, offset=0):\n"; - code += Indent + Indent + "\"\"\"This method is deprecated. Please switch to GetRootAs.\"\"\"\n"; + code += + Indent + Indent + + "\"\"\"This method is deprecated. Please switch to GetRootAs.\"\"\"\n"; code += Indent + Indent + "return cls.GetRootAs(buf, offset)\n"; } @@ -560,7 +562,8 @@ class PythonGenerator : public BaseGenerator { // Add alias with the old name. code += "def " + NormalizedName(struct_def) + "Start(builder):\n"; - code += Indent + "\"\"\"This method is deprecated. Please switch to Start.\"\"\"\n"; + code += Indent + + "\"\"\"This method is deprecated. Please switch to Start.\"\"\"\n"; code += Indent + "return Start(builder)\n"; } @@ -589,7 +592,8 @@ class PythonGenerator : public BaseGenerator { code += ")\n"; // Add alias with the old name. - code += "def " + NormalizedName(struct_def) + "Add" + MakeCamel(NormalizedName(field)); + code += "def " + NormalizedName(struct_def) + "Add" + + MakeCamel(NormalizedName(field)); code += "(builder, "; code += MakeCamel(NormalizedName(field), false); code += "):\n"; @@ -621,7 +625,8 @@ class PythonGenerator : public BaseGenerator { code += "def " + NormalizedName(struct_def) + "Start"; code += MakeCamel(NormalizedName(field)); code += "Vector(builder, numElems):\n"; - code += Indent + "\"\"\"This method is deprecated. Please switch to Start.\"\"\"\n"; + code += Indent + + "\"\"\"This method is deprecated. Please switch to Start.\"\"\"\n"; code += Indent + "return Start"; code += MakeCamel(NormalizedName(field)); code += "Vector(builder, numElems)\n"; @@ -630,7 +635,8 @@ class PythonGenerator : public BaseGenerator { // Set the value of one of the members of a table's vector and fills in the // elements from a bytearray. This is for simplifying the use of nested // flatbuffers. - void BuildVectorOfTableFromBytes(const FieldDef &field, std::string *code_ptr) { + void BuildVectorOfTableFromBytes(const FieldDef &field, + std::string *code_ptr) { auto nested = field.attributes.Lookup("nested_flatbuffer"); if (!nested) { return; } // There is no nested flatbuffer. @@ -679,7 +685,8 @@ class PythonGenerator : public BaseGenerator { // Add alias with the old name. code += "def " + NormalizedName(struct_def) + "End(builder):\n"; - code += Indent + "\"\"\"This method is deprecated. Please switch to End.\"\"\"\n"; + code += Indent + + "\"\"\"This method is deprecated. Please switch to End.\"\"\"\n"; code += Indent + "return End(builder)"; } @@ -1287,9 +1294,8 @@ class PythonGenerator : public BaseGenerator { code_prefix += GenIndents(2) + "if self." + field_instance_name + " is not None:"; if (field.value.type.struct_def->fixed) { - code_prefix += GenIndents(3) + "Start" + - field_accessor_name + "Vector(builder, len(self." + - field_instance_name + "))"; + code_prefix += GenIndents(3) + "Start" + field_accessor_name + + "Vector(builder, len(self." + field_instance_name + "))"; code_prefix += GenIndents(3) + "for i in reversed(range(len(self." + field_instance_name + "))):"; code_prefix += @@ -1305,9 +1311,8 @@ class PythonGenerator : public BaseGenerator { code_prefix += GenIndents(4) + field_instance_name + "list.append(self." + field_instance_name + "[i].Pack(builder))"; - code_prefix += GenIndents(3) + "Start" + - field_accessor_name + "Vector(builder, len(self." + - field_instance_name + "))"; + code_prefix += GenIndents(3) + "Start" + field_accessor_name + + "Vector(builder, len(self." + field_instance_name + "))"; code_prefix += GenIndents(3) + "for i in reversed(range(len(self." + field_instance_name + "))):"; code_prefix += GenIndents(4) + "builder.PrependUOffsetTRelative" + "(" + @@ -1318,8 +1323,8 @@ class PythonGenerator : public BaseGenerator { // Adds the field into the struct. code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; - code += GenIndents(3) + "Add" + field_accessor_name + - "(builder, " + field_instance_name + ")"; + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " + + field_instance_name + ")"; } void GenPackForScalarVectorFieldHelper(const StructDef &struct_def, @@ -1368,8 +1373,8 @@ class PythonGenerator : public BaseGenerator { // Adds the field into the struct. code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; - code += GenIndents(3) + "Add" + field_accessor_name + - "(builder, " + field_instance_name + ")"; + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " + + field_instance_name + ")"; // Creates the field. code_prefix += @@ -1431,8 +1436,8 @@ class PythonGenerator : public BaseGenerator { GenIndents(2) + "if self." + field_instance_name + " is not None:"; } - code += GenIndents(3) + "Add" + field_accessor_name + - "(builder, " + field_instance_name + ")"; + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " + + field_instance_name + ")"; } void GenPackForUnionField(const StructDef &struct_def, const FieldDef &field, @@ -1451,8 +1456,8 @@ class PythonGenerator : public BaseGenerator { code_prefix += GenIndents(3) + field_instance_name + " = self." + field_instance_name + ".Pack(builder)"; code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; - code += GenIndents(3) + "Add" + field_accessor_name + - "(builder, " + field_instance_name + ")"; + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " + + field_instance_name + ")"; } void GenPackForTable(const StructDef &struct_def, std::string *code_ptr) { @@ -1502,8 +1507,8 @@ class PythonGenerator : public BaseGenerator { ")"; code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; - code += GenIndents(3) + "Add" + field_accessor_name + - "(builder, " + field_instance_name + ")"; + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " + + field_instance_name + ")"; break; } default: diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 53e088fe1..9128ce1e2 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -316,9 +316,9 @@ class TsGenerator : public BaseGenerator { GenStructArgs(imports, *field.value.type.struct_def, arguments, nameprefix + field.name + "_"); } else { - *arguments += - ", " + nameprefix + field.name + ": " + - GenTypeName(imports, field, field.value.type, true, field.IsOptional()); + *arguments += ", " + nameprefix + field.name + ": " + + GenTypeName(imports, field, field.value.type, true, + field.IsOptional()); } } } diff --git a/src/util.cpp b/src/util.cpp index 3670a0193..3f61dd514 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -40,14 +40,16 @@ #endif // clang-format on -#include "flatbuffers/base.h" #include "flatbuffers/util.h" #include + #include #include #include +#include "flatbuffers/base.h" + namespace flatbuffers { bool FileExistsRaw(const char *name) { diff --git a/tests/test.cpp b/tests/test.cpp index f2d7207c5..3b94e7b69 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -32,22 +32,21 @@ #include "monster_test_generated.h" #include "namespace_test/namespace_test1_generated.h" #include "namespace_test/namespace_test2_generated.h" -#include "union_vector/union_vector_generated.h" #include "optional_scalars_generated.h" +#include "union_vector/union_vector_generated.h" #if !defined(_MSC_VER) || _MSC_VER >= 1700 -# include "monster_extra_generated.h" # include "arrays_test_generated.h" # include "evolution_test/evolution_v1_generated.h" # include "evolution_test/evolution_v2_generated.h" +# include "monster_extra_generated.h" #endif -#include "native_type_test_generated.h" -#include "test_assert.h" - #include "flatbuffers/flexbuffers.h" #include "monster_test_bfbs_generated.h" // Generated using --bfbs-comments --bfbs-builtins --cpp --bfbs-gen-embed +#include "native_type_test_generated.h" +#include "test_assert.h" -// clang-format off + // clang-format off // Check that char* and uint8_t* are interoperable types. // The reinterpret_cast<> between the pointers are used to simplify data loading. static_assert(flatbuffers::is_same::value || @@ -1545,7 +1544,9 @@ void FuzzTest2() { } } AddToSchemaAndInstances(deprecated ? "(deprecated);\n" : ";\n", - deprecated ? "" : is_last_field ? "\n" : ",\n"); + deprecated ? "" + : is_last_field ? "\n" + : ",\n"); } AddToSchemaAndInstances("}\n\n", "}"); }