From 4cd71d67f1f7c1d9b2e4f21b778c5bb66256c581 Mon Sep 17 00:00:00 2001 From: Flier Lu Date: Thu, 16 Mar 2017 09:34:53 +0800 Subject: [PATCH] GO: add _ postfix to identiy conflict golang keyword (#4221) * add _ postfix to identiy conflict golang keyword * make VS2010 happy --- src/idl_gen_go.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/idl_gen_go.cpp b/src/idl_gen_go.cpp index dadb350f1..88dfd2359 100644 --- a/src/idl_gen_go.cpp +++ b/src/idl_gen_go.cpp @@ -35,6 +35,13 @@ namespace flatbuffers { namespace go { +// see https://golang.org/ref/spec#Keywords +static const char *g_golang_keywords[] = { + "break", "default", "func", "interface", "select", "case", "defer", "go", + "map", "struct", "chan", "else", "goto", "package", "switch", "const", + "fallthrough", "if", "range", "type", "continue", "for", "import", "return", "var", +}; + static std::string GenGetter(const Type &type); static std::string GenMethod(const FieldDef &field); static void GenStructBuilder(const StructDef &struct_def, @@ -43,6 +50,15 @@ static void GenReceiver(const StructDef &struct_def, std::string *code_ptr); static std::string GenTypeBasic(const Type &type); static std::string GenTypeGet(const Type &type); static std::string TypeName(const FieldDef &field); +static std::string GoIdentity(const std::string& name) { + for (size_t i=0; i