mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +00:00
The asserts replaced by FLATBUFFERS_ASSERT. (#4701)
* The asserts replaced by FLATBUFFERS_ASSERT. Several asserts have converted to static_asserts. * Regenerate header monster generate_code.sh
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
86153fd740
commit
a66f9e769b
@@ -826,7 +826,7 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
|
||||
const StructDef *parent_struct_def) {
|
||||
switch (val.type.base_type) {
|
||||
case BASE_TYPE_UNION: {
|
||||
assert(field);
|
||||
FLATBUFFERS_ASSERT(field);
|
||||
std::string constant;
|
||||
// Find corresponding type field we may have already parsed.
|
||||
for (auto elem = field_stack_.rbegin();
|
||||
@@ -843,9 +843,9 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
|
||||
// output these in alphabetical order, meaning it comes after this
|
||||
// value. So we scan past the value to find it, then come back here.
|
||||
auto type_name = field->name + UnionTypeFieldSuffix();
|
||||
assert(parent_struct_def);
|
||||
FLATBUFFERS_ASSERT(parent_struct_def);
|
||||
auto type_field = parent_struct_def->fields.Lookup(type_name);
|
||||
assert(type_field); // Guaranteed by ParseField().
|
||||
FLATBUFFERS_ASSERT(type_field); // Guaranteed by ParseField().
|
||||
// Remember where we are in the source file, so we can come back here.
|
||||
auto backup = *static_cast<ParserState *>(this);
|
||||
ECHECK(SkipAnyJsonValue()); // The table.
|
||||
@@ -882,7 +882,7 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
|
||||
} else if (enum_val->union_type.base_type == BASE_TYPE_STRING) {
|
||||
ECHECK(ParseString(val));
|
||||
} else {
|
||||
assert(false);
|
||||
FLATBUFFERS_ASSERT(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -917,7 +917,7 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
|
||||
}
|
||||
|
||||
void Parser::SerializeStruct(const StructDef &struct_def, const Value &val) {
|
||||
assert(val.constant.length() == struct_def.bytesize);
|
||||
FLATBUFFERS_ASSERT(val.constant.length() == struct_def.bytesize);
|
||||
builder_.Align(struct_def.minalign);
|
||||
builder_.PushBytes(reinterpret_cast<const uint8_t *>(val.constant.c_str()),
|
||||
struct_def.bytesize);
|
||||
@@ -1105,14 +1105,14 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
|
||||
if (struct_def.fixed) {
|
||||
builder_.ClearOffsets();
|
||||
builder_.EndStruct();
|
||||
assert(value);
|
||||
FLATBUFFERS_ASSERT(value);
|
||||
// Temporarily store this struct in the value string, since it is to
|
||||
// be serialized in-place elsewhere.
|
||||
value->assign(
|
||||
reinterpret_cast<const char *>(builder_.GetCurrentBufferPointer()),
|
||||
struct_def.bytesize);
|
||||
builder_.PopBytes(struct_def.bytesize);
|
||||
assert(!ovalue);
|
||||
FLATBUFFERS_ASSERT(!ovalue);
|
||||
} else {
|
||||
auto val = builder_.EndTable(start);
|
||||
if (ovalue) *ovalue = val;
|
||||
@@ -1195,7 +1195,7 @@ CheckedError Parser::ParseNestedFlatbuffer(Value &val, FieldDef *field,
|
||||
|
||||
// Create and initialize new parser
|
||||
Parser nested_parser;
|
||||
assert(field->nested_flatbuffer);
|
||||
FLATBUFFERS_ASSERT(field->nested_flatbuffer);
|
||||
nested_parser.root_struct_def_ = field->nested_flatbuffer;
|
||||
nested_parser.enums_ = enums_;
|
||||
nested_parser.opts = opts;
|
||||
@@ -1307,7 +1307,7 @@ CheckedError Parser::ParseEnumFromString(Type &type, int64_t *result) {
|
||||
}
|
||||
|
||||
CheckedError Parser::ParseHash(Value &e, FieldDef *field) {
|
||||
assert(field);
|
||||
FLATBUFFERS_ASSERT(field);
|
||||
Value *hash_name = field->attributes.Lookup("hash");
|
||||
switch (e.type.base_type) {
|
||||
case BASE_TYPE_SHORT: {
|
||||
@@ -1346,7 +1346,7 @@ CheckedError Parser::ParseHash(Value &e, FieldDef *field) {
|
||||
e.constant = NumToString(hashed_value);
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
default: FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
NEXT();
|
||||
return NoError();
|
||||
@@ -1401,7 +1401,7 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e) {
|
||||
e.constant = NumToString(strtod(attribute_.c_str(), &end));
|
||||
if (*end) return Error("invalid float: " + attribute_);
|
||||
} else {
|
||||
assert(0); // Shouldn't happen, we covered all types.
|
||||
FLATBUFFERS_ASSERT(0); // Shouldn't happen, we covered all types.
|
||||
e.constant = "0";
|
||||
}
|
||||
NEXT();
|
||||
@@ -2279,7 +2279,7 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
|
||||
auto &bt = field.value.type.base_type == BASE_TYPE_VECTOR
|
||||
? field.value.type.element
|
||||
: field.value.type.base_type;
|
||||
assert(bt == BASE_TYPE_STRUCT);
|
||||
FLATBUFFERS_ASSERT(bt == BASE_TYPE_STRUCT);
|
||||
bt = enum_def->underlying_type.base_type;
|
||||
struct_def.refcount--;
|
||||
enum_def->refcount++;
|
||||
@@ -2613,7 +2613,7 @@ Definition::SerializeAttributes(FlatBufferBuilder *builder,
|
||||
std::vector<flatbuffers::Offset<reflection::KeyValue>> attrs;
|
||||
for (auto kv = attributes.dict.begin(); kv != attributes.dict.end(); ++kv) {
|
||||
auto it = parser.known_attributes_.find(kv->first);
|
||||
assert(it != parser.known_attributes_.end());
|
||||
FLATBUFFERS_ASSERT(it != parser.known_attributes_.end());
|
||||
if (!it->second) { // Custom attribute.
|
||||
attrs.push_back(reflection::CreateKeyValue(
|
||||
*builder, builder->CreateString(kv->first),
|
||||
|
||||
Reference in New Issue
Block a user