LIBS: updated flatbuffers
parent
1ac31187b2
commit
d625f88bfe
|
@ -1227,10 +1227,8 @@ class CppGenerator : public BaseGenerator {
|
|||
code_ += " {{NAME}}Union({{NAME}}Union&& u) FLATBUFFERS_NOEXCEPT :";
|
||||
code_ += " type({{NONE}}), value(nullptr)";
|
||||
code_ += " { std::swap(type, u.type); std::swap(value, u.value); }";
|
||||
code_ += " {{NAME}}Union(const {{NAME}}Union &) FLATBUFFERS_NOEXCEPT;";
|
||||
code_ +=
|
||||
" {{NAME}}Union &operator=(const {{NAME}}Union &u) "
|
||||
"FLATBUFFERS_NOEXCEPT";
|
||||
code_ += " {{NAME}}Union(const {{NAME}}Union &);";
|
||||
code_ += " {{NAME}}Union &operator=(const {{NAME}}Union &u)";
|
||||
code_ +=
|
||||
" { {{NAME}}Union t(u); std::swap(type, t.type); std::swap(value, "
|
||||
"t.value); return *this; }";
|
||||
|
@ -1469,8 +1467,7 @@ class CppGenerator : public BaseGenerator {
|
|||
// Union copy constructor
|
||||
code_ +=
|
||||
"inline {{ENUM_NAME}}Union::{{ENUM_NAME}}Union(const "
|
||||
"{{ENUM_NAME}}Union &u) FLATBUFFERS_NOEXCEPT : type(u.type), "
|
||||
"value(nullptr) {";
|
||||
"{{ENUM_NAME}}Union &u) : type(u.type), value(nullptr) {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
|
@ -2152,6 +2149,25 @@ class CppGenerator : public BaseGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
// Generate code to force vector alignment. Return empty string for vector
|
||||
// that doesn't need alignment code.
|
||||
std::string GenVectorForceAlign(const FieldDef &field,
|
||||
const std::string &field_size) {
|
||||
FLATBUFFERS_ASSERT(field.value.type.base_type == BASE_TYPE_VECTOR);
|
||||
// Get the value of the force_align attribute.
|
||||
const auto *force_align = field.attributes.Lookup("force_align");
|
||||
const int align = force_align ? atoi(force_align->constant.c_str()) : 1;
|
||||
// Generate code to do force_align for the vector.
|
||||
if (align > 1) {
|
||||
const auto vtype = field.value.type.VectorType();
|
||||
const auto type = IsStruct(vtype) ? WrapInNameSpace(*vtype.struct_def)
|
||||
: GenTypeWire(vtype, "", false);
|
||||
return "_fbb.ForceVectorAlignment(" + field_size + ", sizeof(" + type +
|
||||
"), " + std::to_string(static_cast<long long>(align)) + ");";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void GenBuilders(const StructDef &struct_def) {
|
||||
code_.SetValue("STRUCT_NAME", Name(struct_def));
|
||||
|
||||
|
@ -2212,11 +2228,6 @@ class CppGenerator : public BaseGenerator {
|
|||
code_ += " start_ = fbb_.StartTable();";
|
||||
code_ += " }";
|
||||
|
||||
// Assignment operator;
|
||||
code_ +=
|
||||
" {{STRUCT_NAME}}Builder &operator="
|
||||
"(const {{STRUCT_NAME}}Builder &);";
|
||||
|
||||
// Finish() function.
|
||||
code_ += " flatbuffers::Offset<{{STRUCT_NAME}}> Finish() {";
|
||||
code_ += " const auto end = fbb_.EndTable(start_);";
|
||||
|
@ -2307,6 +2318,11 @@ class CppGenerator : public BaseGenerator {
|
|||
" auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? "
|
||||
"_fbb.{{CREATE_STRING}}({{FIELD_NAME}}) : 0;";
|
||||
} else if (field.value.type.base_type == BASE_TYPE_VECTOR) {
|
||||
const std::string force_align_code =
|
||||
GenVectorForceAlign(field, Name(field) + "->size()");
|
||||
if (!force_align_code.empty()) {
|
||||
code_ += " if ({{FIELD_NAME}}) { " + force_align_code + " }";
|
||||
}
|
||||
code_ += " auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? \\";
|
||||
const auto vtype = field.value.type.VectorType();
|
||||
const auto has_key = TypeHasKey(vtype);
|
||||
|
@ -2766,6 +2782,11 @@ class CppGenerator : public BaseGenerator {
|
|||
it != struct_def.fields.vec.end(); ++it) {
|
||||
auto &field = **it;
|
||||
if (field.deprecated) { continue; }
|
||||
if (field.value.type.base_type == BASE_TYPE_VECTOR) {
|
||||
const std::string force_align_code =
|
||||
GenVectorForceAlign(field, "_o->" + Name(field) + ".size()");
|
||||
if (!force_align_code.empty()) { code_ += " " + force_align_code; }
|
||||
}
|
||||
code_ += " auto _" + Name(field) + " = " + GenCreateParam(field) + ";";
|
||||
}
|
||||
// Need to call "Create" with the struct namespace.
|
||||
|
|
|
@ -544,7 +544,7 @@ class CSharpGenerator : public BaseGenerator {
|
|||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " FlatBufferConstants.";
|
||||
code += "FLATBUFFERS_1_11_1(); ";
|
||||
code += "FLATBUFFERS_1_12_0(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
|
@ -947,7 +947,8 @@ class CSharpGenerator : public BaseGenerator {
|
|||
}
|
||||
// JVM specifications restrict default constructor params to be < 255.
|
||||
// Longs and doubles take up 2 units, so we set the limit to be < 127.
|
||||
if (has_no_struct_fields && num_fields && num_fields < 127) {
|
||||
if ((has_no_struct_fields || opts.generate_object_based_api) &&
|
||||
num_fields && num_fields < 127) {
|
||||
struct_has_create = true;
|
||||
// Generate a table constructor of the form:
|
||||
// public static int createName(FlatBufferBuilder builder, args...)
|
||||
|
@ -959,13 +960,22 @@ class CSharpGenerator : public BaseGenerator {
|
|||
auto &field = **it;
|
||||
if (field.deprecated) continue;
|
||||
code += ",\n ";
|
||||
code += GenTypeBasic(field.value.type);
|
||||
code += " ";
|
||||
code += field.name;
|
||||
if (!IsScalar(field.value.type.base_type)) code += "Offset";
|
||||
if (IsStruct(field.value.type) && opts.generate_object_based_api) {
|
||||
code += WrapInNameSpace(
|
||||
field.value.type.struct_def->defined_namespace,
|
||||
GenTypeName_ObjectAPI(field.value.type.struct_def->name, opts));
|
||||
code += " ";
|
||||
code += field.name;
|
||||
code += " = null";
|
||||
} else {
|
||||
code += GenTypeBasic(field.value.type);
|
||||
code += " ";
|
||||
code += field.name;
|
||||
if (!IsScalar(field.value.type.base_type)) code += "Offset";
|
||||
|
||||
code += " = ";
|
||||
code += GenDefaultValueBasic(field);
|
||||
code += " = ";
|
||||
code += GenDefaultValueBasic(field);
|
||||
}
|
||||
}
|
||||
code += ") {\n builder.";
|
||||
code += "StartTable(";
|
||||
|
@ -980,8 +990,16 @@ class CSharpGenerator : public BaseGenerator {
|
|||
size == SizeOf(field.value.type.base_type))) {
|
||||
code += " " + struct_def.name + ".";
|
||||
code += "Add";
|
||||
code += MakeCamel(field.name) + "(builder, " + field.name;
|
||||
if (!IsScalar(field.value.type.base_type)) code += "Offset";
|
||||
code += MakeCamel(field.name) + "(builder, ";
|
||||
if (IsStruct(field.value.type) &&
|
||||
opts.generate_object_based_api) {
|
||||
code += GenTypePointer(field.value.type) + ".Pack(builder, " +
|
||||
field.name + ")";
|
||||
} else {
|
||||
code += field.name;
|
||||
if (!IsScalar(field.value.type.base_type)) code += "Offset";
|
||||
}
|
||||
|
||||
code += ");\n";
|
||||
}
|
||||
}
|
||||
|
@ -1643,8 +1661,11 @@ class CSharpGenerator : public BaseGenerator {
|
|||
} else {
|
||||
code += ",\n";
|
||||
if (field.value.type.struct_def->fixed) {
|
||||
code += " " + GenTypeGet(field.value.type) +
|
||||
".Pack(builder, _o." + camel_name + ")";
|
||||
if (opts.generate_object_based_api)
|
||||
code += " _o." + camel_name;
|
||||
else
|
||||
code += " " + GenTypeGet(field.value.type) +
|
||||
".Pack(builder, _o." + camel_name + ")";
|
||||
} else {
|
||||
code += " _" + field.name;
|
||||
}
|
||||
|
|
|
@ -592,7 +592,7 @@ class JavaGenerator : public BaseGenerator {
|
|||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " Constants.";
|
||||
code += "FLATBUFFERS_1_11_1(); ";
|
||||
code += "FLATBUFFERS_1_12_0(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
|
|
|
@ -155,7 +155,12 @@ class JsonSchemaGenerator : public BaseGenerator {
|
|||
comment.append(*comment_line);
|
||||
}
|
||||
if (comment.size() > 0) {
|
||||
code_ += " \"description\" : \"" + comment + "\",";
|
||||
std::string description;
|
||||
if (!EscapeString(comment.c_str(), comment.length(), &description, true,
|
||||
true)) {
|
||||
return false;
|
||||
}
|
||||
code_ += " \"description\" : " + description + ",";
|
||||
}
|
||||
code_ += " \"properties\" : {";
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ class KotlinGenerator : public BaseGenerator {
|
|||
// Force compile time error if not using the same version
|
||||
// runtime.
|
||||
GenerateFunOneLine(writer, "validateVersion", "", "", [&]() {
|
||||
writer += "Constants.FLATBUFFERS_1_11_1()";
|
||||
writer += "Constants.FLATBUFFERS_1_12_0()";
|
||||
});
|
||||
|
||||
GenerateGetRootAsAccessors(Esc(struct_def.name), writer);
|
||||
|
|
|
@ -790,7 +790,7 @@ class SwiftGenerator : public BaseGenerator {
|
|||
}
|
||||
|
||||
std::string ValidateFunc() {
|
||||
return "\tstatic func validateVersion() { FlatBuffersVersion_1_11_1() }";
|
||||
return "\tstatic func validateVersion() { FlatBuffersVersion_1_12_0() }";
|
||||
}
|
||||
|
||||
std::string GenType(const Type &type) const {
|
||||
|
|
|
@ -436,7 +436,7 @@ CheckedError Parser::Next() {
|
|||
default:
|
||||
const auto has_sign = (c == '+') || (c == '-');
|
||||
// '-'/'+' and following identifier - can be a predefined constant like:
|
||||
// NAN, INF, PI, etc.
|
||||
// NAN, INF, PI, etc or it can be a function name like cos/sin/deg.
|
||||
if (IsIdentifierStart(c) || (has_sign && IsIdentifierStart(*cursor_))) {
|
||||
// Collect all chars of an identifier:
|
||||
const char *start = cursor_ - 1;
|
||||
|
@ -1293,8 +1293,15 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||
});
|
||||
ECHECK(err);
|
||||
|
||||
builder_.StartVector(count * InlineSize(type) / InlineAlignment(type),
|
||||
InlineAlignment(type));
|
||||
const auto *force_align = field->attributes.Lookup("force_align");
|
||||
const size_t align =
|
||||
force_align ? static_cast<size_t>(atoi(force_align->constant.c_str()))
|
||||
: 1;
|
||||
const size_t len = count * InlineSize(type) / InlineAlignment(type);
|
||||
const size_t elemsize = InlineAlignment(type);
|
||||
if (align > 1) { builder_.ForceVectorAlignment(len, elemsize, align); }
|
||||
|
||||
builder_.StartVector(len, elemsize);
|
||||
for (uoffset_t i = 0; i < count; i++) {
|
||||
// start at the back, since we're building the data backwards.
|
||||
auto &val = field_stack_.back().first;
|
||||
|
@ -1329,7 +1336,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||
break;
|
||||
}
|
||||
}
|
||||
assert(key);
|
||||
FLATBUFFERS_ASSERT(key);
|
||||
// Now sort it.
|
||||
// We can't use std::sort because for structs the size is not known at
|
||||
// compile time, and for tables our iterators dereference offsets, so can't
|
||||
|
@ -1379,7 +1386,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||
// These are serialized offsets, so are relative where they are
|
||||
// stored in memory, so compute the distance between these pointers:
|
||||
ptrdiff_t diff = (b - a) * sizeof(Offset<Table>);
|
||||
assert(diff >= 0); // Guaranteed by SimpleQsort.
|
||||
FLATBUFFERS_ASSERT(diff >= 0); // Guaranteed by SimpleQsort.
|
||||
auto udiff = static_cast<uoffset_t>(diff);
|
||||
a->o = EndianScalar(ReadScalar<uoffset_t>(a) - udiff);
|
||||
b->o = EndianScalar(ReadScalar<uoffset_t>(b) + udiff);
|
||||
|
@ -1504,45 +1511,6 @@ CheckedError Parser::ParseMetaData(SymbolTable<Value> *attributes) {
|
|||
return NoError();
|
||||
}
|
||||
|
||||
CheckedError Parser::TryTypedValue(const std::string *name, int dtoken,
|
||||
bool check, Value &e, BaseType req,
|
||||
bool *destmatch) {
|
||||
bool match = dtoken == token_;
|
||||
if (match) {
|
||||
FLATBUFFERS_ASSERT(*destmatch == false);
|
||||
*destmatch = true;
|
||||
e.constant = attribute_;
|
||||
// Check token match
|
||||
if (!check) {
|
||||
if (e.type.base_type == BASE_TYPE_NONE) {
|
||||
e.type.base_type = req;
|
||||
} else {
|
||||
return Error(
|
||||
std::string("type mismatch: expecting: ") +
|
||||
kTypeNames[e.type.base_type] + ", found: " + kTypeNames[req] +
|
||||
", name: " + (name ? *name : "") + ", value: " + e.constant);
|
||||
}
|
||||
}
|
||||
// The exponent suffix of hexadecimal float-point number is mandatory.
|
||||
// A hex-integer constant is forbidden as an initializer of float number.
|
||||
if ((kTokenFloatConstant != dtoken) && IsFloat(e.type.base_type)) {
|
||||
const auto &s = e.constant;
|
||||
const auto k = s.find_first_of("0123456789.");
|
||||
if ((std::string::npos != k) && (s.length() > (k + 1)) &&
|
||||
(s[k] == '0' && is_alpha_char(s[k + 1], 'X')) &&
|
||||
(std::string::npos == s.find_first_of("pP", k + 2))) {
|
||||
return Error(
|
||||
"invalid number, the exponent suffix of hexadecimal "
|
||||
"floating-point literals is mandatory: \"" +
|
||||
s + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
NEXT();
|
||||
}
|
||||
return NoError();
|
||||
}
|
||||
|
||||
CheckedError Parser::ParseEnumFromString(const Type &type,
|
||||
std::string *result) {
|
||||
const auto base_type =
|
||||
|
@ -1631,7 +1599,8 @@ template<typename T> inline void SingleValueRepack(Value &e, T val) {
|
|||
if (IsInteger(e.type.base_type)) { e.constant = NumToString(val); }
|
||||
}
|
||||
#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
// Normilaze defaults NaN to unsigned quiet-NaN(0).
|
||||
// Normalize defaults NaN to unsigned quiet-NaN(0) if value was parsed from
|
||||
// hex-float literal.
|
||||
static inline void SingleValueRepack(Value &e, float val) {
|
||||
if (val != val) e.constant = "nan";
|
||||
}
|
||||
|
@ -1640,52 +1609,98 @@ static inline void SingleValueRepack(Value &e, double val) {
|
|||
}
|
||||
#endif
|
||||
|
||||
CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
||||
bool check_now) {
|
||||
// First see if this could be a conversion function:
|
||||
if (token_ == kTokenIdentifier && *cursor_ == '(') {
|
||||
// todo: Extract processing of conversion functions to ParseFunction.
|
||||
const auto functionname = attribute_;
|
||||
if (!IsFloat(e.type.base_type)) {
|
||||
return Error(functionname + ": type of argument mismatch, expecting: " +
|
||||
kTypeNames[BASE_TYPE_DOUBLE] +
|
||||
", found: " + kTypeNames[e.type.base_type] +
|
||||
", name: " + (name ? *name : "") + ", value: " + e.constant);
|
||||
CheckedError Parser::ParseFunction(const std::string *name, Value &e) {
|
||||
// Copy name, attribute will be changed on NEXT().
|
||||
const auto functionname = attribute_;
|
||||
if (!IsFloat(e.type.base_type)) {
|
||||
return Error(functionname + ": type of argument mismatch, expecting: " +
|
||||
kTypeNames[BASE_TYPE_DOUBLE] +
|
||||
", found: " + kTypeNames[e.type.base_type] +
|
||||
", name: " + (name ? *name : "") + ", value: " + e.constant);
|
||||
}
|
||||
NEXT();
|
||||
EXPECT('(');
|
||||
ECHECK(Recurse([&]() { return ParseSingleValue(name, e, false); }));
|
||||
EXPECT(')');
|
||||
// calculate with double precision
|
||||
double x, y = 0.0;
|
||||
ECHECK(atot(e.constant.c_str(), *this, &x));
|
||||
// clang-format off
|
||||
auto func_match = false;
|
||||
#define FLATBUFFERS_FN_DOUBLE(name, op) \
|
||||
if (!func_match && functionname == name) { y = op; func_match = true; }
|
||||
FLATBUFFERS_FN_DOUBLE("deg", x / kPi * 180);
|
||||
FLATBUFFERS_FN_DOUBLE("rad", x * kPi / 180);
|
||||
FLATBUFFERS_FN_DOUBLE("sin", sin(x));
|
||||
FLATBUFFERS_FN_DOUBLE("cos", cos(x));
|
||||
FLATBUFFERS_FN_DOUBLE("tan", tan(x));
|
||||
FLATBUFFERS_FN_DOUBLE("asin", asin(x));
|
||||
FLATBUFFERS_FN_DOUBLE("acos", acos(x));
|
||||
FLATBUFFERS_FN_DOUBLE("atan", atan(x));
|
||||
// TODO(wvo): add more useful conversion functions here.
|
||||
#undef FLATBUFFERS_FN_DOUBLE
|
||||
// clang-format on
|
||||
if (true != func_match) {
|
||||
return Error(std::string("Unknown conversion function: ") + functionname +
|
||||
", field name: " + (name ? *name : "") +
|
||||
", value: " + e.constant);
|
||||
}
|
||||
e.constant = NumToString(y);
|
||||
return NoError();
|
||||
}
|
||||
|
||||
CheckedError Parser::TryTypedValue(const std::string *name, int dtoken,
|
||||
bool check, Value &e, BaseType req,
|
||||
bool *destmatch) {
|
||||
bool match = dtoken == token_;
|
||||
if (match) {
|
||||
FLATBUFFERS_ASSERT(*destmatch == false);
|
||||
*destmatch = true;
|
||||
e.constant = attribute_;
|
||||
// Check token match
|
||||
if (!check) {
|
||||
if (e.type.base_type == BASE_TYPE_NONE) {
|
||||
e.type.base_type = req;
|
||||
} else {
|
||||
return Error(
|
||||
std::string("type mismatch: expecting: ") +
|
||||
kTypeNames[e.type.base_type] + ", found: " + kTypeNames[req] +
|
||||
", name: " + (name ? *name : "") + ", value: " + e.constant);
|
||||
}
|
||||
}
|
||||
// The exponent suffix of hexadecimal float-point number is mandatory.
|
||||
// A hex-integer constant is forbidden as an initializer of float number.
|
||||
if ((kTokenFloatConstant != dtoken) && IsFloat(e.type.base_type)) {
|
||||
const auto &s = e.constant;
|
||||
const auto k = s.find_first_of("0123456789.");
|
||||
if ((std::string::npos != k) && (s.length() > (k + 1)) &&
|
||||
(s[k] == '0' && is_alpha_char(s[k + 1], 'X')) &&
|
||||
(std::string::npos == s.find_first_of("pP", k + 2))) {
|
||||
return Error(
|
||||
"invalid number, the exponent suffix of hexadecimal "
|
||||
"floating-point literals is mandatory: \"" +
|
||||
s + "\"");
|
||||
}
|
||||
}
|
||||
NEXT();
|
||||
EXPECT('(');
|
||||
ECHECK(Recurse([&]() { return ParseSingleValue(name, e, false); }));
|
||||
EXPECT(')');
|
||||
// calculate with double precision
|
||||
double x, y = 0.0;
|
||||
ECHECK(atot(e.constant.c_str(), *this, &x));
|
||||
auto func_match = false;
|
||||
// clang-format off
|
||||
#define FLATBUFFERS_FN_DOUBLE(name, op) \
|
||||
if (!func_match && functionname == name) { y = op; func_match = true; }
|
||||
FLATBUFFERS_FN_DOUBLE("deg", x / kPi * 180);
|
||||
FLATBUFFERS_FN_DOUBLE("rad", x * kPi / 180);
|
||||
FLATBUFFERS_FN_DOUBLE("sin", sin(x));
|
||||
FLATBUFFERS_FN_DOUBLE("cos", cos(x));
|
||||
FLATBUFFERS_FN_DOUBLE("tan", tan(x));
|
||||
FLATBUFFERS_FN_DOUBLE("asin", asin(x));
|
||||
FLATBUFFERS_FN_DOUBLE("acos", acos(x));
|
||||
FLATBUFFERS_FN_DOUBLE("atan", atan(x));
|
||||
// TODO(wvo): add more useful conversion functions here.
|
||||
#undef FLATBUFFERS_FN_DOUBLE
|
||||
// clang-format on
|
||||
if (true != func_match) {
|
||||
return Error(std::string("Unknown conversion function: ") + functionname +
|
||||
", field name: " + (name ? *name : "") +
|
||||
", value: " + e.constant);
|
||||
}
|
||||
e.constant = NumToString(y);
|
||||
return NoError();
|
||||
}
|
||||
return NoError();
|
||||
}
|
||||
|
||||
CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
||||
bool check_now) {
|
||||
const auto in_type = e.type.base_type;
|
||||
const auto is_tok_ident = (token_ == kTokenIdentifier);
|
||||
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);
|
||||
}
|
||||
|
||||
auto match = false;
|
||||
const auto in_type = e.type.base_type;
|
||||
// clang-format off
|
||||
auto match = false;
|
||||
|
||||
#define IF_ECHECK_(force, dtoken, check, req) \
|
||||
if (!match && ((check) || IsConstTrue(force))) \
|
||||
ECHECK(TryTypedValue(name, dtoken, check, e, req, &match))
|
||||
|
@ -1693,14 +1708,14 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
|||
#define FORCE_ECHECK(dtoken, check, req) IF_ECHECK_(true, dtoken, check, req)
|
||||
// clang-format on
|
||||
|
||||
if (token_ == kTokenStringConstant || token_ == kTokenIdentifier) {
|
||||
if (is_tok_ident || is_tok_string) {
|
||||
const auto kTokenStringOrIdent = token_;
|
||||
// The string type is a most probable type, check it first.
|
||||
TRY_ECHECK(kTokenStringConstant, in_type == BASE_TYPE_STRING,
|
||||
BASE_TYPE_STRING);
|
||||
|
||||
// avoid escaped and non-ascii in the string
|
||||
if (!match && (token_ == kTokenStringConstant) && IsScalar(in_type) &&
|
||||
if (!match && is_tok_string && IsScalar(in_type) &&
|
||||
!attr_is_trivial_ascii_string_) {
|
||||
return Error(
|
||||
std::string("type mismatch or invalid value, an initializer of "
|
||||
|
@ -1728,11 +1743,20 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
|||
}
|
||||
// Parse a float/integer number from the string.
|
||||
if (!match) check_now = true; // Re-pack if parsed from string literal.
|
||||
if (!match && (token_ == kTokenStringConstant) && IsScalar(in_type)) {
|
||||
// remove trailing whitespaces from attribute_
|
||||
auto last = attribute_.find_last_not_of(' ');
|
||||
if (std::string::npos != last) // has non-whitespace
|
||||
attribute_.resize(last + 1);
|
||||
// A "scalar-in-string" value needs extra checks.
|
||||
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 (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
|
||||
// as an unsupported function if is_tok_ident is true.
|
||||
if (attribute_.find_last_of(')') != std::string::npos) {
|
||||
return Error("invalid number: " + attribute_);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Float numbers or nan, inf, pi, etc.
|
||||
TRY_ECHECK(kTokenStringOrIdent, IsFloat(in_type), BASE_TYPE_FLOAT);
|
||||
|
|
|
@ -296,8 +296,6 @@ class ResizeContext {
|
|||
}
|
||||
}
|
||||
|
||||
void operator=(const ResizeContext &rc);
|
||||
|
||||
private:
|
||||
const reflection::Schema &schema_;
|
||||
uint8_t *startptr_;
|
||||
|
@ -705,8 +703,10 @@ 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) {
|
||||
Verifier v(buf, length);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 1
|
||||
#define FLATBUFFERS_VERSION_MINOR 11
|
||||
#define FLATBUFFERS_VERSION_MINOR 12
|
||||
#define FLATBUFFERS_VERSION_REVISION 0
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
|
|
|
@ -1795,8 +1795,7 @@ class FlatBufferBuilder {
|
|||
return a.KeyCompareLessThan(&b);
|
||||
}
|
||||
|
||||
private:
|
||||
StructKeyComparator &operator=(const StructKeyComparator &);
|
||||
FLATBUFFERS_DELETE_FUNC(StructKeyComparator &operator=(const StructKeyComparator &))
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
|
|
|
@ -1522,7 +1522,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
|||
Type vector_type = FBT_KEY;
|
||||
// Check bit widths and types for all elements.
|
||||
for (size_t i = start; i < stack_.size(); i += step) {
|
||||
auto elem_width = stack_[i].ElemWidth(buf_.size(), i + prefix_elems);
|
||||
auto elem_width =
|
||||
stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems);
|
||||
bit_width = (std::max)(bit_width, elem_width);
|
||||
if (typed) {
|
||||
if (i == start) {
|
||||
|
|
|
@ -891,6 +891,7 @@ class Parser : public ParserState {
|
|||
FLATBUFFERS_CHECKED_ERROR TokenError();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e,
|
||||
bool check_now);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type,
|
||||
std::string *result);
|
||||
StructDef *LookupCreateStruct(const std::string &name,
|
||||
|
|
|
@ -362,7 +362,6 @@ template<typename T, typename U> class pointer_inside_vector {
|
|||
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec_)) + offset_);
|
||||
}
|
||||
T *operator->() const { return operator*(); }
|
||||
void operator=(const pointer_inside_vector &piv);
|
||||
|
||||
private:
|
||||
size_t offset_;
|
||||
|
@ -470,7 +469,9 @@ 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);
|
||||
const uint8_t *buf, size_t length,
|
||||
uoffset_t max_depth = 64,
|
||||
uoffset_t max_tables = 1000000);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
|
|
@ -161,7 +161,6 @@ struct TypeBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
TypeBuilder &operator=(const TypeBuilder &);
|
||||
flatbuffers::Offset<Type> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Type>(end);
|
||||
|
@ -225,7 +224,6 @@ struct KeyValueBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
KeyValueBuilder &operator=(const KeyValueBuilder &);
|
||||
flatbuffers::Offset<KeyValue> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<KeyValue>(end);
|
||||
|
@ -325,7 +323,6 @@ struct EnumValBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
EnumValBuilder &operator=(const EnumValBuilder &);
|
||||
flatbuffers::Offset<EnumVal> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<EnumVal>(end);
|
||||
|
@ -448,7 +445,6 @@ struct EnumBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
EnumBuilder &operator=(const EnumBuilder &);
|
||||
flatbuffers::Offset<Enum> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Enum>(end);
|
||||
|
@ -617,7 +613,6 @@ struct FieldBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
FieldBuilder &operator=(const FieldBuilder &);
|
||||
flatbuffers::Offset<Field> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Field>(end);
|
||||
|
@ -773,7 +768,6 @@ struct ObjectBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
ObjectBuilder &operator=(const ObjectBuilder &);
|
||||
flatbuffers::Offset<Object> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Object>(end);
|
||||
|
@ -898,7 +892,6 @@ struct RPCCallBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
RPCCallBuilder &operator=(const RPCCallBuilder &);
|
||||
flatbuffers::Offset<RPCCall> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<RPCCall>(end);
|
||||
|
@ -1007,7 +1000,6 @@ struct ServiceBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
ServiceBuilder &operator=(const ServiceBuilder &);
|
||||
flatbuffers::Offset<Service> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Service>(end);
|
||||
|
@ -1123,7 +1115,6 @@ struct SchemaBuilder {
|
|||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
SchemaBuilder &operator=(const SchemaBuilder &);
|
||||
flatbuffers::Offset<Schema> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Schema>(end);
|
||||
|
|
Loading…
Reference in New Issue