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:
Frank Benkstein
2018-11-01 20:51:25 +01:00
committed by Wouter van Oortmerssen
parent 4c3b6c247d
commit 91fe9ba93f
33 changed files with 1773 additions and 37 deletions

View File

@@ -15,6 +15,18 @@ enum +
Any_TestSimpleTableWithEnum = 2,
Any_MyGame_Example2_Monster = 3
enum +
AnyUniqueAliases_NONE = 0,
AnyUniqueAliases_M = 1,
AnyUniqueAliases_T = 2,
AnyUniqueAliases_M2 = 3
enum +
AnyAmbiguousAliases_NONE = 0,
AnyAmbiguousAliases_M1 = 1,
AnyAmbiguousAliases_M2 = 2,
AnyAmbiguousAliases_M3 = 3
namespace MyGame
struct InParentNamespace
@@ -297,11 +309,27 @@ struct Monster : flatbuffers_handle
buf_.read_int64_le(buf_.flatbuffers_field_vector(pos_, 88) + i * 8)
def vector_of_non_owning_references_length():
buf_.flatbuffers_field_vector_len(pos_, 88)
def any_unique_type():
buf_.flatbuffers_field_int8(pos_, 90, 0)
def any_unique_as_M():
MyGame_Example_Monster { buf_, buf_.flatbuffers_field_table(pos_, 92) }
def any_unique_as_T():
MyGame_Example_TestSimpleTableWithEnum { buf_, buf_.flatbuffers_field_table(pos_, 92) }
def any_unique_as_M2():
MyGame_Example2_Monster { buf_, buf_.flatbuffers_field_table(pos_, 92) }
def any_ambiguous_type():
buf_.flatbuffers_field_int8(pos_, 94, 0)
def any_ambiguous_as_M1():
MyGame_Example_Monster { buf_, buf_.flatbuffers_field_table(pos_, 96) }
def any_ambiguous_as_M2():
MyGame_Example_Monster { buf_, buf_.flatbuffers_field_table(pos_, 96) }
def any_ambiguous_as_M3():
MyGame_Example_Monster { buf_, buf_.flatbuffers_field_table(pos_, 96) }
def GetRootAsMonster(buf:string): Monster { buf, buf.flatbuffers_indirect(0) }
def MonsterStart(b_:flatbuffers_builder):
b_.StartObject(43)
b_.StartObject(47)
def MonsterAddPos(b_:flatbuffers_builder, pos:int):
b_.PrependStructSlot(0, pos, 0)
def MonsterAddMana(b_:flatbuffers_builder, mana:int):
@@ -476,6 +504,14 @@ def MonsterCreateVectorOfNonOwningReferencesVector(b_:flatbuffers_builder, v_:[i
b_.StartVector(8, v_.length, 8)
reverse(v_) e_: b_.PrependUint64(e_)
b_.EndVector(v_.length)
def MonsterAddAnyUniqueType(b_:flatbuffers_builder, any_unique_type:int):
b_.PrependUint8Slot(43, any_unique_type, 0)
def MonsterAddAnyUnique(b_:flatbuffers_builder, any_unique:int):
b_.PrependUOffsetTRelativeSlot(44, any_unique, 0)
def MonsterAddAnyAmbiguousType(b_:flatbuffers_builder, any_ambiguous_type:int):
b_.PrependUint8Slot(45, any_ambiguous_type, 0)
def MonsterAddAnyAmbiguous(b_:flatbuffers_builder, any_ambiguous:int):
b_.PrependUOffsetTRelativeSlot(46, any_ambiguous, 0)
def MonsterEnd(b_:flatbuffers_builder):
b_.EndObject()