mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +00:00
make unions with type aliases more usable (#5019)
Some generic C++ and Rust code is not generated when unions use type aliases because of potential ambiguity. Actually check for this ambiguity and only disable offending code only if it is found.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
4c3b6c247d
commit
91fe9ba93f
@@ -611,22 +611,58 @@ class Monster extends Table
|
||||
return $o != 0 ? $this->__vector_len($o) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return byte
|
||||
*/
|
||||
public function getAnyUniqueType()
|
||||
{
|
||||
$o = $this->__offset(90);
|
||||
return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \MyGame\Example\AnyUniqueAliases::NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returnint
|
||||
*/
|
||||
public function getAnyUnique($obj)
|
||||
{
|
||||
$o = $this->__offset(92);
|
||||
return $o != 0 ? $this->__union($obj, $o) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return byte
|
||||
*/
|
||||
public function getAnyAmbiguousType()
|
||||
{
|
||||
$o = $this->__offset(94);
|
||||
return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \MyGame\Example\AnyAmbiguousAliases::NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returnint
|
||||
*/
|
||||
public function getAnyAmbiguous($obj)
|
||||
{
|
||||
$o = $this->__offset(96);
|
||||
return $o != 0 ? $this->__union($obj, $o) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startMonster(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(43);
|
||||
$builder->StartObject(47);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return Monster
|
||||
*/
|
||||
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5, $vector_of_longs, $vector_of_doubles, $parent_namespace_test, $vector_of_referrables, $single_weak_reference, $vector_of_weak_references, $vector_of_strong_referrables, $co_owning_reference, $vector_of_co_owning_references, $non_owning_reference, $vector_of_non_owning_references)
|
||||
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5, $vector_of_longs, $vector_of_doubles, $parent_namespace_test, $vector_of_referrables, $single_weak_reference, $vector_of_weak_references, $vector_of_strong_referrables, $co_owning_reference, $vector_of_co_owning_references, $non_owning_reference, $vector_of_non_owning_references, $any_unique_type, $any_unique, $any_ambiguous_type, $any_ambiguous)
|
||||
{
|
||||
$builder->startObject(43);
|
||||
$builder->startObject(47);
|
||||
self::addPos($builder, $pos);
|
||||
self::addMana($builder, $mana);
|
||||
self::addHp($builder, $hp);
|
||||
@@ -669,6 +705,10 @@ class Monster extends Table
|
||||
self::addVectorOfCoOwningReferences($builder, $vector_of_co_owning_references);
|
||||
self::addNonOwningReference($builder, $non_owning_reference);
|
||||
self::addVectorOfNonOwningReferences($builder, $vector_of_non_owning_references);
|
||||
self::addAnyUniqueType($builder, $any_unique_type);
|
||||
self::addAnyUnique($builder, $any_unique);
|
||||
self::addAnyAmbiguousType($builder, $any_ambiguous_type);
|
||||
self::addAnyAmbiguous($builder, $any_ambiguous);
|
||||
$o = $builder->endObject();
|
||||
$builder->required($o, 10); // name
|
||||
return $o;
|
||||
@@ -1497,6 +1537,36 @@ class Monster extends Table
|
||||
$builder->startVector(8, $numElems, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param byte
|
||||
* @return void
|
||||
*/
|
||||
public static function addAnyUniqueType(FlatBufferBuilder $builder, $anyUniqueType)
|
||||
{
|
||||
$builder->addByteX(43, $anyUniqueType, 0);
|
||||
}
|
||||
|
||||
public static function addAnyUnique(FlatBufferBuilder $builder, $offset)
|
||||
{
|
||||
$builder->addOffsetX(44, $offset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param byte
|
||||
* @return void
|
||||
*/
|
||||
public static function addAnyAmbiguousType(FlatBufferBuilder $builder, $anyAmbiguousType)
|
||||
{
|
||||
$builder->addByteX(45, $anyAmbiguousType, 0);
|
||||
}
|
||||
|
||||
public static function addAnyAmbiguous(FlatBufferBuilder $builder, $offset)
|
||||
{
|
||||
$builder->addOffsetX(46, $offset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
|
||||
Reference in New Issue
Block a user