mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 06:30:54 +00:00
Vector of unions support for java and c# (#4735)
* Eclipse ignore * TypeScript support * Prefixing enums * Test results * Merged JS and TS generators * Fixed AppVeyor build problems * Fixed more AppVeyor build problems * Fixed more AppVeyor build problems * Changed TS flag to options struct * Storing options by value * Removed unneeded const * Re-export support for unions * Uint support * Casting bools to numbers for mutation * TS shell tests * Reverted generates js test file to original version * Backing up js tests and properly generating test data * Not importing flatbuffers for TS test generation * Not overwriting generated js for tests * AppVeyor test fixes * Generating the most strict TS code possible * Not returning null when creating vectors * Not returning null from struct contructors * Vector of unions for ts/js * Sanity check for languages * Indentation fix + output test files * Vectors of unions for php * Fixes to union vector handling + tests * Fix for strictPropertyInitialization * Fix for new aligned operator new for gcc >= 7.1 * Not generating imports/ns prefixes with --gen-all * TypeScript docs * Missing imports of enums * Missing TS links * Enabled vector of unions for java, since it seems to work * Added jitpack config * Added obj to vector of unions getter * Removed unneeded accessor * Bumped jdk version in pom.xml * Vector of unions support for c#
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
5d42c8352e
commit
f11ffedb2b
@@ -853,7 +853,8 @@ class GeneralGenerator : public BaseGenerator {
|
||||
(field.value.type.base_type == BASE_TYPE_STRUCT ||
|
||||
field.value.type.base_type == BASE_TYPE_UNION ||
|
||||
(field.value.type.base_type == BASE_TYPE_VECTOR &&
|
||||
field.value.type.element == BASE_TYPE_STRUCT))) {
|
||||
(field.value.type.element == BASE_TYPE_STRUCT ||
|
||||
field.value.type.element == BASE_TYPE_UNION)))) {
|
||||
optional = lang_.optional_suffix;
|
||||
conditional_cast = "(" + type_name_dest + optional + ")";
|
||||
}
|
||||
@@ -891,7 +892,9 @@ class GeneralGenerator : public BaseGenerator {
|
||||
code += MakeCamel(field.name, lang_.first_camel_upper);
|
||||
code += "(new " + type_name + "(), j); }\n";
|
||||
}
|
||||
} else if (field.value.type.base_type == BASE_TYPE_UNION) {
|
||||
} else if (field.value.type.base_type == BASE_TYPE_UNION ||
|
||||
(field.value.type.base_type == BASE_TYPE_VECTOR &&
|
||||
field.value.type.VectorType().base_type == BASE_TYPE_UNION)) {
|
||||
if (lang_.language == IDLOptions::kCSharp) {
|
||||
// Union types in C# use generic Table-derived type for better type
|
||||
// safety.
|
||||
@@ -963,13 +966,30 @@ class GeneralGenerator : public BaseGenerator {
|
||||
break;
|
||||
case BASE_TYPE_VECTOR: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
if (vectortype.base_type == BASE_TYPE_UNION &&
|
||||
lang_.language == IDLOptions::kCSharp) {
|
||||
conditional_cast = "(TTable?)";
|
||||
getter += "<TTable>";
|
||||
}
|
||||
code += "(";
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
if (lang_.language != IDLOptions::kCSharp)
|
||||
code += type_name + " obj, ";
|
||||
getter = obj + ".__assign";
|
||||
} else if (vectortype.base_type == BASE_TYPE_UNION) {
|
||||
if (lang_.language != IDLOptions::kCSharp)
|
||||
code += type_name + " obj, ";
|
||||
}
|
||||
code += "int j)";
|
||||
const auto body = offset_prefix + conditional_cast + getter + "(";
|
||||
if (vectortype.base_type == BASE_TYPE_UNION) {
|
||||
if (lang_.language != IDLOptions::kCSharp)
|
||||
code += body + "obj, ";
|
||||
else
|
||||
code += " where TTable : struct, IFlatbufferObject" + body;
|
||||
} else {
|
||||
code += body;
|
||||
}
|
||||
code += "int j)" + offset_prefix + conditional_cast + getter + "(";
|
||||
auto index = lang_.accessor_prefix + "__vector(o) + j * " +
|
||||
NumToString(InlineSize(vectortype));
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
|
||||
Reference in New Issue
Block a user