run scripts/clang-format-all.sh

This commit is contained in:
Derek Bailey
2023-05-11 12:23:49 -07:00
parent c2f764c22b
commit 86486a1735
21 changed files with 115 additions and 101 deletions

View File

@@ -85,14 +85,13 @@ inline SizeT GetPrefixedSize(const uint8_t *buf) {
//
// This includes the size of the prefix as well as the buffer:
//
// [size prefix][flatbuffer]
// [size prefix][flatbuffer]
// |---------length--------|
template<typename SizeT = uoffset_t>
inline SizeT GetSizePrefixedBufferLength(const uint8_t * const buf) {
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.

View File

@@ -1212,7 +1212,8 @@ class Parser : public ParserState {
// 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,
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,

View File

@@ -54,8 +54,8 @@ class Registry {
// Now we're ready to generate text.
auto err = GenerateText(parser, flatbuf, dest);
if (err) {
lasterror_ = "unable to generate text for FlatBuffer binary: " +
std::string(err);
lasterror_ =
"unable to generate text for FlatBuffer binary: " + std::string(err);
return false;
}
return true;

View File

@@ -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);
}

View File

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

View File

@@ -17,9 +17,8 @@
#ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_
#define FLATBUFFERS_VECTOR_DOWNWARD_H_
#include <cstdint>
#include <algorithm>
#include <cstdint>
#include "flatbuffers/base.h"
#include "flatbuffers/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_); }

View File

@@ -656,7 +656,8 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
// TODO(derekbailey): figure out a save file without depending on util.h
EnsureDirExists(path);
const std::string file_name = options_.output_path + path + "/" + namer_.File(name);
const std::string file_name =
options_.output_path + path + "/" + namer_.File(name);
SaveFile(file_name.c_str(), code, false);
}

View File

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

View File

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

View File

@@ -2368,8 +2368,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 {

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
#include "alignment_test.h"
#include "flatbuffers/flatbuffer_builder.h"
#include "alignment_test_generated.h"
#include "flatbuffers/flatbuffer_builder.h"
#include "test_assert.h"
namespace flatbuffers {
@@ -16,7 +16,7 @@ void AlignmentTest() {
BadAlignmentSmall *small;
Offset<Vector<const BadAlignmentSmall *>> small_offset =
builder.CreateUninitializedVectorOfStructs(9, &small);
(void)small; // We do not have to write data to trigger the test failure
(void)small; // We do not have to write data to trigger the test failure
Offset<BadAlignmentRoot> root =
CreateBadAlignmentRoot(builder, outer_large, small_offset);

View File

@@ -1,7 +1,7 @@
#include <limits>
#include "flexbuffers_test.h"
#include <limits>
#include "flatbuffers/flexbuffers.h"
#include "flatbuffers/idl.h"
#include "is_quiet_nan.h"

View File

@@ -1,7 +1,7 @@
#include <algorithm>
#include "fuzz_test.h"
#include <algorithm>
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "test_assert.h"
@@ -22,7 +22,7 @@ void lcg_reset() { lcg_seed = 48271; }
template<typename T>
static void CompareTableFieldValue(flatbuffers::Table *table,
flatbuffers::voffset_t voffset, T val) {
flatbuffers::voffset_t voffset, T val) {
T read = table->GetField(voffset, static_cast<T>(0));
TEST_EQ(read, val);
}

View File

@@ -2,8 +2,8 @@
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "monster_test_bfbs_generated.h"
#include "monster_test_generated.h"
#include "monster_test_bfbs_generated.h"
#include "optional_scalars_generated.h"
#include "test_assert.h"
@@ -13,7 +13,7 @@ namespace tests {
using namespace MyGame::Example;
// Check stringify of an default enum value to json
void JsonDefaultTest(const std::string& tests_data_path) {
void JsonDefaultTest(const std::string &tests_data_path) {
// load FlatBuffer schema (.fbs) from disk
std::string schemafile;
TEST_EQ(flatbuffers::LoadFile((tests_data_path + "monster_test.fbs").c_str(),
@@ -44,7 +44,7 @@ void JsonDefaultTest(const std::string& tests_data_path) {
TEST_EQ(std::string::npos != jsongen.find("testf: 3.14159"), true);
}
void JsonEnumsTest(const std::string& tests_data_path) {
void JsonEnumsTest(const std::string &tests_data_path) {
// load FlatBuffer schema (.fbs) from disk
std::string schemafile;
TEST_EQ(flatbuffers::LoadFile((tests_data_path + "monster_test.fbs").c_str(),
@@ -83,7 +83,8 @@ void JsonEnumsTest(const std::string& tests_data_path) {
TEST_EQ(std::string::npos != future_json.find("color: 13"), true);
}
void JsonOptionalTest(const std::string& tests_data_path, bool default_scalars) {
void JsonOptionalTest(const std::string &tests_data_path,
bool default_scalars) {
// load FlatBuffer schema (.fbs) and JSON from disk
std::string schemafile;
std::string jsonfile;
@@ -124,7 +125,7 @@ void JsonOptionalTest(const std::string& tests_data_path, bool default_scalars)
TEST_EQ_STR(jsongen.c_str(), jsonfile.c_str());
}
void ParseIncorrectMonsterJsonTest(const std::string& tests_data_path) {
void ParseIncorrectMonsterJsonTest(const std::string &tests_data_path) {
std::string schemafile;
TEST_EQ(flatbuffers::LoadFile((tests_data_path + "monster_test.bfbs").c_str(),
true, &schemafile),
@@ -179,7 +180,7 @@ table JsonUnionStructTest { union_with_struct: UnionWithStruct; }
root_type JsonUnionStructTest;
)";
// source text to parse and expected result of generation text back
auto json_source =R"({
auto json_source = R"({
union_with_struct_type: "MyStruct",
union_with_struct: {
field: 12345

View File

@@ -38,7 +38,6 @@ void FixedSizedScalarKeyInStructTest() {
bars.push_back(Bar(flatbuffers::make_span(test_float_array4), 1));
auto bar_vec = fbb.CreateVectorOfSortedStructs(&bars);
auto t = CreateFooTable(fbb, 1, 2, test_string, baz_vec, bar_vec);
fbb.Finish(t);
@@ -51,15 +50,11 @@ void FixedSizedScalarKeyInStructTest() {
TEST_EQ(sorted_baz_vec->Get(3)->b(), 4);
uint8_t test_array[4];
auto* key_array = &flatbuffers::CastToArray(test_array);
auto *key_array = &flatbuffers::CastToArray(test_array);
key_array->CopyFromSpan(flatbuffers::make_span(test_array1));
TEST_NOTNULL(
sorted_baz_vec->LookupByKey(key_array));
TEST_EQ(
sorted_baz_vec->LookupByKey(key_array)->b(),
4);
TEST_NOTNULL(sorted_baz_vec->LookupByKey(key_array));
TEST_EQ(sorted_baz_vec->LookupByKey(key_array)->b(), 4);
uint8_t array_int[4] = { 7, 2, 3, 0 };
key_array->CopyFromSpan(flatbuffers::make_span(array_int));
TEST_EQ(sorted_baz_vec->LookupByKey(key_array),
@@ -70,7 +65,7 @@ void FixedSizedScalarKeyInStructTest() {
TEST_EQ(sorted_bar_vec->Get(3)->b(), 4);
float test_float_array[3];
auto* key_float_array = &flatbuffers::CastToArray(test_float_array);
auto *key_float_array = &flatbuffers::CastToArray(test_float_array);
key_float_array->CopyFromSpan(flatbuffers::make_span(test_float_array1));
TEST_NOTNULL(sorted_bar_vec->LookupByKey(key_float_array));
TEST_EQ(sorted_bar_vec->LookupByKey(key_float_array)->b(), 3);
@@ -105,7 +100,6 @@ void StructKeyInStructTest() {
auto orc = foo_builder.Finish();
fbb.Finish(orc);
uint8_t *buf = fbb.GetBufferPointer();
auto foo_table = GetFooTable(buf);
@@ -153,9 +147,14 @@ void NestedStructKeyInStructTest() {
TEST_EQ(sorted_fruit_vec->Get(0)->b(), 3);
TEST_EQ(sorted_fruit_vec->Get(1)->b(), 1);
TEST_EQ(sorted_fruit_vec->Get(2)->b(), 2);
TEST_EQ(sorted_fruit_vec->LookupByKey(Apple(2, Color(flatbuffers::make_span(test_float_array2), 1)))->b(), 1);
TEST_EQ(sorted_fruit_vec->LookupByKey(Apple(1, Color(flatbuffers::make_span(test_float_array2), 1))), static_cast<const Fruit *>(nullptr));
TEST_EQ(sorted_fruit_vec
->LookupByKey(
Apple(2, Color(flatbuffers::make_span(test_float_array2), 1)))
->b(),
1);
TEST_EQ(sorted_fruit_vec->LookupByKey(
Apple(1, Color(flatbuffers::make_span(test_float_array2), 1))),
static_cast<const Fruit *>(nullptr));
}
void FixedSizedStructArrayKeyInStructTest() {

View File

@@ -1,13 +1,14 @@
#include "optional_scalars_test.h"
#include <string>
#include <vector>
#include "flatbuffers/idl.h"
#include "optional_scalars_generated.h"
#include "test_assert.h"
namespace flatbuffers{
namespace tests{
namespace flatbuffers {
namespace tests {
void OptionalScalarsTest() {
// Simple schemas and a "has optional scalar" sentinal.
@@ -97,5 +98,5 @@ void OptionalScalarsTest() {
TEST_ASSERT(opts->maybe_i32() == flatbuffers::Optional<int64_t>(-1));
}
}
}
} // namespace tests
} // namespace flatbuffers

View File

@@ -31,8 +31,9 @@ void RunTest(const flatbuffers::IDLOptions &opts, const std::string &proto_path,
TEST_EQ(import_parser.Parse(import_proto_file.c_str(), include_directories),
true);
std::string import_fbs;
TEST_EQ(fbs_generator->GenerateCodeString(import_parser, "test", import_fbs),
CodeGenerator::Status::OK);
TEST_EQ(
fbs_generator->GenerateCodeString(import_parser, "test", import_fbs),
CodeGenerator::Status::OK);
// auto import_fbs = flatbuffers::GenerateFBS(import_parser, "test", true);
// Since `imported.fbs` isn't in the filesystem AbsolutePath can't figure it
// out by itself. We manually construct it so Parser works.

View File

@@ -1,19 +1,21 @@
#include "reflection_test.h"
#include "arrays_test_generated.h"
#include "flatbuffers/minireflect.h"
#include "flatbuffers/reflection.h"
#include "flatbuffers/reflection_generated.h"
#include "flatbuffers/verifier.h"
#include "test_assert.h"
#include "monster_test.h"
#include "monster_test_generated.h"
#include "test_assert.h"
namespace flatbuffers {
namespace tests {
using namespace MyGame::Example;
void ReflectionTest(const std::string& tests_data_path, uint8_t *flatbuf, size_t length) {
void ReflectionTest(const std::string &tests_data_path, uint8_t *flatbuf,
size_t length) {
// Load a binary schema.
std::string bfbsfile;
TEST_EQ(flatbuffers::LoadFile((tests_data_path + "monster_test.bfbs").c_str(),

View File

@@ -15,8 +15,7 @@ class TestHeapBuilder : public FlatBufferBuilder {
TestHeapBuilder &operator=(const TestHeapBuilder &);
public:
TestHeapBuilder()
: FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
TestHeapBuilder() : FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
TestHeapBuilder(TestHeapBuilder &&other)
: FlatBufferBuilder(std::move(other)) {}
@@ -144,7 +143,7 @@ void FlatBufferBuilderTest() {
}
// forward-declared in test_builder.h
void CheckTestGeneratedIsValid(const MyGame::Example::Color&);
void CheckTestGeneratedIsValid(const MyGame::Example::Color &);
// Link-time check using pointer type.
void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}