mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 10:35:45 +00:00
run scripts/clang-format-all.sh
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
29
src/util.cpp
29
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);
|
||||
|
||||
Reference in New Issue
Block a user