mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
General Codebase clean up (#5939)
* Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case. * Ensuring test/generate_code.sh was ran * Fixed Dart Tests by removing code-gen for included files. * General cleanup of codebase.
This commit is contained in:
@@ -75,10 +75,8 @@ class CodeWriter {
|
||||
void DecrementIdentLevel() {
|
||||
if (cur_ident_lvl_) cur_ident_lvl_--;
|
||||
}
|
||||
|
||||
void SetPadding(const std::string &padding) {
|
||||
pad_ = padding;
|
||||
}
|
||||
|
||||
void SetPadding(const std::string &padding) { pad_ = padding; }
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> value_map_;
|
||||
|
||||
@@ -587,7 +587,7 @@ static inline const char *GetCstring(const String *str) {
|
||||
static inline flatbuffers::string_view GetStringView(const String *str) {
|
||||
return str ? str->string_view() : flatbuffers::string_view();
|
||||
}
|
||||
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
||||
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
||||
|
||||
// Allocator interface. This is flatbuffers-specific and meant only for
|
||||
// `vector_downward` usage.
|
||||
@@ -1803,7 +1803,8 @@ class FlatBufferBuilder {
|
||||
return a.KeyCompareLessThan(&b);
|
||||
}
|
||||
|
||||
FLATBUFFERS_DELETE_FUNC(StructKeyComparator &operator=(const StructKeyComparator &))
|
||||
FLATBUFFERS_DELETE_FUNC(
|
||||
StructKeyComparator &operator=(const StructKeyComparator &))
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
|
||||
@@ -410,9 +410,7 @@ struct EnumDef : public Definition {
|
||||
|
||||
size_t size() const { return vals.vec.size(); }
|
||||
|
||||
const std::vector<EnumVal *> &Vals() const {
|
||||
return vals.vec;
|
||||
}
|
||||
const std::vector<EnumVal *> &Vals() const { return vals.vec; }
|
||||
|
||||
const EnumVal *Lookup(const std::string &enum_name) const {
|
||||
return vals.Lookup(enum_name);
|
||||
|
||||
@@ -469,8 +469,7 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
|
||||
// buf should point to the start of flatbuffer data.
|
||||
// length specifies the size of the flatbuffer data.
|
||||
bool Verify(const reflection::Schema &schema, const reflection::Object &root,
|
||||
const uint8_t *buf, size_t length,
|
||||
uoffset_t max_depth = 64,
|
||||
const uint8_t *buf, size_t length, uoffset_t max_depth = 64,
|
||||
uoffset_t max_tables = 1000000);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <algorithm>
|
||||
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
@@ -1224,14 +1224,15 @@ class JsTsGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
bool CanCreateFactoryMethod(const StructDef &struct_def) {
|
||||
// to preserve backwards compatibility, we allow the first field to be a struct
|
||||
return struct_def.fields.vec.size() < 2 || std::all_of(
|
||||
std::begin(struct_def.fields.vec) + 1,
|
||||
std::end(struct_def.fields.vec),
|
||||
[](const FieldDef *f) -> bool {
|
||||
FLATBUFFERS_ASSERT(f != nullptr);
|
||||
return f->value.type.base_type != BASE_TYPE_STRUCT;
|
||||
});
|
||||
// to preserve backwards compatibility, we allow the first field to be a
|
||||
// struct
|
||||
return struct_def.fields.vec.size() < 2 ||
|
||||
std::all_of(std::begin(struct_def.fields.vec) + 1,
|
||||
std::end(struct_def.fields.vec),
|
||||
[](const FieldDef *f) -> bool {
|
||||
FLATBUFFERS_ASSERT(f != nullptr);
|
||||
return f->value.type.base_type != BASE_TYPE_STRUCT;
|
||||
});
|
||||
}
|
||||
|
||||
// Generate an accessor struct with constructor for a flatbuffers struct.
|
||||
@@ -1876,7 +1877,7 @@ class JsTsGenerator : public BaseGenerator {
|
||||
std::string paramDoc =
|
||||
GenTypeAnnotation(kParam, "flatbuffers.Builder", "builder");
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
const auto &field = **it;
|
||||
if (field.deprecated) continue;
|
||||
paramDoc +=
|
||||
@@ -1896,7 +1897,7 @@ class JsTsGenerator : public BaseGenerator {
|
||||
code += " = function(builder";
|
||||
}
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
const auto &field = **it;
|
||||
if (field.deprecated) continue;
|
||||
|
||||
@@ -1920,7 +1921,7 @@ class JsTsGenerator : public BaseGenerator {
|
||||
std::string methodPrefix =
|
||||
lang_.language == IDLOptions::kTs ? struct_def.name : object_name;
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
const auto &field = **it;
|
||||
if (field.deprecated) continue;
|
||||
|
||||
|
||||
@@ -1358,8 +1358,8 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += " Some({{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
} else {
|
||||
code_ +=
|
||||
" self.{{FIELD_NAME}}().map(|u| "
|
||||
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
" self.{{FIELD_NAME}}().map(|u| "
|
||||
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
}
|
||||
code_ += " } else {";
|
||||
code_ += " None";
|
||||
@@ -1788,7 +1788,7 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "";
|
||||
if (!parser_.opts.generate_all) {
|
||||
for (auto it = parser_.included_files_.begin();
|
||||
it != parser_.included_files_.end(); ++it) {
|
||||
it != parser_.included_files_.end(); ++it) {
|
||||
if (it->second.empty()) continue;
|
||||
auto noext = flatbuffers::StripExtension(it->second);
|
||||
auto basename = flatbuffers::StripPath(noext);
|
||||
|
||||
@@ -1704,9 +1704,7 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
||||
const auto is_tok_string = (token_ == kTokenStringConstant);
|
||||
|
||||
// First see if this could be a conversion function:
|
||||
if (is_tok_ident && *cursor_ == '(') {
|
||||
return ParseFunction(name, e);
|
||||
}
|
||||
if (is_tok_ident && *cursor_ == '(') { return ParseFunction(name, e); }
|
||||
|
||||
// clang-format off
|
||||
auto match = false;
|
||||
@@ -1757,8 +1755,7 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
||||
if (!match && is_tok_string && IsScalar(in_type)) {
|
||||
// Strip trailing whitespaces from attribute_.
|
||||
auto last_non_ws = attribute_.find_last_not_of(' ');
|
||||
if (std::string::npos != last_non_ws)
|
||||
attribute_.resize(last_non_ws + 1);
|
||||
if (std::string::npos != last_non_ws) attribute_.resize(last_non_ws + 1);
|
||||
if (IsFloat(e.type.base_type)) {
|
||||
// The functions strtod() and strtof() accept both 'nan' and
|
||||
// 'nan(number)' literals. While 'nan(number)' is rejected by the parser
|
||||
|
||||
@@ -396,17 +396,17 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
|
||||
case reflection::Obj: {
|
||||
auto &subobjectdef = *schema.objects()->Get(fielddef.type()->index());
|
||||
if (!subobjectdef.is_struct()) {
|
||||
offset =
|
||||
CopyTable(fbb, schema, subobjectdef,
|
||||
*GetFieldT(table, fielddef), use_string_pooling).o;
|
||||
offset = CopyTable(fbb, schema, subobjectdef,
|
||||
*GetFieldT(table, fielddef), use_string_pooling)
|
||||
.o;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case reflection::Union: {
|
||||
auto &subobjectdef = GetUnionType(schema, objectdef, fielddef, table);
|
||||
offset =
|
||||
CopyTable(fbb, schema, subobjectdef, *GetFieldT(table, fielddef),
|
||||
use_string_pooling).o;
|
||||
offset = CopyTable(fbb, schema, subobjectdef,
|
||||
*GetFieldT(table, fielddef), use_string_pooling)
|
||||
.o;
|
||||
break;
|
||||
}
|
||||
case reflection::Vector: {
|
||||
@@ -433,9 +433,8 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
|
||||
if (!elemobjectdef->is_struct()) {
|
||||
std::vector<Offset<const Table *>> elements(vec->size());
|
||||
for (uoffset_t i = 0; i < vec->size(); i++) {
|
||||
elements[i] =
|
||||
CopyTable(fbb, schema, *elemobjectdef, *vec->Get(i),
|
||||
use_string_pooling);
|
||||
elements[i] = CopyTable(fbb, schema, *elemobjectdef,
|
||||
*vec->Get(i), use_string_pooling);
|
||||
}
|
||||
offset = fbb.CreateVector(elements).o;
|
||||
break;
|
||||
@@ -705,8 +704,7 @@ bool VerifyObject(flatbuffers::Verifier &v, const reflection::Schema &schema,
|
||||
}
|
||||
|
||||
bool Verify(const reflection::Schema &schema, const reflection::Object &root,
|
||||
const uint8_t *buf, size_t length,
|
||||
uoffset_t max_depth /*= 64*/,
|
||||
const uint8_t *buf, size_t length, uoffset_t max_depth /*= 64*/,
|
||||
uoffset_t max_tables /*= 1000000*/) {
|
||||
Verifier v(buf, length, max_depth, max_tables);
|
||||
return VerifyObject(v, schema, root, flatbuffers::GetAnyRoot(buf), true);
|
||||
|
||||
Reference in New Issue
Block a user