diff options
Diffstat (limited to 'src/compiler/csharp_generator.cc')
-rw-r--r-- | src/compiler/csharp_generator.cc | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/src/compiler/csharp_generator.cc b/src/compiler/csharp_generator.cc index bc3b0f24cd..e0957bf9bb 100644 --- a/src/compiler/csharp_generator.cc +++ b/src/compiler/csharp_generator.cc @@ -23,24 +23,23 @@ #include "src/compiler/config.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; +using google::protobuf::compiler::csharp::GetFileNamespace; using google::protobuf::compiler::csharp::GetReflectionClassName; -using grpc::protobuf::FileDescriptor; using grpc::protobuf::Descriptor; -using grpc::protobuf::ServiceDescriptor; +using grpc::protobuf::FileDescriptor; using grpc::protobuf::MethodDescriptor; +using grpc::protobuf::ServiceDescriptor; using grpc::protobuf::io::Printer; using grpc::protobuf::io::StringOutputStream; -using grpc_generator::MethodType; using grpc_generator::GetMethodType; -using grpc_generator::METHODTYPE_NO_STREAMING; +using grpc_generator::METHODTYPE_BIDI_STREAMING; using grpc_generator::METHODTYPE_CLIENT_STREAMING; +using grpc_generator::METHODTYPE_NO_STREAMING; using grpc_generator::METHODTYPE_SERVER_STREAMING; -using grpc_generator::METHODTYPE_BIDI_STREAMING; +using grpc_generator::MethodType; using grpc_generator::StringReplace; using std::map; using std::vector; @@ -53,7 +52,7 @@ 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. -bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer *printer, +bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer, grpc::protobuf::SourceLocation location) { grpc::string comments = location.leading_comments.empty() ? location.trailing_comments @@ -100,8 +99,8 @@ bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer *printer, } template <typename DescriptorType> -bool GenerateDocCommentBody(grpc::protobuf::io::Printer *printer, - const DescriptorType *descriptor) { +bool GenerateDocCommentBody(grpc::protobuf::io::Printer* printer, + const DescriptorType* descriptor) { grpc::protobuf::SourceLocation location; if (!descriptor->GetSourceLocation(&location)) { return false; @@ -109,8 +108,8 @@ bool GenerateDocCommentBody(grpc::protobuf::io::Printer *printer, return GenerateDocCommentBodyImpl(printer, location); } -void GenerateDocCommentServerMethod(grpc::protobuf::io::Printer *printer, - const MethodDescriptor *method) { +void GenerateDocCommentServerMethod(grpc::protobuf::io::Printer* printer, + const MethodDescriptor* method) { if (GenerateDocCommentBody(printer, method)) { if (method->client_streaming()) { printer->Print( @@ -141,8 +140,8 @@ void GenerateDocCommentServerMethod(grpc::protobuf::io::Printer *printer, } } -void GenerateDocCommentClientMethod(grpc::protobuf::io::Printer *printer, - const MethodDescriptor *method, +void GenerateDocCommentClientMethod(grpc::protobuf::io::Printer* printer, + const MethodDescriptor* method, bool is_sync, bool use_call_options) { if (GenerateDocCommentBody(printer, method)) { if (!method->client_streaming()) { @@ -173,15 +172,15 @@ void GenerateDocCommentClientMethod(grpc::protobuf::io::Printer *printer, } } -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"; } @@ -202,15 +201,15 @@ std::string GetCSharpMethodType(MethodType method_type) { std::string GetServiceNameFieldName() { return "__ServiceName"; } -std::string GetMarshallerFieldName(const Descriptor *message) { +std::string GetMarshallerFieldName(const Descriptor* message) { return "__Marshaller_" + message->name(); } -std::string GetMethodFieldName(const MethodDescriptor *method) { +std::string GetMethodFieldName(const MethodDescriptor* method) { return "__Method_" + method->name(); } -std::string GetMethodRequestParamMaybe(const MethodDescriptor *method, +std::string GetMethodRequestParamMaybe(const MethodDescriptor* method, bool invocation_param = false) { if (method->client_streaming()) { return ""; @@ -225,7 +224,7 @@ std::string GetAccessLevel(bool internal_access) { return internal_access ? "internal" : "public"; } -std::string GetMethodReturnTypeClient(const MethodDescriptor *method) { +std::string GetMethodReturnTypeClient(const MethodDescriptor* method) { switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: return "grpc::AsyncUnaryCall<" + GetClassName(method->output_type()) + @@ -246,7 +245,7 @@ std::string GetMethodReturnTypeClient(const MethodDescriptor *method) { return ""; } -std::string GetMethodRequestParamServer(const MethodDescriptor *method) { +std::string GetMethodRequestParamServer(const MethodDescriptor* method) { switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: case METHODTYPE_SERVER_STREAMING: @@ -260,7 +259,7 @@ std::string GetMethodRequestParamServer(const MethodDescriptor *method) { return ""; } -std::string GetMethodReturnTypeServer(const MethodDescriptor *method) { +std::string GetMethodReturnTypeServer(const MethodDescriptor* method) { switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: case METHODTYPE_CLIENT_STREAMING: @@ -274,7 +273,7 @@ std::string GetMethodReturnTypeServer(const MethodDescriptor *method) { return ""; } -std::string GetMethodResponseStreamMaybe(const MethodDescriptor *method) { +std::string GetMethodResponseStreamMaybe(const MethodDescriptor* method) { switch (GetMethodType(method)) { case METHODTYPE_NO_STREAMING: case METHODTYPE_CLIENT_STREAMING: @@ -289,13 +288,13 @@ std::string GetMethodResponseStreamMaybe(const MethodDescriptor *method) { } // Gets vector of all messages used as input or output types. -std::vector<const Descriptor *> GetUsedMessages( - const ServiceDescriptor *service) { - std::set<const Descriptor *> descriptor_set; - std::vector<const Descriptor *> +std::vector<const Descriptor*> GetUsedMessages( + const ServiceDescriptor* service) { + std::set<const Descriptor*> descriptor_set; + std::vector<const Descriptor*> result; // vector is to maintain stable ordering for (int i = 0; i < service->method_count(); i++) { - const MethodDescriptor *method = service->method(i); + const MethodDescriptor* method = service->method(i); if (descriptor_set.find(method->input_type()) == descriptor_set.end()) { descriptor_set.insert(method->input_type()); result.push_back(method->input_type()); @@ -308,10 +307,10 @@ std::vector<const Descriptor *> GetUsedMessages( return result; } -void GenerateMarshallerFields(Printer *out, const ServiceDescriptor *service) { - std::vector<const Descriptor *> used_messages = GetUsedMessages(service); +void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) { + std::vector<const Descriptor*> used_messages = GetUsedMessages(service); for (size_t i = 0; i < used_messages.size(); i++) { - const Descriptor *message = used_messages[i]; + const Descriptor* message = used_messages[i]; out->Print( "static readonly grpc::Marshaller<$type$> $fieldname$ = " "grpc::Marshallers.Create((arg) => " @@ -323,7 +322,7 @@ void GenerateMarshallerFields(Printer *out, const ServiceDescriptor *service) { out->Print("\n"); } -void GenerateStaticMethodField(Printer *out, const MethodDescriptor *method) { +void GenerateStaticMethodField(Printer* out, const MethodDescriptor* method) { out->Print( "static readonly grpc::Method<$request$, $response$> $fieldname$ = new " "grpc::Method<$request$, $response$>(\n", @@ -346,8 +345,8 @@ 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("/// <summary>Service descriptor</summary>\n"); @@ -362,7 +361,7 @@ void GenerateServiceDescriptorProperty(Printer *out, out->Print("\n"); } -void GenerateServerClass(Printer *out, const ServiceDescriptor *service) { +void GenerateServerClass(Printer* out, const ServiceDescriptor* service) { out->Print( "/// <summary>Base class for server-side implementations of " "$servicename$</summary>\n", @@ -372,7 +371,7 @@ void GenerateServerClass(Printer *out, const ServiceDescriptor *service) { out->Print("{\n"); out->Indent(); for (int i = 0; i < service->method_count(); i++) { - const MethodDescriptor *method = service->method(i); + const MethodDescriptor* method = service->method(i); GenerateDocCommentServerMethod(out, method); out->Print( "public virtual $returntype$ " @@ -395,7 +394,7 @@ void GenerateServerClass(Printer *out, const ServiceDescriptor *service) { out->Print("\n"); } -void GenerateClientStub(Printer *out, const ServiceDescriptor *service) { +void GenerateClientStub(Printer* out, const ServiceDescriptor* service) { out->Print("/// <summary>Client for $servicename$</summary>\n", "servicename", GetServiceClassName(service)); out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", "name", @@ -443,7 +442,7 @@ void GenerateClientStub(Printer *out, const ServiceDescriptor *service) { out->Print("}\n\n"); for (int i = 0; i < service->method_count(); i++) { - const MethodDescriptor *method = service->method(i); + const MethodDescriptor* method = service->method(i); MethodType method_type = GetMethodType(method); if (method_type == METHODTYPE_NO_STREAMING) { @@ -573,7 +572,7 @@ 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( "/// <summary>Creates service definition that can be registered with a " "server</summary>\n"); @@ -591,7 +590,7 @@ void GenerateBindServiceMethod(Printer *out, const ServiceDescriptor *service) { out->Indent(); out->Indent(); for (int i = 0; i < service->method_count(); i++) { - const MethodDescriptor *method = service->method(i); + const MethodDescriptor* method = service->method(i); out->Print(".AddMethod($methodfield$, serviceImpl.$methodname$)", "methodfield", GetMethodFieldName(method), "methodname", method->name()); @@ -608,7 +607,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); @@ -644,7 +643,7 @@ void GenerateService(Printer *out, const ServiceDescriptor *service, } // anonymous namespace -grpc::string GetServices(const FileDescriptor *file, bool generate_client, +grpc::string GetServices(const FileDescriptor* file, bool generate_client, bool generate_server, bool internal_access) { grpc::string output; { |