Allows structs to be stored directly as member variables.

Introduce a "native_inline" attribute that can be applied on fields that are structs.
This results in NativeTable code generation that sets the struct "inline" rather than
storing it in a pointer.

From cl/140527470.

Change-Id: I208724f552b8b921b20923e0bf82f42cb3582416
This commit is contained in:
Wouter van Oortmerssen
2016-12-02 14:25:08 -08:00
parent d342918790
commit 641b397f8b
4 changed files with 34 additions and 9 deletions

View File

@@ -680,6 +680,11 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
return Error("'key' field must be string or scalar type");
}
}
field->native_inline = field->attributes.Lookup("native_inline") != nullptr;
if (field->native_inline && !IsStruct(field->value.type))
return Error("native_inline can only be defined on structs'");
auto nested = field->attributes.Lookup("nested_flatbuffer");
if (nested) {
if (nested->type.base_type != BASE_TYPE_STRING)
@@ -1758,9 +1763,6 @@ CheckedError Parser::SkipAnyJsonValue() {
case kTokenFloatConstant:
EXPECT(kTokenFloatConstant);
break;
case kTokenNull:
EXPECT(kTokenNull);
break;
default:
return Error(std::string("Unexpected token:") + std::string(1, static_cast<char>(token_)));
}