[GO] Fix support for enums with underscores and Unions with imported members (#5600)
* Fix Enum Stringer method when Enum has underscores Fixes #5481 * Fix go package importing itself when Union has imported members.
This commit is contained in:
parent
c3c32ec942
commit
3c964e10ab
|
@ -81,13 +81,13 @@ class GoGenerator : public BaseGenerator {
|
|||
tracked_imported_namespaces_.clear();
|
||||
needs_imports = false;
|
||||
std::string enumcode;
|
||||
GenEnum(**it, &enumcode);
|
||||
if ((*it)->is_union && parser_.opts.generate_object_based_api) {
|
||||
GenNativeUnion(**it, &enumcode);
|
||||
GenNativeUnionPack(**it, &enumcode);
|
||||
GenNativeUnionUnPack(**it, &enumcode);
|
||||
needs_imports = true;
|
||||
}
|
||||
GenEnum(**it, &enumcode);
|
||||
if (parser_.opts.one_file) {
|
||||
one_file_code += enumcode;
|
||||
} else {
|
||||
|
|
|
@ -10,6 +10,36 @@ import (
|
|||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
||||
type Any byte
|
||||
|
||||
const (
|
||||
AnyNONE Any = 0
|
||||
AnyMonster Any = 1
|
||||
AnyTestSimpleTableWithEnum Any = 2
|
||||
AnyMyGame_Example2_Monster Any = 3
|
||||
)
|
||||
|
||||
var EnumNamesAny = map[Any]string{
|
||||
AnyNONE: "NONE",
|
||||
AnyMonster: "Monster",
|
||||
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
|
||||
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
|
||||
}
|
||||
|
||||
var EnumValuesAny = map[string]Any{
|
||||
"NONE": AnyNONE,
|
||||
"Monster": AnyMonster,
|
||||
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
|
||||
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
|
||||
}
|
||||
|
||||
func (v Any) String() string {
|
||||
if s, ok := EnumNamesAny[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyT struct {
|
||||
Type Any
|
||||
Value interface{}
|
||||
|
@ -44,33 +74,3 @@ func AnyUnPack(t Any, table flatbuffers.Table) *AnyT {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Any byte
|
||||
|
||||
const (
|
||||
AnyNONE Any = 0
|
||||
AnyMonster Any = 1
|
||||
AnyTestSimpleTableWithEnum Any = 2
|
||||
AnyMyGame_Example2_Monster Any = 3
|
||||
)
|
||||
|
||||
var EnumNamesAny = map[Any]string{
|
||||
AnyNONE: "NONE",
|
||||
AnyMonster: "Monster",
|
||||
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
|
||||
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
|
||||
}
|
||||
|
||||
var EnumValuesAny = map[string]Any{
|
||||
"NONE": AnyNONE,
|
||||
"Monster": AnyMonster,
|
||||
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
|
||||
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
|
||||
}
|
||||
|
||||
func (v Any) String() string {
|
||||
if s, ok := EnumNamesAny[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
|
|
@ -8,6 +8,36 @@ import (
|
|||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
|
||||
type AnyAmbiguousAliases byte
|
||||
|
||||
const (
|
||||
AnyAmbiguousAliasesNONE AnyAmbiguousAliases = 0
|
||||
AnyAmbiguousAliasesM1 AnyAmbiguousAliases = 1
|
||||
AnyAmbiguousAliasesM2 AnyAmbiguousAliases = 2
|
||||
AnyAmbiguousAliasesM3 AnyAmbiguousAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyAmbiguousAliases = map[AnyAmbiguousAliases]string{
|
||||
AnyAmbiguousAliasesNONE: "NONE",
|
||||
AnyAmbiguousAliasesM1: "M1",
|
||||
AnyAmbiguousAliasesM2: "M2",
|
||||
AnyAmbiguousAliasesM3: "M3",
|
||||
}
|
||||
|
||||
var EnumValuesAnyAmbiguousAliases = map[string]AnyAmbiguousAliases{
|
||||
"NONE": AnyAmbiguousAliasesNONE,
|
||||
"M1": AnyAmbiguousAliasesM1,
|
||||
"M2": AnyAmbiguousAliasesM2,
|
||||
"M3": AnyAmbiguousAliasesM3,
|
||||
}
|
||||
|
||||
func (v AnyAmbiguousAliases) String() string {
|
||||
if s, ok := EnumNamesAnyAmbiguousAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyAmbiguousAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyAmbiguousAliasesT struct {
|
||||
Type AnyAmbiguousAliases
|
||||
Value interface{}
|
||||
|
@ -42,33 +72,3 @@ func AnyAmbiguousAliasesUnPack(t AnyAmbiguousAliases, table flatbuffers.Table) *
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AnyAmbiguousAliases byte
|
||||
|
||||
const (
|
||||
AnyAmbiguousAliasesNONE AnyAmbiguousAliases = 0
|
||||
AnyAmbiguousAliasesM1 AnyAmbiguousAliases = 1
|
||||
AnyAmbiguousAliasesM2 AnyAmbiguousAliases = 2
|
||||
AnyAmbiguousAliasesM3 AnyAmbiguousAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyAmbiguousAliases = map[AnyAmbiguousAliases]string{
|
||||
AnyAmbiguousAliasesNONE: "NONE",
|
||||
AnyAmbiguousAliasesM1: "M1",
|
||||
AnyAmbiguousAliasesM2: "M2",
|
||||
AnyAmbiguousAliasesM3: "M3",
|
||||
}
|
||||
|
||||
var EnumValuesAnyAmbiguousAliases = map[string]AnyAmbiguousAliases{
|
||||
"NONE": AnyAmbiguousAliasesNONE,
|
||||
"M1": AnyAmbiguousAliasesM1,
|
||||
"M2": AnyAmbiguousAliasesM2,
|
||||
"M3": AnyAmbiguousAliasesM3,
|
||||
}
|
||||
|
||||
func (v AnyAmbiguousAliases) String() string {
|
||||
if s, ok := EnumNamesAnyAmbiguousAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyAmbiguousAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
|
|
@ -10,6 +10,36 @@ import (
|
|||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
||||
type AnyUniqueAliases byte
|
||||
|
||||
const (
|
||||
AnyUniqueAliasesNONE AnyUniqueAliases = 0
|
||||
AnyUniqueAliasesM AnyUniqueAliases = 1
|
||||
AnyUniqueAliasesTS AnyUniqueAliases = 2
|
||||
AnyUniqueAliasesM2 AnyUniqueAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyUniqueAliases = map[AnyUniqueAliases]string{
|
||||
AnyUniqueAliasesNONE: "NONE",
|
||||
AnyUniqueAliasesM: "M",
|
||||
AnyUniqueAliasesTS: "TS",
|
||||
AnyUniqueAliasesM2: "M2",
|
||||
}
|
||||
|
||||
var EnumValuesAnyUniqueAliases = map[string]AnyUniqueAliases{
|
||||
"NONE": AnyUniqueAliasesNONE,
|
||||
"M": AnyUniqueAliasesM,
|
||||
"TS": AnyUniqueAliasesTS,
|
||||
"M2": AnyUniqueAliasesM2,
|
||||
}
|
||||
|
||||
func (v AnyUniqueAliases) String() string {
|
||||
if s, ok := EnumNamesAnyUniqueAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyUniqueAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
||||
type AnyUniqueAliasesT struct {
|
||||
Type AnyUniqueAliases
|
||||
Value interface{}
|
||||
|
@ -44,33 +74,3 @@ func AnyUniqueAliasesUnPack(t AnyUniqueAliases, table flatbuffers.Table) *AnyUni
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AnyUniqueAliases byte
|
||||
|
||||
const (
|
||||
AnyUniqueAliasesNONE AnyUniqueAliases = 0
|
||||
AnyUniqueAliasesM AnyUniqueAliases = 1
|
||||
AnyUniqueAliasesTS AnyUniqueAliases = 2
|
||||
AnyUniqueAliasesM2 AnyUniqueAliases = 3
|
||||
)
|
||||
|
||||
var EnumNamesAnyUniqueAliases = map[AnyUniqueAliases]string{
|
||||
AnyUniqueAliasesNONE: "NONE",
|
||||
AnyUniqueAliasesM: "M",
|
||||
AnyUniqueAliasesTS: "TS",
|
||||
AnyUniqueAliasesM2: "M2",
|
||||
}
|
||||
|
||||
var EnumValuesAnyUniqueAliases = map[string]AnyUniqueAliases{
|
||||
"NONE": AnyUniqueAliasesNONE,
|
||||
"M": AnyUniqueAliasesM,
|
||||
"TS": AnyUniqueAliasesTS,
|
||||
"M2": AnyUniqueAliasesM2,
|
||||
}
|
||||
|
||||
func (v AnyUniqueAliases) String() string {
|
||||
if s, ok := EnumNamesAnyUniqueAliases[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "AnyUniqueAliases(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue