From 7d84a4914fe4784369d0490fb2b8a45684ed1f07 Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 21:34:42 +0200 Subject: [PATCH 01/17] Update idl_gen_fbs.cpp --- src/idl_gen_fbs.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/idl_gen_fbs.cpp b/src/idl_gen_fbs.cpp index 00afe25d4..241a78792 100644 --- a/src/idl_gen_fbs.cpp +++ b/src/idl_gen_fbs.cpp @@ -52,15 +52,18 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema, } // Generate a flatbuffer schema from the Parser's internal representation. -std::string GenerateFBS(const Parser &parser, const std::string &file_name) { - // Proto namespaces may clash with table names, so we have to prefix all: - for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); - ++it) { - for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); - ++comp) { - (*comp) = "_" + (*comp); - } - } +std::string GenerateFBS(const Parser &parser, const std::string &file_name, const bool &escape_proto_identifiers) { + // Proto namespaces may clash with table names, so we have to prefix all: + + if (!escape_proto_identifiers) { + for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); + ++it) { + for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); + ++comp) { + (*comp) = "_" + (*comp); + } + } + } std::string schema; schema += "// Generated from " + file_name + ".proto\n\n"; @@ -119,9 +122,10 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) { bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name) { + const std::string &file_name, + const bool &escape_proto_identifiers) { return SaveFile((path + file_name + ".fbs").c_str(), - GenerateFBS(parser, file_name), false); + GenerateFBS(parser, file_name, escape_proto_identifiers), false); } } // namespace flatbuffers From ff57f52b7229e70a7029c9c50b58a841768359a6 Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 21:37:50 +0200 Subject: [PATCH 02/17] Update flatc.cpp --- src/flatc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index c7ba29e86..1b9559f6e 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -194,7 +194,9 @@ int main(int argc, const char *argv[]) { binary_files_from = filenames.size(); } else if(arg == "--proto") { opts.proto_mode = true; - } else if(arg == "--schema") { + } else if (arg == "--escape-proto-identifiers") { + opts.escape_proto_identifiers = true; + } else if (arg == "--schema") { schema_binary = true; } else if(arg == "-M") { print_make_rules = true; @@ -314,7 +316,7 @@ int main(int argc, const char *argv[]) { } } - if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase); + if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase, opts.escape_proto_identifiers) // We do not want to generate code for the definitions in this file // in any files coming up next. From aae48e3a9d09695b906da0113c410030dd26989b Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 21:41:01 +0200 Subject: [PATCH 03/17] Update idl.h --- include/flatbuffers/idl.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index b22bc08a1..d5dee17af 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -337,7 +337,8 @@ struct IDLOptions { bool generate_all; bool skip_unexpected_fields_in_json; bool generate_name_strings; - + bool escape_proto_identifiers; + // Possible options for the more general generator below. enum Language { kJava, kCSharp, kGo, kMAX }; @@ -356,6 +357,7 @@ struct IDLOptions { generate_all(false), skip_unexpected_fields_in_json(false), generate_name_strings(false), + escape_proto_identifiers(false), lang(IDLOptions::kJava) {} }; @@ -644,10 +646,12 @@ extern bool GenerateGeneral(const Parser &parser, // Generate a schema file from the internal representation, useful after // parsing a .proto schema. extern std::string GenerateFBS(const Parser &parser, - const std::string &file_name); + const std::string &file_name, + const bool &escape_proto_identifiers); extern bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name); + const std::string &file_name, + const bool &escape_proto_identifiers); // Generate a make rule for the generated JavaScript code. // See idl_gen_js.cpp. From 9fd4d664388853a93cdcea17bc51daed8cfb4322 Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 21:51:34 +0200 Subject: [PATCH 04/17] Update flatc.cpp --- src/flatc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index 1b9559f6e..21dbd304d 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -120,8 +120,9 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) { " --no-includes Don\'t generate include statements for included\n" " schemas the generated file depends on (C++).\n" " --gen-mutable Generate accessors that can mutate buffers in-place.\n" - " --gen-onefile Generate single output file for C#\n" - " --gen-name-strings Generate type name functions for C++.\n" + " --gen-onefile Generate single output file for C#.\n" + " --gen-name-strings Generate type name functions for C++.\n" + " --escape-proto-identifiers Disable appending '_' in namespaces names.\n" " --raw-binary Allow binaries without file_indentifier to be read.\n" " This may crash flatc given a mismatched schema.\n" " --proto Input is a .proto, translate to .fbs.\n" From 50437642477695d02ec8c5002cc50f89aa27dc50 Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 21:55:44 +0200 Subject: [PATCH 05/17] Update test.cpp --- tests/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.cpp b/tests/test.cpp index 6f3b06299..15f8561ca 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -478,7 +478,7 @@ void ParseProtoTest() { TEST_EQ(parser.Parse(protofile.c_str(), include_directories), true); // Generate fbs. - auto fbs = flatbuffers::GenerateFBS(parser, "test"); + auto fbs = flatbuffers::GenerateFBS(parser, "test", false); // Ensure generated file is parsable. flatbuffers::Parser parser2; From 4f8abaaf10dc6f092960626ee88e47250aa55653 Mon Sep 17 00:00:00 2001 From: Raman Date: Mon, 4 Jul 2016 22:58:58 +0200 Subject: [PATCH 06/17] Update flatc.cpp --- src/flatc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index 21dbd304d..a07fbcb7c 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -317,7 +317,7 @@ int main(int argc, const char *argv[]) { } } - if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase, opts.escape_proto_identifiers) + if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase, opts.escape_proto_identifiers); // We do not want to generate code for the definitions in this file // in any files coming up next. From 72e8219a65da19dc42874247b7ce49df141b48dc Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 5 Jul 2016 22:20:57 +0200 Subject: [PATCH 07/17] Update idl_parser.cpp --- src/idl_parser.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index b758e9592..8c0fdade3 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -423,6 +423,13 @@ CheckedError Parser::Next() { return NoError(); } else if (isdigit(static_cast(c)) || c == '-') { const char *start = cursor_ - 1; + const char *start_2 = cursor_ + 1; + if (c == '-' && *cursor_ == '0' && (*start_2 == 'x' || *start_2 == 'X')) { + ++start; + ++cursor_; + attribute_.append(&c, &c + 1); + c = '0'; + } if (c == '0' && (*cursor_ == 'x' || *cursor_ == 'X')) { cursor_++; while (isxdigit(static_cast(*cursor_))) cursor_++; From 4bb6ab3cd557d850b0e848261ff980ffd5918316 Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 5 Jul 2016 22:24:21 +0200 Subject: [PATCH 08/17] Update flatc.cpp --- src/flatc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index a07fbcb7c..b8c996372 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -195,9 +195,9 @@ int main(int argc, const char *argv[]) { binary_files_from = filenames.size(); } else if(arg == "--proto") { opts.proto_mode = true; - } else if (arg == "--escape-proto-identifiers") { - opts.escape_proto_identifiers = true; - } else if (arg == "--schema") { + } else if (arg == "--escape-proto-identifiers") { + opts.escape_proto_identifiers = true; + } else if (arg == "--schema") { schema_binary = true; } else if(arg == "-M") { print_make_rules = true; From f738981ed50840902eb9c422fca98272a8afffce Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 5 Jul 2016 22:26:21 +0200 Subject: [PATCH 09/17] Update idl_gen_fbs.cpp --- src/idl_gen_fbs.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/idl_gen_fbs.cpp b/src/idl_gen_fbs.cpp index 241a78792..719cb0cf7 100644 --- a/src/idl_gen_fbs.cpp +++ b/src/idl_gen_fbs.cpp @@ -55,16 +55,15 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema, std::string GenerateFBS(const Parser &parser, const std::string &file_name, const bool &escape_proto_identifiers) { // Proto namespaces may clash with table names, so we have to prefix all: - if (!escape_proto_identifiers) { - for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); - ++it) { - for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); - ++comp) { - (*comp) = "_" + (*comp); - } + if (!escape_proto_identifiers) { + for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); + ++it) { + for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); + ++comp) { + (*comp) = "_" + (*comp); } - } - + } + } std::string schema; schema += "// Generated from " + file_name + ".proto\n\n"; if (parser.opts.include_dependence_headers) { From 248432b92de15298f38e68ce8296b5b7905adafe Mon Sep 17 00:00:00 2001 From: Raman Date: Tue, 5 Jul 2016 23:23:17 +0200 Subject: [PATCH 10/17] Update idl_gen_fbs.cpp --- src/idl_gen_fbs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idl_gen_fbs.cpp b/src/idl_gen_fbs.cpp index 719cb0cf7..5bbf39073 100644 --- a/src/idl_gen_fbs.cpp +++ b/src/idl_gen_fbs.cpp @@ -122,7 +122,7 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name, cons bool GenerateFBS(const Parser &parser, const std::string &path, const std::string &file_name, - const bool &escape_proto_identifiers) { + const bool &escape_proto_identifiers) { return SaveFile((path + file_name + ".fbs").c_str(), GenerateFBS(parser, file_name, escape_proto_identifiers), false); } From 71d30d5c0282d23ebaaf2100f34c681ea9a1f071 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 12:28:02 +0200 Subject: [PATCH 11/17] Update idl.h --- include/flatbuffers/idl.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index d5dee17af..dddfab25c 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -646,12 +646,10 @@ extern bool GenerateGeneral(const Parser &parser, // Generate a schema file from the internal representation, useful after // parsing a .proto schema. extern std::string GenerateFBS(const Parser &parser, - const std::string &file_name, - const bool &escape_proto_identifiers); + const std::string &file_name); extern bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name, - const bool &escape_proto_identifiers); + const std::string &file_name); // Generate a make rule for the generated JavaScript code. // See idl_gen_js.cpp. From d9d47a53bd254ad9855de4ff98336f0a9c257545 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 12:40:50 +0200 Subject: [PATCH 12/17] Update idl_gen_fbs.cpp --- src/idl_gen_fbs.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/idl_gen_fbs.cpp b/src/idl_gen_fbs.cpp index 5bbf39073..c391ed698 100644 --- a/src/idl_gen_fbs.cpp +++ b/src/idl_gen_fbs.cpp @@ -52,18 +52,18 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema, } // Generate a flatbuffer schema from the Parser's internal representation. -std::string GenerateFBS(const Parser &parser, const std::string &file_name, const bool &escape_proto_identifiers) { +std::string GenerateFBS(const Parser &parser, const std::string &file_name) { // Proto namespaces may clash with table names, so we have to prefix all: - - if (!escape_proto_identifiers) { - for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); - ++it) { - for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); - ++comp) { - (*comp) = "_" + (*comp); - } - } + if (!parser.opts.escape_proto_identifiers) { + for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end(); + ++it) { + for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); + ++comp) { + (*comp) = "_" + (*comp); + } + } } + std::string schema; schema += "// Generated from " + file_name + ".proto\n\n"; if (parser.opts.include_dependence_headers) { @@ -121,10 +121,9 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name, cons bool GenerateFBS(const Parser &parser, const std::string &path, - const std::string &file_name, - const bool &escape_proto_identifiers) { + const std::string &file_name) { return SaveFile((path + file_name + ".fbs").c_str(), - GenerateFBS(parser, file_name, escape_proto_identifiers), false); + GenerateFBS(parser, file_name), false); } } // namespace flatbuffers From ffbc93526ecc048bdb867ebcfae66e2bb851c145 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 12:47:14 +0200 Subject: [PATCH 13/17] Update flatc.cpp --- src/flatc.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index b8c996372..7ee2e5749 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -121,8 +121,8 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) { " schemas the generated file depends on (C++).\n" " --gen-mutable Generate accessors that can mutate buffers in-place.\n" " --gen-onefile Generate single output file for C#.\n" - " --gen-name-strings Generate type name functions for C++.\n" - " --escape-proto-identifiers Disable appending '_' in namespaces names.\n" + " --gen-name-strings Generate type name functions for C++.\n" + " --escape-proto-ids Disable appending '_' in namespaces names.\n" " --raw-binary Allow binaries without file_indentifier to be read.\n" " This may crash flatc given a mismatched schema.\n" " --proto Input is a .proto, translate to .fbs.\n" @@ -195,8 +195,8 @@ int main(int argc, const char *argv[]) { binary_files_from = filenames.size(); } else if(arg == "--proto") { opts.proto_mode = true; - } else if (arg == "--escape-proto-identifiers") { - opts.escape_proto_identifiers = true; + } else if (arg == "--escape-proto-ids") { + opts.escape_proto_identifiers = true; } else if (arg == "--schema") { schema_binary = true; } else if(arg == "-M") { @@ -317,7 +317,7 @@ int main(int argc, const char *argv[]) { } } - if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase, opts.escape_proto_identifiers); + if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase); // We do not want to generate code for the definitions in this file // in any files coming up next. From 22697722d94cb63b9d74744462cb0912005df271 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 12:51:06 +0200 Subject: [PATCH 14/17] Update test.cpp --- tests/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.cpp b/tests/test.cpp index 15f8561ca..6f3b06299 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -478,7 +478,7 @@ void ParseProtoTest() { TEST_EQ(parser.Parse(protofile.c_str(), include_directories), true); // Generate fbs. - auto fbs = flatbuffers::GenerateFBS(parser, "test", false); + auto fbs = flatbuffers::GenerateFBS(parser, "test"); // Ensure generated file is parsable. flatbuffers::Parser parser2; From 5f2b4e787231fd2f3dc09a2ab3dd50ca327319f2 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 12:57:07 +0200 Subject: [PATCH 15/17] Update idl_parser.cpp --- src/idl_parser.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 8c0fdade3..b758e9592 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -423,13 +423,6 @@ CheckedError Parser::Next() { return NoError(); } else if (isdigit(static_cast(c)) || c == '-') { const char *start = cursor_ - 1; - const char *start_2 = cursor_ + 1; - if (c == '-' && *cursor_ == '0' && (*start_2 == 'x' || *start_2 == 'X')) { - ++start; - ++cursor_; - attribute_.append(&c, &c + 1); - c = '0'; - } if (c == '0' && (*cursor_ == 'x' || *cursor_ == 'X')) { cursor_++; while (isxdigit(static_cast(*cursor_))) cursor_++; From f0b2cc8f6eb884606dd4b3cf2ec0b6eb71736235 Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 13:32:45 +0200 Subject: [PATCH 16/17] Update flatc.cpp --- src/flatc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index 7ee2e5749..d410718e3 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -195,9 +195,9 @@ int main(int argc, const char *argv[]) { binary_files_from = filenames.size(); } else if(arg == "--proto") { opts.proto_mode = true; - } else if (arg == "--escape-proto-ids") { + } else if(arg == "--escape-proto-ids") { opts.escape_proto_identifiers = true; - } else if (arg == "--schema") { + } else if(arg == "--schema") { schema_binary = true; } else if(arg == "-M") { print_make_rules = true; From df5575de1786502fb63ce3c6d6a53d3c467f021d Mon Sep 17 00:00:00 2001 From: Raman Date: Sat, 9 Jul 2016 13:33:30 +0200 Subject: [PATCH 17/17] Update idl_gen_fbs.cpp --- src/idl_gen_fbs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idl_gen_fbs.cpp b/src/idl_gen_fbs.cpp index c391ed698..237230e8e 100644 --- a/src/idl_gen_fbs.cpp +++ b/src/idl_gen_fbs.cpp @@ -63,7 +63,7 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) { } } } - + std::string schema; schema += "// Generated from " + file_name + ".proto\n\n"; if (parser.opts.include_dependence_headers) {