Vector of unions for TS/JS and PHP (#4404)

* 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
This commit is contained in:
Kamil Rojewski
2017-08-11 18:24:36 +02:00
committed by Wouter van Oortmerssen
parent 7cc72e4b11
commit 46bb05d952
20 changed files with 1608 additions and 27 deletions

View File

@@ -628,8 +628,8 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
type.enum_def->underlying_type, &typefield));
} else if (type.base_type == BASE_TYPE_VECTOR &&
type.element == BASE_TYPE_UNION) {
// Only cpp supports the union vector feature so far.
if (opts.lang_to_generate != IDLOptions::kCpp) {
// Only cpp, js and ts supports the union vector feature so far.
if (!SupportsVectorOfUnions()) {
return Error("Vectors of unions are not yet supported in all "
"the specified programming languages.");
}
@@ -1571,6 +1571,11 @@ CheckedError Parser::CheckClash(std::vector<FieldDef*> &fields,
return NoError();
}
bool Parser::SupportsVectorOfUnions() const {
return opts.lang_to_generate != 0 && (opts.lang_to_generate &
~(IDLOptions::kCpp | IDLOptions::kJs | IDLOptions::kTs | IDLOptions::kPhp)) == 0;
}
static bool compareFieldDefs(const FieldDef *a, const FieldDef *b) {
auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str());
auto b_id = atoi(b->attributes.Lookup("id")->constant.c_str());
@@ -2141,7 +2146,7 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
val_it != enum_def.vals.vec.end();
++val_it) {
auto &val = **val_it;
if (opts.lang_to_generate != IDLOptions::kCpp &&
if (!SupportsVectorOfUnions() &&
val.union_type.struct_def && val.union_type.struct_def->fixed)
return Error(
"only tables can be union elements in the generated language: "