diff options
author | reshilkin <reshilkin@yandex-team.com> | 2023-08-11 12:01:29 +0300 |
---|---|---|
committer | reshilkin <reshilkin@yandex-team.com> | 2023-08-11 13:00:03 +0300 |
commit | 5894c3ce50a49a9f9bc1c0316e2ef0708e3a7ef8 (patch) | |
tree | 624e56690fe689e569d05612fa0e92f2c5bdb75b /contrib/libs/flatbuffers/grpc/src | |
parent | 1eb895279c52b0d2505a31b79ad326b56d0b2681 (diff) | |
download | ydb-5894c3ce50a49a9f9bc1c0316e2ef0708e3a7ef8.tar.gz |
Update contrib/libs/flatbuffers to 23.5.9
Diffstat (limited to 'contrib/libs/flatbuffers/grpc/src')
13 files changed, 800 insertions, 974 deletions
diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/config.h b/contrib/libs/flatbuffers/grpc/src/compiler/config.h deleted file mode 100644 index 4adc594377..0000000000 --- a/contrib/libs/flatbuffers/grpc/src/compiler/config.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef SRC_COMPILER_CONFIG_H -#define SRC_COMPILER_CONFIG_H - -// This file is here only because schema_interface.h, which is copied from gRPC, -// includes it. There is nothing for Flatbuffers to configure. - -#endif // SRC_COMPILER_CONFIG_H diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.cc index 8dd408830c..fd635f2fa5 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.cc @@ -1,65 +1,31 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +#include "src/compiler/cpp_generator.h" #include <map> +#include <sstream> -#include "src/compiler/cpp_generator.h" #include "flatbuffers/util.h" -#include <sstream> - namespace grpc_cpp_generator { namespace { -grpc::string message_header_ext() { return "_generated.h"; } -grpc::string service_header_ext() { return ".grpc.fb.h"; } +static grpc::string service_header_ext() { return ".grpc.fb.h"; } -template <class T> -grpc::string as_string(T x) { +template<class T> +static grpc::string as_string(T x) { std::ostringstream out; out << x; return out.str(); } -inline bool ClientOnlyStreaming(const grpc_generator::Method *method) { +static inline bool ClientOnlyStreaming(const grpc_generator::Method *method) { return method->ClientStreaming() && !method->ServerStreaming(); } -inline bool ServerOnlyStreaming(const grpc_generator::Method *method) { +static inline bool ServerOnlyStreaming(const grpc_generator::Method *method) { return !method->ClientStreaming() && method->ServerStreaming(); } -grpc::string FilenameIdentifier(const grpc::string &filename) { +static grpc::string FilenameIdentifier(const grpc::string &filename) { grpc::string result; for (unsigned i = 0; i < filename.size(); i++) { char c = filename[i]; @@ -74,14 +40,11 @@ grpc::string FilenameIdentifier(const grpc::string &filename) { } return result; } -} // namespace -template <class T, size_t N> -T *array_end(T (&array)[N]) { - return array + N; -} +template<class T, size_t N> +static T *array_end(T (&array)[N]) { return array + N; } -void PrintIncludes(grpc_generator::Printer *printer, +static void PrintIncludes(grpc_generator::Printer *printer, const std::vector<grpc::string> &headers, const Parameters ¶ms) { std::map<grpc::string, grpc::string> vars; @@ -92,9 +55,7 @@ void PrintIncludes(grpc_generator::Printer *printer, auto &s = params.grpc_search_path; if (!s.empty()) { vars["l"] += s; - if (s[s.size() - 1] != '/') { - vars["l"] += '/'; - } + if (s[s.size() - 1] != '/') { vars["l"] += '/'; } } for (auto i = headers.begin(); i != headers.end(); i++) { @@ -103,8 +64,10 @@ void PrintIncludes(grpc_generator::Printer *printer, } } +} // namespace + grpc::string GetHeaderPrologue(grpc_generator::File *file, - const Parameters & /*params*/) { + const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -114,7 +77,7 @@ grpc::string GetHeaderPrologue(grpc_generator::File *file, vars["filename"] = file->filename(); vars["filename_identifier"] = FilenameIdentifier(file->filename()); vars["filename_base"] = file->filename_without_ext(); - vars["message_header_ext"] = message_header_ext(); + vars["message_header_ext"] = params.message_header_extension; printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); printer->Print(vars, @@ -144,15 +107,16 @@ grpc::string GetHeaderIncludes(grpc_generator::File *file, std::map<grpc::string, grpc::string> vars; static const char *headers_strs[] = { - "grpcpp/impl/codegen/async_stream.h", - "grpcpp/impl/codegen/async_unary_call.h", - "grpcpp/impl/codegen/method_handler.h", - "grpcpp/impl/codegen/proto_utils.h", - "grpcpp/impl/codegen/rpc_method.h", - "grpcpp/impl/codegen/service_type.h", - "grpcpp/impl/codegen/status.h", - "grpcpp/impl/codegen/stub_options.h", - "grpcpp/impl/codegen/sync_stream.h"}; + "grpcpp/impl/codegen/async_stream.h", + "grpcpp/impl/codegen/async_unary_call.h", + "grpcpp/impl/codegen/method_handler.h", + "grpcpp/impl/codegen/proto_utils.h", + "grpcpp/impl/codegen/rpc_method.h", + "grpcpp/impl/codegen/service_type.h", + "grpcpp/impl/codegen/status.h", + "grpcpp/impl/codegen/stub_options.h", + "grpcpp/impl/codegen/sync_stream.h" + }; std::vector<grpc::string> headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); printer->Print(vars, "\n"); @@ -176,7 +140,10 @@ grpc::string GetHeaderIncludes(grpc_generator::File *file, return output; } -void PrintHeaderClientMethodInterfaces( + +namespace { + +static void PrintHeaderClientMethodInterfaces( grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars, bool is_public) { (*vars)["Method"] = method->name(); @@ -187,8 +154,8 @@ void PrintHeaderClientMethodInterfaces( grpc::string prefix; grpc::string method_params; // extra arguments to method grpc::string raw_args; // extra arguments to raw version of method - } async_prefixes[] = {{"Async", ", void* tag", ", tag"}, - {"PrepareAsync", "", ""}}; + } async_prefixes[] = { { "Async", ", void* tag", ", tag" }, + { "PrepareAsync", "", "" } }; if (is_public) { if (method->NoStreaming()) { @@ -196,8 +163,9 @@ void PrintHeaderClientMethodInterfaces( *vars, "virtual ::grpc::Status $Method$(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response) = 0;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; printer->Print( *vars, @@ -228,8 +196,9 @@ void PrintHeaderClientMethodInterfaces( "($Method$Raw(context, response));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -262,8 +231,9 @@ void PrintHeaderClientMethodInterfaces( "($Method$Raw(context, request));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -295,8 +265,9 @@ void PrintHeaderClientMethodInterfaces( "$Method$Raw(context));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -318,8 +289,9 @@ void PrintHeaderClientMethodInterfaces( } } else { if (method->NoStreaming()) { - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; printer->Print( *vars, @@ -334,8 +306,9 @@ void PrintHeaderClientMethodInterfaces( "virtual ::grpc::ClientWriterInterface< $Request$>*" " $Method$Raw(" "::grpc::ClientContext* context, $Response$* response) = 0;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; printer->Print( @@ -351,8 +324,9 @@ void PrintHeaderClientMethodInterfaces( "virtual ::grpc::ClientReaderInterface< $Response$>* " "$Method$Raw(" "::grpc::ClientContext* context, const $Request$& request) = 0;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; printer->Print( @@ -367,8 +341,9 @@ void PrintHeaderClientMethodInterfaces( "virtual ::grpc::ClientReaderWriterInterface< $Request$, " "$Response$>* " "$Method$Raw(::grpc::ClientContext* context) = 0;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; printer->Print( @@ -382,7 +357,9 @@ void PrintHeaderClientMethodInterfaces( } } -void PrintHeaderClientMethod(grpc_generator::Printer *printer, + + +static void PrintHeaderClientMethod(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars, bool is_public) { @@ -393,8 +370,8 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, grpc::string prefix; grpc::string method_params; // extra arguments to method grpc::string raw_args; // extra arguments to raw version of method - } async_prefixes[] = {{"Async", ", void* tag", ", tag"}, - {"PrepareAsync", "", ""}}; + } async_prefixes[] = { { "Async", ", void* tag", ", tag" }, + { "PrepareAsync", "", "" } }; if (is_public) { if (method->NoStreaming()) { @@ -402,8 +379,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, *vars, "::grpc::Status $Method$(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response) override;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; printer->Print( *vars, @@ -431,8 +409,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, "($Method$Raw(context, response));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -463,8 +442,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, "($Method$Raw(context, request));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -494,8 +474,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, "$Method$Raw(context));\n"); printer->Outdent(); printer->Print("}\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -516,8 +497,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, } } else { if (method->NoStreaming()) { - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; printer->Print( *vars, @@ -531,8 +513,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, "::grpc::ClientWriter< $Request$>* $Method$Raw(" "::grpc::ClientContext* context, $Response$* response) " "override;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -547,8 +530,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, "::grpc::ClientReader< $Response$>* $Method$Raw(" "::grpc::ClientContext* context, const $Request$& request)" " override;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -562,8 +546,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, printer->Print(*vars, "::grpc::ClientReaderWriter< $Request$, $Response$>* " "$Method$Raw(::grpc::ClientContext* context) override;\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["AsyncRawArgs"] = async_prefix.raw_args; @@ -577,7 +562,7 @@ void PrintHeaderClientMethod(grpc_generator::Printer *printer, } } -void PrintHeaderClientMethodData(grpc_generator::Printer *printer, +static void PrintHeaderClientMethodData(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -585,7 +570,7 @@ void PrintHeaderClientMethodData(grpc_generator::Printer *printer, "const ::grpc::internal::RpcMethod rpcmethod_$Method$_;\n"); } -void PrintHeaderServerMethodSync(grpc_generator::Printer *printer, +static void PrintHeaderServerMethodSync(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -619,7 +604,7 @@ void PrintHeaderServerMethodSync(grpc_generator::Printer *printer, printer->Print(method->GetTrailingComments("//").c_str()); } -void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, +static void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -630,7 +615,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, "class WithAsyncMethod_$Method$ : public BaseClass {\n"); printer->Print( " private:\n" - " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); + " void BaseClassMustBeDerivedFromService(const Service */*service*/) " + "{}\n"); printer->Print(" public:\n"); printer->Indent(); printer->Print(*vars, @@ -646,8 +632,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "$Response$* /*response*/) final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -667,9 +653,9 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, " - "::grpc::ServerReader< $Request$>* reader, " - "$Response$* response) final override {\n" + "::grpc::ServerContext* /*context*/, " + "::grpc::ServerReader< $Request$>* /*reader*/, " + "$Response$* /*response*/) final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -689,8 +675,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "::grpc::ServerWriter< $Response$>* /*writer*/) final override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -712,8 +698,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, " - "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) " + "::grpc::ServerContext* /*context*/, " + "::grpc::ServerReaderWriter< $Response$, $Request$>* /*stream*/) " "final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -734,7 +720,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer *printer, printer->Print(*vars, "};\n"); } -void PrintHeaderServerMethodStreamedUnary( +static void PrintHeaderServerMethodStreamedUnary( grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -747,7 +733,7 @@ void PrintHeaderServerMethodStreamedUnary( "public BaseClass {\n"); printer->Print( " private:\n" - " void BaseClassMustBeDerivedFromService(const Service *service) " + " void BaseClassMustBeDerivedFromService(const Service */*service*/) " "{}\n"); printer->Print(" public:\n"); printer->Indent(); @@ -768,8 +754,8 @@ void PrintHeaderServerMethodStreamedUnary( *vars, "// disable regular version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "$Response$* /*response*/) final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -785,7 +771,7 @@ void PrintHeaderServerMethodStreamedUnary( } } -void PrintHeaderServerMethodSplitStreaming( +static void PrintHeaderServerMethodSplitStreaming( grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -798,8 +784,8 @@ void PrintHeaderServerMethodSplitStreaming( "public BaseClass {\n"); printer->Print( " private:\n" - " void BaseClassMustBeDerivedFromService(const Service *service) " - "{}\n"); + " void BaseClassMustBeDerivedFromService(const Service */*service*/) " + "{ }\n"); printer->Print(" public:\n"); printer->Indent(); printer->Print( @@ -820,8 +806,8 @@ void PrintHeaderServerMethodSplitStreaming( *vars, "// disable regular version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "::grpc::ServerWriter< $Response$>* /*writer*/) final override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -838,7 +824,7 @@ void PrintHeaderServerMethodSplitStreaming( } } -void PrintHeaderServerMethodGeneric( +static void PrintHeaderServerMethodGeneric( grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -849,7 +835,8 @@ void PrintHeaderServerMethodGeneric( "class WithGenericMethod_$Method$ : public BaseClass {\n"); printer->Print( " private:\n" - " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); + " void BaseClassMustBeDerivedFromService(const Service */*service*/) " + "{}\n"); printer->Print(" public:\n"); printer->Indent(); printer->Print(*vars, @@ -865,8 +852,8 @@ void PrintHeaderServerMethodGeneric( *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "$Response$* /*response*/) final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -875,9 +862,9 @@ void PrintHeaderServerMethodGeneric( *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, " - "::grpc::ServerReader< $Request$>* reader, " - "$Response$* response) final override {\n" + "::grpc::ServerContext* /*context*/, " + "::grpc::ServerReader< $Request$>* /*reader*/, " + "$Response$* /*response*/) final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -886,8 +873,8 @@ void PrintHeaderServerMethodGeneric( *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerContext* /*context*/, const $Request$* /*request*/, " + "::grpc::ServerWriter< $Response$>* /*writer*/) final override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -897,8 +884,8 @@ void PrintHeaderServerMethodGeneric( *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" - "::grpc::ServerContext* context, " - "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) " + "::grpc::ServerContext* /*context*/, " + "::grpc::ServerReaderWriter< $Response$, $Request$>* /*stream*/) " "final override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -908,7 +895,7 @@ void PrintHeaderServerMethodGeneric( printer->Print(*vars, "};\n"); } -void PrintHeaderService(grpc_generator::Printer *printer, +static void PrintHeaderService(grpc_generator::Printer *printer, const grpc_generator::Service *service, std::map<grpc::string, grpc::string> *vars) { (*vars)["Service"] = service->name(); @@ -1001,9 +988,7 @@ void PrintHeaderService(grpc_generator::Printer *printer, printer->Print(*vars, "WithAsyncMethod_$method_name$<"); } printer->Print("Service"); - for (int i = 0; i < service->method_count(); ++i) { - printer->Print(" >"); - } + for (int i = 0; i < service->method_count(); ++i) { printer->Print(" >"); } printer->Print(" AsyncService;\n"); // Server side - Generic @@ -1028,9 +1013,7 @@ void PrintHeaderService(grpc_generator::Printer *printer, } printer->Print("Service"); for (int i = 0; i < service->method_count(); ++i) { - if (service->method(i)->NoStreaming()) { - printer->Print(" >"); - } + if (service->method(i)->NoStreaming()) { printer->Print(" >"); } } printer->Print(" StreamedUnaryService;\n"); @@ -1052,9 +1035,7 @@ void PrintHeaderService(grpc_generator::Printer *printer, printer->Print("Service"); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - if (ServerOnlyStreaming(method.get())) { - printer->Print(" >"); - } + if (ServerOnlyStreaming(method.get())) { printer->Print(" >"); } } printer->Print(" SplitStreamedService;\n"); @@ -1085,6 +1066,8 @@ void PrintHeaderService(grpc_generator::Printer *printer, printer->Print(service->GetTrailingComments("//").c_str()); } +} // namespace + grpc::string GetHeaderServices(grpc_generator::File *file, const Parameters ¶ms) { grpc::string output; @@ -1095,9 +1078,7 @@ grpc::string GetHeaderServices(grpc_generator::File *file, // Package string is empty or ends with a dot. It is used to fully qualify // method names. vars["Package"] = file->package(); - if (!file->package().empty()) { - vars["Package"].append("."); - } + if (!file->package().empty()) { vars["Package"].append("."); } if (!params.services_namespace.empty()) { vars["services_namespace"] = params.services_namespace; @@ -1146,7 +1127,7 @@ grpc::string GetHeaderEpilogue(grpc_generator::File *file, } grpc::string GetSourcePrologue(grpc_generator::File *file, - const Parameters & /*params*/) { + const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1155,7 +1136,7 @@ grpc::string GetSourcePrologue(grpc_generator::File *file, vars["filename"] = file->filename(); vars["filename_base"] = file->filename_without_ext(); - vars["message_header_ext"] = message_header_ext(); + vars["message_header_ext"] = params.message_header_extension; vars["service_header_ext"] = service_header_ext(); printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); @@ -1179,14 +1160,15 @@ grpc::string GetSourceIncludes(grpc_generator::File *file, std::map<grpc::string, grpc::string> vars; static const char *headers_strs[] = { - "grpcpp/impl/codegen/async_stream.h", - "grpcpp/impl/codegen/async_unary_call.h", - "grpcpp/impl/codegen/channel_interface.h", - "grpcpp/impl/codegen/client_unary_call.h", - "grpcpp/impl/codegen/method_handler.h", - "grpcpp/impl/codegen/rpc_service_method.h", - "grpcpp/impl/codegen/service_type.h", - "grpcpp/impl/codegen/sync_stream.h"}; + "grpcpp/impl/codegen/async_stream.h", + "grpcpp/impl/codegen/async_unary_call.h", + "grpcpp/impl/codegen/channel_interface.h", + "grpcpp/impl/codegen/client_unary_call.h", + "grpcpp/impl/codegen/method_handler.h", + "grpcpp/impl/codegen/rpc_service_method.h", + "grpcpp/impl/codegen/service_type.h", + "grpcpp/impl/codegen/sync_stream.h" + }; std::vector<grpc::string> headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); @@ -1204,7 +1186,10 @@ grpc::string GetSourceIncludes(grpc_generator::File *file, return output; } -void PrintSourceClientMethod(grpc_generator::Printer *printer, + +namespace { + +static void PrintSourceClientMethod(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -1215,8 +1200,8 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, grpc::string start; // bool literal expressed as string grpc::string method_params; // extra arguments to method grpc::string create_args; // extra arguments to creator - } async_prefixes[] = {{"Async", "true", ", void* tag", ", tag"}, - {"PrepareAsync", "false", "", ", nullptr"}}; + } async_prefixes[] = { { "Async", "true", ", void* tag", ", tag" }, + { "PrepareAsync", "false", "", ", nullptr" } }; if (method->NoStreaming()) { printer->Print(*vars, "::grpc::Status $ns$$Service$::Stub::$Method$(" @@ -1226,8 +1211,9 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, " return ::grpc::internal::BlockingUnaryCall" "(channel_.get(), rpcmethod_$Method$_, " "context, request, response);\n}\n\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncStart"] = async_prefix.start; printer->Print(*vars, @@ -1257,8 +1243,9 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, "rpcmethod_$Method$_, " "context, response);\n" "}\n\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncStart"] = async_prefix.start; (*vars)["AsyncMethodParams"] = async_prefix.method_params; @@ -1289,8 +1276,9 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, "rpcmethod_$Method$_, " "context, request);\n" "}\n\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncStart"] = async_prefix.start; (*vars)["AsyncMethodParams"] = async_prefix.method_params; @@ -1321,8 +1309,9 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, "rpcmethod_$Method$_, " "context);\n" "}\n\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncStart"] = async_prefix.start; (*vars)["AsyncMethodParams"] = async_prefix.method_params; @@ -1344,20 +1333,18 @@ void PrintSourceClientMethod(grpc_generator::Printer *printer, } } -void PrintSourceServerMethod(grpc_generator::Printer *printer, +static void PrintSourceServerMethod(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); (*vars)["Response"] = method->output_type_name(); if (method->NoStreaming()) { - printer->Print(*vars, - "::grpc::Status $ns$$Service$::Service::$Method$(" - "::grpc::ServerContext* context, " - "const $Request$* request, $Response$* response) {\n"); - printer->Print(" (void) context;\n"); - printer->Print(" (void) request;\n"); - printer->Print(" (void) response;\n"); + printer->Print( + *vars, + "::grpc::Status $ns$$Service$::Service::$Method$(" + "::grpc::ServerContext* /*context*/, " + "const $Request$* /*request*/, $Response$* /*response*/) {\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); @@ -1365,12 +1352,9 @@ void PrintSourceServerMethod(grpc_generator::Printer *printer, } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, "::grpc::Status $ns$$Service$::Service::$Method$(" - "::grpc::ServerContext* context, " - "::grpc::ServerReader< $Request$>* reader, " - "$Response$* response) {\n"); - printer->Print(" (void) context;\n"); - printer->Print(" (void) reader;\n"); - printer->Print(" (void) response;\n"); + "::grpc::ServerContext* /*context*/, " + "::grpc::ServerReader< $Request$>* /*reader*/, " + "$Response$* /*response*/) {\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); @@ -1378,12 +1362,9 @@ void PrintSourceServerMethod(grpc_generator::Printer *printer, } else if (ServerOnlyStreaming(method)) { printer->Print(*vars, "::grpc::Status $ns$$Service$::Service::$Method$(" - "::grpc::ServerContext* context, " - "const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) {\n"); - printer->Print(" (void) context;\n"); - printer->Print(" (void) request;\n"); - printer->Print(" (void) writer;\n"); + "::grpc::ServerContext* /*context*/, " + "const $Request$* /*request*/, " + "::grpc::ServerWriter< $Response$>* /*writer*/) {\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); @@ -1391,11 +1372,9 @@ void PrintSourceServerMethod(grpc_generator::Printer *printer, } else if (method->BidiStreaming()) { printer->Print(*vars, "::grpc::Status $ns$$Service$::Service::$Method$(" - "::grpc::ServerContext* context, " + "::grpc::ServerContext* /*context*/, " "::grpc::ServerReaderWriter< $Response$, $Request$>* " - "stream) {\n"); - printer->Print(" (void) context;\n"); - printer->Print(" (void) stream;\n"); + "/*stream*/) {\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); @@ -1403,7 +1382,7 @@ void PrintSourceServerMethod(grpc_generator::Printer *printer, } } -void PrintSourceService(grpc_generator::Printer *printer, +static void PrintSourceService(grpc_generator::Printer *printer, const grpc_generator::Service *service, std::map<grpc::string, grpc::string> *vars) { (*vars)["Service"] = service->name(); @@ -1421,7 +1400,7 @@ void PrintSourceService(grpc_generator::Printer *printer, printer->Print(*vars, "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub(" "const std::shared_ptr< ::grpc::ChannelInterface>& channel, " - "const ::grpc::StubOptions& options) {\n" + "const ::grpc::StubOptions& /*options*/) {\n" " std::unique_ptr< $ns$$Service$::Stub> stub(new " "$ns$$Service$::Stub(channel));\n" " return stub;\n" @@ -1520,6 +1499,8 @@ void PrintSourceService(grpc_generator::Printer *printer, } } +} // namespace + grpc::string GetSourceServices(grpc_generator::File *file, const Parameters ¶ms) { grpc::string output; @@ -1530,9 +1511,7 @@ grpc::string GetSourceServices(grpc_generator::File *file, // Package string is empty or ends with a dot. It is used to fully qualify // method names. vars["Package"] = file->package(); - if (!file->package().empty()) { - vars["Package"].append("."); - } + if (!file->package().empty()) { vars["Package"].append("."); } if (!params.services_namespace.empty()) { vars["ns"] = params.services_namespace + "::"; vars["prefix"] = params.services_namespace; @@ -1567,9 +1546,8 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, return temp; } -// TODO(mmukhi): Make sure we need parameters or not. grpc::string GetMockPrologue(grpc_generator::File *file, - const Parameters & /*params*/) { + const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1578,7 +1556,7 @@ grpc::string GetMockPrologue(grpc_generator::File *file, vars["filename"] = file->filename(); vars["filename_base"] = file->filename_without_ext(); - vars["message_header_ext"] = message_header_ext(); + vars["message_header_ext"] = params.message_header_extension; vars["service_header_ext"] = service_header_ext(); printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); @@ -1604,9 +1582,9 @@ grpc::string GetMockIncludes(grpc_generator::File *file, std::map<grpc::string, grpc::string> vars; static const char *headers_strs[] = { - "grpcpp/impl/codegen/async_stream.h", - "grpcpp/impl/codegen/sync_stream.h", - "gmock/gmock.h", + "grpcpp/impl/codegen/async_stream.h", + "grpcpp/impl/codegen/sync_stream.h", + "gmock/gmock.h", }; std::vector<grpc::string> headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); @@ -1625,7 +1603,10 @@ grpc::string GetMockIncludes(grpc_generator::File *file, return output; } -void PrintMockClientMethods(grpc_generator::Printer *printer, + +namespace { + +static void PrintMockClientMethods(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *vars) { (*vars)["Method"] = method->name(); @@ -1636,15 +1617,17 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, grpc::string prefix; grpc::string method_params; // extra arguments to method int extra_method_param_count; - } async_prefixes[] = {{"Async", ", void* tag", 1}, {"PrepareAsync", "", 0}}; + } async_prefixes[] = { { "Async", ", void* tag", 1 }, + { "PrepareAsync", "", 0 } }; if (method->NoStreaming()) { printer->Print( *vars, "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response));\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; printer->Print( *vars, @@ -1659,12 +1642,13 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientWriterInterface< $Request$>*" "(::grpc::ClientContext* context, $Response$* response));\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["MockArgs"] = - flatbuffers::NumToString(3 + async_prefix.extra_method_param_count); + flatbuffers::NumToString(3 + async_prefix.extra_method_param_count); printer->Print(*vars, "MOCK_METHOD$MockArgs$($AsyncPrefix$$Method$Raw, " "::grpc::ClientAsyncWriterInterface< $Request$>*" @@ -1677,8 +1661,9 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientReaderInterface< $Response$>*" "(::grpc::ClientContext* context, const $Request$& request));\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["MockArgs"] = @@ -1696,8 +1681,9 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, "MOCK_METHOD1($Method$Raw, " "::grpc::ClientReaderWriterInterface< $Request$, $Response$>*" "(::grpc::ClientContext* context));\n"); - for (size_t i = 0; i < sizeof(async_prefixes)/sizeof(async_prefixes[0]); i ++) { - auto& async_prefix = async_prefixes[i]; + for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]); + i++) { + auto &async_prefix = async_prefixes[i]; (*vars)["AsyncPrefix"] = async_prefix.prefix; (*vars)["AsyncMethodParams"] = async_prefix.method_params; (*vars)["MockArgs"] = @@ -1712,7 +1698,7 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, } } -void PrintMockService(grpc_generator::Printer *printer, +static void PrintMockService(grpc_generator::Printer *printer, const grpc_generator::Service *service, std::map<grpc::string, grpc::string> *vars) { (*vars)["Service"] = service->name(); @@ -1728,6 +1714,8 @@ void PrintMockService(grpc_generator::Printer *printer, printer->Print("};\n"); } +} // namespace + grpc::string GetMockServices(grpc_generator::File *file, const Parameters ¶ms) { grpc::string output; @@ -1738,9 +1726,7 @@ grpc::string GetMockServices(grpc_generator::File *file, // Package string is empty or ends with a dot. It is used to fully qualify // method names. vars["Package"] = file->package(); - if (!file->package().empty()) { - vars["Package"].append("."); - } + if (!file->package().empty()) { vars["Package"].append("."); } if (!params.services_namespace.empty()) { vars["services_namespace"] = params.services_namespace; diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.h b/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.h index 6119ebe289..a9af1a6794 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/cpp_generator.h @@ -1,36 +1,3 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - #ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H #define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H @@ -41,12 +8,11 @@ #include <memory> #include <vector> -#include "src/compiler/config.h" #include "src/compiler/schema_interface.h" #ifndef GRPC_CUSTOM_STRING -#include <string> -#define GRPC_CUSTOM_STRING std::string +# include <string> +# define GRPC_CUSTOM_STRING std::string #endif namespace grpc { @@ -67,6 +33,8 @@ struct Parameters { grpc::string grpc_search_path; // Generate GMOCK code to facilitate unit testing. bool generate_mock_code; + // By default, use "_generated.h" + std::string message_header_extension; }; // Return the prologue of the generated header file. diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.cc index d646451aa6..ad4694b107 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.cc @@ -1,47 +1,13 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation AN/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +#include "src/compiler/go_generator.h" -#include <map> #include <cctype> +#include <map> #include <sstream> -#include "src/compiler/go_generator.h" - -template <class T> -grpc::string as_string(T x) { - std::ostringstream out; - out << x; - return out.str(); +template<class T> grpc::string as_string(T x) { + std::ostringstream out; + out << x; + return out.str(); } inline bool ClientOnlyStreaming(const grpc_generator::Method *method) { @@ -53,24 +19,23 @@ inline bool ServerOnlyStreaming(const grpc_generator::Method *method) { } namespace grpc_go_generator { +namespace { // Returns string with first letter to lowerCase -grpc::string unexportName(grpc::string s) { - if (s.empty()) - return s; - s[0] = static_cast<char>(std::tolower(s[0])); - return s; +static grpc::string unexportName(grpc::string s) { + if (s.empty()) return s; + s[0] = static_cast<char>(std::tolower(s[0])); + return s; } // Returns string with first letter to uppercase -grpc::string exportName(grpc::string s) { - if (s.empty()) - return s; - s[0] = static_cast<char>(std::toupper(s[0])); - return s; +static grpc::string exportName(grpc::string s) { + if (s.empty()) return s; + s[0] = static_cast<char>(std::toupper(s[0])); + return s; } -void GenerateError(grpc_generator::Printer *printer, +static void GenerateError(grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars, const bool multiple_return = true) { printer->Print(vars, "if $Error_Check$ {\n"); @@ -82,50 +47,65 @@ void GenerateError(grpc_generator::Printer *printer, } // Generates imports for the service -void GenerateImports(grpc_generator::File *file, grpc_generator::Printer *printer, +static void GenerateImports(grpc_generator::File *file, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { - vars["filename"] = file->filename(); - printer->Print("//Generated by gRPC Go plugin\n"); - printer->Print("//If you make any local changes, they will be lost\n"); - printer->Print(vars, "//source: $filename$\n\n"); - printer->Print(vars, "package $Package$\n\n"); - printer->Print("import (\n"); - printer->Indent(); - printer->Print(vars, "$context$ \"context\"\n"); + vars["filename"] = file->filename(); + printer->Print("//Generated by gRPC Go plugin\n"); + printer->Print("//If you make any local changes, they will be lost\n"); + printer->Print(vars, "//source: $filename$\n\n"); + printer->Print(vars, "package $Package$\n\n"); + printer->Print("import (\n"); + printer->Indent(); + printer->Print(vars, "$context$ \"context\"\n"); printer->Print("flatbuffers \"github.com/google/flatbuffers/go\"\n"); - printer->Print(vars, "$grpc$ \"google.golang.org/grpc\"\n"); + printer->Print(vars, "$grpc$ \"google.golang.org/grpc\"\n"); printer->Print("\"google.golang.org/grpc/codes\"\n"); printer->Print("\"google.golang.org/grpc/status\"\n"); - printer->Outdent(); - printer->Print(")\n\n"); + printer->Outdent(); + printer->Print(")\n\n"); } // Generates Server method signature source -void GenerateServerMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer, +static void GenerateServerMethodSignature(const grpc_generator::Method *method, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { vars["Method"] = exportName(method->name()); - vars["Request"] = method->get_input_type_name(); - vars["Response"] = (vars["CustomMethodIO"] == "") ? method->get_output_type_name() : vars["CustomMethodIO"]; - if (method->NoStreaming()) { - printer->Print(vars, "$Method$($context$.Context, *$Request$) (*$Response$, error)$Ending$"); - } else if (ServerOnlyStreaming(method)) { - printer->Print(vars, "$Method$(*$Request$, $Service$_$Method$Server) error$Ending$"); - } else { - printer->Print(vars, "$Method$($Service$_$Method$Server) error$Ending$"); - } + vars["Request"] = method->get_input_type_name(); + vars["Response"] = (vars["CustomMethodIO"] == "") + ? method->get_output_type_name() + : vars["CustomMethodIO"]; + if (method->NoStreaming()) { + printer->Print( + vars, + "$Method$($context$.Context, *$Request$) (*$Response$, error)$Ending$"); + } else if (ServerOnlyStreaming(method)) { + printer->Print( + vars, "$Method$(*$Request$, $Service$_$Method$Server) error$Ending$"); + } else { + printer->Print(vars, "$Method$($Service$_$Method$Server) error$Ending$"); + } } -void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer, +static void GenerateServerMethod(const grpc_generator::Method *method, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { - vars["Method"] = exportName(method->name()); - vars["Request"] = method->get_input_type_name(); - vars["Response"] = (vars["CustomMethodIO"] == "") ? method->get_output_type_name() : vars["CustomMethodIO"]; - vars["FullMethodName"] = "/" + vars["ServicePrefix"] + vars["Service"] + "/" + vars["Method"]; - vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; - if (method->NoStreaming()) { - printer->Print(vars, "func $Handler$(srv interface{}, ctx $context$.Context,\n\tdec func(interface{}) error, interceptor $grpc$.UnaryServerInterceptor) (interface{}, error) {\n"); - printer->Indent(); - printer->Print(vars, "in := new($Request$)\n"); + vars["Method"] = exportName(method->name()); + vars["Request"] = method->get_input_type_name(); + vars["Response"] = (vars["CustomMethodIO"] == "") + ? method->get_output_type_name() + : vars["CustomMethodIO"]; + vars["FullMethodName"] = + "/" + vars["ServicePrefix"] + vars["Service"] + "/" + vars["Method"]; + vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; + if (method->NoStreaming()) { + printer->Print( + vars, + "func $Handler$(srv interface{}, ctx $context$.Context,\n\tdec " + "func(interface{}) error, interceptor $grpc$.UnaryServerInterceptor) " + "(interface{}, error) {\n"); + printer->Indent(); + printer->Print(vars, "in := new($Request$)\n"); vars["Error_Check"] = "err := dec(in); err != nil"; GenerateError(printer, vars); printer->Print("if interceptor == nil {\n"); @@ -133,258 +113,281 @@ void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator:: printer->Print(vars, "return srv.($Service$Server).$Method$(ctx, in)\n"); printer->Outdent(); printer->Print("}\n"); - printer->Print(vars, "info := &$grpc$.UnaryServerInfo{\n"); - printer->Indent(); - printer->Print("Server: srv,\n"); - printer->Print(vars, "FullMethod: \"$FullMethodName$\",\n"); - printer->Outdent(); - printer->Print("}\n"); + printer->Print(vars, "info := &$grpc$.UnaryServerInfo{\n"); + printer->Indent(); + printer->Print("Server: srv,\n"); + printer->Print(vars, "FullMethod: \"$FullMethodName$\",\n"); + printer->Outdent(); + printer->Print("}\n"); printer->Outdent(); printer->Print("\n"); printer->Indent(); - printer->Print(vars, "handler := func(ctx $context$.Context, req interface{}) (interface{}, error) {\n"); - printer->Indent(); - printer->Print(vars, "return srv.($Service$Server).$Method$(ctx, req.(*$Request$))\n"); - printer->Outdent(); - printer->Print("}\n"); - printer->Print("return interceptor(ctx, in, info, handler)\n"); - printer->Outdent(); - printer->Print("}\n"); - return; - } - vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Server"; - printer->Print(vars, "func $Handler$(srv interface{}, stream $grpc$.ServerStream) error {\n"); - printer->Indent(); - if (ServerOnlyStreaming(method)) { - printer->Print(vars, "m := new($Request$)\n"); + printer->Print(vars, + "handler := func(ctx $context$.Context, req interface{}) " + "(interface{}, error) {\n"); + printer->Indent(); + printer->Print( + vars, "return srv.($Service$Server).$Method$(ctx, req.(*$Request$))\n"); + printer->Outdent(); + printer->Print("}\n"); + printer->Print("return interceptor(ctx, in, info, handler)\n"); + printer->Outdent(); + printer->Print("}\n"); + return; + } + vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Server"; + printer->Print( + vars, + "func $Handler$(srv interface{}, stream $grpc$.ServerStream) error {\n"); + printer->Indent(); + if (ServerOnlyStreaming(method)) { + printer->Print(vars, "m := new($Request$)\n"); vars["Error_Check"] = "err := stream.RecvMsg(m); err != nil"; GenerateError(printer, vars, false); - printer->Print(vars, "return srv.($Service$Server).$Method$(m, &$StreamType${stream})\n"); - } else { - printer->Print(vars, "return srv.($Service$Server).$Method$(&$StreamType${stream})\n"); - } - printer->Outdent(); - printer->Print("}\n\n"); - - bool genSend = method->BidiStreaming() || ServerOnlyStreaming(method); - bool genRecv = method->BidiStreaming() || ClientOnlyStreaming(method); - bool genSendAndClose = ClientOnlyStreaming(method); - - printer->Print(vars, "type $Service$_$Method$Server interface {\n"); - printer->Indent(); - if (genSend) { - printer->Print(vars, "Send(*$Response$) error\n"); - } - if (genRecv) { - printer->Print(vars, "Recv() (*$Request$, error)\n"); - } - if (genSendAndClose) { - printer->Print(vars, "SendAndClose(*$Response$) error\n"); - } - printer->Print(vars, "$grpc$.ServerStream\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - printer->Print(vars, "type $StreamType$ struct {\n"); - printer->Indent(); - printer->Print(vars, "$grpc$.ServerStream\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - if (genSend) { - printer->Print(vars, "func (x *$StreamType$) Send(m *$Response$) error {\n"); - printer->Indent(); - printer->Print("return x.ServerStream.SendMsg(m)\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - if (genRecv) { - printer->Print(vars, "func (x *$StreamType$) Recv() (*$Request$, error) {\n"); - printer->Indent(); - printer->Print(vars, "m := new($Request$)\n"); + printer->Print( + vars, + "return srv.($Service$Server).$Method$(m, &$StreamType${stream})\n"); + } else { + printer->Print( + vars, "return srv.($Service$Server).$Method$(&$StreamType${stream})\n"); + } + printer->Outdent(); + printer->Print("}\n\n"); + + bool genSend = method->BidiStreaming() || ServerOnlyStreaming(method); + bool genRecv = method->BidiStreaming() || ClientOnlyStreaming(method); + bool genSendAndClose = ClientOnlyStreaming(method); + + printer->Print(vars, "type $Service$_$Method$Server interface {\n"); + printer->Indent(); + if (genSend) { printer->Print(vars, "Send(*$Response$) error\n"); } + if (genRecv) { printer->Print(vars, "Recv() (*$Request$, error)\n"); } + if (genSendAndClose) { + printer->Print(vars, "SendAndClose(*$Response$) error\n"); + } + printer->Print(vars, "$grpc$.ServerStream\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + printer->Print(vars, "type $StreamType$ struct {\n"); + printer->Indent(); + printer->Print(vars, "$grpc$.ServerStream\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + if (genSend) { + printer->Print(vars, + "func (x *$StreamType$) Send(m *$Response$) error {\n"); + printer->Indent(); + printer->Print("return x.ServerStream.SendMsg(m)\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } + if (genRecv) { + printer->Print(vars, + "func (x *$StreamType$) Recv() (*$Request$, error) {\n"); + printer->Indent(); + printer->Print(vars, "m := new($Request$)\n"); vars["Error_Check"] = "err := x.ServerStream.RecvMsg(m); err != nil"; GenerateError(printer, vars); - printer->Print("return m, nil\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - if (genSendAndClose) { - printer->Print(vars, "func (x *$StreamType$) SendAndClose(m *$Response$) error {\n"); - printer->Indent(); - printer->Print("return x.ServerStream.SendMsg(m)\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - + printer->Print("return m, nil\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } + if (genSendAndClose) { + printer->Print( + vars, "func (x *$StreamType$) SendAndClose(m *$Response$) error {\n"); + printer->Indent(); + printer->Print("return x.ServerStream.SendMsg(m)\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } } // Generates Client method signature source -void GenerateClientMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer, +static void GenerateClientMethodSignature(const grpc_generator::Method *method, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { - vars["Method"] = exportName(method->name()); - vars["Request"] = ", in *" + ((vars["CustomMethodIO"] == "") ? method->get_input_type_name() : vars["CustomMethodIO"]); - if (ClientOnlyStreaming(method) || method->BidiStreaming()) { - vars["Request"] = ""; - } - vars["Response"] = "*" + method->get_output_type_name(); - if (ClientOnlyStreaming(method) || method->BidiStreaming() || ServerOnlyStreaming(method)) { - vars["Response"] = vars["Service"] + "_" + vars["Method"] + "Client" ; - } - printer->Print(vars, "$Method$(ctx $context$.Context$Request$,\n\topts ...$grpc$.CallOption) ($Response$, error)$Ending$"); + vars["Method"] = exportName(method->name()); + vars["Request"] = + ", in *" + ((vars["CustomMethodIO"] == "") ? method->get_input_type_name() + : vars["CustomMethodIO"]); + if (ClientOnlyStreaming(method) || method->BidiStreaming()) { + vars["Request"] = ""; + } + vars["Response"] = "*" + method->get_output_type_name(); + if (ClientOnlyStreaming(method) || method->BidiStreaming() || + ServerOnlyStreaming(method)) { + vars["Response"] = vars["Service"] + "_" + vars["Method"] + "Client"; + } + printer->Print(vars, + "$Method$(ctx $context$.Context$Request$,\n\topts " + "...$grpc$.CallOption) ($Response$, error)$Ending$"); } // Generates Client method source -void GenerateClientMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer, +static void GenerateClientMethod(const grpc_generator::Method *method, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { - printer->Print(vars, "func (c *$ServiceUnexported$Client) "); + printer->Print(vars, "func (c *$ServiceUnexported$Client) "); vars["Ending"] = " {\n"; - GenerateClientMethodSignature(method, printer, vars); - printer->Indent(); - vars["Method"] = exportName(method->name()); - vars["Request"] = (vars["CustomMethodIO"] == "") ? method->get_input_type_name() : vars["CustomMethodIO"]; - vars["Response"] = method->get_output_type_name(); - vars["FullMethodName"] = "/" + vars["ServicePrefix"] + vars["Service"] + "/" + vars["Method"]; - if (method->NoStreaming()) { - printer->Print(vars, "out := new($Response$)\n"); - printer->Print(vars, "err := c.cc.Invoke(ctx, \"$FullMethodName$\", in, out, opts...)\n"); + GenerateClientMethodSignature(method, printer, vars); + printer->Indent(); + vars["Method"] = exportName(method->name()); + vars["Request"] = (vars["CustomMethodIO"] == "") + ? method->get_input_type_name() + : vars["CustomMethodIO"]; + vars["Response"] = method->get_output_type_name(); + vars["FullMethodName"] = + "/" + vars["ServicePrefix"] + vars["Service"] + "/" + vars["Method"]; + if (method->NoStreaming()) { + printer->Print(vars, "out := new($Response$)\n"); + printer->Print( + vars, + "err := c.cc.Invoke(ctx, \"$FullMethodName$\", in, out, opts...)\n"); vars["Error_Check"] = "err != nil"; GenerateError(printer, vars); - printer->Print("return out, nil\n"); - printer->Outdent(); - printer->Print("}\n\n"); - return; - } - vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Client"; - printer->Print(vars, "stream, err := c.cc.NewStream(ctx, &$MethodDesc$, \"$FullMethodName$\", opts...)\n"); + printer->Print("return out, nil\n"); + printer->Outdent(); + printer->Print("}\n\n"); + return; + } + vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Client"; + printer->Print(vars, + "stream, err := c.cc.NewStream(ctx, &$MethodDesc$, " + "\"$FullMethodName$\", opts...)\n"); vars["Error_Check"] = "err != nil"; GenerateError(printer, vars); - printer->Print(vars, "x := &$StreamType${stream}\n"); - if (ServerOnlyStreaming(method)) { + printer->Print(vars, "x := &$StreamType${stream}\n"); + if (ServerOnlyStreaming(method)) { vars["Error_Check"] = "err := x.ClientStream.SendMsg(in); err != nil"; GenerateError(printer, vars); vars["Error_Check"] = "err := x.ClientStream.CloseSend(); err != nil"; GenerateError(printer, vars); - } - printer->Print("return x, nil\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - bool genSend = method->BidiStreaming() || ClientOnlyStreaming(method); - bool genRecv = method->BidiStreaming() || ServerOnlyStreaming(method); - bool genCloseAndRecv = ClientOnlyStreaming(method); - - //Stream interface - printer->Print(vars, "type $Service$_$Method$Client interface {\n"); - printer->Indent(); - if (genSend) { - printer->Print(vars, "Send(*$Request$) error\n"); - } - if (genRecv) { - printer->Print(vars, "Recv() (*$Response$, error)\n"); - } - if (genCloseAndRecv) { - printer->Print(vars, "CloseAndRecv() (*$Response$, error)\n"); - } - printer->Print(vars, "$grpc$.ClientStream\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - //Stream Client - printer->Print(vars, "type $StreamType$ struct {\n"); - printer->Indent(); - printer->Print(vars, "$grpc$.ClientStream\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - if (genSend) { - printer->Print(vars, "func (x *$StreamType$) Send(m *$Request$) error {\n"); - printer->Indent(); - printer->Print("return x.ClientStream.SendMsg(m)\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - - if (genRecv) { - printer->Print(vars, "func (x *$StreamType$) Recv() (*$Response$, error) {\n"); - printer->Indent(); - printer->Print(vars, "m := new($Response$)\n"); + } + printer->Print("return x, nil\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + bool genSend = method->BidiStreaming() || ClientOnlyStreaming(method); + bool genRecv = method->BidiStreaming() || ServerOnlyStreaming(method); + bool genCloseAndRecv = ClientOnlyStreaming(method); + + // Stream interface + printer->Print(vars, "type $Service$_$Method$Client interface {\n"); + printer->Indent(); + if (genSend) { printer->Print(vars, "Send(*$Request$) error\n"); } + if (genRecv) { printer->Print(vars, "Recv() (*$Response$, error)\n"); } + if (genCloseAndRecv) { + printer->Print(vars, "CloseAndRecv() (*$Response$, error)\n"); + } + printer->Print(vars, "$grpc$.ClientStream\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + // Stream Client + printer->Print(vars, "type $StreamType$ struct {\n"); + printer->Indent(); + printer->Print(vars, "$grpc$.ClientStream\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + if (genSend) { + printer->Print(vars, "func (x *$StreamType$) Send(m *$Request$) error {\n"); + printer->Indent(); + printer->Print("return x.ClientStream.SendMsg(m)\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } + + if (genRecv) { + printer->Print(vars, + "func (x *$StreamType$) Recv() (*$Response$, error) {\n"); + printer->Indent(); + printer->Print(vars, "m := new($Response$)\n"); vars["Error_Check"] = "err := x.ClientStream.RecvMsg(m); err != nil"; GenerateError(printer, vars); - printer->Print("return m, nil\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - - if (genCloseAndRecv) { - printer->Print(vars, "func (x *$StreamType$) CloseAndRecv() (*$Response$, error) {\n"); - printer->Indent(); + printer->Print("return m, nil\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } + + if (genCloseAndRecv) { + printer->Print( + vars, "func (x *$StreamType$) CloseAndRecv() (*$Response$, error) {\n"); + printer->Indent(); vars["Error_Check"] = "err := x.ClientStream.CloseSend(); err != nil"; GenerateError(printer, vars); - printer->Print(vars, "m := new($Response$)\n"); + printer->Print(vars, "m := new($Response$)\n"); vars["Error_Check"] = "err := x.ClientStream.RecvMsg(m); err != nil"; GenerateError(printer, vars); - printer->Print("return m, nil\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } + printer->Print("return m, nil\n"); + printer->Outdent(); + printer->Print("}\n\n"); + } } // Generates client API for the service -void GenerateService(const grpc_generator::Service *service, grpc_generator::Printer* printer, +void GenerateService(const grpc_generator::Service *service, + grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> vars) { - vars["Service"] = exportName(service->name()); - // Client Interface - printer->Print(vars, "// Client API for $Service$ service\n"); - printer->Print(vars, "type $Service$Client interface {\n"); - printer->Indent(); + vars["Service"] = exportName(service->name()); + // Client Interface + printer->Print(vars, "// Client API for $Service$ service\n"); + printer->Print(vars, "type $Service$Client interface {\n"); + printer->Indent(); vars["Ending"] = "\n"; - for (int i = 0; i < service->method_count(); i++) { - GenerateClientMethodSignature(service->method(i).get(), printer, vars); - } - printer->Outdent(); - printer->Print("}\n\n"); - - // Client structure - vars["ServiceUnexported"] = unexportName(vars["Service"]); - printer->Print(vars, "type $ServiceUnexported$Client struct {\n"); - printer->Indent(); - printer->Print(vars, "cc $grpc$.ClientConnInterface\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - // NewClient - printer->Print(vars, "func New$Service$Client(cc $grpc$.ClientConnInterface) $Service$Client {\n"); - printer->Indent(); - printer->Print(vars, "return &$ServiceUnexported$Client{cc}"); - printer->Outdent(); - printer->Print("\n}\n\n"); - - int unary_methods = 0, streaming_methods = 0; - vars["ServiceDesc"] = "_" + vars["Service"] + "_serviceDesc"; - for (int i = 0; i < service->method_count(); i++) { - auto method = service->method(i); - if (method->NoStreaming()) { - vars["MethodDesc"] = vars["ServiceDesc"] + ".Method[" + as_string(unary_methods) + "]"; - unary_methods++; - } else { - vars["MethodDesc"] = vars["ServiceDesc"] + ".Streams[" + as_string(streaming_methods) + "]"; - streaming_methods++; - } - GenerateClientMethod(method.get(), printer, vars); - } - - //Server Interface - printer->Print(vars, "// Server API for $Service$ service\n"); - printer->Print(vars, "type $Service$Server interface {\n"); - printer->Indent(); + for (int i = 0; i < service->method_count(); i++) { + GenerateClientMethodSignature(service->method(i).get(), printer, vars); + } + printer->Outdent(); + printer->Print("}\n\n"); + + // Client structure + vars["ServiceUnexported"] = unexportName(vars["Service"]); + printer->Print(vars, "type $ServiceUnexported$Client struct {\n"); + printer->Indent(); + printer->Print(vars, "cc $grpc$.ClientConnInterface\n"); + printer->Outdent(); + printer->Print("}\n\n"); + + // NewClient + printer->Print(vars, + "func New$Service$Client(cc $grpc$.ClientConnInterface) " + "$Service$Client {\n"); + printer->Indent(); + printer->Print(vars, "return &$ServiceUnexported$Client{cc}"); + printer->Outdent(); + printer->Print("\n}\n\n"); + + int unary_methods = 0, streaming_methods = 0; + vars["ServiceDesc"] = "_" + vars["Service"] + "_serviceDesc"; + for (int i = 0; i < service->method_count(); i++) { + auto method = service->method(i); + if (method->NoStreaming()) { + vars["MethodDesc"] = + vars["ServiceDesc"] + ".Method[" + as_string(unary_methods) + "]"; + unary_methods++; + } else { + vars["MethodDesc"] = vars["ServiceDesc"] + ".Streams[" + + as_string(streaming_methods) + "]"; + streaming_methods++; + } + GenerateClientMethod(method.get(), printer, vars); + } + + // Server Interface + printer->Print(vars, "// Server API for $Service$ service\n"); + printer->Print(vars, "type $Service$Server interface {\n"); + printer->Indent(); vars["Ending"] = "\n"; - for (int i = 0; i < service->method_count(); i++) { - GenerateServerMethodSignature(service->method(i).get(), printer, vars); - } + for (int i = 0; i < service->method_count(); i++) { + GenerateServerMethodSignature(service->method(i).get(), printer, vars); + } printer->Print(vars, "mustEmbedUnimplemented$Service$Server()\n"); - printer->Outdent(); - printer->Print("}\n\n"); + printer->Outdent(); + printer->Print("}\n\n"); printer->Print(vars, "type Unimplemented$Service$Server struct {\n"); printer->Print("}\n\n"); @@ -397,13 +400,17 @@ void GenerateService(const grpc_generator::Service *service, grpc_generator::Pri printer->Print(vars, "func (Unimplemented$Service$Server) "); GenerateServerMethodSignature(method.get(), printer, vars); printer->Indent(); - printer->Print(vars, "return $Nil$status.Errorf(codes.Unimplemented, \"method $Method$ not implemented\")\n"); + printer->Print(vars, + "return $Nil$status.Errorf(codes.Unimplemented, \"method " + "$Method$ not implemented\")\n"); printer->Outdent(); printer->Print("}\n"); printer->Print("\n"); } - printer->Print(vars, "func (Unimplemented$Service$Server) mustEmbedUnimplemented$Service$Server() {}"); + printer->Print(vars, + "func (Unimplemented$Service$Server) " + "mustEmbedUnimplemented$Service$Server() {}"); printer->Print("\n\n"); printer->Print(vars, "type Unsafe$Service$Server interface {\n"); @@ -411,91 +418,90 @@ void GenerateService(const grpc_generator::Service *service, grpc_generator::Pri printer->Print(vars, "mustEmbedUnimplemented$Service$Server()\n"); printer->Outdent(); printer->Print("}\n\n"); - // Server registration. - printer->Print(vars, "func Register$Service$Server(s $grpc$.ServiceRegistrar, srv $Service$Server) {\n"); - printer->Indent(); - printer->Print(vars, "s.RegisterService(&$ServiceDesc$, srv)\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - for (int i = 0; i < service->method_count(); i++) { - GenerateServerMethod(service->method(i).get(), printer, vars); - } - - - //Service Descriptor - printer->Print(vars, "var $ServiceDesc$ = $grpc$.ServiceDesc{\n"); - printer->Indent(); - printer->Print(vars, "ServiceName: \"$ServicePrefix$$Service$\",\n"); - printer->Print(vars, "HandlerType: (*$Service$Server)(nil),\n"); - printer->Print(vars, "Methods: []$grpc$.MethodDesc{\n"); - printer->Indent(); - for (int i = 0; i < service->method_count(); i++) { - auto method = service->method(i); - vars["Method"] = exportName(method->name()); - vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; - if (method->NoStreaming()) { - printer->Print("{\n"); - printer->Indent(); - printer->Print(vars, "MethodName: \"$Method$\",\n"); - printer->Print(vars, "Handler: $Handler$,\n"); - printer->Outdent(); - printer->Print("},\n"); - } - } - printer->Outdent(); - printer->Print("},\n"); - printer->Print(vars, "Streams: []$grpc$.StreamDesc{\n"); - printer->Indent(); - for (int i = 0; i < service->method_count(); i++) { - auto method = service->method(i); - vars["Method"] = exportName(method->name()); - vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; - if (!method->NoStreaming()) { - printer->Print("{\n"); - printer->Indent(); - printer->Print(vars, "StreamName: \"$Method$\",\n"); - printer->Print(vars, "Handler: $Handler$,\n"); - if (ClientOnlyStreaming(method.get())) { - printer->Print("ClientStreams: true,\n"); - } else if (ServerOnlyStreaming(method.get())) { - printer->Print("ServerStreams: true,\n"); - } else { - printer->Print("ServerStreams: true,\n"); - printer->Print("ClientStreams: true,\n"); - } - printer->Outdent(); - printer->Print("},\n"); - } - } - printer->Outdent(); - printer->Print("},\n"); - printer->Outdent(); - printer->Print("}\n"); + // Server registration. + printer->Print(vars, + "func Register$Service$Server(s $grpc$.ServiceRegistrar, srv " + "$Service$Server) {\n"); + printer->Indent(); + printer->Print(vars, "s.RegisterService(&$ServiceDesc$, srv)\n"); + printer->Outdent(); + printer->Print("}\n\n"); -} + for (int i = 0; i < service->method_count(); i++) { + GenerateServerMethod(service->method(i).get(), printer, vars); + } + // Service Descriptor + printer->Print(vars, "var $ServiceDesc$ = $grpc$.ServiceDesc{\n"); + printer->Indent(); + printer->Print(vars, "ServiceName: \"$ServicePrefix$$Service$\",\n"); + printer->Print(vars, "HandlerType: (*$Service$Server)(nil),\n"); + printer->Print(vars, "Methods: []$grpc$.MethodDesc{\n"); + printer->Indent(); + for (int i = 0; i < service->method_count(); i++) { + auto method = service->method(i); + vars["Method"] = exportName(method->name()); + vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; + if (method->NoStreaming()) { + printer->Print("{\n"); + printer->Indent(); + printer->Print(vars, "MethodName: \"$Method$\",\n"); + printer->Print(vars, "Handler: $Handler$,\n"); + printer->Outdent(); + printer->Print("},\n"); + } + } + printer->Outdent(); + printer->Print("},\n"); + printer->Print(vars, "Streams: []$grpc$.StreamDesc{\n"); + printer->Indent(); + for (int i = 0; i < service->method_count(); i++) { + auto method = service->method(i); + vars["Method"] = exportName(method->name()); + vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler"; + if (!method->NoStreaming()) { + printer->Print("{\n"); + printer->Indent(); + printer->Print(vars, "StreamName: \"$Method$\",\n"); + printer->Print(vars, "Handler: $Handler$,\n"); + if (ClientOnlyStreaming(method.get())) { + printer->Print("ClientStreams: true,\n"); + } else if (ServerOnlyStreaming(method.get())) { + printer->Print("ServerStreams: true,\n"); + } else { + printer->Print("ServerStreams: true,\n"); + printer->Print("ClientStreams: true,\n"); + } + printer->Outdent(); + printer->Print("},\n"); + } + } + printer->Outdent(); + printer->Print("},\n"); + printer->Outdent(); + printer->Print("}\n"); +} +} // namespace // Returns source for the service grpc::string GenerateServiceSource(grpc_generator::File *file, const grpc_generator::Service *service, grpc_go_generator::Parameters *parameters) { - grpc::string out; - auto p = file->CreatePrinter(&out, '\t'); + grpc::string out; + auto p = file->CreatePrinter(&out, '\t'); p->SetIndentationSize(1); - auto printer = p.get(); - std::map<grpc::string, grpc::string> vars; - vars["Package"] = parameters->package_name; - vars["ServicePrefix"] = parameters->service_prefix; - if (!parameters->service_prefix.empty()) - vars["ServicePrefix"].append("."); - vars["grpc"] = "grpc"; - vars["context"] = "context"; - GenerateImports(file, printer, vars); - if (parameters->custom_method_io_type != "") { - vars["CustomMethodIO"] = parameters->custom_method_io_type; - } - GenerateService(service, printer, vars); - return out; + auto printer = p.get(); + std::map<grpc::string, grpc::string> vars; + vars["Package"] = parameters->package_name; + vars["ServicePrefix"] = parameters->service_prefix; + if (!parameters->service_prefix.empty()) vars["ServicePrefix"].append("."); + vars["grpc"] = "grpc"; + vars["context"] = "context"; + GenerateImports(file, printer, vars); + if (parameters->custom_method_io_type != "") { + vars["CustomMethodIO"] = parameters->custom_method_io_type; + } + GenerateService(service, printer, vars); + return out; } -}// Namespace grpc_go_generator +} // Namespace grpc_go_generator diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.h b/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.h index baa94e0599..766e100c58 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/go_generator.h @@ -1,40 +1,8 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - #ifndef GRPC_INTERNAL_COMPILER_GO_GENERATOR_H #define GRPC_INTERNAL_COMPILER_GO_GENERATOR_H -//go generator is used to generate GRPC code for serialization system, such as flatbuffers +// go generator is used to generate GRPC code for serialization system, such as +// flatbuffers #include <memory> #include <vector> @@ -43,14 +11,15 @@ namespace grpc_go_generator { struct Parameters { - //Defines the custom parameter types for methods - //eg: flatbuffers uses flatbuffers.Builder as input for the client and output for the server + // Defines the custom parameter types for methods + // eg: flatbuffers uses flatbuffers.Builder as input for the client and output + // for the server grpc::string custom_method_io_type; - //Package name for the service + // Package name for the service grpc::string package_name; - //Prefix for RPC Calls + // Prefix for RPC Calls grpc::string service_prefix; }; @@ -59,6 +28,6 @@ grpc::string GenerateServiceSource(grpc_generator::File *file, const grpc_generator::Service *service, grpc_go_generator::Parameters *parameters); -} +} // namespace grpc_go_generator #endif // GRPC_INTERNAL_COMPILER_GO_GENERATOR_H diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/java_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/java_generator.cc index d2cf5ccc14..bfe2b111db 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/java_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/java_generator.cc @@ -23,21 +23,18 @@ #include <utility> #include <vector> -// just to get flatbuffer_version_string() -#include <flatbuffers/flatbuffers.h> -#include <flatbuffers/util.h> +#include "flatbuffers/util.h" #define to_string flatbuffers::NumToString // Stringify helpers used solely to cast GRPC_VERSION #ifndef STR -#define STR(s) #s +# define STR(s) # s #endif #ifndef XSTR -#define XSTR(s) STR(s) +# define XSTR(s) STR(s) #endif - typedef grpc_generator::Printer Printer; typedef std::map<grpc::string, grpc::string> VARS; typedef grpc_generator::Service ServiceDescriptor; @@ -47,13 +44,13 @@ typedef grpc_generator::Method MethodDescriptor; namespace grpc_java_generator { typedef std::string string; +namespace { // Generates imports for the service -void GenerateImports(grpc_generator::File* file, - grpc_generator::Printer* printer, VARS& vars) { +static void GenerateImports(grpc_generator::File *file, + grpc_generator::Printer *printer, VARS &vars) { vars["filename"] = file->filename(); - printer->Print( - vars, - "//Generated by flatc compiler (version $flatc_version$)\n"); + printer->Print(vars, + "//Generated by flatc compiler (version $flatc_version$)\n"); printer->Print("//If you make any local changes, they will be lost\n"); printer->Print(vars, "//source: $filename$.fbs\n\n"); printer->Print(vars, "package $Package$;\n\n"); @@ -67,7 +64,7 @@ void GenerateImports(grpc_generator::File* file, // Adjust a method name prefix identifier to follow the JavaBean spec: // - decapitalize the first letter // - remove embedded underscores & capitalize the following letter -static string MixedLower(const string& word) { +static string MixedLower(const string &word) { string w; w += static_cast<string::value_type>(tolower(word[0])); bool after_underscore = false; @@ -87,7 +84,7 @@ static string MixedLower(const string& word) { // - An underscore is inserted where a lower case letter is followed by an // upper case letter. // - All letters are converted to upper case -static string ToAllUpperCase(const string& word) { +static string ToAllUpperCase(const string &word) { string w; for (size_t i = 0; i < word.length(); ++i) { w += static_cast<string::value_type>(toupper(word[i])); @@ -98,47 +95,47 @@ static string ToAllUpperCase(const string& word) { return w; } -static inline string LowerMethodName(const MethodDescriptor* method) { +static inline string LowerMethodName(const MethodDescriptor *method) { return MixedLower(method->name()); } -static inline string MethodPropertiesFieldName(const MethodDescriptor* method) { +static inline string MethodPropertiesFieldName(const MethodDescriptor *method) { return "METHOD_" + ToAllUpperCase(method->name()); } static inline string MethodPropertiesGetterName( - const MethodDescriptor* method) { + const MethodDescriptor *method) { return MixedLower("get_" + method->name() + "_method"); } -static inline string MethodIdFieldName(const MethodDescriptor* method) { +static inline string MethodIdFieldName(const MethodDescriptor *method) { return "METHODID_" + ToAllUpperCase(method->name()); } -static inline string JavaClassName(VARS& vars, const string& name) { +static inline string JavaClassName(VARS &vars, const string &name) { // string name = google::protobuf::compiler::java::ClassName(desc); return vars["Package"] + name; } -static inline string ServiceClassName(const string& service_name) { +static inline string ServiceClassName(const string &service_name) { return service_name + "Grpc"; } // TODO(nmittler): Remove once protobuf includes javadoc methods in // distribution. -template <typename ITR> -static void GrpcSplitStringToIteratorUsing(const string& full, - const char* delim, ITR& result) { +template<typename ITR> +static void GrpcSplitStringToIteratorUsing(const string &full, + const char *delim, ITR &result) { // Optimize the common case where delim is a single character. if (delim[0] != '\0' && delim[1] == '\0') { char c = delim[0]; - const char* p = full.data(); - const char* end = p + full.size(); + const char *p = full.data(); + const char *end = p + full.size(); while (p != end) { if (*p == c) { ++p; } else { - const char* start = p; + const char *start = p; while (++p != end && *p != c) ; *result++ = string(start, p - start); @@ -160,13 +157,13 @@ static void GrpcSplitStringToIteratorUsing(const string& full, } } -static void GrpcSplitStringUsing(const string& full, const char* delim, - std::vector<string>* result) { +static void GrpcSplitStringUsing(const string &full, const char *delim, + std::vector<string> *result) { std::back_insert_iterator<std::vector<string>> it(*result); GrpcSplitStringToIteratorUsing(full, delim, it); } -static std::vector<string> GrpcSplit(const string& full, const char* delim) { +static std::vector<string> GrpcSplit(const string &full, const char *delim) { std::vector<string> result; GrpcSplitStringUsing(full, delim, &result); return result; @@ -174,7 +171,7 @@ static std::vector<string> GrpcSplit(const string& full, const char* delim) { // TODO(nmittler): Remove once protobuf includes javadoc methods in // distribution. -static string GrpcEscapeJavadoc(const string& input) { +static string GrpcEscapeJavadoc(const string &input) { string result; result.reserve(input.size() * 2); @@ -221,9 +218,7 @@ static string GrpcEscapeJavadoc(const string& input) { // Java interprets Unicode escape sequences anywhere! result.append("\"); break; - default: - result.push_back(c); - break; + default: result.push_back(c); break; } prev = c; @@ -232,7 +227,7 @@ static string GrpcEscapeJavadoc(const string& input) { return result; } -static std::vector<string> GrpcGetDocLines(const string& comments) { +static std::vector<string> GrpcGetDocLines(const string &comments) { if (!comments.empty()) { // TODO(kenton): Ideally we should parse the comment text as Markdown and // write it back as HTML, but this requires a Markdown parser. For now @@ -243,27 +238,23 @@ static std::vector<string> GrpcGetDocLines(const string& comments) { string escapedComments = GrpcEscapeJavadoc(comments); std::vector<string> lines = GrpcSplit(escapedComments, "\n"); - while (!lines.empty() && lines.back().empty()) { - lines.pop_back(); - } + while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } return lines; } return std::vector<string>(); } static std::vector<string> GrpcGetDocLinesForDescriptor( - const DescriptorType* descriptor) { + const DescriptorType *descriptor) { return descriptor->GetAllComments(); // return GrpcGetDocLines(descriptor->GetLeadingComments("///")); } -static void GrpcWriteDocCommentBody(Printer* printer, VARS& vars, - const std::vector<string>& lines, +static void GrpcWriteDocCommentBody(Printer *printer, VARS &vars, + const std::vector<string> &lines, bool surroundWithPreTag) { if (!lines.empty()) { - if (surroundWithPreTag) { - printer->Print(" * <pre>\n"); - } + if (surroundWithPreTag) { printer->Print(" * <pre>\n"); } for (size_t i = 0; i < lines.size(); i++) { // Most lines should start with a space. Watch out for lines that start @@ -277,73 +268,72 @@ static void GrpcWriteDocCommentBody(Printer* printer, VARS& vars, } } - if (surroundWithPreTag) { - printer->Print(" * </pre>\n"); - } + if (surroundWithPreTag) { printer->Print(" * </pre>\n"); } } } -static void GrpcWriteDocComment(Printer* printer, VARS& vars, - const string& comments) { +static void GrpcWriteDocComment(Printer *printer, VARS &vars, + const string &comments) { printer->Print("/**\n"); std::vector<string> lines = GrpcGetDocLines(comments); GrpcWriteDocCommentBody(printer, vars, lines, false); printer->Print(" */\n"); } -static void GrpcWriteServiceDocComment(Printer* printer, VARS& vars, - const ServiceDescriptor* service) { +static void GrpcWriteServiceDocComment(Printer *printer, VARS &vars, + const ServiceDescriptor *service) { printer->Print("/**\n"); std::vector<string> lines = GrpcGetDocLinesForDescriptor(service); GrpcWriteDocCommentBody(printer, vars, lines, true); printer->Print(" */\n"); } -void GrpcWriteMethodDocComment(Printer* printer, VARS& vars, - const MethodDescriptor* method) { +static void GrpcWriteMethodDocComment(Printer *printer, VARS &vars, + const MethodDescriptor *method) { printer->Print("/**\n"); std::vector<string> lines = GrpcGetDocLinesForDescriptor(method); GrpcWriteDocCommentBody(printer, vars, lines, true); printer->Print(" */\n"); } -//outputs static singleton extractor for type stored in "extr_type" and "extr_type_name" vars -static void PrintTypeExtractor(Printer* p, VARS& vars) { - p->Print( - vars, - "private static volatile FlatbuffersUtils.FBExtactor<$extr_type$> " - "extractorOf$extr_type_name$;\n" - "private static FlatbuffersUtils.FBExtactor<$extr_type$> " - "getExtractorOf$extr_type_name$() {\n" - " if (extractorOf$extr_type_name$ != null) return " - "extractorOf$extr_type_name$;\n" - " synchronized ($service_class_name$.class) {\n" - " if (extractorOf$extr_type_name$ != null) return " - "extractorOf$extr_type_name$;\n" - " extractorOf$extr_type_name$ = new " - "FlatbuffersUtils.FBExtactor<$extr_type$>() {\n" - " public $extr_type$ extract (ByteBuffer buffer) {\n" - " return " - "$extr_type$.getRootAs$extr_type_name$(buffer);\n" - " }\n" - " };\n" - " return extractorOf$extr_type_name$;\n" - " }\n" - "}\n\n"); +// outputs static singleton extractor for type stored in "extr_type" and +// "extr_type_name" vars +static void PrintTypeExtractor(Printer *p, VARS &vars) { + p->Print(vars, + "private static volatile FlatbuffersUtils.FBExtactor<$extr_type$> " + "extractorOf$extr_type_name$;\n" + "private static FlatbuffersUtils.FBExtactor<$extr_type$> " + "getExtractorOf$extr_type_name$() {\n" + " if (extractorOf$extr_type_name$ != null) return " + "extractorOf$extr_type_name$;\n" + " synchronized ($service_class_name$.class) {\n" + " if (extractorOf$extr_type_name$ != null) return " + "extractorOf$extr_type_name$;\n" + " extractorOf$extr_type_name$ = new " + "FlatbuffersUtils.FBExtactor<$extr_type$>() {\n" + " public $extr_type$ extract (ByteBuffer buffer) {\n" + " return " + "$extr_type$.getRootAs$extr_type_name$(buffer);\n" + " }\n" + " };\n" + " return extractorOf$extr_type_name$;\n" + " }\n" + "}\n\n"); } -static void PrintMethodFields(Printer* p, VARS& vars, - const ServiceDescriptor* service) { +static void PrintMethodFields(Printer *p, VARS &vars, + const ServiceDescriptor *service) { p->Print("// Static method descriptors that strictly reflect the proto.\n"); vars["service_name"] = service->name(); - //set of names of rpc input- and output- types that were already encountered. - //this is needed to avoid duplicating type extractor since it's possible that - //the same type is used as an input or output type of more than a single RPC method + // set of names of rpc input- and output- types that were already encountered. + // this is needed to avoid duplicating type extractor since it's possible that + // the same type is used as an input or output type of more than a single RPC + // method std::set<std::string> encounteredTypes; for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - vars["arg_in_id"] = to_string(2L * i); //trying to make msvc 10 happy + vars["arg_in_id"] = to_string(2L * i); // trying to make msvc 10 happy vars["arg_out_id"] = to_string(2L * i + 1); vars["method_name"] = method->name(); vars["input_type_name"] = method->get_input_type_name(); @@ -353,8 +343,10 @@ static void PrintMethodFields(Printer* p, VARS& vars, vars["method_field_name"] = MethodPropertiesFieldName(method.get()); vars["method_new_field_name"] = MethodPropertiesGetterName(method.get()); vars["method_method_name"] = MethodPropertiesGetterName(method.get()); - bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); - bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); + bool client_streaming = + method->ClientStreaming() || method->BidiStreaming(); + bool server_streaming = + method->ServerStreaming() || method->BidiStreaming(); if (client_streaming) { if (server_streaming) { vars["method_type"] = "BIDI_STREAMING"; @@ -394,32 +386,32 @@ static void PrintMethodFields(Printer* p, VARS& vars, } p->Print( - vars, - "@$ExperimentalApi$(\"https://github.com/grpc/grpc-java/issues/" - "1901\")\n" - "public static $MethodDescriptor$<$input_type$,\n" - " $output_type$> $method_method_name$() {\n" - " $MethodDescriptor$<$input_type$, $output_type$> " - "$method_new_field_name$;\n" - " if (($method_new_field_name$ = " - "$service_class_name$.$method_new_field_name$) == null) {\n" - " synchronized ($service_class_name$.class) {\n" - " if (($method_new_field_name$ = " - "$service_class_name$.$method_new_field_name$) == null) {\n" - " $service_class_name$.$method_new_field_name$ = " - "$method_new_field_name$ = \n" - " $MethodDescriptor$.<$input_type$, " - "$output_type$>newBuilder()\n" - " .setType($MethodType$.$method_type$)\n" - " .setFullMethodName(generateFullMethodName(\n" - " \"$Package$$service_name$\", \"$method_name$\"))\n" - " .setSampledToLocalTracing(true)\n" - " .setRequestMarshaller(FlatbuffersUtils.marshaller(\n" - " $input_type$.class, " - "getExtractorOf$input_type_name$()))\n" - " .setResponseMarshaller(FlatbuffersUtils.marshaller(\n" - " $output_type$.class, " - "getExtractorOf$output_type_name$()))\n"); + vars, + "@$ExperimentalApi$(\"https://github.com/grpc/grpc-java/issues/" + "1901\")\n" + "public static $MethodDescriptor$<$input_type$,\n" + " $output_type$> $method_method_name$() {\n" + " $MethodDescriptor$<$input_type$, $output_type$> " + "$method_new_field_name$;\n" + " if (($method_new_field_name$ = " + "$service_class_name$.$method_new_field_name$) == null) {\n" + " synchronized ($service_class_name$.class) {\n" + " if (($method_new_field_name$ = " + "$service_class_name$.$method_new_field_name$) == null) {\n" + " $service_class_name$.$method_new_field_name$ = " + "$method_new_field_name$ = \n" + " $MethodDescriptor$.<$input_type$, " + "$output_type$>newBuilder()\n" + " .setType($MethodType$.$method_type$)\n" + " .setFullMethodName(generateFullMethodName(\n" + " \"$Package$$service_name$\", \"$method_name$\"))\n" + " .setSampledToLocalTracing(true)\n" + " .setRequestMarshaller(FlatbuffersUtils.marshaller(\n" + " $input_type$.class, " + "getExtractorOf$input_type_name$()))\n" + " .setResponseMarshaller(FlatbuffersUtils.marshaller(\n" + " $output_type$.class, " + "getExtractorOf$output_type_name$()))\n"); // vars["proto_method_descriptor_supplier"] = service->name() + // "MethodDescriptorSupplier"; @@ -451,11 +443,11 @@ enum StubType { enum CallType { ASYNC_CALL = 0, BLOCKING_CALL = 1, FUTURE_CALL = 2 }; -static void PrintBindServiceMethodBody(Printer* p, VARS& vars, - const ServiceDescriptor* service); +static void PrintBindServiceMethodBody(Printer *p, VARS &vars, + const ServiceDescriptor *service); // Prints a client interface or implementation class, or a server interface. -static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, +static void PrintStub(Printer *p, VARS &vars, const ServiceDescriptor *service, StubType type) { const string service_name = service->name(); vars["service_name"] = service_name; @@ -476,7 +468,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, break; case BLOCKING_CLIENT_INTERFACE: interface = true; - FLATBUFFERS_FALLTHROUGH(); // fall thru + FLATBUFFERS_FALLTHROUGH(); // fall thru case BLOCKING_CLIENT_IMPL: call_type = BLOCKING_CALL; stub_name += "BlockingStub"; @@ -484,7 +476,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, break; case FUTURE_CLIENT_INTERFACE: interface = true; - FLATBUFFERS_FALLTHROUGH(); // fall thru + FLATBUFFERS_FALLTHROUGH(); // fall thru case FUTURE_CLIENT_IMPL: call_type = FUTURE_CALL; stub_name += "FutureStub"; @@ -501,9 +493,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, vars["client_name"] = client_name; // Class head - if (!interface) { - GrpcWriteServiceDocComment(p, vars, service); - } + if (!interface) { GrpcWriteServiceDocComment(p, vars, service); } if (impl_base) { p->Print(vars, "public static abstract class $abstract_name$ implements " @@ -546,8 +536,10 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, vars["output_type"] = JavaClassName(vars, method->get_output_type_name()); vars["lower_method_name"] = LowerMethodName(&*method); vars["method_method_name"] = MethodPropertiesGetterName(&*method); - bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); - bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); + bool client_streaming = + method->ClientStreaming() || method->BidiStreaming(); + bool server_streaming = + method->ServerStreaming() || method->BidiStreaming(); if (call_type == BLOCKING_CALL && client_streaming) { // Blocking client interface with client streaming is not available @@ -563,9 +555,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, p->Print("\n"); // TODO(nmittler): Replace with WriteMethodDocComment once included by the // protobuf distro. - if (!interface) { - GrpcWriteMethodDocComment(p, vars, &*method); - } + if (!interface) { GrpcWriteMethodDocComment(p, vars, &*method); } p->Print("public "); switch (call_type) { case BLOCKING_CALL: @@ -630,8 +620,7 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, "responseObserver);\n"); } break; - default: - break; + default: break; } } else if (!interface) { switch (call_type) { @@ -706,15 +695,15 @@ static void PrintStub(Printer* p, VARS& vars, const ServiceDescriptor* service, } static bool CompareMethodClientStreaming( - const std::unique_ptr<const grpc_generator::Method>& method1, - const std::unique_ptr<const grpc_generator::Method>& method2) { + const std::unique_ptr<const grpc_generator::Method> &method1, + const std::unique_ptr<const grpc_generator::Method> &method2) { return method1->ClientStreaming() < method2->ClientStreaming(); } // Place all method invocations into a single class to reduce memory footprint // on Android. -static void PrintMethodHandlerClass(Printer* p, VARS& vars, - const ServiceDescriptor* service) { +static void PrintMethodHandlerClass(Printer *p, VARS &vars, + const ServiceDescriptor *service) { // Sort method ids based on ClientStreaming() so switch tables are compact. std::vector<std::unique_ptr<const grpc_generator::Method>> sorted_methods( service->method_count()); @@ -724,7 +713,7 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars, stable_sort(sorted_methods.begin(), sorted_methods.end(), CompareMethodClientStreaming); for (size_t i = 0; i < sorted_methods.size(); i++) { - auto& method = sorted_methods[i]; + auto &method = sorted_methods[i]; vars["method_id"] = to_string(i); vars["method_id_name"] = MethodIdFieldName(&*method); p->Print(vars, @@ -757,9 +746,7 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars, for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - if (method->ClientStreaming() || method->BidiStreaming()) { - continue; - } + if (method->ClientStreaming() || method->BidiStreaming()) { continue; } vars["method_id_name"] = MethodIdFieldName(&*method); vars["lower_method_name"] = LowerMethodName(&*method); vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); @@ -791,9 +778,7 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars, for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - if (!(method->ClientStreaming() || method->BidiStreaming())) { - continue; - } + if (!(method->ClientStreaming() || method->BidiStreaming())) { continue; } vars["method_id_name"] = MethodIdFieldName(&*method); vars["lower_method_name"] = LowerMethodName(&*method); vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); @@ -818,8 +803,8 @@ static void PrintMethodHandlerClass(Printer* p, VARS& vars, p->Print("}\n\n"); } -static void PrintGetServiceDescriptorMethod(Printer* p, VARS& vars, - const ServiceDescriptor* service) { +static void PrintGetServiceDescriptorMethod(Printer *p, VARS &vars, + const ServiceDescriptor *service) { vars["service_name"] = service->name(); // vars["proto_base_descriptor_supplier"] = service->name() + // "BaseDescriptorSupplier"; vars["proto_file_descriptor_supplier"] = @@ -911,8 +896,8 @@ static void PrintGetServiceDescriptorMethod(Printer* p, VARS& vars, p->Print("}\n"); } -static void PrintBindServiceMethodBody(Printer* p, VARS& vars, - const ServiceDescriptor* service) { +static void PrintBindServiceMethodBody(Printer *p, VARS &vars, + const ServiceDescriptor *service) { vars["service_name"] = service->name(); p->Indent(); p->Print(vars, @@ -927,8 +912,10 @@ static void PrintBindServiceMethodBody(Printer* p, VARS& vars, vars["input_type"] = JavaClassName(vars, method->get_input_type_name()); vars["output_type"] = JavaClassName(vars, method->get_output_type_name()); vars["method_id_name"] = MethodIdFieldName(&*method); - bool client_streaming = method->ClientStreaming() || method->BidiStreaming(); - bool server_streaming = method->ServerStreaming() || method->BidiStreaming(); + bool client_streaming = + method->ClientStreaming() || method->BidiStreaming(); + bool server_streaming = + method->ServerStreaming() || method->BidiStreaming(); if (client_streaming) { if (server_streaming) { vars["calls_method"] = "asyncBidiStreamingCall"; @@ -962,8 +949,8 @@ static void PrintBindServiceMethodBody(Printer* p, VARS& vars, p->Outdent(); } -static void PrintService(Printer* p, VARS& vars, - const ServiceDescriptor* service, +static void PrintService(Printer *p, VARS &vars, + const ServiceDescriptor *service, bool disable_version) { vars["service_name"] = service->name(); vars["service_class_name"] = ServiceClassName(service->name()); @@ -1043,7 +1030,7 @@ static void PrintService(Printer* p, VARS& vars, p->Print("}\n"); } -void PrintStaticImports(Printer* p) { +static void PrintStaticImports(Printer *p) { p->Print( "import java.nio.ByteBuffer;\n" "import static " @@ -1076,8 +1063,8 @@ void PrintStaticImports(Printer* p) { "io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;\n\n"); } -void GenerateService(const grpc_generator::Service* service, - grpc_generator::Printer* printer, VARS& vars, +static void GenerateService(const grpc_generator::Service *service, + grpc_generator::Printer *printer, VARS &vars, bool disable_version) { // All non-generated classes must be referred by fully qualified names to // avoid collision with generated classes. @@ -1111,10 +1098,11 @@ void GenerateService(const grpc_generator::Service* service, PrintService(printer, vars, service, disable_version); } +} // namespace grpc::string GenerateServiceSource( - grpc_generator::File* file, const grpc_generator::Service* service, - grpc_java_generator::Parameters* parameters) { + grpc_generator::File *file, const grpc_generator::Service *service, + grpc_java_generator::Parameters *parameters) { grpc::string out; auto printer = file->CreatePrinter(&out); VARS vars; diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.cc index 8108db45d5..d5f69e20e7 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.cc @@ -23,8 +23,9 @@ #include "src/compiler/python_generator.h" namespace grpc_python_generator { +namespace { -grpc::string GenerateMethodType(const grpc_generator::Method *method) { +static grpc::string GenerateMethodType(const grpc_generator::Method *method) { if (method->NoStreaming()) return "unary_unary"; @@ -131,6 +132,7 @@ void GenerateRegister(const grpc_generator::Service *service, printer->Outdent(); printer->Print("\n"); } +} // namespace grpc::string Generate(grpc_generator::File *file, const grpc_generator::Service *service) { diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.h b/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.h index 4f8f5cc806..40d29aada5 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/python_generator.h @@ -21,7 +21,6 @@ #include <utility> -#include "src/compiler/config.h" #include "src/compiler/schema_interface.h" namespace grpc_python_generator { diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/schema_interface.h b/contrib/libs/flatbuffers/grpc/src/compiler/schema_interface.h index 0449498198..f89288d756 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/schema_interface.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/schema_interface.h @@ -19,11 +19,10 @@ #ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H +#include <map> #include <memory> #include <vector> -#include "src/compiler/config.h" - #ifndef GRPC_CUSTOM_STRING # include <string> # define GRPC_CUSTOM_STRING std::string @@ -93,7 +92,7 @@ struct Printer { virtual void Print(const std::map<grpc::string, grpc::string> &vars, const char *template_string) = 0; virtual void Print(const char *string) = 0; - virtual void SetIndentationSize(const int size) = 0; + virtual void SetIndentationSize(const size_t size) = 0; virtual void Indent() = 0; virtual void Outdent() = 0; }; diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.cc index 403a803ef1..b0a96d869a 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.cc @@ -28,8 +28,9 @@ #include "src/compiler/swift_generator.h" namespace grpc_swift_generator { +namespace { -std::string WrapInNameSpace(const std::vector<std::string> &components, +static std::string WrapInNameSpace(const std::vector<std::string> &components, const grpc::string &name) { std::string qualified_name; for (auto it = components.begin(); it != components.end(); ++it) @@ -37,14 +38,14 @@ std::string WrapInNameSpace(const std::vector<std::string> &components, return qualified_name + name; } -grpc::string GenerateMessage(const std::vector<std::string> &components, +static grpc::string GenerateMessage(const std::vector<std::string> &components, const grpc::string &name) { return "Message<" + WrapInNameSpace(components, name) + ">"; } // MARK: - Client -void GenerateClientFuncName(const grpc_generator::Method *method, +static void GenerateClientFuncName(const grpc_generator::Method *method, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -82,7 +83,7 @@ void GenerateClientFuncName(const grpc_generator::Method *method, " ) -> BidirectionalStreamingCall<$Input$, $Output$>"); } -void GenerateClientFuncBody(const grpc_generator::Method *method, +static void GenerateClientFuncBody(const grpc_generator::Method *method, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -372,6 +373,7 @@ void GenerateServerProtocol(const grpc_generator::Service *service, } printer->Print("}"); } +} // namespace grpc::string Generate(grpc_generator::File *file, const grpc_generator::Service *service) { diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.h b/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.h index 1639cb07c8..2a226fa940 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/swift_generator.h @@ -1,40 +1,22 @@ /* + * Copyright 2020 Google Inc. All rights reserved. * - * Copyright 2020, Google Inc. - * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include <memory> #include <vector> -#include "src/compiler/config.h" #include "src/compiler/schema_interface.h" #ifndef GRPC_CUSTOM_STRING diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.cc b/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.cc index e49fd8d925..ff362b774a 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.cc +++ b/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.cc @@ -21,50 +21,42 @@ * be maintained according to the Swift-grpc repository */ +#include "src/compiler/ts_generator.h" + #include <map> #include <sstream> #include "flatbuffers/util.h" #include "src/compiler/schema_interface.h" -#include "src/compiler/ts_generator.h" namespace grpc_ts_generator { +namespace { -grpc::string ToDasherizedCase(const grpc::string pascal_case) { - std::string dasherized_case; - char p = 0; - for (size_t i = 0; i < pascal_case.length(); i++) { - char const &c = pascal_case[i]; - if (flatbuffers::is_alpha_upper(c)) { - if (i > 0 && p != flatbuffers::kPathSeparator) dasherized_case += "-"; - dasherized_case += flatbuffers::CharToLower(c); - } else { - dasherized_case += c; - } - p = c; - } - return dasherized_case; -} - -grpc::string GenerateNamespace(const std::vector<std::string> namepsace, +static grpc::string GenerateNamespace(const std::vector<std::string> ns, const std::string filename, const bool include_separator) { grpc::string path = ""; if (include_separator) path += "."; - for (auto it = namepsace.begin(); it < namepsace.end(); it++) { + for (auto it = ns.begin(); it < ns.end(); it++) { if (include_separator) path += "/"; - path += include_separator ? ToDasherizedCase(*it) : *it + "_"; + path += include_separator + ? flatbuffers::ConvertCase(*it, flatbuffers::Case::kDasher, + flatbuffers::Case::kUpperCamel) + : *it + "_"; } if (include_separator) path += "/"; - path += include_separator ? ToDasherizedCase(filename) : filename; + path += include_separator + ? flatbuffers::ConvertCase(filename, flatbuffers::Case::kDasher, + flatbuffers::Case::kUpperCamel) + : filename; return path; } // MARK: - Shared code -void GenerateImports(const grpc_generator::Service *service, +static void GenerateImports(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary, const bool grpc_var_import) { @@ -105,15 +97,15 @@ void GenerateImports(const grpc_generator::Service *service, } printer->Print("\n"); if (grpc_var_import) - printer->Print("var grpc = require('grpc');\n"); + printer->Print("var grpc = require('@grpc/grpc-js');\n"); else - printer->Print("import * as grpc from 'grpc';\n"); + printer->Print("import * as grpc from '@grpc/grpc-js';\n"); printer->Print("\n"); } // MARK: - Generate Main GRPC Code -void GetStreamType(grpc_generator::Printer *printer, +static void GetStreamType(grpc_generator::Printer *printer, const grpc_generator::Method *method, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -125,7 +117,7 @@ void GetStreamType(grpc_generator::Printer *printer, printer->Print(vars, "responseStream: $ServerStreaming$,\n"); } -void GenerateSerializeMethod(grpc_generator::Printer *printer, +static void GenerateSerializeMethod(grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; printer->Print(vars, "function serialize_$Type$(buffer_args) {\n"); @@ -136,12 +128,12 @@ void GenerateSerializeMethod(grpc_generator::Printer *printer, "throw new Error('Expected argument of type $VALUE$');\n"); printer->Outdent(); printer->Print("}\n"); - printer->Print(vars, "return buffer_args.serialize();\n"); + printer->Print(vars, "return Buffer.from(buffer_args.serialize());\n"); printer->Outdent(); printer->Print("}\n\n"); } -void GenerateDeserializeMethod( +static void GenerateDeserializeMethod( grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -154,7 +146,7 @@ void GenerateDeserializeMethod( printer->Print("}\n\n"); } -void GenerateMethods(const grpc_generator::Service *service, +static void GenerateMethods(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -186,7 +178,7 @@ void GenerateMethods(const grpc_generator::Service *service, } } -void GenerateService(const grpc_generator::Service *service, +static void GenerateService(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -221,6 +213,8 @@ void GenerateService(const grpc_generator::Service *service, "grpc.makeGenericClientConstructor($NAME$);"); } +} // namespace + grpc::string Generate(grpc_generator::File *file, const grpc_generator::Service *service, const grpc::string &filename) { @@ -242,9 +236,11 @@ grpc::string Generate(grpc_generator::File *file, return output; } +namespace { + // MARK: - Generate Interface -void FillInterface(grpc_generator::Printer *printer, +static void FillInterface(grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; printer->Print(vars, @@ -262,7 +258,7 @@ void FillInterface(grpc_generator::Printer *printer, printer->Print("}\n"); } -void GenerateInterfaces(const grpc_generator::Service *service, +static void GenerateInterfaces(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -284,11 +280,13 @@ void GenerateInterfaces(const grpc_generator::Service *service, } } -void GenerateExportedInterface( +static void GenerateExportedInterface( const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; - printer->Print(vars, "export interface I$ServiceName$Server {\n"); + printer->Print(vars, + "export interface I$ServiceName$Server extends " + "grpc.UntypedServiceImplementation {\n"); printer->Indent(); for (auto it = 0; it < service->method_count(); it++) { auto method = service->method(it); @@ -326,7 +324,7 @@ void GenerateExportedInterface( printer->Print("}\n"); } -void GenerateMainInterface(const grpc_generator::Service *service, +static void GenerateMainInterface(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -351,11 +349,11 @@ void GenerateMainInterface(const grpc_generator::Service *service, GenerateExportedInterface(service, printer, &vars); } -grpc::string GenerateMetaData() { return "metadata: grpc.Metadata"; } +static grpc::string GenerateMetaData() { return "metadata: grpc.Metadata"; } -grpc::string GenerateOptions() { return "options: Partial<grpc.CallOptions>"; } +static grpc::string GenerateOptions() { return "options: Partial<grpc.CallOptions>"; } -void GenerateUnaryClientInterface( +static void GenerateUnaryClientInterface( grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -370,7 +368,7 @@ void GenerateUnaryClientInterface( printer->Print(vars, (main + meta_data + options + callback).c_str()); } -void GenerateClientWriteStreamInterface( +static void GenerateClientWriteStreamInterface( grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -387,7 +385,7 @@ void GenerateClientWriteStreamInterface( printer->Print(vars, (main + meta_data + options + callback).c_str()); } -void GenerateClientReadableStreamInterface( +static void GenerateClientReadableStreamInterface( grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -399,7 +397,7 @@ void GenerateClientReadableStreamInterface( printer->Print(vars, (main + options + end_function).c_str()); } -void GenerateDepluxStreamInterface( +static void GenerateDepluxStreamInterface( grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -415,7 +413,7 @@ void GenerateDepluxStreamInterface( .c_str()); } -void GenerateClientInterface(const grpc_generator::Service *service, +static void GenerateClientInterface(const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -453,7 +451,7 @@ void GenerateClientInterface(const grpc_generator::Service *service, printer->Print("}\n"); } -void GenerateClientClassInterface( +static void GenerateClientClassInterface( const grpc_generator::Service *service, grpc_generator::Printer *printer, std::map<grpc::string, grpc::string> *dictonary) { auto vars = *dictonary; @@ -463,7 +461,7 @@ void GenerateClientClassInterface( printer->Indent(); printer->Print( "constructor(address: string, credentials: grpc.ChannelCredentials, " - "options?: object);"); + "options?: object);\n"); for (auto it = 0; it < service->method_count(); it++) { auto method = service->method(it); vars["MethodName"] = method->name(); @@ -494,6 +492,8 @@ void GenerateClientClassInterface( printer->Outdent(); printer->Print("}\n"); } +} // namespace + grpc::string GenerateInterface(grpc_generator::File *file, const grpc_generator::Service *service, diff --git a/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.h b/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.h index a33bb3c5d2..a356659daa 100644 --- a/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.h +++ b/contrib/libs/flatbuffers/grpc/src/compiler/ts_generator.h @@ -1,41 +1,7 @@ -/* - * - * Copyright 2020, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - #include <memory> -#include <vector> #include <set> +#include <vector> -#include "src/compiler/config.h" #include "src/compiler/schema_interface.h" #ifndef GRPC_CUSTOM_STRING @@ -58,4 +24,3 @@ grpc::string GenerateInterface(grpc_generator::File *file, const grpc_generator::Service *service, const grpc::string &filename); } // namespace grpc_ts_generator - |