diff options
| author | heretic <[email protected]> | 2022-03-25 12:34:53 +0300 |
|---|---|---|
| committer | heretic <[email protected]> | 2022-03-25 12:34:53 +0300 |
| commit | a41f3739eed6fceb6f62056a7620d220958a47e7 (patch) | |
| tree | 278103258b510cb4a96761ea79d6ccd397ca05a0 /contrib/libs/grpc/src/compiler | |
| parent | 73d3613a82e5c217fcbe0ab8bbf8120c1ed1af55 (diff) | |
Update grpc to 1.43.2 DTCC-864
ref:50a492c335cda70f458797cf945e49fe739c2715
Diffstat (limited to 'contrib/libs/grpc/src/compiler')
18 files changed, 342 insertions, 349 deletions
diff --git a/contrib/libs/grpc/src/compiler/config.h b/contrib/libs/grpc/src/compiler/config.h index 6ccffea5f5e..80ce021962a 100644 --- a/contrib/libs/grpc/src/compiler/config.h +++ b/contrib/libs/grpc/src/compiler/config.h @@ -19,10 +19,10 @@ #ifndef SRC_COMPILER_CONFIG_H #define SRC_COMPILER_CONFIG_H -#include "src/compiler/config_protobuf.h" - #include <util/generic/string.h> +#include "src/compiler/config_protobuf.h" + #ifdef GRPC_CUSTOM_STRING #warning GRPC_CUSTOM_STRING is no longer supported. Please use TString. #endif diff --git a/contrib/libs/grpc/src/compiler/cpp_generator.cc b/contrib/libs/grpc/src/compiler/cpp_generator.cc index c093085b4a5..a4d2becbe2f 100644 --- a/contrib/libs/grpc/src/compiler/cpp_generator.cc +++ b/contrib/libs/grpc/src/compiler/cpp_generator.cc @@ -16,10 +16,9 @@ * */ -#include <map> - #include "src/compiler/cpp_generator.h" +#include <map> #include <sstream> #include <util/string/cast.h> @@ -142,12 +141,8 @@ TString GetHeaderIncludes(grpc_generator::File* file, PrintIncludes(printer.get(), params.additional_header_includes, false, ""); } - // TODO(vjpai): Remove port_platform.h from header list when callback API is - // fully de-experimentalized since we will no longer be using - // macros from it. static const char* headers_strs[] = { "functional", - "grpc/impl/codegen/port_platform.h", "grpcpp/impl/codegen/async_generic_service.h", "grpcpp/impl/codegen/async_stream.h", "grpcpp/impl/codegen/async_unary_call.h", @@ -593,12 +588,12 @@ void PrintHeaderClientMethodCallbackInterfacesStart( // are pure; even though this is new (post-1.0) API, it can be pure because // it is an entirely new interface that happens to be scoped within // StubInterface, not new additions to StubInterface itself - printer->Print("class experimental_async_interface {\n"); + printer->Print("class async_interface {\n"); // All methods in this new interface are public. There is no need for private // "Raw" methods since the callback-based API returns unowned raw pointers printer->Print(" public:\n"); printer->Indent(); - printer->Print("virtual ~experimental_async_interface() {}\n"); + printer->Print("virtual ~async_interface() {}\n"); } void PrintHeaderClientMethodCallbackInterfaces( @@ -613,55 +608,27 @@ void PrintHeaderClientMethodCallbackInterfaces( "virtual void $Method$(::grpc::ClientContext* context, " "const $Request$* request, $Response$* response, " "std::function<void(::grpc::Status)>) = 0;\n"); - // TODO(vjpai): Remove experimental versions and macros when callback API is - // fully de-experimentalized. printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - "virtual void $Method$(::grpc::ClientContext* context, " - "const $Request$* request, $Response$* response, " - "::grpc::ClientUnaryReactor* reactor) = 0;\n" - "#else\n" "virtual void $Method$(::grpc::ClientContext* context, " "const $Request$* request, $Response$* response, " - "::grpc::experimental::ClientUnaryReactor* reactor) = 0;\n" - "#endif\n"); + "::grpc::ClientUnaryReactor* reactor) = 0;\n"); } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual void $Method$(::grpc::ClientContext* context, " "$Response$* response, " "::grpc::ClientWriteReactor< $Request$>* " - "reactor) = 0;\n" - "#else\n" - "virtual void $Method$(::grpc::ClientContext* context, " - "$Response$* response, " - "::grpc::experimental::ClientWriteReactor< $Request$>* " - "reactor) = 0;\n" - "#endif\n"); + "reactor) = 0;\n"); } else if (ServerOnlyStreaming(method)) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual void $Method$(::grpc::ClientContext* context, " "const $Request$* request, " "::grpc::ClientReadReactor< $Response$>* " - "reactor) = 0;\n" - "#else\n" - "virtual void $Method$(::grpc::ClientContext* context, " - "const $Request$* request, " - "::grpc::experimental::ClientReadReactor< $Response$>* " - "reactor) = 0;\n" - "#endif\n"); + "reactor) = 0;\n"); } else if (method->BidiStreaming()) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual void $Method$(::grpc::ClientContext* context, " "::grpc::ClientBidiReactor< " - "$Request$,$Response$>* reactor) = 0;\n" - "#else\n" - "virtual void $Method$(::grpc::ClientContext* context, " - "::grpc::experimental::ClientBidiReactor< " - "$Request$,$Response$>* reactor) = 0;\n" - "#endif\n"); + "$Request$,$Response$>* reactor) = 0;\n"); } } @@ -670,31 +637,30 @@ void PrintHeaderClientMethodCallbackInterfacesEnd( std::map<TString, TString>* /*vars*/) { printer->Outdent(); printer->Print("};\n"); + // TODO: Remove typedef when all uses of experimental_async are migrated off. printer->Print( - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - "typedef class experimental_async_interface async_interface;\n" - "#endif\n"); + "typedef class async_interface experimental_async_interface;\n"); // Declare a function to give the async stub contents. It can't be pure // since this is a new API in StubInterface, but it is meaningless by default // (since any stub that wants to use it must have its own implementation of // the callback functions therein), so make the default return value nullptr. // Intentionally include the word "class" to avoid possible shadowing. + // TODO: Remove experimental_async call when possible, replace with nullptr. printer->Print( - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - "async_interface* async() { return experimental_async(); }\n" - "#endif\n"); + "virtual class async_interface* async() { return nullptr; }\n"); + + // TODO: Remove experimental_async call when possible. printer->Print( - "virtual class experimental_async_interface* experimental_async() { " - "return nullptr; }\n"); + "class async_interface* experimental_async() { return async(); }\n"); } void PrintHeaderClientMethodCallbackStart( grpc_generator::Printer* printer, std::map<TString, TString>* /*vars*/) { // This declares the stub entry for the callback-based API. - printer->Print("class experimental_async final :\n"); - printer->Print(" public StubInterface::experimental_async_interface {\n"); + printer->Print("class async final :\n"); + printer->Print(" public StubInterface::async_interface {\n"); printer->Print(" public:\n"); printer->Indent(); } @@ -711,55 +677,28 @@ void PrintHeaderClientMethodCallback(grpc_generator::Printer* printer, "void $Method$(::grpc::ClientContext* context, " "const $Request$* request, $Response$* response, " "std::function<void(::grpc::Status)>) override;\n"); - printer->Print( - *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - "void $Method$(::grpc::ClientContext* context, " - "const $Request$* request, $Response$* response, " - "::grpc::ClientUnaryReactor* reactor) override;\n" - "#else\n" - "void $Method$(::grpc::ClientContext* context, " - "const $Request$* request, $Response$* response, " - "::grpc::experimental::ClientUnaryReactor* reactor) override;\n" - "#endif\n"); + printer->Print(*vars, + "void $Method$(::grpc::ClientContext* context, " + "const $Request$* request, $Response$* response, " + "::grpc::ClientUnaryReactor* reactor) override;\n"); } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "void $Method$(::grpc::ClientContext* context, " "$Response$* response, " "::grpc::ClientWriteReactor< $Request$>* " - "reactor) override;\n" - "#else\n" - "void $Method$(::grpc::ClientContext* context, " - "$Response$* response, " - "::grpc::experimental::ClientWriteReactor< $Request$>* " - "reactor) override;\n" - "#endif\n"); + "reactor) override;\n"); } else if (ServerOnlyStreaming(method)) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "void $Method$(::grpc::ClientContext* context, " "const $Request$* request, " "::grpc::ClientReadReactor< $Response$>* " - "reactor) override;\n" - "#else\n" - "void $Method$(::grpc::ClientContext* context, " - "const $Request$* request, " - "::grpc::experimental::ClientReadReactor< $Response$>* " - "reactor) override;\n" - "#endif\n"); + "reactor) override;\n"); } else if (method->BidiStreaming()) { printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "void $Method$(::grpc::ClientContext* context, " "::grpc::ClientBidiReactor< " - "$Request$,$Response$>* reactor) override;\n" - "#else\n" - "void $Method$(::grpc::ClientContext* context, " - "::grpc::experimental::ClientBidiReactor< " - "$Request$,$Response$>* reactor) override;\n" - "#endif\n"); + "$Request$,$Response$>* reactor) override;\n"); } } @@ -770,7 +709,7 @@ void PrintHeaderClientMethodCallbackEnd( printer->Print(" private:\n"); printer->Indent(); printer->Print("friend class Stub;\n"); - printer->Print("explicit experimental_async(Stub* stub): stub_(stub) { }\n"); + printer->Print("explicit async(Stub* stub): stub_(stub) { }\n"); // include a function with a phony use of stub_ to avoid an unused // private member warning for service with no methods printer->Print("Stub* stub() { return stub_; }\n"); @@ -779,7 +718,7 @@ void PrintHeaderClientMethodCallbackEnd( printer->Print("};\n"); printer->Print( - "class experimental_async_interface* experimental_async() override { " + "class async* async() override { " "return &async_stub_; }\n"); } @@ -972,18 +911,10 @@ void PrintHeaderServerCallbackMethodsHelper( " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual ::grpc::ServerUnaryReactor* $Method$(\n" " ::grpc::CallbackServerContext* /*context*/, " "const $RealRequest$* /*request*/, " - "$RealResponse$* /*response*/)\n" - "#else\n" - "virtual ::grpc::experimental::ServerUnaryReactor* " - "$Method$(\n" - " ::grpc::experimental::CallbackServerContext* " - "/*context*/, const $RealRequest$* /*request*/, " - "$RealResponse$* /*response*/)\n" - "#endif\n" + "$RealResponse$* /*response*/)" " { return nullptr; }\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( @@ -997,17 +928,10 @@ void PrintHeaderServerCallbackMethodsHelper( " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); printer->Print(*vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual ::grpc::ServerReadReactor< " "$RealRequest$>* $Method$(\n" " ::grpc::CallbackServerContext* " - "/*context*/, $RealResponse$* /*response*/)\n" - "#else\n" - "virtual ::grpc::experimental::ServerReadReactor< " - "$RealRequest$>* $Method$(\n" - " ::grpc::experimental::CallbackServerContext* " - "/*context*/, $RealResponse$* /*response*/)\n" - "#endif\n" + "/*context*/, $RealResponse$* /*response*/)" " { return nullptr; }\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( @@ -1022,16 +946,9 @@ void PrintHeaderServerCallbackMethodsHelper( "}\n"); printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual ::grpc::ServerWriteReactor< $RealResponse$>* $Method$(\n" " ::grpc::CallbackServerContext* " - "/*context*/, const $RealRequest$* /*request*/)\n" - "#else\n" - "virtual ::grpc::experimental::ServerWriteReactor< $RealResponse$>* " - "$Method$(\n" - " ::grpc::experimental::CallbackServerContext* " - "/*context*/, const $RealRequest$* /*request*/)\n" - "#endif\n" + "/*context*/, const $RealRequest$* /*request*/)" " { return nullptr; }\n"); } else if (method->BidiStreaming()) { printer->Print( @@ -1046,16 +963,9 @@ void PrintHeaderServerCallbackMethodsHelper( "}\n"); printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" "virtual ::grpc::ServerBidiReactor< $RealRequest$, $RealResponse$>* " "$Method$(\n" " ::grpc::CallbackServerContext* /*context*/)\n" - "#else\n" - "virtual ::grpc::experimental::ServerBidiReactor< " - "$RealRequest$, $RealResponse$>* " - "$Method$(\n" - " ::grpc::experimental::CallbackServerContext* /*context*/)\n" - "#endif\n" " { return nullptr; }\n"); } } @@ -1071,117 +981,70 @@ void PrintHeaderServerMethodCallback(grpc_generator::Printer* printer, (*vars)["RealRequest"] = method->input_type_name(); (*vars)["RealResponse"] = method->output_type_name(); printer->Print(*vars, "template <class BaseClass>\n"); - printer->Print( - *vars, - "class ExperimentalWithCallbackMethod_$Method$ : public BaseClass {\n"); + printer->Print(*vars, + "class WithCallbackMethod_$Method$ : public BaseClass {\n"); printer->Print( " private:\n" " void BaseClassMustBeDerivedFromService(const Service* /*service*/) " "{}\n"); printer->Print(" public:\n"); printer->Indent(); - printer->Print(*vars, "ExperimentalWithCallbackMethod_$Method$() {\n"); + printer->Print(*vars, "WithCallbackMethod_$Method$() {\n"); if (method->NoStreaming()) { printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodCallback($Idx$,\n" + " ::grpc::Service::MarkMethodCallback($Idx$,\n" " new ::grpc::internal::CallbackUnaryHandler< " "$RealRequest$, $RealResponse$>(\n" " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " + " ::grpc::CallbackServerContext* context, " "const $RealRequest$* " "request, " "$RealResponse$* response) { " "return this->$Method$(context, request, response); }));}\n"); printer->Print(*vars, "void SetMessageAllocatorFor_$Method$(\n" - " ::grpc::experimental::MessageAllocator< " + " ::grpc::MessageAllocator< " "$RealRequest$, $RealResponse$>* allocator) {\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" " ::grpc::internal::MethodHandler* const handler = " "::grpc::Service::GetHandler($Idx$);\n" - "#else\n" - " ::grpc::internal::MethodHandler* const handler = " - "::grpc::Service::experimental().GetHandler($Idx$);\n" - "#endif\n" " static_cast<::grpc::internal::CallbackUnaryHandler< " "$RealRequest$, $RealResponse$>*>(handler)\n" " ->SetMessageAllocator(allocator);\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodCallback($Idx$,\n" + " ::grpc::Service::MarkMethodCallback($Idx$,\n" " new ::grpc::internal::CallbackClientStreamingHandler< " "$RealRequest$, $RealResponse$>(\n" " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " + " ::grpc::CallbackServerContext* context, " "$RealResponse$* " "response) { " "return this->$Method$(context, response); }));\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodCallback($Idx$,\n" + " ::grpc::Service::MarkMethodCallback($Idx$,\n" " new ::grpc::internal::CallbackServerStreamingHandler< " "$RealRequest$, $RealResponse$>(\n" " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " + " ::grpc::CallbackServerContext* context, " "const $RealRequest$* " "request) { " "return this->$Method$(context, request); }));\n"); } else if (method->BidiStreaming()) { - printer->Print( - *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodCallback($Idx$,\n" - " new ::grpc::internal::CallbackBidiHandler< " - "$RealRequest$, $RealResponse$>(\n" - " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context) " - "{ return this->$Method$(context); }));\n"); + printer->Print(*vars, + " ::grpc::Service::MarkMethodCallback($Idx$,\n" + " new ::grpc::internal::CallbackBidiHandler< " + "$RealRequest$, $RealResponse$>(\n" + " [this](\n" + " ::grpc::CallbackServerContext* context) " + "{ return this->$Method$(context); }));\n"); } printer->Print(*vars, "}\n"); printer->Print(*vars, - "~ExperimentalWithCallbackMethod_$Method$() override {\n" + "~WithCallbackMethod_$Method$() override {\n" " BaseClassMustBeDerivedFromService(this);\n" "}\n"); PrintHeaderServerCallbackMethodsHelper(printer, method, vars); @@ -1201,7 +1064,7 @@ void PrintHeaderServerMethodRawCallback( (*vars)["RealResponse"] = "::grpc::ByteBuffer"; printer->Print(*vars, "template <class BaseClass>\n"); printer->Print(*vars, - "class ExperimentalWithRawCallbackMethod_$Method$ : public " + "class WithRawCallbackMethod_$Method$ : public " "BaseClass {\n"); printer->Print( " private:\n" @@ -1209,93 +1072,51 @@ void PrintHeaderServerMethodRawCallback( "{}\n"); printer->Print(" public:\n"); printer->Indent(); - printer->Print(*vars, "ExperimentalWithRawCallbackMethod_$Method$() {\n"); + printer->Print(*vars, "WithRawCallbackMethod_$Method$() {\n"); if (method->NoStreaming()) { - printer->Print( - *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodRawCallback($Idx$,\n" - " new ::grpc::internal::CallbackUnaryHandler< " - "$RealRequest$, $RealResponse$>(\n" - " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " - "const $RealRequest$* " - "request, " - "$RealResponse$* response) { return " - "this->$Method$(context, request, response); }));\n"); + printer->Print(*vars, + " ::grpc::Service::MarkMethodRawCallback($Idx$,\n" + " new ::grpc::internal::CallbackUnaryHandler< " + "$RealRequest$, $RealResponse$>(\n" + " [this](\n" + " ::grpc::CallbackServerContext* context, " + "const $RealRequest$* " + "request, " + "$RealResponse$* response) { return " + "this->$Method$(context, request, response); }));\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodRawCallback($Idx$,\n" + " ::grpc::Service::MarkMethodRawCallback($Idx$,\n" " new ::grpc::internal::CallbackClientStreamingHandler< " "$RealRequest$, $RealResponse$>(\n" " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " + " ::grpc::CallbackServerContext* context, " "$RealResponse$* response) " "{ return this->$Method$(context, response); }));\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodRawCallback($Idx$,\n" + " ::grpc::Service::MarkMethodRawCallback($Idx$,\n" " new ::grpc::internal::CallbackServerStreamingHandler< " "$RealRequest$, $RealResponse$>(\n" " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context, " + " ::grpc::CallbackServerContext* context, " "const" "$RealRequest$* request) { return " "this->$Method$(context, request); }));\n"); } else if (method->BidiStreaming()) { - printer->Print( - *vars, - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::Service::\n" - "#else\n" - " ::grpc::Service::experimental().\n" - "#endif\n" - " MarkMethodRawCallback($Idx$,\n" - " new ::grpc::internal::CallbackBidiHandler< " - "$RealRequest$, $RealResponse$>(\n" - " [this](\n" - "#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n" - " ::grpc::CallbackServerContext*\n" - "#else\n" - " ::grpc::experimental::CallbackServerContext*\n" - "#endif\n" - " context) " - "{ return this->$Method$(context); }));\n"); + printer->Print(*vars, + " ::grpc::Service::MarkMethodRawCallback($Idx$,\n" + " new ::grpc::internal::CallbackBidiHandler< " + "$RealRequest$, $RealResponse$>(\n" + " [this](\n" + " ::grpc::CallbackServerContext* context) " + "{ return this->$Method$(context); }));\n"); } printer->Print(*vars, "}\n"); printer->Print(*vars, - "~ExperimentalWithRawCallbackMethod_$Method$() override {\n" + "~WithRawCallbackMethod_$Method$() override {\n" " BaseClassMustBeDerivedFromService(this);\n" "}\n"); PrintHeaderServerCallbackMethodsHelper(printer, method, vars); @@ -1552,7 +1373,7 @@ void PrintHeaderService(grpc_generator::Printer* printer, } PrintHeaderClientMethodCallbackInterfacesEnd(printer, vars); printer->Outdent(); - printer->Print("private:\n"); + printer->Print(" private:\n"); printer->Indent(); for (int i = 0; i < service->method_count(); ++i) { PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, @@ -1566,7 +1387,8 @@ void PrintHeaderService(grpc_generator::Printer* printer, printer->Indent(); printer->Print( "Stub(const std::shared_ptr< ::grpc::ChannelInterface>& " - "channel);\n"); + "channel, const ::grpc::StubOptions& options = " + "::grpc::StubOptions());\n"); for (int i = 0; i < service->method_count(); ++i) { PrintHeaderClientMethod(printer, service->method(i).get(), vars, true); } @@ -1579,7 +1401,7 @@ void PrintHeaderService(grpc_generator::Printer* printer, printer->Print("\n private:\n"); printer->Indent(); printer->Print("std::shared_ptr< ::grpc::ChannelInterface> channel_;\n"); - printer->Print("class experimental_async async_stub_{this};\n"); + printer->Print("class async async_stub_{this};\n"); for (int i = 0; i < service->method_count(); ++i) { PrintHeaderClientMethod(printer, service->method(i).get(), vars, false); } @@ -1632,31 +1454,21 @@ void PrintHeaderService(grpc_generator::Printer* printer, PrintHeaderServerMethodCallback(printer, service->method(i).get(), vars); } - printer->Print("#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL\n"); printer->Print("typedef "); for (int i = 0; i < service->method_count(); ++i) { (*vars)["method_name"] = service->method(i)->name(); - printer->Print(*vars, "ExperimentalWithCallbackMethod_$method_name$<"); + printer->Print(*vars, "WithCallbackMethod_$method_name$<"); } printer->Print("Service"); for (int i = 0; i < service->method_count(); ++i) { printer->Print(" >"); } printer->Print(" CallbackService;\n"); - printer->Print("#endif\n\n"); - printer->Print("typedef "); - - for (int i = 0; i < service->method_count(); ++i) { - (*vars)["method_name"] = service->method(i)->name(); - printer->Print(*vars, "ExperimentalWithCallbackMethod_$method_name$<"); - } - printer->Print("Service"); - for (int i = 0; i < service->method_count(); ++i) { - printer->Print(" >"); - } - printer->Print(" ExperimentalCallbackService;\n"); + // TODO: Remove following typedef once all uses of ExperimentalCallbackService + // are migrated to CallbackService + printer->Print("typedef CallbackService ExperimentalCallbackService;\n"); // Server side - Generic for (int i = 0; i < service->method_count(); ++i) { @@ -1907,7 +1719,7 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "context, request, response);\n}\n\n"); printer->Print(*vars, - "void $ns$$Service$::Stub::experimental_async::$Method$(" + "void $ns$$Service$::Stub::async::$Method$(" "::grpc::ClientContext* context, " "const $Request$* request, $Response$* response, " "std::function<void(::grpc::Status)> f) {\n"); @@ -1919,10 +1731,10 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "context, request, response, std::move(f));\n}\n\n"); printer->Print(*vars, - "void $ns$$Service$::Stub::experimental_async::$Method$(" + "void $ns$$Service$::Stub::async::$Method$(" "::grpc::ClientContext* context, " "const $Request$* request, $Response$* response, " - "::grpc::experimental::ClientUnaryReactor* reactor) {\n"); + "::grpc::ClientUnaryReactor* reactor) {\n"); printer->Print(*vars, " ::grpc::internal::ClientCallbackUnaryFactory::Create" "< ::grpc::protobuf::MessageLite, " @@ -1969,12 +1781,11 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "context, response);\n" "}\n\n"); - printer->Print( - *vars, - "void $ns$$Service$::" - "Stub::experimental_async::$Method$(::grpc::ClientContext* context, " - "$Response$* response, " - "::grpc::experimental::ClientWriteReactor< $Request$>* reactor) {\n"); + printer->Print(*vars, + "void $ns$$Service$::" + "Stub::async::$Method$(::grpc::ClientContext* context, " + "$Response$* response, " + "::grpc::ClientWriteReactor< $Request$>* reactor) {\n"); printer->Print(*vars, " ::grpc::internal::ClientCallbackWriterFactory< " "$Request$>::Create(" @@ -2015,12 +1826,11 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "context, request);\n" "}\n\n"); - printer->Print( - *vars, - "void $ns$$Service$::Stub::experimental_async::$Method$(::grpc::" - "ClientContext* context, " - "const $Request$* request, " - "::grpc::experimental::ClientReadReactor< $Response$>* reactor) {\n"); + printer->Print(*vars, + "void $ns$$Service$::Stub::async::$Method$(::grpc::" + "ClientContext* context, " + "const $Request$* request, " + "::grpc::ClientReadReactor< $Response$>* reactor) {\n"); printer->Print(*vars, " ::grpc::internal::ClientCallbackReaderFactory< " "$Response$>::Create(" @@ -2061,12 +1871,11 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "context);\n" "}\n\n"); - printer->Print( - *vars, - "void $ns$$Service$::Stub::experimental_async::$Method$(::grpc::" - "ClientContext* context, " - "::grpc::experimental::ClientBidiReactor< $Request$,$Response$>* " - "reactor) {\n"); + printer->Print(*vars, + "void $ns$$Service$::Stub::async::$Method$(::grpc::" + "ClientContext* context, " + "::grpc::ClientBidiReactor< $Request$,$Response$>* " + "reactor) {\n"); printer->Print(*vars, " ::grpc::internal::ClientCallbackReaderWriterFactory< " "$Request$,$Response$>::Create(" @@ -2171,18 +1980,20 @@ void PrintSourceService(grpc_generator::Printer* printer, printer->Print(*vars, "};\n\n"); } + (*vars)["OptionsVariableName"] = service->method_count() ? "options" : ""; printer->Print(*vars, "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub(" "const std::shared_ptr< ::grpc::ChannelInterface>& channel, " "const ::grpc::StubOptions& options) {\n" " (void)options;\n" " std::unique_ptr< $ns$$Service$::Stub> stub(new " - "$ns$$Service$::Stub(channel));\n" + "$ns$$Service$::Stub(channel, options));\n" " return stub;\n" "}\n\n"); printer->Print(*vars, "$ns$$Service$::Stub::Stub(const std::shared_ptr< " - "::grpc::ChannelInterface>& channel)\n"); + "::grpc::ChannelInterface>& channel, const " + "::grpc::StubOptions& $OptionsVariableName$)\n"); printer->Indent(); printer->Print(": channel_(channel)"); for (int i = 0; i < service->method_count(); ++i) { @@ -2201,12 +2012,13 @@ void PrintSourceService(grpc_generator::Printer* printer, } else { (*vars)["StreamingType"] = "BIDI_STREAMING"; } - printer->Print(*vars, - ", rpcmethod_$Method$_(" - "$prefix$$Service$_method_names[$Idx$], " - "::grpc::internal::RpcMethod::$StreamingType$, " - "channel" - ")\n"); + printer->Print( + *vars, + ", rpcmethod_$Method$_(" + "$prefix$$Service$_method_names[$Idx$], options.suffix_for_stats()," + "::grpc::internal::RpcMethod::$StreamingType$, " + "channel" + ")\n"); } printer->Print("{}\n\n"); printer->Outdent(); diff --git a/contrib/libs/grpc/src/compiler/cpp_plugin.h b/contrib/libs/grpc/src/compiler/cpp_plugin.h index 0c289a7395b..d8789dbca2a 100644 --- a/contrib/libs/grpc/src/compiler/cpp_plugin.h +++ b/contrib/libs/grpc/src/compiler/cpp_plugin.h @@ -23,7 +23,6 @@ #include <sstream> #include "src/compiler/config.h" - #include "src/compiler/cpp_generator.h" #include "src/compiler/generator_helpers.h" #include "src/compiler/protobuf_plugin.h" diff --git a/contrib/libs/grpc/src/compiler/csharp_generator.cc b/contrib/libs/grpc/src/compiler/csharp_generator.cc index 099f03aff08..15d5361a205 100644 --- a/contrib/libs/grpc/src/compiler/csharp_generator.cc +++ b/contrib/libs/grpc/src/compiler/csharp_generator.cc @@ -16,13 +16,14 @@ * */ +#include "src/compiler/csharp_generator.h" + #include <cctype> #include <map> #include <sstream> #include <vector> #include "src/compiler/config.h" -#include "src/compiler/csharp_generator.h" #include "src/compiler/csharp_generator_helpers.h" using grpc::protobuf::Descriptor; @@ -38,7 +39,7 @@ namespace grpc_csharp_generator { namespace { // This function is a massaged version of -// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc +// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc // Currently, we cannot easily reuse the functionality as // google/protobuf/compiler/csharp/csharp_doc_comment.h is not a public header. // TODO(jtattermusch): reuse the functionality from google/protobuf. @@ -88,6 +89,17 @@ bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer, return true; } +void GenerateGeneratedCodeAttribute(grpc::protobuf::io::Printer* printer) { + // Mark the code as generated using the [GeneratedCode] attribute. + // We don't provide plugin version info in attribute the because: + // * the version information is not readily available from the plugin's code. + // * it would cause a lot of churn in the pre-generated code + // in this repository every time the version is updated. + printer->Print( + "[global::System.CodeDom.Compiler.GeneratedCode(\"grpc_csharp_plugin\", " + "null)]\n"); +} + template <typename DescriptorType> bool GenerateDocCommentBody(grpc::protobuf::io::Printer* printer, const DescriptorType* descriptor) { @@ -304,6 +316,7 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { std::vector<const Descriptor*> used_messages = GetUsedMessages(service); if (used_messages.size() != 0) { // Generate static helper methods for serialization/deserialization + GenerateGeneratedCodeAttribute(out); out->Print( "static void __Helper_SerializeMessage(" "global::Google.Protobuf.IMessage message, " @@ -331,6 +344,7 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { out->Outdent(); out->Print("}\n\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "static class __Helper_MessageCache<T>\n" "{\n"); @@ -343,6 +357,7 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { out->Outdent(); out->Print("}\n\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "static T __Helper_DeserializeMessage<T>(" "grpc::DeserializationContext context, " @@ -368,6 +383,7 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { for (size_t i = 0; i < used_messages.size(); i++) { const Descriptor* message = used_messages[i]; + GenerateGeneratedCodeAttribute(out); out->Print( "static readonly grpc::Marshaller<$type$> $fieldname$ = " "grpc::Marshallers.Create(__Helper_SerializeMessage, " @@ -379,6 +395,7 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { } void GenerateStaticMethodField(Printer* out, const MethodDescriptor* method) { + GenerateGeneratedCodeAttribute(out); out->Print( "static readonly grpc::Method<$request$, $response$> $fieldname$ = new " "grpc::Method<$request$, $response$>(\n", @@ -433,6 +450,7 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor* service) { for (int i = 0; i < service->method_count(); i++) { const MethodDescriptor* method = service->method(i); GenerateDocCommentServerMethod(out, method); + GenerateGeneratedCodeAttribute(out); out->Print( "public virtual $returntype$ " "$methodname$($request$$response_stream_maybe$, " @@ -468,6 +486,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { "/// <param name=\"channel\">The channel to use to make remote " "calls.</param>\n", "servicename", GetServiceClassName(service)); + GenerateGeneratedCodeAttribute(out); out->Print("public $name$(grpc::ChannelBase channel) : base(channel)\n", "name", GetClientClassName(service)); out->Print("{\n"); @@ -478,6 +497,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { "/// <param name=\"callInvoker\">The callInvoker to use to make remote " "calls.</param>\n", "servicename", GetServiceClassName(service)); + GenerateGeneratedCodeAttribute(out); out->Print( "public $name$(grpc::CallInvoker callInvoker) : base(callInvoker)\n", "name", GetClientClassName(service)); @@ -486,6 +506,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { out->Print( "/// <summary>Protected parameterless constructor to allow creation" " of test doubles.</summary>\n"); + GenerateGeneratedCodeAttribute(out); out->Print("protected $name$() : base()\n", "name", GetClientClassName(service)); out->Print("{\n"); @@ -494,6 +515,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { "/// <summary>Protected constructor to allow creation of configured " "clients.</summary>\n" "/// <param name=\"configuration\">The client configuration.</param>\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "protected $name$(ClientBaseConfiguration configuration)" " : base(configuration)\n", @@ -506,6 +528,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { if (!method->client_streaming() && !method->server_streaming()) { // unary calls have an extra synchronous stub method GenerateDocCommentClientMethod(out, method, true, false); + GenerateGeneratedCodeAttribute(out); out->Print( "public virtual $response$ $methodname$($request$ request, " "grpc::Metadata " @@ -528,6 +551,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { // overload taking CallOptions as a param GenerateDocCommentClientMethod(out, method, true, true); + GenerateGeneratedCodeAttribute(out); out->Print( "public virtual $response$ $methodname$($request$ request, " "grpc::CallOptions options)\n", @@ -549,6 +573,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { method_name += "Async"; // prevent name clash with synchronous method. } GenerateDocCommentClientMethod(out, method, false, false); + GenerateGeneratedCodeAttribute(out); out->Print( "public virtual $returntype$ " "$methodname$($request_maybe$grpc::Metadata " @@ -573,6 +598,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { // overload taking CallOptions as a param GenerateDocCommentClientMethod(out, method, false, true); + GenerateGeneratedCodeAttribute(out); out->Print( "public virtual $returntype$ " "$methodname$($request_maybe$grpc::CallOptions " @@ -615,6 +641,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { out->Print( "/// <summary>Creates a new instance of client from given " "<c>ClientBaseConfiguration</c>.</summary>\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "protected override $name$ NewInstance(ClientBaseConfiguration " "configuration)\n", @@ -638,6 +665,7 @@ void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor* service) { out->Print( "/// <param name=\"serviceImpl\">An object implementing the server-side" " handling logic.</param>\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "public static grpc::ServerServiceDefinition BindService($implclass$ " "serviceImpl)\n", @@ -679,6 +707,7 @@ void GenerateBindServiceWithBinderMethod(Printer* out, out->Print( "/// <param name=\"serviceImpl\">An object implementing the server-side" " handling logic.</param>\n"); + GenerateGeneratedCodeAttribute(out); out->Print( "public static void BindService(grpc::ServiceBinderBase serviceBinder, " "$implclass$ " @@ -709,6 +738,7 @@ void GenerateService(Printer* out, const ServiceDescriptor* service, bool generate_client, bool generate_server, bool internal_access) { GenerateDocCommentBody(out, service); + out->Print("$access_level$ static partial class $classname$\n", "access_level", GetAccessLevel(internal_access), "classname", GetServiceClassName(service)); diff --git a/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h b/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h index a8af7f3ccd1..d1a5b3a2a0f 100644 --- a/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h +++ b/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h @@ -25,9 +25,10 @@ namespace grpc_csharp_generator { inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file, - TString* file_name_or_error) { - *file_name_or_error = - grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs"; + const TString& file_suffix, + TString& out_file_name_or_error) { + out_file_name_or_error = + grpc_generator::FileNameInUpperCamel(file, false) + file_suffix; return true; } diff --git a/contrib/libs/grpc/src/compiler/node_generator.cc b/contrib/libs/grpc/src/compiler/node_generator.cc index 89e4871a660..d890320e8a5 100644 --- a/contrib/libs/grpc/src/compiler/node_generator.cc +++ b/contrib/libs/grpc/src/compiler/node_generator.cc @@ -16,11 +16,12 @@ * */ +#include "src/compiler/node_generator.h" + #include <map> #include "src/compiler/config.h" #include "src/compiler/generator_helpers.h" -#include "src/compiler/node_generator.h" #include "src/compiler/node_generator_helpers.h" using grpc::protobuf::Descriptor; diff --git a/contrib/libs/grpc/src/compiler/objective_c_generator.cc b/contrib/libs/grpc/src/compiler/objective_c_generator.cc index 07826b6a8d8..ec7b90f8a7a 100644 --- a/contrib/libs/grpc/src/compiler/objective_c_generator.cc +++ b/contrib/libs/grpc/src/compiler/objective_c_generator.cc @@ -16,16 +16,17 @@ * */ +#include "src/compiler/objective_c_generator.h" + #include <map> #include <set> #include <sstream> +#include <google/protobuf/compiler/objectivec/objectivec_helpers.h> + #include "src/compiler/config.h" -#include "src/compiler/objective_c_generator.h" #include "src/compiler/objective_c_generator_helpers.h" -#include <google/protobuf/compiler/objectivec/objectivec_helpers.h> - using ::google::protobuf::compiler::objectivec::ClassName; using ::grpc::protobuf::FileDescriptor; using ::grpc::protobuf::MethodDescriptor; diff --git a/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h b/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h index ae296741cec..c8336a3fc93 100644 --- a/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h +++ b/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h @@ -20,11 +20,12 @@ #define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H #include <map> -#include "src/compiler/config.h" -#include "src/compiler/generator_helpers.h" #include <google/protobuf/compiler/objectivec/objectivec_helpers.h> +#include "src/compiler/config.h" +#include "src/compiler/generator_helpers.h" + namespace grpc_objective_c_generator { using ::grpc::protobuf::FileDescriptor; @@ -37,7 +38,7 @@ inline string MessageHeaderName(const FileDescriptor* file) { inline string ServiceClassName(const ServiceDescriptor* service) { const FileDescriptor* file = service->file(); - string prefix = file->options().objc_class_prefix(); + string prefix = google::protobuf::compiler::objectivec::FileClassPrefix(file); return prefix + service->name(); } diff --git a/contrib/libs/grpc/src/compiler/php_generator.cc b/contrib/libs/grpc/src/compiler/php_generator.cc index b35d3f2a02e..a0c1ef9be1d 100644 --- a/contrib/libs/grpc/src/compiler/php_generator.cc +++ b/contrib/libs/grpc/src/compiler/php_generator.cc @@ -19,6 +19,7 @@ #include <map> #include <google/protobuf/compiler/php/php_generator.h> + #include "src/compiler/config.h" #include "src/compiler/generator_helpers.h" #include "src/compiler/php_generator_helpers.h" @@ -131,34 +132,177 @@ void PrintMethod(const MethodDescriptor* method, Printer* out) { out->Print("}\n\n"); } -// Prints out the service descriptor object -void PrintService(const ServiceDescriptor* service, - const TString& class_suffix, Printer* out) { +void PrintServerMethod(const MethodDescriptor* method, Printer* out) { map<TString, TString> vars; + const Descriptor* input_type = method->input_type(); + const Descriptor* output_type = method->output_type(); + vars["service_name"] = method->service()->full_name(); + vars["method_name"] = method->name(); + vars["input_type_id"] = + MessageIdentifierName(GeneratedClassName(input_type), input_type->file()); + vars["output_type_id"] = MessageIdentifierName( + GeneratedClassName(output_type), output_type->file()); + out->Print("/**\n"); - out->Print(GetPHPComments(service, " *").c_str()); - out->Print(" */\n"); - vars["name"] = GetPHPServiceClassname(service, class_suffix); - out->Print(vars, "class $name$ extends \\Grpc\\BaseStub {\n\n"); + out->Print(GetPHPComments(method, " *").c_str()); + + const char* method_template; + if (method->client_streaming() && method->server_streaming()) { + method_template = + " * @param \\Grpc\\ServerCallReader $$reader read client request data " + "of \\$input_type_id$\n" + " * @param \\Grpc\\ServerCallWriter $$writer write response data of " + "\\$output_type_id$\n" + " * @param \\Grpc\\ServerContext $$context server request context\n" + " * @return void\n" + " */\n" + "public function $method_name$(\n" + " \\Grpc\\ServerCallReader $$reader,\n" + " \\Grpc\\ServerCallWriter $$writer,\n" + " \\Grpc\\ServerContext $$context\n" + "): void {\n" + " $$context->setStatus(\\Grpc\\Status::unimplemented());\n" + " $$writer->finish();\n" + "}\n\n"; + } else if (method->client_streaming()) { + method_template = + " * @param \\Grpc\\ServerCallReader $$reader read client request data " + "of \\$input_type_id$\n" + " * @param \\Grpc\\ServerContext $$context server request context\n" + " * @return \\$output_type_id$ for response data, null if if error " + "occured\n" + " * initial metadata (if any) and status (if not ok) should be set " + "to $$context\n" + " */\n" + "public function $method_name$(\n" + " \\Grpc\\ServerCallReader $$reader,\n" + " \\Grpc\\ServerContext $$context\n" + "): ?\\$output_type_id$ {\n" + " $$context->setStatus(\\Grpc\\Status::unimplemented());\n" + " return null;\n" + "}\n\n"; + } else if (method->server_streaming()) { + method_template = + " * @param \\$input_type_id$ $$request client request\n" + " * @param \\Grpc\\ServerCallWriter $$writer write response data of " + "\\$output_type_id$\n" + " * @param \\Grpc\\ServerContext $$context server request context\n" + " * @return void\n" + " */\n" + "public function $method_name$(\n" + " \\$input_type_id$ $$request,\n" + " \\Grpc\\ServerCallWriter $$writer,\n" + " \\Grpc\\ServerContext $$context\n" + "): void {\n" + " $$context->setStatus(\\Grpc\\Status::unimplemented());\n" + " $$writer->finish();\n" + "}\n\n"; + } else { + method_template = + " * @param \\$input_type_id$ $$request client request\n" + " * @param \\Grpc\\ServerContext $$context server request context\n" + " * @return \\$output_type_id$ for response data, null if if error " + "occured\n" + " * initial metadata (if any) and status (if not ok) should be set " + "to $$context\n" + " */\n" + "public function $method_name$(\n" + " \\$input_type_id$ $$request,\n" + " \\Grpc\\ServerContext $$context\n" + "): ?\\$output_type_id$ {\n" + " $$context->setStatus(\\Grpc\\Status::unimplemented());\n" + " return null;\n" + "}\n\n"; + } + out->Print(vars, method_template); +} + +void PrintServerMethodDescriptors(const ServiceDescriptor* service, + Printer* out) { + map<TString, TString> vars; + vars["service_name"] = service->full_name(); + + out->Print( + "/**\n" + " * Get the method descriptors of the service for server registration\n" + " *\n" + " * @return array of \\Grpc\\MethodDescriptor for the service methods\n" + " */\n" + "public final function getMethodDescriptors(): array\n{\n"); out->Indent(); out->Indent(); - out->Print( - "/**\n * @param string $$hostname hostname\n" - " * @param array $$opts channel options\n" - " * @param \\Grpc\\Channel $$channel (optional) re-use channel " - "object\n */\n" - "public function __construct($$hostname, $$opts, " - "$$channel = null) {\n"); + out->Print("return [\n"); out->Indent(); out->Indent(); - out->Print("parent::__construct($$hostname, $$opts, $$channel);\n"); + for (int i = 0; i < service->method_count(); i++) { + auto method = service->method(i); + auto input_type = method->input_type(); + vars["method_name"] = method->name(); + vars["input_type_id"] = MessageIdentifierName( + GeneratedClassName(input_type), input_type->file()); + if (method->client_streaming() && method->server_streaming()) { + vars["call_type"] = "BIDI_STREAMING_CALL"; + } else if (method->client_streaming()) { + vars["call_type"] = "CLIENT_STREAMING_CALL"; + } else if (method->server_streaming()) { + vars["call_type"] = "SERVER_STREAMING_CALL"; + } else { + vars["call_type"] = "UNARY_CALL"; + } + out->Print( + vars, + "'/$service_name$/$method_name$' => new \\Grpc\\MethodDescriptor(\n" + " $$this,\n" + " '$method_name$',\n" + " '\\$input_type_id$',\n" + " \\Grpc\\MethodDescriptor::$call_type$\n" + "),\n"); + } + out->Outdent(); + out->Outdent(); + out->Print("];\n"); out->Outdent(); out->Outdent(); out->Print("}\n\n"); +} + +// Prints out the service descriptor object +void PrintService(const ServiceDescriptor* service, + const TString& class_suffix, bool is_server, + Printer* out) { + map<TString, TString> vars; + out->Print("/**\n"); + out->Print(GetPHPComments(service, " *").c_str()); + out->Print(" */\n"); + vars["name"] = GetPHPServiceClassname(service, class_suffix, is_server); + vars["extends"] = is_server ? "" : "extends \\Grpc\\BaseStub "; + out->Print(vars, "class $name$ $extends${\n\n"); + out->Indent(); + out->Indent(); + if (!is_server) { + out->Print( + "/**\n * @param string $$hostname hostname\n" + " * @param array $$opts channel options\n" + " * @param \\Grpc\\Channel $$channel (optional) re-use channel object\n" + " */\n" + "public function __construct($$hostname, $$opts, " + "$$channel = null) {\n"); + out->Indent(); + out->Indent(); + out->Print("parent::__construct($$hostname, $$opts, $$channel);\n"); + out->Outdent(); + out->Outdent(); + out->Print("}\n\n"); + } for (int i = 0; i < service->method_count(); i++) { - TString method_name = - grpc_generator::LowercaseFirstLetter(service->method(i)->name()); - PrintMethod(service->method(i), out); + if (is_server) { + PrintServerMethod(service->method(i), out); + } else { + PrintMethod(service->method(i), out); + } + } + if (is_server) { + PrintServerMethodDescriptors(service, out); } out->Outdent(); out->Outdent(); @@ -168,7 +312,7 @@ void PrintService(const ServiceDescriptor* service, TString GenerateFile(const FileDescriptor* file, const ServiceDescriptor* service, - const TString& class_suffix) { + const TString& class_suffix, bool is_server) { TString output; { StringOutputStream output_stream(&output); @@ -188,7 +332,7 @@ TString GenerateFile(const FileDescriptor* file, vars["package"] = php_namespace; out.Print(vars, "namespace $package$;\n\n"); - PrintService(service, class_suffix, &out); + PrintService(service, class_suffix, is_server, &out); } return output; } diff --git a/contrib/libs/grpc/src/compiler/php_generator_helpers.h b/contrib/libs/grpc/src/compiler/php_generator_helpers.h index 70a31eaf75e..93479e20a28 100644 --- a/contrib/libs/grpc/src/compiler/php_generator_helpers.h +++ b/contrib/libs/grpc/src/compiler/php_generator_helpers.h @@ -28,8 +28,10 @@ namespace grpc_php_generator { inline TString GetPHPServiceClassname( const grpc::protobuf::ServiceDescriptor* service, - const TString& class_suffix) { - return service->name() + (class_suffix == "" ? "Client" : class_suffix); + const TString& class_suffix, bool is_server) { + return service->name() + + (class_suffix == "" ? (is_server ? "" : "Client") : class_suffix) + + (is_server ? "Stub" : ""); } // ReplaceAll replaces all instances of search with replace in s. @@ -46,7 +48,7 @@ inline TString ReplaceAll(TString s, const TString& search, inline TString GetPHPServiceFilename( const grpc::protobuf::FileDescriptor* file, const grpc::protobuf::ServiceDescriptor* service, - const TString& class_suffix) { + const TString& class_suffix, bool is_server) { std::ostringstream oss; if (file->options().has_php_namespace()) { oss << ReplaceAll(file->options().php_namespace(), "\\", "/"); @@ -58,8 +60,8 @@ inline TString GetPHPServiceFilename( << grpc_generator::CapitalizeFirstLetter(tokens[i]); } } - return oss.str() + "/" + GetPHPServiceClassname(service, class_suffix) + - ".php"; + return oss.str() + "/" + + GetPHPServiceClassname(service, class_suffix, is_server) + ".php"; } // Get leading or trailing comments in a string. Comment lines start with "// ". diff --git a/contrib/libs/grpc/src/compiler/protobuf_plugin.h b/contrib/libs/grpc/src/compiler/protobuf_plugin.h index ef844ea0551..8e6b77a6e11 100644 --- a/contrib/libs/grpc/src/compiler/protobuf_plugin.h +++ b/contrib/libs/grpc/src/compiler/protobuf_plugin.h @@ -19,14 +19,14 @@ #ifndef GRPC_INTERNAL_COMPILER_PROTOBUF_PLUGIN_H #define GRPC_INTERNAL_COMPILER_PROTOBUF_PLUGIN_H +#include <vector> + #include "src/compiler/config.h" #include "src/compiler/cpp_generator_helpers.h" #include "src/compiler/python_generator_helpers.h" #include "src/compiler/python_private_generator.h" #include "src/compiler/schema_interface.h" -#include <vector> - // Get leading or trailing comments in a string. template <typename DescriptorType> inline TString GetCommentsHelper(const DescriptorType* desc, bool leading, diff --git a/contrib/libs/grpc/src/compiler/python_generator.cc b/contrib/libs/grpc/src/compiler/python_generator.cc index d083d19f0b3..b8ce31ca72e 100644 --- a/contrib/libs/grpc/src/compiler/python_generator.cc +++ b/contrib/libs/grpc/src/compiler/python_generator.cc @@ -16,6 +16,8 @@ * */ +#include "src/compiler/python_generator.h" + #include <algorithm> #include <cassert> #include <cctype> @@ -33,7 +35,6 @@ #include "src/compiler/config.h" #include "src/compiler/generator_helpers.h" #include "src/compiler/protobuf_plugin.h" -#include "src/compiler/python_generator.h" #include "src/compiler/python_generator_helpers.h" #include "src/compiler/python_private_generator.h" diff --git a/contrib/libs/grpc/src/compiler/python_generator.h b/contrib/libs/grpc/src/compiler/python_generator.h index bcde0a5e358..6d33969ba53 100644 --- a/contrib/libs/grpc/src/compiler/python_generator.h +++ b/contrib/libs/grpc/src/compiler/python_generator.h @@ -34,7 +34,7 @@ struct GeneratorConfiguration { TString grpc_package_root; // TODO(https://github.com/grpc/grpc/issues/8622): Drop this. TString beta_package_root; - // TODO(https://github.com/google/protobuf/issues/888): Drop this. + // TODO(https://github.com/protocolbuffers/protobuf/issues/888): Drop this. TString import_prefix; std::vector<TString> prefixes_to_filter; }; diff --git a/contrib/libs/grpc/src/compiler/python_generator_helpers.h b/contrib/libs/grpc/src/compiler/python_generator_helpers.h index b68ef915ef1..9138add02bf 100644 --- a/contrib/libs/grpc/src/compiler/python_generator_helpers.h +++ b/contrib/libs/grpc/src/compiler/python_generator_helpers.h @@ -61,7 +61,7 @@ static TString StripModulePrefixes( return raw_module_name; } -// TODO(https://github.com/google/protobuf/issues/888): +// TODO(https://github.com/protocolbuffers/protobuf/issues/888): // Export `ModuleName` from protobuf's // `src/google/protobuf/compiler/python/python_generator.cc` file. TString ModuleName(const TString& filename, @@ -74,7 +74,7 @@ TString ModuleName(const TString& filename, prefixes_to_filter); } -// TODO(https://github.com/google/protobuf/issues/888): +// TODO(https://github.com/protocolbuffers/protobuf/issues/888): // Export `ModuleAlias` from protobuf's // `src/google/protobuf/compiler/python/python_generator.cc` file. TString ModuleAlias(const TString& filename, diff --git a/contrib/libs/grpc/src/compiler/ruby_generator.cc b/contrib/libs/grpc/src/compiler/ruby_generator.cc index 0fba63735c8..f5b9e9db870 100644 --- a/contrib/libs/grpc/src/compiler/ruby_generator.cc +++ b/contrib/libs/grpc/src/compiler/ruby_generator.cc @@ -16,12 +16,13 @@ * */ +#include "src/compiler/ruby_generator.h" + #include <cctype> #include <map> #include <vector> #include "src/compiler/config.h" -#include "src/compiler/ruby_generator.h" #include "src/compiler/ruby_generator_helpers-inl.h" #include "src/compiler/ruby_generator_map-inl.h" #include "src/compiler/ruby_generator_string-inl.h" @@ -109,7 +110,7 @@ void PrintService(const ServiceDescriptor* service, Printer* out) { // ruby generator // to ensure compatibility (with the exception of int and string type changes). // See -// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/ruby/ruby_generator.cc#L250 +// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/ruby/ruby_generator.cc#L250 // TODO: keep up to date with protoc code generation, though this behavior isn't // expected to change bool IsLower(char ch) { return ch >= 'a' && ch <= 'z'; } diff --git a/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h b/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h index 4c75780b1a3..1221a5a7051 100644 --- a/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h +++ b/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h @@ -19,14 +19,14 @@ #ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H #define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H -#include "src/compiler/config.h" - #include <initializer_list> #include <iostream> #include <map> #include <ostream> // NOLINT #include <vector> +#include "src/compiler/config.h" + using std::initializer_list; using std::map; using std::vector; diff --git a/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h b/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h index 956539f392a..0df783023e1 100644 --- a/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h +++ b/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h @@ -19,12 +19,12 @@ #ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H #define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H -#include "src/compiler/config.h" - #include <algorithm> #include <sstream> #include <vector> +#include "src/compiler/config.h" + using std::getline; using std::transform; diff --git a/contrib/libs/grpc/src/compiler/schema_interface.h b/contrib/libs/grpc/src/compiler/schema_interface.h index 60b9d337e8d..361c62ea974 100644 --- a/contrib/libs/grpc/src/compiler/schema_interface.h +++ b/contrib/libs/grpc/src/compiler/schema_interface.h @@ -19,12 +19,12 @@ #ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H -#include "src/compiler/config.h" - #include <memory> #include <util/generic/string.h> #include <vector> +#include "src/compiler/config.h" + #ifdef GRPC_CUSTOM_STRING #warning GRPC_CUSTOM_STRING is no longer supported. Please use TString. #endif |
