diff --git a/src/compiler/config.h b/src/compiler/config.h index 1cbd842f0af..ba44cd8a31c 100644 --- a/src/compiler/config.h +++ b/src/compiler/config.h @@ -60,7 +60,8 @@ #ifndef GRPC_CUSTOM_PARSEGENERATORPARAMETER #include -#define GRPC_CUSTOM_PARSEGENERATORPARAMETER ::google::protobuf::compiler::ParseGeneratorParameter +#define GRPC_CUSTOM_PARSEGENERATORPARAMETER \ + ::google::protobuf::compiler::ParseGeneratorParameter #endif #ifndef GRPC_CUSTOM_STRING @@ -81,8 +82,8 @@ static inline int PluginMain(int argc, char* argv[], const CodeGenerator* generator) { return GRPC_CUSTOM_PLUGINMAIN(argc, argv, generator); } -static inline void ParseGeneratorParameter(const string& parameter, - std::vector >* options) { +static inline void ParseGeneratorParameter( + const string& parameter, std::vector >* options) { GRPC_CUSTOM_PARSEGENERATORPARAMETER(parameter, options); } diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 2288ba41636..c386115ec20 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -64,19 +64,22 @@ grpc::string FilenameIdentifier(const grpc::string &filename) { } } // namespace -template -T *array_end(T (&array)[N]) { return array + N; } +template +T *array_end(T (&array)[N]) { + return array + N; +} -void PrintIncludes(Printer *printer, const std::vector& headers, const Parameters ¶ms) { +void PrintIncludes(Printer *printer, const std::vector &headers, + const Parameters ¶ms) { std::map vars; vars["l"] = params.use_system_headers ? '<' : '"'; vars["r"] = params.use_system_headers ? '>' : '"'; - auto& s = params.grpc_search_path; + auto &s = params.grpc_search_path; if (!s.empty()) { vars["l"] += s; - if (s[s.size()-1] != '/') { + if (s[s.size() - 1] != '/') { vars["l"] += '/'; } } @@ -101,7 +104,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) { printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); printer->Print(vars, - "// If you make any local change, they will be lost.\n"); + "// If you make any local change, they will be lost.\n"); printer->Print(vars, "// source: $filename$\n"); grpc::string leading_comments = file->GetLeadingComments(); if (!leading_comments.empty()) { @@ -117,8 +120,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) { return output; } -grpc::string GetHeaderIncludes(File *file, - const Parameters ¶ms) { +grpc::string GetHeaderIncludes(File *file, const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -126,15 +128,14 @@ grpc::string GetHeaderIncludes(File *file, std::map vars; static const char *headers_strs[] = { - "grpc++/impl/codegen/async_stream.h", - "grpc++/impl/codegen/async_unary_call.h", - "grpc++/impl/codegen/proto_utils.h", - "grpc++/impl/codegen/rpc_method.h", - "grpc++/impl/codegen/service_type.h", - "grpc++/impl/codegen/status.h", - "grpc++/impl/codegen/stub_options.h", - "grpc++/impl/codegen/sync_stream.h" - }; + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/async_unary_call.h", + "grpc++/impl/codegen/proto_utils.h", + "grpc++/impl/codegen/rpc_method.h", + "grpc++/impl/codegen/service_type.h", + "grpc++/impl/codegen/status.h", + "grpc++/impl/codegen/stub_options.h", + "grpc++/impl/codegen/sync_stream.h"}; std::vector headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); printer->Print(vars, "\n"); @@ -309,8 +310,7 @@ void PrintHeaderClientMethodInterfaces( } } -void PrintHeaderClientMethod(Printer *printer, - const Method *method, +void PrintHeaderClientMethod(Printer *printer, const Method *method, std::map *vars, bool is_public) { (*vars)["Method"] = method->name(); @@ -490,10 +490,8 @@ void PrintHeaderServerMethodSync(Printer *printer, const Method *method, printer->Print(method->GetTrailingComments().c_str()); } -void PrintHeaderServerMethodAsync( - Printer *printer, - const Method *method, - std::map *vars) { +void PrintHeaderServerMethodAsync(Printer *printer, const Method *method, + std::map *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); (*vars)["Response"] = method->output_type_name(); @@ -607,8 +605,7 @@ void PrintHeaderServerMethodAsync( } void PrintHeaderServerMethodGeneric( - Printer *printer, - const Method *method, + Printer *printer, const Method *method, std::map *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); @@ -677,8 +674,7 @@ void PrintHeaderServerMethodGeneric( printer->Print(*vars, "};\n"); } -void PrintHeaderService(Printer *printer, - const Service *service, +void PrintHeaderService(Printer *printer, const Service *service, std::map *vars) { (*vars)["Service"] = service->name(); @@ -696,14 +692,16 @@ void PrintHeaderService(Printer *printer, printer->Print("virtual ~StubInterface() {}\n"); for (int i = 0; i < service->method_count(); ++i) { printer->Print(service->method(i)->GetLeadingComments().c_str()); - PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, true); + PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, + true); printer->Print(service->method(i)->GetTrailingComments().c_str()); } printer->Outdent(); printer->Print("private:\n"); printer->Indent(); for (int i = 0; i < service->method_count(); ++i) { - PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, false); + PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, + false); } printer->Outdent(); printer->Print("};\n"); @@ -711,7 +709,8 @@ void PrintHeaderService(Printer *printer, "class Stub GRPC_FINAL : public StubInterface" " {\n public:\n"); printer->Indent(); - printer->Print("Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);\n"); + printer->Print( + "Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);\n"); for (int i = 0; i < service->method_count(); ++i) { PrintHeaderClientMethod(printer, service->method(i).get(), vars, true); } @@ -776,8 +775,7 @@ void PrintHeaderService(Printer *printer, printer->Print(service->GetTrailingComments().c_str()); } -grpc::string GetHeaderServices(File *file, - const Parameters ¶ms) { +grpc::string GetHeaderServices(File *file, const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -849,7 +847,7 @@ grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) { printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n"); printer->Print(vars, - "// If you make any local change, they will be lost.\n"); + "// If you make any local change, they will be lost.\n"); printer->Print(vars, "// source: $filename$\n\n"); printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n"); @@ -860,8 +858,7 @@ grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) { return output; } -grpc::string GetSourceIncludes(File *file, - const Parameters ¶ms) { +grpc::string GetSourceIncludes(File *file, const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -869,15 +866,14 @@ grpc::string GetSourceIncludes(File *file, std::map vars; static const char *headers_strs[] = { - "grpc++/impl/codegen/async_stream.h", - "grpc++/impl/codegen/async_unary_call.h", - "grpc++/impl/codegen/channel_interface.h", - "grpc++/impl/codegen/client_unary_call.h", - "grpc++/impl/codegen/method_handler_impl.h", - "grpc++/impl/codegen/rpc_service_method.h", - "grpc++/impl/codegen/service_type.h", - "grpc++/impl/codegen/sync_stream.h" - }; + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/async_unary_call.h", + "grpc++/impl/codegen/channel_interface.h", + "grpc++/impl/codegen/client_unary_call.h", + "grpc++/impl/codegen/method_handler_impl.h", + "grpc++/impl/codegen/rpc_service_method.h", + "grpc++/impl/codegen/service_type.h", + "grpc++/impl/codegen/sync_stream.h"}; std::vector headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); @@ -895,8 +891,7 @@ grpc::string GetSourceIncludes(File *file, return output; } -void PrintSourceClientMethod(Printer *printer, - const Method *method, +void PrintSourceClientMethod(Printer *printer, const Method *method, std::map *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); @@ -996,8 +991,7 @@ void PrintSourceClientMethod(Printer *printer, } } -void PrintSourceServerMethod(Printer *printer, - const Method *method, +void PrintSourceServerMethod(Printer *printer, const Method *method, std::map *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); @@ -1055,8 +1049,7 @@ void PrintSourceServerMethod(Printer *printer, } } -void PrintSourceService(Printer *printer, - const Service *service, +void PrintSourceService(Printer *printer, const Service *service, std::map *vars) { (*vars)["Service"] = service->name(); @@ -1168,8 +1161,7 @@ void PrintSourceService(Printer *printer, } } -grpc::string GetSourceServices(File *file, - const Parameters ¶ms) { +grpc::string GetSourceServices(File *file, const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index fc0296cd282..38f8f738ed9 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -48,7 +48,7 @@ using grpc_cpp_generator::GetCppComments; class ProtoBufMethod : public grpc_cpp_generator::Method { public: ProtoBufMethod(const grpc::protobuf::MethodDescriptor *method) - : method_(method) {} + : method_(method) {} grpc::string name() const { return method_->name(); } @@ -90,14 +90,14 @@ class ProtoBufMethod : public grpc_cpp_generator::Method { class ProtoBufService : public grpc_cpp_generator::Service { public: ProtoBufService(const grpc::protobuf::ServiceDescriptor *service) - : service_(service) {} + : service_(service) {} grpc::string name() const { return service_->name(); } int method_count() const { return service_->method_count(); }; std::unique_ptr method(int i) const { return std::unique_ptr( - new ProtoBufMethod(service_->method(i))); + new ProtoBufMethod(service_->method(i))); }; grpc::string GetLeadingComments() const { @@ -115,7 +115,7 @@ class ProtoBufService : public grpc_cpp_generator::Service { class ProtoBufPrinter : public grpc_cpp_generator::Printer { public: ProtoBufPrinter(grpc::string *str) - : output_stream_(str), printer_(&output_stream_, '$') {} + : output_stream_(str), printer_(&output_stream_, '$') {} void Print(const std::map &vars, const char *string_template) { @@ -152,13 +152,14 @@ class ProtoBufFile : public grpc_cpp_generator::File { int service_count() const { return file_->service_count(); }; std::unique_ptr service(int i) const { - return std::unique_ptr ( - new ProtoBufService(file_->service(i))); + return std::unique_ptr( + new ProtoBufService(file_->service(i))); } - std::unique_ptr CreatePrinter(grpc::string *str) const { + std::unique_ptr CreatePrinter( + grpc::string *str) const { return std::unique_ptr( - new ProtoBufPrinter(str)); + new ProtoBufPrinter(str)); } grpc::string GetLeadingComments() const { @@ -197,12 +198,11 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { if (!parameter.empty()) { std::vector parameters_list = - grpc_generator::tokenize(parameter, ","); + grpc_generator::tokenize(parameter, ","); for (auto parameter_string = parameters_list.begin(); - parameter_string != parameters_list.end(); - parameter_string++) { + parameter_string != parameters_list.end(); parameter_string++) { std::vector param = - grpc_generator::tokenize(*parameter_string, "="); + grpc_generator::tokenize(*parameter_string, "="); if (param[0] == "services_namespace") { generator_parameters.services_namespace = param[1]; } else if (param[0] == "use_system_headers") { @@ -232,8 +232,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc_cpp_generator::GetHeaderEpilogue(&pbfile, generator_parameters); std::unique_ptr header_output( context->Open(file_name + ".grpc.pb.h")); - grpc::protobuf::io::CodedOutputStream header_coded_out( - header_output.get()); + grpc::protobuf::io::CodedOutputStream header_coded_out(header_output.get()); header_coded_out.WriteRaw(header_code.data(), header_code.size()); grpc::string source_code = @@ -243,8 +242,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc_cpp_generator::GetSourceEpilogue(&pbfile, generator_parameters); std::unique_ptr source_output( context->Open(file_name + ".grpc.pb.cc")); - grpc::protobuf::io::CodedOutputStream source_coded_out( - source_output.get()); + grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); return true; diff --git a/src/compiler/csharp_generator.cc b/src/compiler/csharp_generator.cc index f5a0876cf98..591e5ae3d42 100644 --- a/src/compiler/csharp_generator.cc +++ b/src/compiler/csharp_generator.cc @@ -36,11 +36,10 @@ #include #include -#include "src/compiler/csharp_generator.h" #include "src/compiler/config.h" -#include "src/compiler/csharp_generator_helpers.h" #include "src/compiler/csharp_generator.h" - +#include "src/compiler/csharp_generator.h" +#include "src/compiler/csharp_generator_helpers.h" using google::protobuf::compiler::csharp::GetFileNamespace; using google::protobuf::compiler::csharp::GetClassName; @@ -61,7 +60,6 @@ using grpc_generator::StringReplace; using std::map; using std::vector; - namespace grpc_csharp_generator { namespace { @@ -70,34 +68,43 @@ namespace { // 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. -void GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer, grpc::protobuf::SourceLocation location) { - grpc::string comments = location.leading_comments.empty() ? - location.trailing_comments : location.leading_comments; +void GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer *printer, + grpc::protobuf::SourceLocation location) { + grpc::string comments = location.leading_comments.empty() + ? location.trailing_comments + : location.leading_comments; if (comments.empty()) { return; } - // XML escaping... no need for apostrophes etc as the whole text is going to be a child + // XML escaping... no need for apostrophes etc as the whole text is going to + // be a child // node of a summary element, not part of an attribute. comments = grpc_generator::StringReplace(comments, "&", "&", true); comments = grpc_generator::StringReplace(comments, "<", "<", true); std::vector lines; grpc_generator::Split(comments, '\n', &lines); - // TODO: We really should work out which part to put in the summary and which to put in the remarks... - // but that needs to be part of a bigger effort to understand the markdown better anyway. + // TODO: We really should work out which part to put in the summary and which + // to put in the remarks... + // but that needs to be part of a bigger effort to understand the markdown + // better anyway. printer->Print("/// \n"); bool last_was_empty = false; - // We squash multiple blank lines down to one, and remove any trailing blank lines. We need - // to preserve the blank lines themselves, as this is relevant in the markdown. - // Note that we can't remove leading or trailing whitespace as *that's* relevant in markdown too. + // We squash multiple blank lines down to one, and remove any trailing blank + // lines. We need + // to preserve the blank lines themselves, as this is relevant in the + // markdown. + // Note that we can't remove leading or trailing whitespace as *that's* + // relevant in markdown too. // (We don't skip "just whitespace" lines, either.) - for (std::vector::iterator it = lines.begin(); it != lines.end(); ++it) { + for (std::vector::iterator it = lines.begin(); + it != lines.end(); ++it) { grpc::string line = *it; if (line.empty()) { last_was_empty = true; } else { if (last_was_empty) { - printer->Print("///\n"); + printer->Print("///\n"); } last_was_empty = false; printer->Print("/// $line$\n", "line", *it); @@ -107,23 +114,23 @@ void GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer, grpc::prot } template -void GenerateDocCommentBody( - grpc::protobuf::io::Printer* printer, const DescriptorType* descriptor) { +void GenerateDocCommentBody(grpc::protobuf::io::Printer *printer, + const DescriptorType *descriptor) { grpc::protobuf::SourceLocation location; if (descriptor->GetSourceLocation(&location)) { GenerateDocCommentBodyImpl(printer, location); } } -std::string GetServiceClassName(const ServiceDescriptor* service) { +std::string GetServiceClassName(const ServiceDescriptor *service) { return service->name(); } -std::string GetClientClassName(const ServiceDescriptor* service) { +std::string GetClientClassName(const ServiceDescriptor *service) { return service->name() + "Client"; } -std::string GetServerClassName(const ServiceDescriptor* service) { +std::string GetServerClassName(const ServiceDescriptor *service) { return service->name() + "Base"; } @@ -138,13 +145,11 @@ std::string GetCSharpMethodType(MethodType method_type) { case METHODTYPE_BIDI_STREAMING: return "MethodType.DuplexStreaming"; } - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; return ""; } -std::string GetServiceNameFieldName() { - return "__ServiceName"; -} +std::string GetServiceNameFieldName() { return "__ServiceName"; } std::string GetMarshallerFieldName(const Descriptor *message) { return "__Marshaller_" + message->name(); @@ -155,7 +160,7 @@ std::string GetMethodFieldName(const MethodDescriptor *method) { } std::string GetMethodRequestParamMaybe(const MethodDescriptor *method, - bool invocation_param=false) { + bool invocation_param = false) { if (method->client_streaming()) { return ""; } @@ -174,16 +179,16 @@ std::string GetMethodReturnTypeClient(const MethodDescriptor *method) { case METHODTYPE_NO_STREAMING: return "AsyncUnaryCall<" + GetClassName(method->output_type()) + ">"; case METHODTYPE_CLIENT_STREAMING: - return "AsyncClientStreamingCall<" + GetClassName(method->input_type()) - + ", " + GetClassName(method->output_type()) + ">"; + return "AsyncClientStreamingCall<" + GetClassName(method->input_type()) + + ", " + GetClassName(method->output_type()) + ">"; case METHODTYPE_SERVER_STREAMING: - return "AsyncServerStreamingCall<" + GetClassName(method->output_type()) - + ">"; + return "AsyncServerStreamingCall<" + GetClassName(method->output_type()) + + ">"; case METHODTYPE_BIDI_STREAMING: - return "AsyncDuplexStreamingCall<" + GetClassName(method->input_type()) - + ", " + GetClassName(method->output_type()) + ">"; + return "AsyncDuplexStreamingCall<" + GetClassName(method->input_type()) + + ", " + GetClassName(method->output_type()) + ">"; } - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; return ""; } @@ -194,10 +199,10 @@ std::string GetMethodRequestParamServer(const MethodDescriptor *method) { return GetClassName(method->input_type()) + " request"; case METHODTYPE_CLIENT_STREAMING: case METHODTYPE_BIDI_STREAMING: - return "IAsyncStreamReader<" + GetClassName(method->input_type()) - + "> requestStream"; + return "IAsyncStreamReader<" + GetClassName(method->input_type()) + + "> requestStream"; } - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; return ""; } @@ -205,12 +210,13 @@ std::string GetMethodReturnTypeServer(const MethodDescriptor *method) { switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: case METHODTYPE_CLIENT_STREAMING: - return "global::System.Threading.Tasks.Task<" + GetClassName(method->output_type()) + ">"; + return "global::System.Threading.Tasks.Task<" + + GetClassName(method->output_type()) + ">"; case METHODTYPE_SERVER_STREAMING: case METHODTYPE_BIDI_STREAMING: return "global::System.Threading.Tasks.Task"; } - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; return ""; } @@ -221,18 +227,19 @@ std::string GetMethodResponseStreamMaybe(const MethodDescriptor *method) { return ""; case METHODTYPE_SERVER_STREAMING: case METHODTYPE_BIDI_STREAMING: - return ", IServerStreamWriter<" + GetClassName(method->output_type()) - + "> responseStream"; + return ", IServerStreamWriter<" + GetClassName(method->output_type()) + + "> responseStream"; } - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; return ""; } // Gets vector of all messages used as input or output types. -std::vector GetUsedMessages( +std::vector GetUsedMessages( const ServiceDescriptor *service) { - std::set descriptor_set; - std::vector result; // vector is to maintain stable ordering + std::set descriptor_set; + std::vector + result; // vector is to maintain stable ordering for (int i = 0; i < service->method_count(); i++) { const MethodDescriptor *method = service->method(i); if (descriptor_set.find(method->input_type()) == descriptor_set.end()) { @@ -247,21 +254,25 @@ std::vector GetUsedMessages( return result; } -void GenerateMarshallerFields(Printer* out, const ServiceDescriptor *service) { - std::vector used_messages = GetUsedMessages(service); +void GenerateMarshallerFields(Printer *out, const ServiceDescriptor *service) { + std::vector used_messages = GetUsedMessages(service); for (size_t i = 0; i < used_messages.size(); i++) { const Descriptor *message = used_messages[i]; out->Print( - "static readonly Marshaller<$type$> $fieldname$ = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), $type$.Parser.ParseFrom);\n", + "static readonly Marshaller<$type$> $fieldname$ = " + "Marshallers.Create((arg) => " + "global::Google.Protobuf.MessageExtensions.ToByteArray(arg), " + "$type$.Parser.ParseFrom);\n", "fieldname", GetMarshallerFieldName(message), "type", GetClassName(message)); } out->Print("\n"); } -void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) { +void GenerateStaticMethodField(Printer *out, const MethodDescriptor *method) { out->Print( - "static readonly Method<$request$, $response$> $fieldname$ = new Method<$request$, $response$>(\n", + "static readonly Method<$request$, $response$> $fieldname$ = new " + "Method<$request$, $response$>(\n", "fieldname", GetMethodFieldName(method), "request", GetClassName(method->input_type()), "response", GetClassName(method->output_type())); @@ -270,7 +281,7 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) { out->Print("$methodtype$,\n", "methodtype", GetCSharpMethodType(GetMethodType(method))); out->Print("$servicenamefield$,\n", "servicenamefield", - GetServiceNameFieldName()); + GetServiceNameFieldName()); out->Print("\"$methodname$\",\n", "methodname", method->name()); out->Print("$requestmarshaller$,\n", "requestmarshaller", GetMarshallerFieldName(method->input_type())); @@ -281,11 +292,14 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) { out->Outdent(); } -void GenerateServiceDescriptorProperty(Printer* out, const ServiceDescriptor *service) { +void GenerateServiceDescriptorProperty(Printer *out, + const ServiceDescriptor *service) { std::ostringstream index; index << service->index(); out->Print("/// Service descriptor\n"); - out->Print("public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor\n"); + out->Print( + "public static global::Google.Protobuf.Reflection.ServiceDescriptor " + "Descriptor\n"); out->Print("{\n"); out->Print(" get { return $umbrella$.Descriptor.Services[$index$]; }\n", "umbrella", GetReflectionClassName(service->file()), "index", @@ -294,9 +308,11 @@ void GenerateServiceDescriptorProperty(Printer* out, const ServiceDescriptor *se out->Print("\n"); } -void GenerateServerClass(Printer* out, const ServiceDescriptor *service) { - out->Print("/// Base class for server-side implementations of $servicename$\n", - "servicename", GetServiceClassName(service)); +void GenerateServerClass(Printer *out, const ServiceDescriptor *service) { + out->Print( + "/// Base class for server-side implementations of " + "$servicename$\n", + "servicename", GetServiceClassName(service)); out->Print("public abstract class $name$\n", "name", GetServerClassName(service)); out->Print("{\n"); @@ -305,7 +321,8 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor *service) { const MethodDescriptor *method = service->method(i); GenerateDocCommentBody(out, method); out->Print( - "public virtual $returntype$ $methodname$($request$$response_stream_maybe$, " + "public virtual $returntype$ " + "$methodname$($request$$response_stream_maybe$, " "ServerCallContext context)\n", "methodname", method->name(), "returntype", GetMethodReturnTypeServer(method), "request", @@ -313,8 +330,9 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor *service) { GetMethodResponseStreamMaybe(method)); out->Print("{\n"); out->Indent(); - out->Print("throw new RpcException(" - "new Status(StatusCode.Unimplemented, \"\"));\n"); + out->Print( + "throw new RpcException(" + "new Status(StatusCode.Unimplemented, \"\"));\n"); out->Outdent(); out->Print("}\n\n"); } @@ -323,41 +341,49 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor *service) { out->Print("\n"); } -void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { - out->Print("/// Client for $servicename$\n", - "servicename", GetServiceClassName(service)); - out->Print( - "public class $name$ : ClientBase<$name$>\n", - "name", GetClientClassName(service)); +void GenerateClientStub(Printer *out, const ServiceDescriptor *service) { + out->Print("/// Client for $servicename$\n", "servicename", + GetServiceClassName(service)); + out->Print("public class $name$ : ClientBase<$name$>\n", "name", + GetClientClassName(service)); out->Print("{\n"); out->Indent(); // constructors - out->Print("/// Creates a new client for $servicename$\n" - "/// The channel to use to make remote calls.\n", - "servicename", GetServiceClassName(service)); - out->Print("public $name$(Channel channel) : base(channel)\n", - "name", GetClientClassName(service)); + out->Print( + "/// Creates a new client for $servicename$\n" + "/// The channel to use to make remote " + "calls.\n", + "servicename", GetServiceClassName(service)); + out->Print("public $name$(Channel channel) : base(channel)\n", "name", + GetClientClassName(service)); out->Print("{\n"); out->Print("}\n"); - out->Print("/// Creates a new client for $servicename$ that uses a custom CallInvoker.\n" - "/// The callInvoker to use to make remote calls.\n", - "servicename", GetServiceClassName(service)); + out->Print( + "/// Creates a new client for $servicename$ that uses a custom " + "CallInvoker.\n" + "/// The callInvoker to use to make remote " + "calls.\n", + "servicename", GetServiceClassName(service)); out->Print("public $name$(CallInvoker callInvoker) : base(callInvoker)\n", "name", GetClientClassName(service)); out->Print("{\n"); out->Print("}\n"); - out->Print("/// Protected parameterless constructor to allow creation" - " of test doubles.\n"); - out->Print("protected $name$() : base()\n", - "name", GetClientClassName(service)); + out->Print( + "/// Protected parameterless constructor to allow creation" + " of test doubles.\n"); + out->Print("protected $name$() : base()\n", "name", + GetClientClassName(service)); out->Print("{\n"); out->Print("}\n"); - out->Print("/// Protected constructor to allow creation of configured clients.\n" - "/// The client configuration.\n"); - out->Print("protected $name$(ClientBaseConfiguration configuration)" - " : base(configuration)\n", - "name", GetClientClassName(service)); + out->Print( + "/// Protected constructor to allow creation of configured " + "clients.\n" + "/// The client configuration.\n"); + out->Print( + "protected $name$(ClientBaseConfiguration configuration)" + " : base(configuration)\n", + "name", GetClientClassName(service)); out->Print("{\n"); out->Print("}\n\n"); @@ -368,27 +394,36 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { if (method_type == METHODTYPE_NO_STREAMING) { // unary calls have an extra synchronous stub method GenerateDocCommentBody(out, method); - out->Print("public virtual $response$ $methodname$($request$ request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))\n", + out->Print( + "public virtual $response$ $methodname$($request$ request, Metadata " + "headers = null, DateTime? deadline = null, CancellationToken " + "cancellationToken = default(CancellationToken))\n", "methodname", method->name(), "request", GetClassName(method->input_type()), "response", GetClassName(method->output_type())); out->Print("{\n"); out->Indent(); - out->Print("return $methodname$(request, new CallOptions(headers, deadline, cancellationToken));\n", - "methodname", method->name()); + out->Print( + "return $methodname$(request, new CallOptions(headers, deadline, " + "cancellationToken));\n", + "methodname", method->name()); out->Outdent(); out->Print("}\n"); // overload taking CallOptions as a param GenerateDocCommentBody(out, method); - out->Print("public virtual $response$ $methodname$($request$ request, CallOptions options)\n", + out->Print( + "public virtual $response$ $methodname$($request$ request, " + "CallOptions options)\n", "methodname", method->name(), "request", GetClassName(method->input_type()), "response", GetClassName(method->output_type())); out->Print("{\n"); out->Indent(); - out->Print("return CallInvoker.BlockingUnaryCall($methodfield$, null, options, request);\n", - "methodfield", GetMethodFieldName(method)); + out->Print( + "return CallInvoker.BlockingUnaryCall($methodfield$, null, options, " + "request);\n", + "methodfield", GetMethodFieldName(method)); out->Outdent(); out->Print("}\n"); } @@ -399,23 +434,28 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { } GenerateDocCommentBody(out, method); out->Print( - "public virtual $returntype$ $methodname$($request_maybe$Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))\n", - "methodname", method_name, "request_maybe", - GetMethodRequestParamMaybe(method), "returntype", - GetMethodReturnTypeClient(method)); + "public virtual $returntype$ $methodname$($request_maybe$Metadata " + "headers = null, DateTime? deadline = null, CancellationToken " + "cancellationToken = default(CancellationToken))\n", + "methodname", method_name, "request_maybe", + GetMethodRequestParamMaybe(method), "returntype", + GetMethodReturnTypeClient(method)); out->Print("{\n"); out->Indent(); - out->Print("return $methodname$($request_maybe$new CallOptions(headers, deadline, cancellationToken));\n", - "methodname", method_name, - "request_maybe", GetMethodRequestParamMaybe(method, true)); + out->Print( + "return $methodname$($request_maybe$new CallOptions(headers, deadline, " + "cancellationToken));\n", + "methodname", method_name, "request_maybe", + GetMethodRequestParamMaybe(method, true)); out->Outdent(); out->Print("}\n"); // overload taking CallOptions as a param GenerateDocCommentBody(out, method); out->Print( - "public virtual $returntype$ $methodname$($request_maybe$CallOptions options)\n", + "public virtual $returntype$ $methodname$($request_maybe$CallOptions " + "options)\n", "methodname", method_name, "request_maybe", GetMethodRequestParamMaybe(method), "returntype", GetMethodReturnTypeClient(method)); @@ -423,36 +463,45 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { out->Indent(); switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: - out->Print("return CallInvoker.AsyncUnaryCall($methodfield$, null, options, request);\n", - "methodfield", GetMethodFieldName(method)); + out->Print( + "return CallInvoker.AsyncUnaryCall($methodfield$, null, options, " + "request);\n", + "methodfield", GetMethodFieldName(method)); break; case METHODTYPE_CLIENT_STREAMING: - out->Print("return CallInvoker.AsyncClientStreamingCall($methodfield$, null, options);\n", - "methodfield", GetMethodFieldName(method)); + out->Print( + "return CallInvoker.AsyncClientStreamingCall($methodfield$, null, " + "options);\n", + "methodfield", GetMethodFieldName(method)); break; case METHODTYPE_SERVER_STREAMING: out->Print( - "return CallInvoker.AsyncServerStreamingCall($methodfield$, null, options, request);\n", + "return CallInvoker.AsyncServerStreamingCall($methodfield$, null, " + "options, request);\n", "methodfield", GetMethodFieldName(method)); break; case METHODTYPE_BIDI_STREAMING: - out->Print("return CallInvoker.AsyncDuplexStreamingCall($methodfield$, null, options);\n", - "methodfield", GetMethodFieldName(method)); + out->Print( + "return CallInvoker.AsyncDuplexStreamingCall($methodfield$, null, " + "options);\n", + "methodfield", GetMethodFieldName(method)); break; default: - GOOGLE_LOG(FATAL)<< "Can't get here."; + GOOGLE_LOG(FATAL) << "Can't get here."; } out->Outdent(); out->Print("}\n"); } // override NewInstance method - out->Print("protected override $name$ NewInstance(ClientBaseConfiguration configuration)\n", - "name", GetClientClassName(service)); + out->Print( + "protected override $name$ NewInstance(ClientBaseConfiguration " + "configuration)\n", + "name", GetClientClassName(service)); out->Print("{\n"); out->Indent(); - out->Print("return new $name$(configuration);\n", - "name", GetClientClassName(service)); + out->Print("return new $name$(configuration);\n", "name", + GetClientClassName(service)); out->Outdent(); out->Print("}\n"); @@ -461,11 +510,13 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) { out->Print("\n"); } -void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service) { +void GenerateBindServiceMethod(Printer *out, const ServiceDescriptor *service) { out->Print( - "/// Creates service definition that can be registered with a server\n"); + "/// Creates service definition that can be registered with a " + "server\n"); out->Print( - "public static ServerServiceDefinition BindService($implclass$ serviceImpl)\n", + "public static ServerServiceDefinition BindService($implclass$ " + "serviceImpl)\n", "implclass", GetServerClassName(service)); out->Print("{\n"); out->Indent(); @@ -491,7 +542,7 @@ void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service) { out->Print("\n"); } -void GenerateService(Printer* out, const ServiceDescriptor *service, +void GenerateService(Printer *out, const ServiceDescriptor *service, bool generate_client, bool generate_server, bool internal_access) { GenerateDocCommentBody(out, service); diff --git a/src/compiler/csharp_generator_helpers.h b/src/compiler/csharp_generator_helpers.h index 9bdf6fb5356..f5d36f257a2 100644 --- a/src/compiler/csharp_generator_helpers.h +++ b/src/compiler/csharp_generator_helpers.h @@ -41,14 +41,16 @@ namespace grpc_csharp_generator { inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file, grpc::string *file_name_or_error) { - *file_name_or_error = grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs"; + *file_name_or_error = + grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs"; return true; } // Get leading or trailing comments in a string. Comment lines start with "// ". // Leading detached comments are put in in front of leading comments. template -inline grpc::string GetCsharpComments(const DescriptorType *desc, bool leading) { +inline grpc::string GetCsharpComments(const DescriptorType *desc, + bool leading) { return grpc_generator::GetPrefixedComments(desc, leading, "//"); } diff --git a/src/compiler/csharp_plugin.cc b/src/compiler/csharp_plugin.cc index 5350e73f108..7def72c54c7 100644 --- a/src/compiler/csharp_plugin.cc +++ b/src/compiler/csharp_plugin.cc @@ -67,10 +67,8 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { } } - grpc::string code = grpc_csharp_generator::GetServices(file, - generate_client, - generate_server, - internal_access); + grpc::string code = grpc_csharp_generator::GetServices( + file, generate_client, generate_server, internal_access); if (code.size() == 0) { return true; // don't generate a file if there are no services } diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h index 9a88c2bfccd..88d96c00809 100644 --- a/src/compiler/generator_helpers.h +++ b/src/compiler/generator_helpers.h @@ -84,7 +84,7 @@ inline grpc::string StringReplace(grpc::string str, const grpc::string &from, } str.replace(pos, from.length(), to); pos += to.length(); - } while(replace_all); + } while (replace_all); return str; } @@ -139,8 +139,8 @@ inline grpc::string LowerUnderscoreToUpperCamel(grpc::string str) { return result; } -inline grpc::string FileNameInUpperCamel(const grpc::protobuf::FileDescriptor *file, - bool include_package_path) { +inline grpc::string FileNameInUpperCamel( + const grpc::protobuf::FileDescriptor *file, bool include_package_path) { std::vector tokens = tokenize(StripProto(file->name()), "/"); grpc::string result = ""; if (include_package_path) { @@ -152,7 +152,8 @@ inline grpc::string FileNameInUpperCamel(const grpc::protobuf::FileDescriptor *f return result; } -inline grpc::string FileNameInUpperCamel(const grpc::protobuf::FileDescriptor *file) { +inline grpc::string FileNameInUpperCamel( + const grpc::protobuf::FileDescriptor *file) { return FileNameInUpperCamel(file, true); } @@ -163,7 +164,8 @@ enum MethodType { METHODTYPE_BIDI_STREAMING }; -inline MethodType GetMethodType(const grpc::protobuf::MethodDescriptor *method) { +inline MethodType GetMethodType( + const grpc::protobuf::MethodDescriptor *method) { if (method->client_streaming()) { if (method->server_streaming()) { return METHODTYPE_BIDI_STREAMING; @@ -254,7 +256,7 @@ inline grpc::string GenerateCommentsWithPrefix( const std::vector &in, const grpc::string &prefix) { std::ostringstream oss; for (auto it = in.begin(); it != in.end(); it++) { - const grpc::string& elem = *it; + const grpc::string &elem = *it; if (elem.empty()) { oss << prefix << "\n"; } else if (elem[0] == ' ') { diff --git a/src/compiler/node_generator.cc b/src/compiler/node_generator.cc index 1fe090d17af..c3852020a3a 100644 --- a/src/compiler/node_generator.cc +++ b/src/compiler/node_generator.cc @@ -67,15 +67,15 @@ grpc::string ModuleAlias(const grpc::string filename) { // Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript // message file foo/bar/baz.js -grpc::string GetJSMessageFilename(const grpc::string& filename) { +grpc::string GetJSMessageFilename(const grpc::string &filename) { grpc::string name = filename; return grpc_generator::StripProto(name) + "_pb.js"; } // Given a filename like foo/bar/baz.proto, returns the root directory // path ../../ -grpc::string GetRootPath(const grpc::string& from_filename, - const grpc::string& to_filename) { +grpc::string GetRootPath(const grpc::string &from_filename, + const grpc::string &to_filename) { if (to_filename.find("google/protobuf") == 0) { // Well-known types (.proto files in the google/protobuf directory) are // assumed to come from the 'google-protobuf' npm package. We may want to @@ -96,21 +96,24 @@ grpc::string GetRootPath(const grpc::string& from_filename, // Return the relative path to load to_file from the directory containing // from_file, assuming that both paths are relative to the same directory -grpc::string GetRelativePath(const grpc::string& from_file, - const grpc::string& to_file) { +grpc::string GetRelativePath(const grpc::string &from_file, + const grpc::string &to_file) { return GetRootPath(from_file, to_file) + to_file; } /* Finds all message types used in all services in the file, and returns them * as a map of fully qualified message type name to message descriptor */ -map GetAllMessages(const FileDescriptor *file) { - map message_types; - for (int service_num = 0; service_num < file->service_count(); service_num++) { - const ServiceDescriptor* service = file->service(service_num); - for (int method_num = 0; method_num < service->method_count(); method_num++) { - const MethodDescriptor* method = service->method(method_num); - const Descriptor* input_type = method->input_type(); - const Descriptor* output_type = method->output_type(); +map GetAllMessages( + const FileDescriptor *file) { + map message_types; + for (int service_num = 0; service_num < file->service_count(); + service_num++) { + const ServiceDescriptor *service = file->service(service_num); + for (int method_num = 0; method_num < service->method_count(); + method_num++) { + const MethodDescriptor *method = service->method(method_num); + const Descriptor *input_type = method->input_type(); + const Descriptor *output_type = method->output_type(); message_types[input_type->name()] = input_type; message_types[output_type->name()] = output_type; } @@ -118,7 +121,7 @@ map GetAllMessages(const FileDescriptor *file) return message_types; } -grpc::string MessageIdentifierName(const grpc::string& name) { +grpc::string MessageIdentifierName(const grpc::string &name) { return grpc_generator::StringReplace(name, ".", "_"); } @@ -194,18 +197,18 @@ void PrintService(const ServiceDescriptor *service, Printer *out) { out->Print(template_vars, "var $name$Service = exports.$name$Service = {\n"); out->Indent(); for (int i = 0; i < service->method_count(); i++) { - grpc::string method_name = grpc_generator::LowercaseFirstLetter( - service->method(i)->name()); + grpc::string method_name = + grpc_generator::LowercaseFirstLetter(service->method(i)->name()); out->Print(GetNodeComments(service->method(i), true).c_str()); - out->Print("$method_name$: ", - "method_name", method_name); + out->Print("$method_name$: ", "method_name", method_name); PrintMethod(service->method(i), out); out->Print(",\n"); out->Print(GetNodeComments(service->method(i), false).c_str()); } out->Outdent(); out->Print("};\n\n"); - out->Print(template_vars, "exports.$name$Client = " + out->Print(template_vars, + "exports.$name$Client = " "grpc.makeGenericClientConstructor($name$Service);\n"); out->Print(GetNodeComments(service, false).c_str()); } @@ -213,27 +216,25 @@ void PrintService(const ServiceDescriptor *service, Printer *out) { void PrintImports(const FileDescriptor *file, Printer *out) { out->Print("var grpc = require('grpc');\n"); if (file->message_type_count() > 0) { - grpc::string file_path = GetRelativePath(file->name(), - GetJSMessageFilename( - file->name())); - out->Print("var $module_alias$ = require('$file_path$');\n", - "module_alias", ModuleAlias(file->name()), - "file_path", file_path); + grpc::string file_path = + GetRelativePath(file->name(), GetJSMessageFilename(file->name())); + out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias", + ModuleAlias(file->name()), "file_path", file_path); } for (int i = 0; i < file->dependency_count(); i++) { grpc::string file_path = GetRelativePath( file->name(), GetJSMessageFilename(file->dependency(i)->name())); - out->Print("var $module_alias$ = require('$file_path$');\n", - "module_alias", ModuleAlias(file->dependency(i)->name()), - "file_path", file_path); + out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias", + ModuleAlias(file->dependency(i)->name()), "file_path", + file_path); } out->Print("\n"); } void PrintTransformers(const FileDescriptor *file, Printer *out) { - map messages = GetAllMessages(file); - for (std::map::iterator it = + map messages = GetAllMessages(file); + for (std::map::iterator it = messages.begin(); it != messages.end(); it++) { PrintMessageTransformer(it->second, out); @@ -246,7 +247,6 @@ void PrintServices(const FileDescriptor *file, Printer *out) { PrintService(file->service(i), out); } } - } grpc::string GenerateFile(const FileDescriptor *file) { diff --git a/src/compiler/node_generator_helpers.h b/src/compiler/node_generator_helpers.h index 5862772841c..efe94ab00d6 100644 --- a/src/compiler/node_generator_helpers.h +++ b/src/compiler/node_generator_helpers.h @@ -48,7 +48,7 @@ inline grpc::string GetJSServiceFilename(const grpc::string& filename) { // Get leading or trailing comments in a string. Comment lines start with "// ". // Leading detached comments are put in in front of leading comments. template -inline grpc::string GetNodeComments(const DescriptorType *desc, bool leading) { +inline grpc::string GetNodeComments(const DescriptorType* desc, bool leading) { return grpc_generator::GetPrefixedComments(desc, leading, "//"); } diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 4be8cb41879..1d7faf120dc 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -49,9 +49,9 @@ using ::std::map; namespace grpc_objective_c_generator { namespace { -void PrintProtoRpcDeclarationAsPragma(Printer *printer, - const MethodDescriptor *method, - map< ::grpc::string, ::grpc::string> vars) { +void PrintProtoRpcDeclarationAsPragma( + Printer *printer, const MethodDescriptor *method, + map< ::grpc::string, ::grpc::string> vars) { vars["client_stream"] = method->client_streaming() ? "stream " : ""; vars["server_stream"] = method->server_streaming() ? "stream " : ""; @@ -61,7 +61,7 @@ void PrintProtoRpcDeclarationAsPragma(Printer *printer, } template -static void PrintAllComments(const DescriptorType* desc, Printer* printer) { +static void PrintAllComments(const DescriptorType *desc, Printer *printer) { std::vector comments; grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED, &comments); @@ -100,7 +100,8 @@ void PrintMethodSignature(Printer *printer, const MethodDescriptor *method, if (method->server_streaming()) { printer->Print(vars, " eventHandler:(void(^)(BOOL done, " - "$response_class$ *_Nullable response, NSError *_Nullable error))eventHandler"); + "$response_class$ *_Nullable response, NSError *_Nullable " + "error))eventHandler"); } else { printer->Print(vars, " handler:(void(^)($response_class$ *_Nullable response, " @@ -123,7 +124,8 @@ void PrintAdvancedSignature(Printer *printer, const MethodDescriptor *method, PrintMethodSignature(printer, method, vars); } -inline map< ::grpc::string, ::grpc::string> GetMethodVars(const MethodDescriptor *method) { +inline map< ::grpc::string, ::grpc::string> GetMethodVars( + const MethodDescriptor *method) { map< ::grpc::string, ::grpc::string> res; res["method_name"] = method->name(); res["request_type"] = method->input_type()->name(); @@ -210,7 +212,8 @@ void PrintMethodImplementations(Printer *printer, grpc::protobuf::io::StringOutputStream output_stream(&output); Printer printer(&output_stream, '$'); - map< ::grpc::string, ::grpc::string> vars = {{"service_class", ServiceClassName(service)}}; + map< ::grpc::string, ::grpc::string> vars = { + {"service_class", ServiceClassName(service)}}; printer.Print(vars, "@protocol $service_class$ \n\n"); @@ -237,21 +240,23 @@ void PrintMethodImplementations(Printer *printer, } ::grpc::string GetSource(const ServiceDescriptor *service) { - ::grpc::string output; + ::grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. grpc::protobuf::io::StringOutputStream output_stream(&output); Printer printer(&output_stream, '$'); - map< ::grpc::string,::grpc::string> vars = {{"service_name", service->name()}, - {"service_class", ServiceClassName(service)}, - {"package", service->file()->package()}}; + map< ::grpc::string, ::grpc::string> vars = { + {"service_name", service->name()}, + {"service_class", ServiceClassName(service)}, + {"package", service->file()->package()}}; printer.Print(vars, "@implementation $service_class$\n\n"); printer.Print("// Designated initializer\n"); printer.Print("- (instancetype)initWithHost:(NSString *)host {\n"); - printer.Print(vars, + printer.Print( + vars, " return (self = [super initWithHost:host" " packageName:@\"$package$\" serviceName:@\"$service_name$\"]);\n"); printer.Print("}\n\n"); diff --git a/src/compiler/objective_c_generator_helpers.h b/src/compiler/objective_c_generator_helpers.h index 1f8c80014f0..b482f028a10 100644 --- a/src/compiler/objective_c_generator_helpers.h +++ b/src/compiler/objective_c_generator_helpers.h @@ -53,6 +53,5 @@ inline string ServiceClassName(const ServiceDescriptor *service) { string prefix = file->options().objc_class_prefix(); return prefix + service->name(); } - } #endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index be647764024..8de0997ebea 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -42,7 +42,8 @@ #include using ::google::protobuf::compiler::objectivec::ProtobufLibraryFrameworkName; -using ::google::protobuf::compiler::objectivec::IsProtobufLibraryBundledProtoFile; +using ::google::protobuf::compiler::objectivec:: + IsProtobufLibraryBundledProtoFile; class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { public: @@ -53,7 +54,6 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { const ::grpc::string ¶meter, grpc::protobuf::compiler::GeneratorContext *context, ::grpc::string *error) const { - if (file->service_count() == 0) { // No services. Do nothing. return true; @@ -66,29 +66,32 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { // Generate .pbrpc.h ::grpc::string imports = ::grpc::string("#import \"") + file_name + - ".pbobjc.h\"\n\n" - "#import \n" - "#import \n" - "#import \n"; + ".pbobjc.h\"\n\n" + "#import \n" + "#import \n" + "#import \n"; // TODO(jcanizales): Instead forward-declare the input and output types // and import the files in the .pbrpc.m ::grpc::string proto_imports; for (int i = 0; i < file->dependency_count(); i++) { - ::grpc::string header = grpc_objective_c_generator::MessageHeaderName( - file->dependency(i)); + ::grpc::string header = + grpc_objective_c_generator::MessageHeaderName(file->dependency(i)); const grpc::protobuf::FileDescriptor *dependency = file->dependency(i); if (IsProtobufLibraryBundledProtoFile(dependency)) { ::grpc::string base_name = header; grpc_generator::StripPrefix(&base_name, "google/protobuf/"); // create the import code snippet proto_imports += - "#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS\n" - " #import <" + ::grpc::string(ProtobufLibraryFrameworkName) + - "/" + base_name + ">\n" - "#else\n" - " #import \"" + header + "\"\n" - "#endif\n"; + "#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS\n" + " #import <" + + ::grpc::string(ProtobufLibraryFrameworkName) + "/" + base_name + + ">\n" + "#else\n" + " #import \"" + + header + + "\"\n" + "#endif\n"; } else { proto_imports += ::grpc::string("#import \"") + header + "\"\n"; } @@ -100,21 +103,22 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { declarations += grpc_objective_c_generator::GetHeader(service); } - static const ::grpc::string kNonNullBegin = "\nNS_ASSUME_NONNULL_BEGIN\n\n"; + static const ::grpc::string kNonNullBegin = + "\nNS_ASSUME_NONNULL_BEGIN\n\n"; static const ::grpc::string kNonNullEnd = "\nNS_ASSUME_NONNULL_END\n"; - Write(context, file_name + ".pbrpc.h", - imports + '\n' + proto_imports + '\n' + kNonNullBegin + - declarations + kNonNullEnd); + Write(context, file_name + ".pbrpc.h", imports + '\n' + proto_imports + + '\n' + kNonNullBegin + + declarations + kNonNullEnd); } { // Generate .pbrpc.m ::grpc::string imports = ::grpc::string("#import \"") + file_name + - ".pbrpc.h\"\n\n" - "#import \n" - "#import \n"; + ".pbrpc.h\"\n\n" + "#import \n" + "#import \n"; ::grpc::string definitions; for (int i = 0; i < file->service_count(); i++) { @@ -131,7 +135,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { private: // Write the given code into the given file. void Write(grpc::protobuf::compiler::GeneratorContext *context, - const ::grpc::string &filename, const ::grpc::string &code) const { + const ::grpc::string &filename, const ::grpc::string &code) const { std::unique_ptr output( context->Open(filename)); grpc::protobuf::io::CodedOutputStream coded_out(output.get()); diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc index c5f1ed80611..0f61b1fb6c0 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -74,16 +74,18 @@ PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config) PythonGrpcGenerator::~PythonGrpcGenerator() {} -bool PythonGrpcGenerator::Generate( - const FileDescriptor* file, const grpc::string& parameter, - GeneratorContext* context, grpc::string* error) const { +bool PythonGrpcGenerator::Generate(const FileDescriptor* file, + const grpc::string& parameter, + GeneratorContext* context, + grpc::string* error) const { // Get output file name. grpc::string file_name; static const int proto_suffix_length = strlen(".proto"); if (file->name().size() > static_cast(proto_suffix_length) && file->name().find_last_of(".proto") == file->name().size() - 1) { - file_name = file->name().substr( - 0, file->name().size() - proto_suffix_length) + "_pb2.py"; + file_name = + file->name().substr(0, file->name().size() - proto_suffix_length) + + "_pb2.py"; } else { *error = "Invalid proto file name. Proto file must end with .proto"; return false; @@ -115,7 +117,7 @@ map ListToDict( assert(values.size() % 2 == 0); map value_map; auto value_iter = values.begin(); - for (unsigned i = 0; i < values.size()/2; ++i) { + for (unsigned i = 0; i < values.size() / 2; ++i) { grpc::string key = *value_iter; ++value_iter; grpc::string value = *value_iter; @@ -138,9 +140,7 @@ class IndentScope { printer_->Indent(); } - ~IndentScope() { - printer_->Outdent(); - } + ~IndentScope() { printer_->Outdent(); } private: Printer* printer_; @@ -173,7 +173,6 @@ grpc::string ModuleAlias(const grpc::string& filename) { return module_name; } - bool GetModuleAndMessagePath(const Descriptor* type, const ServiceDescriptor* service, grpc::string* out) { @@ -182,7 +181,7 @@ bool GetModuleAndMessagePath(const Descriptor* type, do { message_path.push_back(path_elem_type); path_elem_type = path_elem_type->containing_type(); - } while (path_elem_type); // implicit nullptr comparison; don't be explicit + } while (path_elem_type); // implicit nullptr comparison; don't be explicit grpc::string file_name = type->file()->name(); static const int proto_suffix_length = strlen(".proto"); if (!(file_name.size() > static_cast(proto_suffix_length) && @@ -190,11 +189,11 @@ bool GetModuleAndMessagePath(const Descriptor* type, return false; } grpc::string service_file_name = service->file()->name(); - grpc::string module = service_file_name == file_name ? - "" : ModuleAlias(file_name) + "."; + grpc::string module = + service_file_name == file_name ? "" : ModuleAlias(file_name) + "."; grpc::string message_type; - for (auto path_iter = message_path.rbegin(); - path_iter != message_path.rend(); ++path_iter) { + for (auto path_iter = message_path.rbegin(); path_iter != message_path.rend(); + ++path_iter) { message_type += (*path_iter)->name() + "."; } // no pop_back prior to C++11 @@ -229,8 +228,7 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer) { printer->Print("\"\"\"\n"); } -bool PrintBetaServicer(const ServiceDescriptor* service, - Printer* out) { +bool PrintBetaServicer(const ServiceDescriptor* service, Printer* out) { out->Print("\n\n"); out->Print("class Beta$Service$Servicer(object):\n", "Service", service->name()); @@ -239,10 +237,10 @@ bool PrintBetaServicer(const ServiceDescriptor* service, PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { auto meth = service->method(i); - grpc::string arg_name = meth->client_streaming() ? - "request_iterator" : "request"; - out->Print("def $Method$(self, $ArgName$, context):\n", - "Method", meth->name(), "ArgName", arg_name); + grpc::string arg_name = + meth->client_streaming() ? "request_iterator" : "request"; + out->Print("def $Method$(self, $ArgName$, context):\n", "Method", + meth->name(), "ArgName", arg_name); { IndentScope raii_method_indent(out); PrintAllComments(meth, out); @@ -253,8 +251,7 @@ bool PrintBetaServicer(const ServiceDescriptor* service, return true; } -bool PrintBetaStub(const ServiceDescriptor* service, - Printer* out) { +bool PrintBetaStub(const ServiceDescriptor* service, Printer* out) { out->Print("\n\n"); out->Print("class Beta$Service$Stub(object):\n", "Service", service->name()); { @@ -262,10 +259,12 @@ bool PrintBetaStub(const ServiceDescriptor* service, PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { const MethodDescriptor* meth = service->method(i); - grpc::string arg_name = meth->client_streaming() ? - "request_iterator" : "request"; + grpc::string arg_name = + meth->client_streaming() ? "request_iterator" : "request"; auto methdict = ListToDict({"Method", meth->name(), "ArgName", arg_name}); - out->Print(methdict, "def $Method$(self, $ArgName$, timeout, metadata=None, with_call=False, protocol_options=None):\n"); + out->Print(methdict, + "def $Method$(self, $ArgName$, timeout, metadata=None, " + "with_call=False, protocol_options=None):\n"); { IndentScope raii_method_indent(out); PrintAllComments(meth, out); @@ -282,9 +281,10 @@ bool PrintBetaStub(const ServiceDescriptor* service, bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name, const ServiceDescriptor* service, Printer* out) { out->Print("\n\n"); - out->Print("def beta_create_$Service$_server(servicer, pool=None, " - "pool_size=None, default_timeout=None, maximum_timeout=None):\n", - "Service", service->name()); + out->Print( + "def beta_create_$Service$_server(servicer, pool=None, " + "pool_size=None, default_timeout=None, maximum_timeout=None):\n", + "Service", service->name()); { IndentScope raii_create_server_indent(out); map method_implementation_constructors; @@ -315,58 +315,62 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name, } out->Print("request_deserializers = {\n"); for (auto name_and_input_module_class_pair = - input_message_modules_and_classes.begin(); + input_message_modules_and_classes.begin(); name_and_input_module_class_pair != - input_message_modules_and_classes.end(); + input_message_modules_and_classes.end(); name_and_input_module_class_pair++) { IndentScope raii_indent(out); - out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " - "$InputTypeModuleAndClass$.FromString,\n", - "PackageQualifiedServiceName", package_qualified_service_name, - "MethodName", name_and_input_module_class_pair->first, - "InputTypeModuleAndClass", - name_and_input_module_class_pair->second); + out->Print( + "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " + "$InputTypeModuleAndClass$.FromString,\n", + "PackageQualifiedServiceName", package_qualified_service_name, + "MethodName", name_and_input_module_class_pair->first, + "InputTypeModuleAndClass", name_and_input_module_class_pair->second); } out->Print("}\n"); out->Print("response_serializers = {\n"); for (auto name_and_output_module_class_pair = - output_message_modules_and_classes.begin(); + output_message_modules_and_classes.begin(); name_and_output_module_class_pair != - output_message_modules_and_classes.end(); + output_message_modules_and_classes.end(); name_and_output_module_class_pair++) { IndentScope raii_indent(out); - out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " - "$OutputTypeModuleAndClass$.SerializeToString,\n", - "PackageQualifiedServiceName", package_qualified_service_name, - "MethodName", name_and_output_module_class_pair->first, - "OutputTypeModuleAndClass", - name_and_output_module_class_pair->second); + out->Print( + "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " + "$OutputTypeModuleAndClass$.SerializeToString,\n", + "PackageQualifiedServiceName", package_qualified_service_name, + "MethodName", name_and_output_module_class_pair->first, + "OutputTypeModuleAndClass", + name_and_output_module_class_pair->second); } out->Print("}\n"); out->Print("method_implementations = {\n"); for (auto name_and_implementation_constructor = - method_implementation_constructors.begin(); - name_and_implementation_constructor != - method_implementation_constructors.end(); - name_and_implementation_constructor++) { + method_implementation_constructors.begin(); + name_and_implementation_constructor != + method_implementation_constructors.end(); + name_and_implementation_constructor++) { IndentScope raii_descriptions_indent(out); const grpc::string method_name = name_and_implementation_constructor->first; - out->Print("(\'$PackageQualifiedServiceName$\', \'$Method$\'): " - "face_utilities.$Constructor$(servicer.$Method$),\n", - "PackageQualifiedServiceName", package_qualified_service_name, - "Method", name_and_implementation_constructor->first, - "Constructor", name_and_implementation_constructor->second); + out->Print( + "(\'$PackageQualifiedServiceName$\', \'$Method$\'): " + "face_utilities.$Constructor$(servicer.$Method$),\n", + "PackageQualifiedServiceName", package_qualified_service_name, + "Method", name_and_implementation_constructor->first, "Constructor", + name_and_implementation_constructor->second); } out->Print("}\n"); - out->Print("server_options = beta_implementations.server_options(" - "request_deserializers=request_deserializers, " - "response_serializers=response_serializers, " - "thread_pool=pool, thread_pool_size=pool_size, " - "default_timeout=default_timeout, " - "maximum_timeout=maximum_timeout)\n"); - out->Print("return beta_implementations.server(method_implementations, " - "options=server_options)\n"); + out->Print( + "server_options = beta_implementations.server_options(" + "request_deserializers=request_deserializers, " + "response_serializers=response_serializers, " + "thread_pool=pool, thread_pool_size=pool_size, " + "default_timeout=default_timeout, " + "maximum_timeout=maximum_timeout)\n"); + out->Print( + "return beta_implementations.server(method_implementations, " + "options=server_options)\n"); } return true; } @@ -374,10 +378,11 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name, bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, const ServiceDescriptor* service, Printer* out) { map dict = ListToDict({ - "Service", service->name(), - }); + "Service", service->name(), + }); out->Print("\n\n"); - out->Print(dict, "def beta_create_$Service$_stub(channel, host=None," + out->Print(dict, + "def beta_create_$Service$_stub(channel, host=None," " metadata_transformer=None, pool=None, pool_size=None):\n"); { IndentScope raii_create_server_indent(out); @@ -387,8 +392,7 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, for (int i = 0; i < service->method_count(); ++i) { const MethodDescriptor* method = service->method(i); const grpc::string method_cardinality = - grpc::string(method->client_streaming() ? "STREAM" : "UNARY") + - "_" + + grpc::string(method->client_streaming() ? "STREAM" : "UNARY") + "_" + grpc::string(method->server_streaming() ? "STREAM" : "UNARY"); grpc::string input_message_module_and_class; if (!GetModuleAndMessagePath(method->input_type(), service, @@ -409,32 +413,33 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, } out->Print("request_serializers = {\n"); for (auto name_and_input_module_class_pair = - input_message_modules_and_classes.begin(); + input_message_modules_and_classes.begin(); name_and_input_module_class_pair != - input_message_modules_and_classes.end(); + input_message_modules_and_classes.end(); name_and_input_module_class_pair++) { IndentScope raii_indent(out); - out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " - "$InputTypeModuleAndClass$.SerializeToString,\n", - "PackageQualifiedServiceName", package_qualified_service_name, - "MethodName", name_and_input_module_class_pair->first, - "InputTypeModuleAndClass", - name_and_input_module_class_pair->second); + out->Print( + "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " + "$InputTypeModuleAndClass$.SerializeToString,\n", + "PackageQualifiedServiceName", package_qualified_service_name, + "MethodName", name_and_input_module_class_pair->first, + "InputTypeModuleAndClass", name_and_input_module_class_pair->second); } out->Print("}\n"); out->Print("response_deserializers = {\n"); for (auto name_and_output_module_class_pair = - output_message_modules_and_classes.begin(); + output_message_modules_and_classes.begin(); name_and_output_module_class_pair != - output_message_modules_and_classes.end(); + output_message_modules_and_classes.end(); name_and_output_module_class_pair++) { IndentScope raii_indent(out); - out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " - "$OutputTypeModuleAndClass$.FromString,\n", - "PackageQualifiedServiceName", package_qualified_service_name, - "MethodName", name_and_output_module_class_pair->first, - "OutputTypeModuleAndClass", - name_and_output_module_class_pair->second); + out->Print( + "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): " + "$OutputTypeModuleAndClass$.FromString,\n", + "PackageQualifiedServiceName", package_qualified_service_name, + "MethodName", name_and_output_module_class_pair->first, + "OutputTypeModuleAndClass", + name_and_output_module_class_pair->second); } out->Print("}\n"); out->Print("cardinalities = {\n"); @@ -443,17 +448,19 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, name_and_cardinality++) { IndentScope raii_descriptions_indent(out); out->Print("\'$Method$\': cardinality.Cardinality.$Cardinality$,\n", - "Method", name_and_cardinality->first, - "Cardinality", name_and_cardinality->second); + "Method", name_and_cardinality->first, "Cardinality", + name_and_cardinality->second); } out->Print("}\n"); - out->Print("stub_options = beta_implementations.stub_options(" - "host=host, metadata_transformer=metadata_transformer, " - "request_serializers=request_serializers, " - "response_deserializers=response_deserializers, " - "thread_pool=pool, thread_pool_size=pool_size)\n"); out->Print( - "return beta_implementations.dynamic_stub(channel, \'$PackageQualifiedServiceName$\', " + "stub_options = beta_implementations.stub_options(" + "host=host, metadata_transformer=metadata_transformer, " + "request_serializers=request_serializers, " + "response_deserializers=response_deserializers, " + "thread_pool=pool, thread_pool_size=pool_size)\n"); + out->Print( + "return beta_implementations.dynamic_stub(channel, " + "\'$PackageQualifiedServiceName$\', " "cardinalities, options=stub_options)\n", "PackageQualifiedServiceName", package_qualified_service_name); } @@ -476,43 +483,41 @@ bool PrintStub(const grpc::string& package_qualified_service_name, out->Print("Args:\n"); { IndentScope raii_args_indent(out); - out->Print("channel: A grpc.Channel.\n"); + out->Print("channel: A grpc.Channel.\n"); } out->Print("\"\"\"\n"); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - auto multi_callable_constructor = - grpc::string(method->client_streaming() ? "stream" : "unary") + - "_" + - grpc::string(method->server_streaming() ? "stream" : "unary"); - grpc::string request_module_and_class; - if (!GetModuleAndMessagePath(method->input_type(), service, - &request_module_and_class)) { - return false; - } - grpc::string response_module_and_class; - if (!GetModuleAndMessagePath(method->output_type(), service, - &response_module_and_class)) { + auto multi_callable_constructor = + grpc::string(method->client_streaming() ? "stream" : "unary") + + "_" + grpc::string(method->server_streaming() ? "stream" : "unary"); + grpc::string request_module_and_class; + if (!GetModuleAndMessagePath(method->input_type(), service, + &request_module_and_class)) { + return false; + } + grpc::string response_module_and_class; + if (!GetModuleAndMessagePath(method->output_type(), service, + &response_module_and_class)) { return false; - } - out->Print("self.$Method$ = channel.$MultiCallableConstructor$(\n", - "Method", method->name(), - "MultiCallableConstructor", multi_callable_constructor); - { + } + out->Print("self.$Method$ = channel.$MultiCallableConstructor$(\n", + "Method", method->name(), "MultiCallableConstructor", + multi_callable_constructor); + { IndentScope raii_first_attribute_indent(out); IndentScope raii_second_attribute_indent(out); - out->Print( - "'/$PackageQualifiedService$/$Method$',\n", - "PackageQualifiedService", package_qualified_service_name, - "Method", method->name()); - out->Print( - "request_serializer=$RequestModuleAndClass$.SerializeToString,\n", - "RequestModuleAndClass", request_module_and_class); - out->Print( + out->Print("'/$PackageQualifiedService$/$Method$',\n", + "PackageQualifiedService", package_qualified_service_name, + "Method", method->name()); + out->Print( + "request_serializer=$RequestModuleAndClass$.SerializeToString,\n", + "RequestModuleAndClass", request_module_and_class); + out->Print( "response_deserializer=$ResponseModuleAndClass$.FromString,\n", - "ResponseModuleAndClass", response_module_and_class); - out->Print(")\n"); - } + "ResponseModuleAndClass", response_module_and_class); + out->Print(")\n"); + } } } } @@ -527,11 +532,11 @@ bool PrintServicer(const ServiceDescriptor* service, Printer* out) { PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - grpc::string arg_name = method->client_streaming() ? - "request_iterator" : "request"; + grpc::string arg_name = + method->client_streaming() ? "request_iterator" : "request"; out->Print("\n"); - out->Print("def $Method$(self, $ArgName$, context):\n", - "Method", method->name(), "ArgName", arg_name); + out->Print("def $Method$(self, $ArgName$, context):\n", "Method", + method->name(), "ArgName", arg_name); { IndentScope raii_method_indent(out); PrintAllComments(method, out); @@ -544,11 +549,12 @@ bool PrintServicer(const ServiceDescriptor* service, Printer* out) { return true; } -bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name, - const ServiceDescriptor* service, Printer* out) { +bool PrintAddServicerToServer( + const grpc::string& package_qualified_service_name, + const ServiceDescriptor* service, Printer* out) { out->Print("\n\n"); out->Print("def add_$Service$Servicer_to_server(servicer, server):\n", - "Service", service->name()); + "Service", service->name()); { IndentScope raii_class_indent(out); out->Print("rpc_method_handlers = {\n"); @@ -557,34 +563,37 @@ bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name IndentScope raii_dict_second_indent(out); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); - auto method_handler_constructor = + auto method_handler_constructor = grpc::string(method->client_streaming() ? "stream" : "unary") + - "_" + + "_" + grpc::string(method->server_streaming() ? "stream" : "unary") + "_rpc_method_handler"; - grpc::string request_module_and_class; - if (!GetModuleAndMessagePath(method->input_type(), service, - &request_module_and_class)) { - return false; - } - grpc::string response_module_and_class; - if (!GetModuleAndMessagePath(method->output_type(), service, - &response_module_and_class)) { + grpc::string request_module_and_class; + if (!GetModuleAndMessagePath(method->input_type(), service, + &request_module_and_class)) { return false; - } - out->Print("'$Method$': grpc.$MethodHandlerConstructor$(\n", - "Method", method->name(), - "MethodHandlerConstructor", method_handler_constructor); - { + } + grpc::string response_module_and_class; + if (!GetModuleAndMessagePath(method->output_type(), service, + &response_module_and_class)) { + return false; + } + out->Print("'$Method$': grpc.$MethodHandlerConstructor$(\n", "Method", + method->name(), "MethodHandlerConstructor", + method_handler_constructor); + { IndentScope raii_call_first_indent(out); - IndentScope raii_call_second_indent(out); - out->Print("servicer.$Method$,\n", "Method", method->name()); - out->Print("request_deserializer=$RequestModuleAndClass$.FromString,\n", - "RequestModuleAndClass", request_module_and_class); - out->Print("response_serializer=$ResponseModuleAndClass$.SerializeToString,\n", - "ResponseModuleAndClass", response_module_and_class); - } - out->Print("),\n"); + IndentScope raii_call_second_indent(out); + out->Print("servicer.$Method$,\n", "Method", method->name()); + out->Print( + "request_deserializer=$RequestModuleAndClass$.FromString,\n", + "RequestModuleAndClass", request_module_and_class); + out->Print( + "response_serializer=$ResponseModuleAndClass$.SerializeToString," + "\n", + "ResponseModuleAndClass", response_module_and_class); + } + out->Print("),\n"); } } out->Print("}\n"); @@ -593,7 +602,7 @@ bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name IndentScope raii_call_first_indent(out); IndentScope raii_call_second_indent(out); out->Print("'$PackageQualifiedServiceName$', rpc_method_handlers)\n", - "PackageQualifiedServiceName", package_qualified_service_name); + "PackageQualifiedServiceName", package_qualified_service_name); } out->Print("server.add_generic_rpc_handlers((generic_handler,))\n"); } @@ -605,10 +614,12 @@ bool PrintPreamble(const FileDescriptor* file, out->Print("import $Package$\n", "Package", config.grpc_package_root); out->Print("from $Package$ import implementations as beta_implementations\n", "Package", config.beta_package_root); - out->Print("from $Package$ import interfaces as beta_interfaces\n", - "Package", config.beta_package_root); + out->Print("from $Package$ import interfaces as beta_interfaces\n", "Package", + config.beta_package_root); out->Print("from grpc.framework.common import cardinality\n"); - out->Print("from grpc.framework.interfaces.face import utilities as face_utilities\n"); + out->Print( + "from grpc.framework.interfaces.face import utilities as " + "face_utilities\n"); return true; } @@ -632,12 +643,14 @@ pair GetServices(const FileDescriptor* file, auto service = file->service(i); auto package_qualified_service_name = package + service->name(); if (!(PrintStub(package_qualified_service_name, service, &out) && - PrintServicer(service, &out) && - PrintAddServicerToServer(package_qualified_service_name, service, &out) && - PrintBetaServicer(service, &out) && - PrintBetaStub(service, &out) && - PrintBetaServerFactory(package_qualified_service_name, service, &out) && - PrintBetaStubFactory(package_qualified_service_name, service, &out))) { + PrintServicer(service, &out) && + PrintAddServicerToServer(package_qualified_service_name, service, + &out) && + PrintBetaServicer(service, &out) && PrintBetaStub(service, &out) && + PrintBetaServerFactory(package_qualified_service_name, service, + &out) && + PrintBetaStubFactory(package_qualified_service_name, service, + &out))) { return make_pair(false, ""); } } diff --git a/src/compiler/python_generator.h b/src/compiler/python_generator.h index 7ed99eff0bf..9bbb83bca6e 100644 --- a/src/compiler/python_generator.h +++ b/src/compiler/python_generator.h @@ -57,6 +57,7 @@ class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { const grpc::string& parameter, grpc::protobuf::compiler::GeneratorContext* context, grpc::string* error) const; + private: GeneratorConfiguration config_; }; diff --git a/src/compiler/ruby_generator.cc b/src/compiler/ruby_generator.cc index 1501c3f3e01..02202568cb4 100644 --- a/src/compiler/ruby_generator.cc +++ b/src/compiler/ruby_generator.cc @@ -55,17 +55,20 @@ namespace { // Prints out the method using the ruby gRPC DSL. void PrintMethod(const MethodDescriptor *method, const grpc::string &package, Printer *out) { - grpc::string input_type = RubyTypeOf(method->input_type()->full_name(), package); + grpc::string input_type = + RubyTypeOf(method->input_type()->full_name(), package); if (method->client_streaming()) { input_type = "stream(" + input_type + ")"; } - grpc::string output_type = RubyTypeOf(method->output_type()->full_name(), package); + grpc::string output_type = + RubyTypeOf(method->output_type()->full_name(), package); if (method->server_streaming()) { output_type = "stream(" + output_type + ")"; } - std::map method_vars = - ListToDict({"mth.name", method->name(), "input.type", input_type, - "output.type", output_type, }); + std::map method_vars = ListToDict({ + "mth.name", method->name(), "input.type", input_type, "output.type", + output_type, + }); out->Print(GetRubyComments(method, true).c_str()); out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n"); out->Print(GetRubyComments(method, false).c_str()); @@ -79,8 +82,9 @@ void PrintService(const ServiceDescriptor *service, const grpc::string &package, } // Begin the service module - std::map module_vars = - ListToDict({"module.name", CapitalizeFirst(service->name()), }); + std::map module_vars = ListToDict({ + "module.name", CapitalizeFirst(service->name()), + }); out->Print(module_vars, "module $module.name$\n"); out->Indent(); @@ -130,8 +134,9 @@ grpc::string GetServices(const FileDescriptor *file) { } // Write out a file header. - std::map header_comment_vars = ListToDict( - {"file.name", file->name(), "file.package", file->package(), }); + std::map header_comment_vars = ListToDict({ + "file.name", file->name(), "file.package", file->package(), + }); out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); out.Print(header_comment_vars, "# Source: $file.name$ for package '$file.package$'\n"); @@ -147,16 +152,18 @@ grpc::string GetServices(const FileDescriptor *file) { // Write out require statemment to import the separately generated file // that defines the messages used by the service. This is generated by the // main ruby plugin. - std::map dep_vars = - ListToDict({"dep.name", MessagesRequireName(file), }); + std::map dep_vars = ListToDict({ + "dep.name", MessagesRequireName(file), + }); out.Print(dep_vars, "require '$dep.name$'\n"); // Write out services within the modules out.Print("\n"); std::vector modules = Split(file->package(), '.'); for (size_t i = 0; i < modules.size(); ++i) { - std::map module_vars = - ListToDict({"module.name", CapitalizeFirst(modules[i]), }); + std::map module_vars = ListToDict({ + "module.name", CapitalizeFirst(modules[i]), + }); out.Print(module_vars, "module $module.name$\n"); out.Indent(); } diff --git a/src/compiler/ruby_generator_map-inl.h b/src/compiler/ruby_generator_map-inl.h index 6b87774f213..75ba7fc8f19 100644 --- a/src/compiler/ruby_generator_map-inl.h +++ b/src/compiler/ruby_generator_map-inl.h @@ -36,8 +36,8 @@ #include "src/compiler/config.h" -#include #include +#include #include #include // NOLINT #include @@ -53,8 +53,7 @@ namespace grpc_ruby_generator { inline std::map ListToDict( const initializer_list &values) { if (values.size() % 2 != 0) { - std::cerr << "Not every 'key' has a value in `values`." - << std::endl; + std::cerr << "Not every 'key' has a value in `values`." << std::endl; } std::map value_map; auto value_iter = values.begin(); diff --git a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh index eab7611b3f3..462c65ab5e9 100755 --- a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh +++ b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh @@ -31,7 +31,7 @@ set -e # directories to run against -DIRS="src/core/lib src/core/ext src/cpp test/core test/cpp include" +DIRS="src/core/lib src/core/ext src/cpp test/core test/cpp include src/compiler" # file matching patterns to check GLOB="*.h *.c *.cc"