mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 16:00:59 +00:00
[Lobster] optional scalars support
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user