[Lobster] optional scalars support

This commit is contained in:
Wouter van Oortmerssen
2020-08-18 14:00:02 -07:00
parent e86d5b8e97
commit 77f966f89f
7 changed files with 237 additions and 6 deletions

View File

@@ -110,11 +110,14 @@ class LobsterGenerator : public BaseGenerator {
offsets + ")";
} else {
auto defval = field.nullable ? "0" : field.value.constant;
acc = "buf_.flatbuffers_field_" + GenTypeName(field.value.type) +
"(pos_, " + offsets + ", " + field.value.constant + ")";
"(pos_, " + offsets + ", " + defval + ")";
}
if (field.value.type.enum_def)
acc = NormalizedName(*field.value.type.enum_def) + "(" + acc + ")";
if (field.nullable)
acc += ", buf_.flatbuffers_field_present(pos_, " + offsets + ")";
code += def + "():\n return " + acc + "\n";
return;
}
@@ -198,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))
if (IsScalar(field.value.type.base_type) && !field.nullable)
code += ", " + field.value.constant;
code += ")\n return this\n";
}

View File

@@ -2258,7 +2258,8 @@ CheckedError Parser::CheckClash(std::vector<FieldDef *> &fields,
bool Parser::SupportsNullableScalars() const {
return !(opts.lang_to_generate & ~(IDLOptions::kRust | IDLOptions::kSwift));
return !(opts.lang_to_generate &
~(IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster));
}
bool Parser::SupportsAdvancedUnionFeatures() const {