mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 01:28:52 +00:00
Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)
* Define presence. * Migrate to IsRequired and IsOptional methods * moved stuff around * Removed optional and required bools from FieldDef * change assert to return error * Fix tests.cpp * MakeFieldPresence helper * fmt * old c++ compatibility stuff Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -110,13 +110,13 @@ class LobsterGenerator : public BaseGenerator {
|
||||
offsets + ")";
|
||||
|
||||
} else {
|
||||
auto defval = field.optional ? "0" : field.value.constant;
|
||||
auto defval = field.IsOptional() ? "0" : field.value.constant;
|
||||
acc = "buf_.flatbuffers_field_" + GenTypeName(field.value.type) +
|
||||
"(pos_, " + offsets + ", " + defval + ")";
|
||||
}
|
||||
if (field.value.type.enum_def)
|
||||
acc = NormalizedName(*field.value.type.enum_def) + "(" + acc + ")";
|
||||
if (field.optional)
|
||||
if (field.IsOptional())
|
||||
acc += ", buf_.flatbuffers_field_present(pos_, " + offsets + ")";
|
||||
code += def + "():\n return " + acc + "\n";
|
||||
return;
|
||||
@@ -201,7 +201,7 @@ class LobsterGenerator : public BaseGenerator {
|
||||
NormalizedName(field) + ":" + LobsterType(field.value.type) +
|
||||
"):\n b_.Prepend" + GenMethod(field.value.type) + "Slot(" +
|
||||
NumToString(offset) + ", " + NormalizedName(field);
|
||||
if (IsScalar(field.value.type.base_type) && !field.optional)
|
||||
if (IsScalar(field.value.type.base_type) && !field.IsOptional())
|
||||
code += ", " + field.value.constant;
|
||||
code += ")\n return this\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user