diff options
author | David Reiss <davidn@gmail.com> | 2019-05-20 14:46:36 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-05-20 14:46:36 -0700 |
commit | c5e2d37337c8d84177111629083ec31e974816bd (patch) | |
tree | 7d0f735908ac9ede528e092e3ef99b143b2bf682 | |
parent | fe83b68ac68f221a8a7cf105e541b6d6d682ad80 (diff) | |
download | flatbuffers-c5e2d37337c8d84177111629083ec31e974816bd.tar.gz flatbuffers-c5e2d37337c8d84177111629083ec31e974816bd.tar.bz2 flatbuffers-c5e2d37337c8d84177111629083ec31e974816bd.zip |
[Go] Change two more sites to use enum types (#5359)
Fixes #5357 (regression introduced by #5235)
-rw-r--r-- | src/idl_gen_go.cpp | 8 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.go | 16 | ||||
-rw-r--r-- | tests/MyGame/Example/TestSimpleTableWithEnum.go | 4 | ||||
-rw-r--r-- | tests/MyGame/Example/Vec3.go | 4 | ||||
-rw-r--r-- | tests/go_test.go | 7 | ||||
-rw-r--r-- | tests/namespace_test/NamespaceA/TableInFirstNS.go | 4 |
6 files changed, 22 insertions, 21 deletions
diff --git a/src/idl_gen_go.cpp b/src/idl_gen_go.cpp index 7987d90a..6556741e 100644 --- a/src/idl_gen_go.cpp +++ b/src/idl_gen_go.cpp @@ -497,7 +497,7 @@ class GoGenerator : public BaseGenerator { std::string &code = *code_ptr; code += std::string(", ") + nameprefix; code += GoIdentity(field.name); - code += " " + GenTypeBasic(field.value.type); + code += " " + TypeName(field); } } } @@ -525,7 +525,7 @@ class GoGenerator : public BaseGenerator { (nameprefix + (field.name + "_")).c_str(), code_ptr); } else { code += "\tbuilder.Prepend" + GenMethod(field) + "("; - code += nameprefix + GoIdentity(field.name) + ")\n"; + code += CastToBaseType(field.value.type, nameprefix + GoIdentity(field.name)) + ")\n"; } } } @@ -556,7 +556,7 @@ class GoGenerator : public BaseGenerator { if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) { code += "flatbuffers.UOffsetT"; } else { - code += GenTypeBasic(field.value.type); + code += TypeName(field); } code += ") {\n"; code += "\tbuilder.Prepend"; @@ -567,7 +567,7 @@ class GoGenerator : public BaseGenerator { code += "("; code += GoIdentity(field.name) + ")"; } else { - code += GoIdentity(field.name); + code += CastToBaseType(field.value.type, GoIdentity(field.name)); } code += ", " + GenConstant(field); code += ")\n}\n"; diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go index ab32ccfd..dabb596c 100644 --- a/tests/MyGame/Example/Monster.go +++ b/tests/MyGame/Example/Monster.go @@ -836,11 +836,11 @@ func MonsterAddInventory(builder *flatbuffers.Builder, inventory flatbuffers.UOf func MonsterStartInventoryVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1) } -func MonsterAddColor(builder *flatbuffers.Builder, color byte) { - builder.PrependByteSlot(6, color, 8) +func MonsterAddColor(builder *flatbuffers.Builder, color Color) { + builder.PrependByteSlot(6, byte(color), 8) } -func MonsterAddTestType(builder *flatbuffers.Builder, testType byte) { - builder.PrependByteSlot(7, testType, 0) +func MonsterAddTestType(builder *flatbuffers.Builder, testType Any) { + builder.PrependByteSlot(7, byte(testType), 0) } func MonsterAddTest(builder *flatbuffers.Builder, test flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(8, flatbuffers.UOffsetT(test), 0) @@ -995,14 +995,14 @@ func MonsterAddVectorOfNonOwningReferences(builder *flatbuffers.Builder, vectorO func MonsterStartVectorOfNonOwningReferencesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(8, numElems, 8) } -func MonsterAddAnyUniqueType(builder *flatbuffers.Builder, anyUniqueType byte) { - builder.PrependByteSlot(43, anyUniqueType, 0) +func MonsterAddAnyUniqueType(builder *flatbuffers.Builder, anyUniqueType AnyUniqueAliases) { + builder.PrependByteSlot(43, byte(anyUniqueType), 0) } func MonsterAddAnyUnique(builder *flatbuffers.Builder, anyUnique flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(44, flatbuffers.UOffsetT(anyUnique), 0) } -func MonsterAddAnyAmbiguousType(builder *flatbuffers.Builder, anyAmbiguousType byte) { - builder.PrependByteSlot(45, anyAmbiguousType, 0) +func MonsterAddAnyAmbiguousType(builder *flatbuffers.Builder, anyAmbiguousType AnyAmbiguousAliases) { + builder.PrependByteSlot(45, byte(anyAmbiguousType), 0) } func MonsterAddAnyAmbiguous(builder *flatbuffers.Builder, anyAmbiguous flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(46, flatbuffers.UOffsetT(anyAmbiguous), 0) diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.go b/tests/MyGame/Example/TestSimpleTableWithEnum.go index 78c4d713..35a6c7c0 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.go +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.go @@ -41,8 +41,8 @@ func (rcv *TestSimpleTableWithEnum) MutateColor(n Color) bool { func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { builder.StartObject(1) } -func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color byte) { - builder.PrependByteSlot(0, color, 2) +func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color Color) { + builder.PrependByteSlot(0, byte(color), 2) } func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() diff --git a/tests/MyGame/Example/Vec3.go b/tests/MyGame/Example/Vec3.go index a9feaae0..9131afdc 100644 --- a/tests/MyGame/Example/Vec3.go +++ b/tests/MyGame/Example/Vec3.go @@ -62,7 +62,7 @@ func (rcv *Vec3) Test3(obj *Test) *Test { return obj } -func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 byte, test3_a int16, test3_b int8) flatbuffers.UOffsetT { +func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 Color, test3_a int16, test3_b int8) flatbuffers.UOffsetT { builder.Prep(8, 32) builder.Pad(2) builder.Prep(2, 4) @@ -70,7 +70,7 @@ func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, t builder.PrependInt8(test3_b) builder.PrependInt16(test3_a) builder.Pad(1) - builder.PrependByte(test2) + builder.PrependByte(byte(test2)) builder.PrependFloat64(test1) builder.Pad(4) builder.PrependFloat32(z) diff --git a/tests/go_test.go b/tests/go_test.go index 87741602..47847050 100644 --- a/tests/go_test.go +++ b/tests/go_test.go @@ -1189,7 +1189,7 @@ func CheckGeneratedBuild(fail func(string, ...interface{})) ([]byte, flatbuffers example.MonsterStart(b) - pos := example.CreateVec3(b, 1.0, 2.0, 3.0, 3.0, 2, 5, 6) + pos := example.CreateVec3(b, 1.0, 2.0, 3.0, 3.0, example.ColorGreen, 5, 6) example.MonsterAddPos(b, pos) example.MonsterAddHp(b, 80) @@ -1479,11 +1479,12 @@ func CheckDocExample(buf []byte, off flatbuffers.UOffsetT, fail func(string, ... str := builder.CreateString("MyMonster") example.MonsterStart(builder) - example.MonsterAddPos(builder, example.CreateVec3(builder, 1.0, 2.0, 3.0, 3.0, 4, 5, 6)) + example.MonsterAddPos(builder, example.CreateVec3(builder, 1.0, 2.0, 3.0, 3.0, example.Color(4), 5, 6)) example.MonsterAddHp(builder, 80) example.MonsterAddName(builder, str) example.MonsterAddInventory(builder, inv) example.MonsterAddTestType(builder, 1) + example.MonsterAddColor(builder, example.ColorRed) // example.MonsterAddTest(builder, mon2) // example.MonsterAddTest4(builder, test4s) _ = example.MonsterEnd(builder) @@ -1871,7 +1872,7 @@ func BenchmarkBuildGold(b *testing.B) { example.MonsterStart(bldr) - pos := example.CreateVec3(bldr, 1.0, 2.0, 3.0, 3.0, 2, 5, 6) + pos := example.CreateVec3(bldr, 1.0, 2.0, 3.0, 3.0, example.ColorGreen, 5, 6) example.MonsterAddPos(bldr, pos) example.MonsterAddHp(bldr, 80) diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.go b/tests/namespace_test/NamespaceA/TableInFirstNS.go index c8da74a9..b248b973 100644 --- a/tests/namespace_test/NamespaceA/TableInFirstNS.go +++ b/tests/namespace_test/NamespaceA/TableInFirstNS.go @@ -72,8 +72,8 @@ func TableInFirstNSStart(builder *flatbuffers.Builder) { func TableInFirstNSAddFooTable(builder *flatbuffers.Builder, fooTable flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(fooTable), 0) } -func TableInFirstNSAddFooEnum(builder *flatbuffers.Builder, fooEnum int8) { - builder.PrependInt8Slot(1, fooEnum, 0) +func TableInFirstNSAddFooEnum(builder *flatbuffers.Builder, fooEnum EnumInNestedNS) { + builder.PrependInt8Slot(1, int8(fooEnum), 0) } func TableInFirstNSAddFooStruct(builder *flatbuffers.Builder, fooStruct flatbuffers.UOffsetT) { builder.PrependStructSlot(2, flatbuffers.UOffsetT(fooStruct), 0) |