summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Bailey <derekbailey@google.com>2023-05-11 12:23:49 -0700
committerDerek Bailey <derekbailey@google.com>2023-05-11 12:23:49 -0700
commit86486a1735bc38f5629447251206934ef205f6e4 (patch)
tree905c97f7e0a64c3ff5ed0a93f04b797b308b56fa /src
parentc2f764c22b0f9ad6b0bb1125519e7d8fc7c70608 (diff)
downloadflatbuffers-86486a1735bc38f5629447251206934ef205f6e4.tar.gz
flatbuffers-86486a1735bc38f5629447251206934ef205f6e4.tar.bz2
flatbuffers-86486a1735bc38f5629447251206934ef205f6e4.zip
run `scripts/clang-format-all.sh`
Diffstat (limited to 'src')
-rw-r--r--src/bfbs_gen_lua.cpp3
-rw-r--r--src/file_name_saving_file_manager.cpp4
-rw-r--r--src/idl_gen_text.cpp8
-rw-r--r--src/idl_parser.cpp8
-rw-r--r--src/reflection.cpp57
-rw-r--r--src/util.cpp29
6 files changed, 61 insertions, 48 deletions
diff --git a/src/bfbs_gen_lua.cpp b/src/bfbs_gen_lua.cpp
index b9883424..185e8596 100644
--- a/src/bfbs_gen_lua.cpp
+++ b/src/bfbs_gen_lua.cpp
@@ -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);
}
diff --git a/src/file_name_saving_file_manager.cpp b/src/file_name_saving_file_manager.cpp
index fc4a4aa1..b43c7b6e 100644
--- a/src/file_name_saving_file_manager.cpp
+++ b/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/src/idl_gen_text.cpp b/src/idl_gen_text.cpp
index c1d69f23..17d51803 100644
--- a/src/idl_gen_text.cpp
+++ b/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
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index 055277b2..fe1d6398 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -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 {
diff --git a/src/reflection.cpp b/src/reflection.cpp
index 0d0814ef..f064c1c6 100644
--- a/src/reflection.cpp
+++ b/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/src/util.cpp b/src/util.cpp
index 38d8536c..b201246f 100644
--- a/src/util.cpp
+++ b/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);