mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 12:43:24 +00:00
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:
committed by
Wouter van Oortmerssen
parent
7cc72e4b11
commit
46bb05d952
@@ -67,7 +67,10 @@ namespace php {
|
||||
std::string &code = *code_ptr;
|
||||
code += "<?php\n";
|
||||
code = code + "// " + FlatBuffersGeneratedWarning() + "\n\n";
|
||||
code += "namespace " + name_space_name + ";\n\n";
|
||||
|
||||
if (!name_space_name.empty()) {
|
||||
code += "namespace " + name_space_name + ";\n\n";
|
||||
}
|
||||
|
||||
if (needs_imports) {
|
||||
code += "use \\Google\\FlatBuffers\\Struct;\n";
|
||||
@@ -428,6 +431,31 @@ namespace php {
|
||||
code += Indent + "}\n\n";
|
||||
}
|
||||
|
||||
// Get the value of a vector's union member. Uses a named return
|
||||
// argument to conveniently set the zero value for the result.
|
||||
void GetMemberOfVectorOfUnion(const FieldDef &field,
|
||||
std::string *code_ptr) {
|
||||
std::string &code = *code_ptr;
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
|
||||
code += Indent + "/**\n";
|
||||
code += Indent + " * @param int offset\n";
|
||||
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
|
||||
code += Indent + " */\n";
|
||||
code += Indent + "public function get";
|
||||
code += MakeCamel(field.name);
|
||||
code += "($j, $obj)\n";
|
||||
code += Indent + "{\n";
|
||||
code += Indent + Indent +
|
||||
"$o = $this->__offset(" +
|
||||
NumToString(field.value.offset) +
|
||||
");\n";
|
||||
code += Indent + Indent + "return $o != 0 ? ";
|
||||
code += "$this->__union($obj, $this->__vector($o) + $j * ";
|
||||
code += NumToString(InlineSize(vectortype)) + " - $this->bb_pos) : null;\n";
|
||||
code += Indent + "}\n\n";
|
||||
}
|
||||
|
||||
// Recursively generate arguments for a constructor, to deal with nested
|
||||
// structs.
|
||||
static void StructBuilderArgs(const StructDef &struct_def,
|
||||
@@ -703,7 +731,9 @@ namespace php {
|
||||
break;
|
||||
case BASE_TYPE_VECTOR: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
if (vectortype.base_type == BASE_TYPE_UNION) {
|
||||
GetMemberOfVectorOfUnion(field, code_ptr);
|
||||
} else if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
GetMemberOfVectorOfStruct(struct_def, field, code_ptr);
|
||||
} else {
|
||||
GetMemberOfVectorOfNonStruct(field, code_ptr);
|
||||
|
||||
Reference in New Issue
Block a user