mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
Fix native_type non-native_inline fields, add tests (#8655)
* Fix native_type non-native_inline fields, add tests * Format * Add 'native_type_test' and 'native_inline_table_test' to generate_code.py * Remove '--gen-compare' from native_type_test generation
This commit is contained in:
@@ -3217,7 +3217,13 @@ class CppGenerator : public BaseGenerator {
|
||||
const auto pack_name = struct_attrs.Lookup("native_type_pack_name");
|
||||
if (pack_name) { unpack_call += pack_name->constant; }
|
||||
unpack_call += "(*" + val + ")";
|
||||
return unpack_call;
|
||||
if (invector || afield.native_inline) {
|
||||
return unpack_call;
|
||||
} else {
|
||||
const auto name = native_type->constant;
|
||||
const auto ptype = GenTypeNativePtr(name, &afield, true);
|
||||
return ptype + "(new " + name + "(" + unpack_call + "))";
|
||||
}
|
||||
} else if (invector || afield.native_inline) {
|
||||
return "*" + val;
|
||||
} else {
|
||||
@@ -3601,12 +3607,16 @@ class CppGenerator : public BaseGenerator {
|
||||
if (IsStruct(field.value.type)) {
|
||||
const auto &struct_attribs = field.value.type.struct_def->attributes;
|
||||
const auto native_type = struct_attribs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
if (native_type && field.native_inline) {
|
||||
code += "::flatbuffers::Pack";
|
||||
const auto pack_name =
|
||||
struct_attribs.Lookup("native_type_pack_name");
|
||||
if (pack_name) { code += pack_name->constant; }
|
||||
code += "(" + value + ")";
|
||||
} else if (native_type && !field.native_inline) {
|
||||
code += WrapInNameSpace(*field.value.type.struct_def) + "{};";
|
||||
code += " if (_o->" + Name(field) + ") _" + Name(field) +
|
||||
" = ::flatbuffers::Pack(*_o->" + Name(field) + ")";
|
||||
} else if (field.native_inline) {
|
||||
code += "&" + value;
|
||||
} else {
|
||||
@@ -3735,16 +3745,22 @@ class CppGenerator : public BaseGenerator {
|
||||
if (field->deprecated) { continue; }
|
||||
|
||||
bool pass_by_address = false;
|
||||
bool check_ptr = false;
|
||||
if (field->value.type.base_type == BASE_TYPE_STRUCT) {
|
||||
if (IsStruct(field->value.type)) {
|
||||
auto native_type =
|
||||
field->value.type.struct_def->attributes.Lookup("native_type");
|
||||
auto native_inline = field->attributes.Lookup("native_inline");
|
||||
if (native_type) { pass_by_address = true; }
|
||||
if (native_type && !native_inline) { check_ptr = true; }
|
||||
}
|
||||
}
|
||||
|
||||
// Call the CreateX function using values from |_o|.
|
||||
if (pass_by_address) {
|
||||
if (pass_by_address && check_ptr) {
|
||||
code_ += ",\n _o->" + Name(*field) + " ? &_" + Name(*field) +
|
||||
" : nullptr\\";
|
||||
} else if (pass_by_address) {
|
||||
code_ += ",\n &_" + Name(*field) + "\\";
|
||||
} else {
|
||||
code_ += ",\n _" + Name(*field) + "\\";
|
||||
|
||||
Reference in New Issue
Block a user