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
This commit is contained in:
Derek Bailey
2021-05-15 12:54:08 -07:00
committed by GitHub
parent f83ee1af59
commit ef0eb3701d
14 changed files with 65 additions and 67 deletions

View File

@@ -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), 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. 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. Include other details as appropriate.

View File

@@ -21,7 +21,7 @@ source ~/.nvm/nvm.sh
nvm alias default node nvm alias default node
nvm use default nvm use default
sh src/clang-format-git.sh sh scripts/clang-format-git.sh
# Check formatting for go lang # Check formatting for go lang

View File

@@ -11,7 +11,7 @@ If you are interesting in contributing to the flatbuffers project, please take a
## C++ ## 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 ## Swift

View File

@@ -1397,12 +1397,10 @@ class Builder FLATBUFFERS_FINAL_CLASS {
template<typename T> static Type GetScalarType() { template<typename T> static Type GetScalarType() {
static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types"); static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types");
return flatbuffers::is_floating_point<T>::value return flatbuffers::is_floating_point<T>::value ? FBT_FLOAT
? FBT_FLOAT : flatbuffers::is_same<T, bool>::value
: flatbuffers::is_same<T, bool>::value ? FBT_BOOL
? FBT_BOOL : (flatbuffers::is_unsigned<T>::value ? FBT_UINT : FBT_INT);
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT
: FBT_INT);
} }
public: public:

View File

@@ -307,15 +307,9 @@ struct FieldDef : public Definition {
bool IsScalarOptional() const { bool IsScalarOptional() const {
return IsScalar(value.type.base_type) && IsOptional(); return IsScalar(value.type.base_type) && IsOptional();
} }
bool IsOptional() const { bool IsOptional() const { return presence == kOptional; }
return presence == kOptional; bool IsRequired() const { return presence == kRequired; }
} bool IsDefault() const { return presence == kDefault; }
bool IsRequired() const {
return presence == kRequired;
}
bool IsDefault() const {
return presence == kDefault;
}
Value value; Value value;
bool deprecated; // Field is allowed to be present in old data, but can't be. bool deprecated; // Field is allowed to be present in old data, but can't be.

View File

@@ -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

View File

@@ -1,6 +1,6 @@
# Running it twice corrects some bugs in clang-format. # Running it twice corrects some bugs in clang-format.
for run in {1..2} for run in {1..2}
do 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 done
git checkout include/flatbuffers/reflection_generated.h git checkout include/flatbuffers/reflection_generated.h

View File

@@ -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

View File

@@ -1009,10 +1009,9 @@ class CppGenerator : public BaseGenerator {
? bt - BASE_TYPE_UTYPE + ET_UTYPE ? bt - BASE_TYPE_UTYPE + ET_UTYPE
: ET_SEQUENCE; : ET_SEQUENCE;
int ref_idx = -1; int ref_idx = -1;
std::string ref_name = std::string ref_name = type.struct_def ? WrapInNameSpace(*type.struct_def)
type.struct_def : type.enum_def ? WrapInNameSpace(*type.enum_def)
? WrapInNameSpace(*type.struct_def) : "";
: type.enum_def ? WrapInNameSpace(*type.enum_def) : "";
if (!ref_name.empty()) { if (!ref_name.empty()) {
auto rit = type_refs.begin(); auto rit = type_refs.begin();
for (; rit != type_refs.end(); ++rit) { for (; rit != type_refs.end(); ++rit) {

View File

@@ -1515,11 +1515,10 @@ class CSharpGenerator : public BaseGenerator {
case BASE_TYPE_ARRAY: { case BASE_TYPE_ARRAY: {
auto type_name = GenTypeGet_ObjectAPI(field.value.type, opts); auto type_name = GenTypeGet_ObjectAPI(field.value.type, opts);
auto length_str = NumToString(field.value.type.fixed_length); auto length_str = NumToString(field.value.type.fixed_length);
auto unpack_method = field.value.type.struct_def == nullptr auto unpack_method = field.value.type.struct_def == nullptr ? ""
? "" : field.value.type.struct_def->fixed
: field.value.type.struct_def->fixed ? ".UnPack()"
? ".UnPack()" : "?.UnPack()";
: "?.UnPack()";
code += start + "new " + type_name.substr(0, type_name.length() - 1) + code += start + "new " + type_name.substr(0, type_name.length() - 1) +
length_str + "];\n"; length_str + "];\n";
code += " for (var _j = 0; _j < " + length_str + "; ++_j) { _o." + code += " for (var _j = 0; _j < " + length_str + "; ++_j) { _o." +

View File

@@ -141,7 +141,9 @@ class PythonGenerator : public BaseGenerator {
code += Indent + "def GetRootAs"; code += Indent + "def GetRootAs";
code += NormalizedName(struct_def); code += NormalizedName(struct_def);
code += "(cls, buf, offset=0):\n"; 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"; code += Indent + Indent + "return cls.GetRootAs(buf, offset)\n";
} }
@@ -560,7 +562,8 @@ class PythonGenerator : public BaseGenerator {
// Add alias with the old name. // Add alias with the old name.
code += "def " + NormalizedName(struct_def) + "Start(builder):\n"; 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"; code += Indent + "return Start(builder)\n";
} }
@@ -589,7 +592,8 @@ class PythonGenerator : public BaseGenerator {
code += ")\n"; code += ")\n";
// Add alias with the old name. // 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 += "(builder, ";
code += MakeCamel(NormalizedName(field), false); code += MakeCamel(NormalizedName(field), false);
code += "):\n"; code += "):\n";
@@ -621,7 +625,8 @@ class PythonGenerator : public BaseGenerator {
code += "def " + NormalizedName(struct_def) + "Start"; code += "def " + NormalizedName(struct_def) + "Start";
code += MakeCamel(NormalizedName(field)); code += MakeCamel(NormalizedName(field));
code += "Vector(builder, numElems):\n"; 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 += Indent + "return Start";
code += MakeCamel(NormalizedName(field)); code += MakeCamel(NormalizedName(field));
code += "Vector(builder, numElems)\n"; 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 // 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 // elements from a bytearray. This is for simplifying the use of nested
// flatbuffers. // 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"); auto nested = field.attributes.Lookup("nested_flatbuffer");
if (!nested) { return; } // There is no nested flatbuffer. if (!nested) { return; } // There is no nested flatbuffer.
@@ -679,7 +685,8 @@ class PythonGenerator : public BaseGenerator {
// Add alias with the old name. // Add alias with the old name.
code += "def " + NormalizedName(struct_def) + "End(builder):\n"; 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)"; code += Indent + "return End(builder)";
} }
@@ -1287,9 +1294,8 @@ class PythonGenerator : public BaseGenerator {
code_prefix += code_prefix +=
GenIndents(2) + "if self." + field_instance_name + " is not None:"; GenIndents(2) + "if self." + field_instance_name + " is not None:";
if (field.value.type.struct_def->fixed) { if (field.value.type.struct_def->fixed) {
code_prefix += GenIndents(3) + "Start" + code_prefix += GenIndents(3) + "Start" + field_accessor_name +
field_accessor_name + "Vector(builder, len(self." + "Vector(builder, len(self." + field_instance_name + "))";
field_instance_name + "))";
code_prefix += GenIndents(3) + "for i in reversed(range(len(self." + code_prefix += GenIndents(3) + "for i in reversed(range(len(self." +
field_instance_name + "))):"; field_instance_name + "))):";
code_prefix += code_prefix +=
@@ -1305,9 +1311,8 @@ class PythonGenerator : public BaseGenerator {
code_prefix += GenIndents(4) + field_instance_name + "list.append(self." + code_prefix += GenIndents(4) + field_instance_name + "list.append(self." +
field_instance_name + "[i].Pack(builder))"; field_instance_name + "[i].Pack(builder))";
code_prefix += GenIndents(3) + "Start" + code_prefix += GenIndents(3) + "Start" + field_accessor_name +
field_accessor_name + "Vector(builder, len(self." + "Vector(builder, len(self." + field_instance_name + "))";
field_instance_name + "))";
code_prefix += GenIndents(3) + "for i in reversed(range(len(self." + code_prefix += GenIndents(3) + "for i in reversed(range(len(self." +
field_instance_name + "))):"; field_instance_name + "))):";
code_prefix += GenIndents(4) + "builder.PrependUOffsetTRelative" + "(" + code_prefix += GenIndents(4) + "builder.PrependUOffsetTRelative" + "(" +
@@ -1318,8 +1323,8 @@ class PythonGenerator : public BaseGenerator {
// Adds the field into the struct. // Adds the field into the struct.
code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; code += GenIndents(2) + "if self." + field_instance_name + " is not None:";
code += GenIndents(3) + "Add" + field_accessor_name + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " +
"(builder, " + field_instance_name + ")"; field_instance_name + ")";
} }
void GenPackForScalarVectorFieldHelper(const StructDef &struct_def, void GenPackForScalarVectorFieldHelper(const StructDef &struct_def,
@@ -1368,8 +1373,8 @@ class PythonGenerator : public BaseGenerator {
// Adds the field into the struct. // Adds the field into the struct.
code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; code += GenIndents(2) + "if self." + field_instance_name + " is not None:";
code += GenIndents(3) + "Add" + field_accessor_name + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " +
"(builder, " + field_instance_name + ")"; field_instance_name + ")";
// Creates the field. // Creates the field.
code_prefix += code_prefix +=
@@ -1431,8 +1436,8 @@ class PythonGenerator : public BaseGenerator {
GenIndents(2) + "if self." + field_instance_name + " is not None:"; GenIndents(2) + "if self." + field_instance_name + " is not None:";
} }
code += GenIndents(3) + "Add" + field_accessor_name + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " +
"(builder, " + field_instance_name + ")"; field_instance_name + ")";
} }
void GenPackForUnionField(const StructDef &struct_def, const FieldDef &field, 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." + code_prefix += GenIndents(3) + field_instance_name + " = self." +
field_instance_name + ".Pack(builder)"; field_instance_name + ".Pack(builder)";
code += GenIndents(2) + "if self." + field_instance_name + " is not None:"; code += GenIndents(2) + "if self." + field_instance_name + " is not None:";
code += GenIndents(3) + "Add" + field_accessor_name + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " +
"(builder, " + field_instance_name + ")"; field_instance_name + ")";
} }
void GenPackForTable(const StructDef &struct_def, std::string *code_ptr) { 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 + code += GenIndents(2) + "if self." + field_instance_name +
" is not None:"; " is not None:";
code += GenIndents(3) + "Add" + field_accessor_name + code += GenIndents(3) + "Add" + field_accessor_name + "(builder, " +
"(builder, " + field_instance_name + ")"; field_instance_name + ")";
break; break;
} }
default: default:

View File

@@ -316,9 +316,9 @@ class TsGenerator : public BaseGenerator {
GenStructArgs(imports, *field.value.type.struct_def, arguments, GenStructArgs(imports, *field.value.type.struct_def, arguments,
nameprefix + field.name + "_"); nameprefix + field.name + "_");
} else { } else {
*arguments += *arguments += ", " + nameprefix + field.name + ": " +
", " + nameprefix + field.name + ": " + GenTypeName(imports, field, field.value.type, true,
GenTypeName(imports, field, field.value.type, true, field.IsOptional()); field.IsOptional());
} }
} }
} }

View File

@@ -40,14 +40,16 @@
#endif #endif
// clang-format on // clang-format on
#include "flatbuffers/base.h"
#include "flatbuffers/util.h" #include "flatbuffers/util.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <clocale> #include <clocale>
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include "flatbuffers/base.h"
namespace flatbuffers { namespace flatbuffers {
bool FileExistsRaw(const char *name) { bool FileExistsRaw(const char *name) {

View File

@@ -32,22 +32,21 @@
#include "monster_test_generated.h" #include "monster_test_generated.h"
#include "namespace_test/namespace_test1_generated.h" #include "namespace_test/namespace_test1_generated.h"
#include "namespace_test/namespace_test2_generated.h" #include "namespace_test/namespace_test2_generated.h"
#include "union_vector/union_vector_generated.h"
#include "optional_scalars_generated.h" #include "optional_scalars_generated.h"
#include "union_vector/union_vector_generated.h"
#if !defined(_MSC_VER) || _MSC_VER >= 1700 #if !defined(_MSC_VER) || _MSC_VER >= 1700
# include "monster_extra_generated.h"
# include "arrays_test_generated.h" # include "arrays_test_generated.h"
# include "evolution_test/evolution_v1_generated.h" # include "evolution_test/evolution_v1_generated.h"
# include "evolution_test/evolution_v2_generated.h" # include "evolution_test/evolution_v2_generated.h"
# include "monster_extra_generated.h"
#endif #endif
#include "native_type_test_generated.h"
#include "test_assert.h"
#include "flatbuffers/flexbuffers.h" #include "flatbuffers/flexbuffers.h"
#include "monster_test_bfbs_generated.h" // Generated using --bfbs-comments --bfbs-builtins --cpp --bfbs-gen-embed #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. // Check that char* and uint8_t* are interoperable types.
// The reinterpret_cast<> between the pointers are used to simplify data loading. // The reinterpret_cast<> between the pointers are used to simplify data loading.
static_assert(flatbuffers::is_same<uint8_t, char>::value || static_assert(flatbuffers::is_same<uint8_t, char>::value ||
@@ -1545,7 +1544,9 @@ void FuzzTest2() {
} }
} }
AddToSchemaAndInstances(deprecated ? "(deprecated);\n" : ";\n", AddToSchemaAndInstances(deprecated ? "(deprecated);\n" : ";\n",
deprecated ? "" : is_last_field ? "\n" : ",\n"); deprecated ? ""
: is_last_field ? "\n"
: ",\n");
} }
AddToSchemaAndInstances("}\n\n", "}"); AddToSchemaAndInstances("}\n\n", "}");
} }