Commit 55dec4d2 authored by sfariv's avatar sfariv Committed by Wouter van Oortmerssen

added check for presence of required fields. (flatc) c++ (#4316)

* added check for presence of required fields.

* updates to resolve Travis CI build error.

* fixes for resolving appveyor build errors.

* fixes for resolving appveyor build errors.

* fixes for resolving appveyor build errors.

* updates per aardappel's comments.

* updated a variable's name.

* updates per aardappel's comments.
parent 0f5f7faa
......@@ -897,6 +897,29 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
EXPECT(',');
}
// Check if all required fields are parsed.
for (auto field_it = struct_def.fields.vec.begin();
field_it != struct_def.fields.vec.end();
++field_it) {
auto required_field = *field_it;
if (!required_field->required) {
continue;
}
bool found = false;
for (auto pf_it = field_stack_.end() - fieldn;
pf_it != field_stack_.end();
++pf_it) {
auto parsed_field = pf_it->second;
if (parsed_field == required_field) {
found = true;
break;
}
}
if (!found) {
return Error("required field is missing: " + required_field->name + " in " + struct_def.name);
}
}
if (struct_def.fixed && fieldn != struct_def.fields.vec.size())
return Error("struct: wrong number of initializers: " + struct_def.name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment