From d70f5ac6b02f250dca8e2c6e8f59a4223d1f66f6 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 29 Jul 2016 10:45:32 -0700 Subject: [PATCH] Added backwards compatible --no-union-value-namespacing Change-Id: Ia78dd3b0f213e9ffa49dcec699dcbb21fe6517da Tested: on Linux. --- include/flatbuffers/idl.h | 2 ++ src/flatc.cpp | 2 ++ src/idl_parser.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 1f4501629..25706e84f 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -347,6 +347,7 @@ struct IDLOptions { bool generate_name_strings; bool escape_proto_identifiers; bool generate_object_based_api; + bool union_value_namespacing; // Possible options for the more general generator below. enum Language { kJava, kCSharp, kGo, kMAX }; @@ -368,6 +369,7 @@ struct IDLOptions { generate_name_strings(false), escape_proto_identifiers(false), generate_object_based_api(false), + union_value_namespacing(true), lang(IDLOptions::kJava) {} }; diff --git a/src/flatc.cpp b/src/flatc.cpp index a568bbb24..b174cbd43 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -195,6 +195,8 @@ int main(int argc, const char *argv[]) { } else if(arg == "--scoped-enums") { opts.prefixed_enums = false; opts.scoped_enums = true; + } else if (arg == "--no-union-value-namespacing") { + opts.union_value_namespacing = false; } else if(arg == "--gen-mutable") { opts.mutable_buffer = true; } else if(arg == "--gen-name-strings") { diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index fc2136757..b03655c92 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1216,10 +1216,12 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) { EXPECT(kTokenIdentifier); if (is_union) { ECHECK(ParseNamespacing(&full_name, &value_name)); - // Since we can't namespace the actual enum identifiers, turn - // namespace parts into part of the identifier. - value_name = full_name; - std::replace(value_name.begin(), value_name.end(), '.', '_'); + if (opts.union_value_namespacing) { + // Since we can't namespace the actual enum identifiers, turn + // namespace parts into part of the identifier. + value_name = full_name; + std::replace(value_name.begin(), value_name.end(), '.', '_'); + } } auto prevsize = enum_def.vals.vec.size(); auto value = enum_def.vals.vec.size()